[gnome-shell] gdm: port gnome-shell --gdm-mode to systemd



commit c7fa719cc39ab84facd9ca85730309c4a0eb326c
Author: Lennart Poettering <lennart poettering net>
Date:   Sat Feb 11 01:38:41 2012 +0100

    gdm: port gnome-shell --gdm-mode to systemd
    
    ConsoleKit is obsoleted by systemd-logind. Accordingly, port
    the current CK code to systemd. In order to be nice to
    the Debian people fall back to CK if systemd is not found,
    so that the code makes the best of whatever it runs on.

 js/Makefile.am      |    1 +
 js/gdm/powerMenu.js |  109 +++++++++++++++++++++++++++++++++++++--------------
 js/gdm/systemd.js   |   31 ++++++++++++++
 3 files changed, 111 insertions(+), 30 deletions(-)
---
diff --git a/js/Makefile.am b/js/Makefile.am
index 4c41bff..14a25b5 100644
--- a/js/Makefile.am
+++ b/js/Makefile.am
@@ -7,6 +7,7 @@ nobase_dist_js_DATA = 	\
 	gdm/fingerprint.js	\
 	gdm/loginDialog.js	\
 	gdm/powerMenu.js	\
+	gdm/systemd.js	 	\
 	extensionPrefs/main.js	\
 	misc/config.js		\
 	misc/docInfo.js		\
diff --git a/js/gdm/powerMenu.js b/js/gdm/powerMenu.js
index efe1a8f..59ebc42 100644
--- a/js/gdm/powerMenu.js
+++ b/js/gdm/powerMenu.js
@@ -22,6 +22,8 @@ const Lang = imports.lang;
 const UPowerGlib = imports.gi.UPowerGlib;
 
 const ConsoleKit = imports.gdm.consoleKit;
+const Systemd = imports.gdm.systemd;
+
 const PanelMenu = imports.ui.panelMenu;
 const PopupMenu = imports.ui.popupMenu;
 
@@ -32,6 +34,7 @@ const PowerMenuButton = new Lang.Class({
     _init: function() {
         this.parent('system-shutdown', null);
         this._consoleKitManager = new ConsoleKit.ConsoleKitManager();
+        this._systemdLoginManager = new Systemd.SystemdLoginManager();
         this._upClient = new UPowerGlib.Client();
 
         this._createSubMenu();
@@ -61,39 +64,75 @@ const PowerMenuButton = new Lang.Class({
     },
 
     _updateHaveShutdown: function() {
-        this._consoleKitManager.CanStopRemote(Lang.bind(this,
-            function(result, error) {
-                if (!error)
-                    this._haveShutdown = result;
-                else
-                    this._haveShutdown = false;
-
-                if (this._haveShutdown) {
-                    this._powerOffItem.actor.show();
-                } else {
-                    this._powerOffItem.actor.hide();
-                }
 
-                this._updateVisibility();
-            }));
+        if (Systemd.haveSystemd()) {
+            this._systemdLoginManager.CanPowerOffRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveShutdown = result != 'no';
+                    else
+                        this._haveShutdown = false;
+
+                    if (this._haveShutdown)
+                        this._powerOffItem.actor.show();
+                    else
+                        this._powerOffItem.actor.hide();
+
+                    this._updateVisibility();
+                }));
+        } else {
+            this._consoleKitManager.CanStopRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveShutdown = result;
+                    else
+                        this._haveShutdown = false;
+
+                    if (this._haveShutdown) {
+                        this._powerOffItem.actor.show();
+                    } else {
+                        this._powerOffItem.actor.hide();
+                    }
+
+                    this._updateVisibility();
+                }));
+        }
     },
 
     _updateHaveRestart: function() {
-        this._consoleKitManager.CanRestartRemote(Lang.bind(this,
-            function(result, error) {
-                if (!error)
-                    this._haveRestart = result;
-                else
-                    this._haveRestart = false;
-
-                if (this._haveRestart) {
-                    this._restartItem.actor.show();
-                } else {
-                    this._restartItem.actor.hide();
-                }
 
-                this._updateVisibility();
-            }));
+        if (Systemd.haveSystemd()) {
+            this._systemdLoginManager.CanRebootRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveRestart = result != 'no';
+                    else
+                        this._haveRestart = false;
+
+                    if (this._haveRestart)
+                        this._restartItem.actor.show();
+                    else
+                        this._restartItem.actor.hide();
+
+                    this._updateVisibility();
+                }));
+        } else {
+            this._consoleKitManager.CanRestartRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveRestart = result;
+                    else
+                        this._haveRestart = false;
+
+                    if (this._haveRestart) {
+                        this._restartItem.actor.show();
+                    } else {
+                        this._restartItem.actor.hide();
+                    }
+
+                    this._updateVisibility();
+                }));
+        }
     },
 
     _updateHaveSuspend: function() {
@@ -132,12 +171,22 @@ const PowerMenuButton = new Lang.Class({
     },
 
     _onActivateRestart: function() {
-        if (this._haveRestart)
+        if (!this._haveRestart)
+            return;
+
+        if (Systemd.haveSystemd())
+            this._systemdLoginManager.RebootRemote(true);
+        else
             this._consoleKitManager.RestartRemote();
     },
 
     _onActivatePowerOff: function() {
-        if (this._haveShutdown)
+        if (!this._haveShutdown)
+            return;
+
+        if (Systemd.haveSystemd())
+            this._systemdLoginManager.PowerOffRemote(true);
+        else
             this._consoleKitManager.StopRemote();
     }
 });
diff --git a/js/gdm/systemd.js b/js/gdm/systemd.js
new file mode 100644
index 0000000..8dd73ab
--- /dev/null
+++ b/js/gdm/systemd.js
@@ -0,0 +1,31 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+
+const SystemdLoginManagerIface = <interface name='org.freedesktop.login1.Manager'>
+<method name='PowerOff'>
+    <arg type='b' direction='in'/>
+</method>
+<method name='Reboot'>
+    <arg type='b' direction='in'/>
+</method>
+<method name='CanPowerOff'>
+    <arg type='s' direction='out'/>
+</method>
+<method name='CanReboot'>
+    <arg type='s' direction='out'/>
+</method>
+</interface>;
+
+const SystemdLoginManagerProxy = Gio.DBusProxy.makeProxyWrapper(SystemdLoginManagerIface);
+
+function SystemdLoginManager() {
+    return new SystemdLoginManagerProxy(Gio.DBus.system,
+                                        'org.freedesktop.login1',
+                                        '/org/freedesktop/login1');
+};
+
+function haveSystemd() {
+    return GLib.access("/sys/fs/cgroup/systemd", 0) >= 0;
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]