Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run our session manager as a separate process #779

Merged
merged 4 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions compositor/SubprocessSupervisor.vala

This file was deleted.

1 change: 1 addition & 0 deletions compositor/WindowManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ namespace GreeterCompositor {
ShellClientsManager.init (this);

if (GLib.Environment.get_variable ("DESKTOP_SESSION") != "installer") {
start_command.begin ({ "io.elementary.greeter-session-manager" });
start_command.begin ({ "io.elementary.greeter" });
}

Expand Down
3 changes: 0 additions & 3 deletions compositor/main.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ namespace GreeterCompositor {
// Ensure we present ourselves as Pantheon so we pick up the right GSettings
// overrides
GLib.Environment.set_variable ("XDG_CURRENT_DESKTOP", "Pantheon", true);

var settings_daemon = new SettingsDaemon ();
settings_daemon.start ();
}

var ctx = new Meta.Context ("Mutter(GreeterCompositor)");
Expand Down
2 changes: 0 additions & 2 deletions compositor/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ compositor_files = files(
'main.vala',
'MediaFeedback.vala',
'PointerLocator.vala',
'SettingsDaemon.vala',
'SubprocessSupervisor.vala',
'Utils.vala',
'WindowManager.vala',
'Zoom.vala'
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ compositor_resources = gnome.compile_resources(
subdir('protocol')
subdir('src')
subdir('compositor')
subdir('session-manager')
subdir('data')
subdir('po')
vapigen = find_program('vapigen', required: false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,12 @@
/* -*- Mode:Vala; indent-tabs-mode:nil; tab-width:4 -*-
*
* Copyright (C) 2011 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Michael Terry <michael.terry@canonical.com>
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
*/

public class GreeterCompositor.SettingsDaemon : Object {
private GreeterCompositor.GnomeSessionManager session_manager;
private int n_names = 0;
private SubprocessSupervisor[] supervisors = {};

public void start () {
/* Pretend to be GNOME session */
session_manager = new GreeterCompositor.GnomeSessionManager ();
n_names++;
GLib.Bus.own_name (BusType.SESSION, "org.gnome.SessionManager", BusNameOwnerFlags.NONE,
(c) => {
try {
c.register_object ("/org/gnome/SessionManager", session_manager);
} catch (Error e) {
warning ("Failed to register /org/gnome/SessionManager: %s", e.message);
}
},
() => {
debug ("Acquired org.gnome.SessionManager");
start_settings_daemon ();
},
() => debug ("Failed to acquire name org.gnome.SessionManager"));
}

private void start_settings_daemon () {
n_names--;
if (n_names != 0) {
return;
}

debug ("All bus names acquired, starting gnome-settings-daemon");

string[] daemons = {
"gsd-a11y-settings",
"gsd-color",
"gsd-media-keys",
"gsd-sound",
"gsd-power",
"gsd-xsettings"
};

foreach (var daemon in daemons) {
try {
supervisors += new GreeterCompositor.SubprocessSupervisor ({Constants.GSD_DIR + daemon});
} catch (GLib.Error e) {
critical ("Could not start %s: %s", daemon, e.message);
}
}
}
}

[DBus (name="org.gnome.SessionManager")]
public class GreeterCompositor.GnomeSessionManager : GLib.Object {
private Gee.ArrayList<GreeterCompositor.GnomeSessionManagerClient> clients;
private Gee.ArrayList<unowned GreeterCompositor.GnomeSessionManagerClient> inhibitors;
public class GreeterSessionManager.GnomeSessionManager : GLib.Object {
private Gee.ArrayList<GnomeSessionManagerClient> clients;
private Gee.ArrayList<unowned GnomeSessionManagerClient> inhibitors;

public string session_name { owned get; set; default = "pantheon"; }
public string renderer { owned get; set; default = ""; }
Expand All @@ -86,8 +21,8 @@ public class GreeterCompositor.GnomeSessionManager : GLib.Object {
public signal void session_over ();

construct {
clients = new Gee.ArrayList<GreeterCompositor.GnomeSessionManagerClient> ();
inhibitors = new Gee.ArrayList<unowned GreeterCompositor.GnomeSessionManagerClient> ();
clients = new Gee.ArrayList<GnomeSessionManagerClient> ();
inhibitors = new Gee.ArrayList<unowned GnomeSessionManagerClient> ();
}

public void setenv (string variable, string value) throws GLib.Error {
Expand Down Expand Up @@ -188,7 +123,7 @@ public class GreeterCompositor.GnomeSessionManager : GLib.Object {
}

[DBus (name = "org.gnome.SessionManager.Client")]
public class GreeterCompositor.GnomeSessionManagerClient : GLib.Object {
public class GreeterSessionManager.GnomeSessionManagerClient : GLib.Object {
static uint32 serial_id = 0;

private string app_id;
Expand All @@ -203,7 +138,7 @@ public class GreeterCompositor.GnomeSessionManagerClient : GLib.Object {

try {
var session_bus = GLib.Bus.get_sync (GLib.BusType.SESSION);
session_bus.register_object<GreeterCompositor.GnomeSessionManagerClient> (object_path, this);
session_bus.register_object<GnomeSessionManagerClient> (object_path, this);
} catch (Error e) {
critical (e.message);
}
Expand Down
51 changes: 51 additions & 0 deletions session-manager/SettingsDaemon.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2011 Canonical Ltd
* 2025 elementary, Inc. (https://elementary.io)
*/

public class GreeterSessionManager.SettingsDaemon : GLib.Object {
private const string[] DAEMONS = {
"gsd-a11y-settings",
"gsd-color",
"gsd-media-keys",
"gsd-sound",
"gsd-power",
"gsd-xsettings"
};

private SubprocessSupervisor[] supervisors = {};

construct {
/* Pretend to be GNOME session */
GLib.Bus.own_name (
BusType.SESSION, "org.gnome.SessionManager", BusNameOwnerFlags.NONE,
(connection) => {
try {
connection.register_object ("/org/gnome/SessionManager", new GnomeSessionManager ());
} catch (Error e) {
critical ("Failed to register /org/gnome/SessionManager: %s", e.message);
}
},
() => {
debug ("Acquired org.gnome.SessionManager");
start_settings_daemon ();
},
() => {
critical ("Lost org.gnome.SessionManager");
}
);
}

private void start_settings_daemon () {
debug ("All bus names acquired, starting gnome-settings-daemon");

foreach (unowned var daemon in DAEMONS) {
try {
supervisors += new SubprocessSupervisor ({ Constants.GSD_DIR + daemon });
} catch (Error e) {
critical ("Could not start %s: %s", daemon, e.message);
}
}
}
}
37 changes: 37 additions & 0 deletions session-manager/SubprocessSupervisor.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* SPDX-License-Identifier: GPL-2.0-or-later
* SPDX-FileCopyrightText: 2018, 2025 elementary, Inc. (https://elementary.io)
* Authors: Corentin Noël <corentin@elementary.io>
*/

public class GreeterSessionManager.SubprocessSupervisor : GLib.Object {
public string[] exec { get; construct; }

private GLib.Subprocess? subprocess = null;

public SubprocessSupervisor (string[] exec) throws GLib.Error {
Object (exec: exec);
}

construct {
ensure_run.begin ();
}

~SubprocessSupervisor () {
if (subprocess != null) {
subprocess.force_exit ();
}
}

private async void ensure_run () {
try {
subprocess = new GLib.Subprocess.newv (exec, GLib.SubprocessFlags.STDIN_INHERIT | GLib.SubprocessFlags.STDERR_MERGE);

if (!yield subprocess.wait_check_async ()) {
ensure_run.begin ();
}
} catch (Error e) {
critical ("Couldn't create subprocess: %s", e.message);
}
}
}
15 changes: 15 additions & 0 deletions session-manager/main.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
*/

public class GreeterSessionManager.Application : GLib.Object {
public static int main (string[] args) {
new SettingsDaemon ();

var loop = new GLib.MainLoop (GLib.MainContext.default (), true);
loop.run ();

return 0;
}
}
22 changes: 22 additions & 0 deletions session-manager/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
gee_dep = dependency('gee-0.8')
gio_dep = dependency('gio-2.0')
glib_dep = dependency('glib-2.0')
gobject_dep = dependency('gobject-2.0')

install_path = join_paths(get_option('prefix'), get_option('sbindir'))

files = files(
'main.vala',
'SessionManager.vala',
'SettingsDaemon.vala',
'SubprocessSupervisor.vala'
)

executable(
meson.project_name()+'-session-manager',
files,
config_header,
dependencies: [ gee_dep, gio_dep, glib_dep, gobject_dep ],
install : true,
install_dir: install_path
)