[Xfce4-commits] [xfce/xfce4-session] 18/30: Add a switch user button to the logout dialog (Bug #10345)

noreply at xfce.org noreply at xfce.org
Sun May 15 18:03:37 CEST 2016


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfce4-session.

commit a3a388b3568b07de2c4ddeb23da663f2ea623499
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Sun Apr 24 07:53:07 2016 +0300

    Add a switch user button to the logout dialog (Bug #10345)
    
    If the display manager provides the org.freedesktop.DisplayManager
    dbus API with the SwitchToGreeter call, the switch to user button
    will show up on the logout dialog.
---
 xfce4-session/xfsm-logout-dialog.c | 32 +++++++++++++
 xfce4-session/xfsm-shutdown.c      | 95 ++++++++++++++++++++++++++++++++++++++
 xfce4-session/xfsm-shutdown.h      |  9 ++++
 3 files changed, 136 insertions(+)

diff --git a/xfce4-session/xfsm-logout-dialog.c b/xfce4-session/xfsm-logout-dialog.c
index 8d51577..0a08af6 100644
--- a/xfce4-session/xfsm-logout-dialog.c
+++ b/xfce4-session/xfsm-logout-dialog.c
@@ -146,6 +146,7 @@ xfsm_logout_dialog_init (XfsmLogoutDialog *dialog)
   gboolean       can_restart;
   gboolean       can_suspend = FALSE;
   gboolean       can_hibernate = FALSE;
+  gboolean       can_switch_user = FALSE;
   gboolean       auth_suspend = FALSE;
   gboolean       auth_hibernate = FALSE;
   GError        *error = NULL;
@@ -337,6 +338,37 @@ xfsm_logout_dialog_init (XfsmLogoutDialog *dialog)
     }
 
   /**
+   * Switch User
+   *
+   * Hide the button if system cannot switch user, requires the display
+   * manager to provide the org.freedesktop.DisplayManager dbus API
+   **/
+  if (xfconf_channel_get_bool (channel, "/shutdown/ShowSwitchUser", TRUE))
+    {
+      if (xfsm_shutdown_can_switch_user (dialog->shutdown, &can_switch_user, &error))
+        {
+          if (can_switch_user)
+            {
+              button = xfsm_logout_dialog_button (_("Switch _User"), "avatar-default",
+                                                  "avatar-default-symbolic", XFSM_SHUTDOWN_SWITCH_USER,
+                                                  dialog);
+
+              gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+              gtk_widget_set_sensitive (button, auth_hibernate);
+              gtk_widget_show (button);
+
+              gtk_widget_show (hbox);
+            }
+        }
+      else
+        {
+          g_printerr ("%s: Querying switch user failed: %s\n\n",
+                      PACKAGE_NAME, ERROR_MSG (error));
+          g_clear_error (&error);
+        }
+    }
+
+  /**
    * Save session
    **/
   if (xfsm_shutdown_can_save_session (dialog->shutdown)
diff --git a/xfce4-session/xfsm-shutdown.c b/xfce4-session/xfsm-shutdown.c
index d8209f2..e797e82 100644
--- a/xfce4-session/xfsm-shutdown.c
+++ b/xfce4-session/xfsm-shutdown.c
@@ -57,6 +57,7 @@
 
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
 #include <libxfce4util/libxfce4util.h>
 #include <gtk/gtk.h>
 #ifdef HAVE_UPOWER
@@ -353,6 +354,49 @@ xfsm_shutdown_try_hibernate (XfsmShutdown  *shutdown,
   return xfsm_shutdown_fallback_try_action (XFSM_SHUTDOWN_HIBERNATE, error);
 }
 
+gboolean
+xfsm_shutdown_try_switch_user (XfsmShutdown  *shutdown,
+                               GError       **error)
+{
+  GDBusProxy  *display_proxy;
+  GVariant    *unused = NULL;
+  const gchar *DBUS_NAME = "org.freedesktop.DisplayManager";
+  const gchar *DBUS_INTERFACE = "org.freedesktop.DisplayManager.Seat";
+  const gchar *DBUS_OBJECT_PATH = "/org/freedesktop/DisplayManager/Seat0";
+
+  g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
+
+  display_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                 G_DBUS_PROXY_FLAGS_NONE,
+                                                 NULL,
+                                                 DBUS_NAME,
+                                                 DBUS_OBJECT_PATH,
+                                                 DBUS_INTERFACE,
+                                                 NULL,
+                                                 error);
+
+  if (display_proxy == NULL || error != NULL)
+    {
+      return FALSE;
+    }
+
+  unused = g_dbus_proxy_call_sync (display_proxy,
+                                  "SwitchToGreeter",
+                                  g_variant_new ("()"),
+                                  G_DBUS_CALL_FLAGS_NONE,
+                                  3000,
+                                  NULL,
+                                  error);
+
+  if (unused != NULL)
+    {
+      g_variant_unref (unused);
+    }
+
+  g_object_unref (display_proxy);
+
+  return (error == NULL);
+}
 
 
 gboolean
@@ -502,6 +546,57 @@ xfsm_shutdown_can_hibernate (XfsmShutdown  *shutdown,
 
 
 gboolean
+xfsm_shutdown_can_switch_user (XfsmShutdown  *shutdown,
+                               gboolean      *can_switch_user,
+                               GError       **error)
+{
+  GDBusProxy  *display_proxy;
+  gchar       *owner = NULL;
+  const gchar *DBUS_NAME = "org.freedesktop.DisplayManager";
+  const gchar *DBUS_INTERFACE = "org.freedesktop.DisplayManager.Seat";
+  const gchar *DBUS_OBJECT_PATH = g_getenv ("XDG_SEAT_PATH");
+
+  *can_switch_user = FALSE;
+
+  g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
+
+  if (DBUS_OBJECT_PATH == NULL)
+    {
+      return TRUE;
+    }
+
+  display_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                                 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+                                                 NULL,
+                                                 DBUS_NAME,
+                                                 DBUS_OBJECT_PATH,
+                                                 DBUS_INTERFACE,
+                                                 NULL,
+                                                 error);
+
+  if (display_proxy == NULL)
+    {
+      xfsm_verbose ("display proxy returned NULL\n");
+      return FALSE;
+    }
+
+  /* is there anyone actually providing a service? */
+  owner = g_dbus_proxy_get_name_owner (display_proxy);
+  if (owner != NULL)
+  {
+    g_object_unref (display_proxy);
+    g_free (owner);
+    *can_switch_user = TRUE;
+    return TRUE;
+  }
+
+  xfsm_verbose ("no owner NULL\n");
+  return TRUE;
+}
+
+
+
+gboolean
 xfsm_shutdown_can_save_session (XfsmShutdown *shutdown)
 {
   g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
diff --git a/xfce4-session/xfsm-shutdown.h b/xfce4-session/xfsm-shutdown.h
index eac26bf..0af91f3 100644
--- a/xfce4-session/xfsm-shutdown.h
+++ b/xfce4-session/xfsm-shutdown.h
@@ -40,6 +40,7 @@ typedef enum
   XFSM_SHUTDOWN_RESTART,
   XFSM_SHUTDOWN_SUSPEND,
   XFSM_SHUTDOWN_HIBERNATE,
+  XFSM_SHUTDOWN_SWITCH_USER,
 }
 XfsmShutdownType;
 
@@ -78,6 +79,9 @@ gboolean      xfsm_shutdown_try_suspend      (XfsmShutdown      *shutdown,
 gboolean      xfsm_shutdown_try_hibernate    (XfsmShutdown      *shutdown,
                                               GError           **error);
 
+gboolean      xfsm_shutdown_try_switch_user  (XfsmShutdown      *shutdown,
+                                              GError           **error);
+
 gboolean      xfsm_shutdown_can_restart      (XfsmShutdown      *shutdown,
                                               gboolean          *can_restart,
                                               GError           **error);
@@ -96,6 +100,11 @@ gboolean      xfsm_shutdown_can_hibernate    (XfsmShutdown      *shutdown,
                                               gboolean          *auth_hibernate,
                                               GError           **error);
 
+gboolean      xfsm_shutdown_can_switch_user  (XfsmShutdown      *shutdown,
+                                              gboolean          *can_switch_user,
+                                              GError           **error);
+
+
 gboolean      xfsm_shutdown_can_save_session (XfsmShutdown      *shutdown);
 
 #endif	/* !__XFSM_SHUTDOWN_H__ */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list