a70f6d5
From 88fe0974aff7caddecd3701062922feac95ca722 Mon Sep 17 00:00:00 2001
a70f6d5
From: Michael Webster <miketwebster@gmail.com>
a70f6d5
Date: Tue, 13 Feb 2018 22:38:14 -0500
a70f6d5
Subject: [PATCH] Use dbus to check for user background support, as it should
a70f6d5
 now end up being more broadly-supported, rather than just being an Ubuntu
a70f6d5
 patch.
a70f6d5
a70f6d5
see https://github.com/linuxmint/slick-greeter/issues/94
a70f6d5
---
a70f6d5
 usr/lib/lightdm-settings/lightdm-settings | 80 +++++++++++++++++++++++++++++--
a70f6d5
 1 file changed, 76 insertions(+), 4 deletions(-)
a70f6d5
a70f6d5
diff --git a/usr/lib/lightdm-settings/lightdm-settings b/usr/lib/lightdm-settings/lightdm-settings
a70f6d5
index 0e98ea0..44f2bcf 100755
a70f6d5
--- a/usr/lib/lightdm-settings/lightdm-settings
a70f6d5
+++ b/usr/lib/lightdm-settings/lightdm-settings
a70f6d5
@@ -136,10 +136,7 @@ class Application(Gtk.Application):
a70f6d5
         section.add_row(row)
a70f6d5
 
a70f6d5
         try:
a70f6d5
-            distro = lsb_release.get_lsb_information()['ID']
a70f6d5
-            if distro.lower() in ['linuxmint', 'ubuntu', 'elementary']:
a70f6d5
-                # AccountsService doesn't support Background selection. It's something that is patched in Ubuntu, so only support this feature
a70f6d5
-                # in Ubuntu derivatives
a70f6d5
+            if self.should_show_user_bg_switch ():
a70f6d5
                 row = SettingsRow(Gtk.Label(_("Draw user backgrounds")), SettingsSwitch(keyfile, settings, "draw-user-backgrounds"))
a70f6d5
                 row.set_tooltip_text(_("When a user is selected, show that user's background."))
a70f6d5
                 section.add_row(row)
a70f6d5
@@ -363,6 +360,81 @@ class Application(Gtk.Application):
a70f6d5
                         pass
a70f6d5
         return (value)
a70f6d5
 
a70f6d5
+    def should_show_user_bg_switch (self):
a70f6d5
+        # Setting the user background was an ubuntu-only patch to AccountsService, but as
a70f6d5
+        # of lightdm 1.25.2, it's provided as a plugin to AccountsService.  We can check on
a70f6d5
+        # the bus to see if we have either form of support (either via AccountsService.User or
a70f6d5
+        # DisplayManager.AccountsService)
a70f6d5
+        #
a70f6d5
+        # It doesn't matter whether we're root here - we don't care about the return values,
a70f6d5
+        # just that the calls succeed.
a70f6d5
+        #
a70f6d5
+        # see https://github.com/linuxmint/slick-greeter/issues/94
a70f6d5
+
a70f6d5
+        # Find a user node
a70f6d5
+        try:
a70f6d5
+            proxy = Gio.DBusProxy.new_for_bus_sync(Gio.BusType.SYSTEM,
a70f6d5
+                                                   Gio.DBusProxyFlags.NONE,
a70f6d5
+                                                   None,
a70f6d5
+                                                   "org.freedesktop.Accounts",
a70f6d5
+                                                   "/org/freedesktop/Accounts",
a70f6d5
+                                                   "org.freedesktop.Accounts",
a70f6d5
+                                                   None)
a70f6d5
+
a70f6d5
+            user_var = proxy.call_sync("FindUserByName",
a70f6d5
+                                       GLib.Variant("(s)", (GLib.get_user_name(),)),
a70f6d5
+                                       Gio.DBusCallFlags.NONE,
a70f6d5
+                                       -1,
a70f6d5
+                                       None)
a70f6d5
+        except GLib.Error as e:
a70f6d5
+            print(e.message)
a70f6d5
+            return False
a70f6d5
+
a70f6d5
+        try:
a70f6d5
+            object_path = user_var.unpack()[0]
a70f6d5
+        except IndexError:
a70f6d5
+            return False
a70f6d5
+
a70f6d5
+        # Initialize a properties interface
a70f6d5
+        try:
a70f6d5
+            props = Gio.DBusProxy.new_for_bus_sync(Gio.BusType.SYSTEM,
a70f6d5
+                                                   Gio.DBusProxyFlags.NONE,
a70f6d5
+                                                   None,
a70f6d5
+                                                   "org.freedesktop.Accounts",
a70f6d5
+                                                   object_path,
a70f6d5
+                                                   "org.freedesktop.DBus.Properties",
a70f6d5
+                                                   None)
a70f6d5
+        except GLib.Error as e:
a70f6d5
+            print(e.message)
a70f6d5
+            return False
a70f6d5
+
a70f6d5
+        # Try the new way (plugin)
a70f6d5
+        try:
a70f6d5
+            ret = props.call_sync("Get",
a70f6d5
+                                  GLib.Variant("(ss)",
a70f6d5
+                                               ("org.freedesktop.DisplayManager.AccountsService",
a70f6d5
+                                               "BackgroundFile")),
a70f6d5
+                                  Gio.DBusCallFlags.NONE,
a70f6d5
+                                  -1,
a70f6d5
+                                  None)
a70f6d5
+        except GLib.Error as e:
a70f6d5
+            print(e.message)
a70f6d5
+
a70f6d5
+            # Try the old way (patched AccountsService)
a70f6d5
+            try:
a70f6d5
+                ret = props.call_sync("Get",
a70f6d5
+                                      GLib.Variant("(ss)",
a70f6d5
+                                                   ("org.freedesktop.Accounts.User",
a70f6d5
+                                                   "BackgroundFile")),
a70f6d5
+                                      Gio.DBusCallFlags.NONE,
a70f6d5
+                                      -1,
a70f6d5
+                                      None)
a70f6d5
+            except GLib.Error as e:
a70f6d5
+                print(e.message)
a70f6d5
+                return False
a70f6d5
+
a70f6d5
+        return True
a70f6d5
+
a70f6d5
 if __name__ == "__main__":
a70f6d5
     app = Application()
a70f6d5
     app.run(None)