[gnome-shell/wip/laney/systemd-user: 3/3] endSessionDialog, loginManager: Get the session ID from logind if XDG_SESSION_ID unset



commit c8bb126fb85c8bcce67f7eda0d89815c1a4d0579
Author: Iain Lane <iain orangesquash org uk>
Date:   Mon Jan 8 14:23:52 2018 +0000

    endSessionDialog, loginManager: Get the session ID from logind if XDG_SESSION_ID unset
    
    If we're started by systemd, we won't be in the user's display session.
    However, this is still the session that will get locked & unlocked. Ask
    logind what the 'display' or 'greeter' session is, and watch for the
    Unlock signal for that session to know when to unlock.

 js/misc/loginManager.js   | 45 +++++++++++++++++++++++++++++++++++++++++++--
 js/ui/endSessionDialog.js | 10 +++++++++-
 2 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/js/misc/loginManager.js b/js/misc/loginManager.js
index 4eb0686aa..b58f51567 100644
--- a/js/misc/loginManager.js
+++ b/js/misc/loginManager.js
@@ -40,14 +40,23 @@ const SystemdLoginSessionIface = '<node> \
 <signal name="Lock" /> \
 <signal name="Unlock" /> \
 <property name="Active" type="b" access="read" /> \
+<property name="Class" type="s" access="read" /> \
 <method name="SetLockedHint"> \
     <arg type="b" direction="in"/> \
 </method> \
 </interface> \
 </node>';
 
+const SystemdLoginUserIface = '<node> \
+<interface name="org.freedesktop.login1.User"> \
+<property name="Display" type="(so)" access="read" /> \
+<property name="Sessions" type="a(so)" access="read" /> \
+</interface> \
+</node>';
+
 const SystemdLoginManager = Gio.DBusProxy.makeProxyWrapper(SystemdLoginManagerIface);
 const SystemdLoginSession = Gio.DBusProxy.makeProxyWrapper(SystemdLoginSessionIface);
+const SystemdLoginUser = Gio.DBusProxy.makeProxyWrapper(SystemdLoginUserIface);
 
 function haveSystemd() {
     return GLib.access("/run/systemd/seats", 0) >= 0;
@@ -109,6 +118,9 @@ var LoginManagerSystemd = new Lang.Class({
         this._proxy = new SystemdLoginManager(Gio.DBus.system,
                                               'org.freedesktop.login1',
                                               '/org/freedesktop/login1');
+        this._userProxy = new SystemdLoginUser(Gio.DBus.system,
+                                               'org.freedesktop.login1',
+                                               '/org/freedesktop/login1/user/self');
         this._proxy.connectSignal('PrepareForSleep',
                                   this._prepareForSleep.bind(this));
     },
@@ -121,8 +133,33 @@ var LoginManagerSystemd = new Lang.Class({
 
         let sessionId = GLib.getenv('XDG_SESSION_ID');
         if (!sessionId) {
-            log('Unset XDG_SESSION_ID, getCurrentSessionProxy() called outside a user session.');
-            return;
+            log('Unset XDG_SESSION_ID, getCurrentSessionProxy() called outside a user session. Asking logind 
directly.');
+            let [session, session_object_path] = this._userProxy.Display;
+            if (session) {
+                log('Will monitor session ' + session);
+                sessionId = session;
+            } else {
+                log('Failed to find "Display" session; are we the greeter?');
+
+                let allSessions = this._userProxy.Sessions;
+
+                for (let [session, session_object_path] of allSessions) {
+                    let sessionProxy =  new SystemdLoginSession(Gio.DBus.system,
+                                                                'org.freedesktop.login1',
+                                                                session_object_path);
+                    log('Considering ' + session + ', class=' + sessionProxy.Class);
+                    if (sessionProxy.Class == 'greeter') {
+                        log('Yes, will monitor session ' + session);
+                        sessionId = session;
+                        break;
+                    }
+                }
+
+                if (!sessionId) {
+                    log('No, failed to get session from logind.');
+                    return;
+                }
+            }
         }
 
         this._proxy.GetSessionRemote(sessionId, (result, error) => {
@@ -137,6 +174,10 @@ var LoginManagerSystemd = new Lang.Class({
         });
     },
 
+    getCurrentSession() {
+        return this._currentSession;
+    },
+
     canSuspend(asyncCallback) {
         this._proxy.CanSuspendRemote((result, error) => {
             if (error) {
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index 7d18d0b79..f7ec73c98 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -697,7 +697,15 @@ var EndSessionDialog = new Lang.Class({
                 if (proxy.State == 'closing')
                     continue;
 
-                if (proxy.Id == GLib.getenv('XDG_SESSION_ID'))
+                let sessionId = GLib.getenv('XDG_SESSION_ID');
+                if (!sessionId) {
+                        let currentSession = this._loginManager.getCurrentSession();
+                        if (currentSession) {
+                                sessionId = currentSession.Id;
+                        }
+                }
+
+                if (proxy.Id == sessionId)
                     continue;
 
                 let session = { user: this._userManager.get_user(userName),


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