[Xfce4-commits] [xfce/xfce4-session] 01/01: Add switch-user to the xfsm-logout program

noreply at xfce.org noreply at xfce.org
Tue Jun 28 14:47:38 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 ac387875a5e0d4239848fa3560757fb7ef0c2338
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Tue Jun 28 15:46:16 2016 +0300

    Add switch-user to the xfsm-logout program
---
 xfce4-session-logout/main.c         | 19 ++++++++++++-
 xfce4-session/xfsm-manager-dbus.xml |  5 ++++
 xfce4-session/xfsm-manager.c        | 57 ++++++++++++++++++++++++++++++++-----
 xfce4-session/xfsm-shutdown.c       | 13 +++++++--
 4 files changed, 83 insertions(+), 11 deletions(-)

diff --git a/xfce4-session-logout/main.c b/xfce4-session-logout/main.c
index 2ed8a9e..e94d015 100644
--- a/xfce4-session-logout/main.c
+++ b/xfce4-session-logout/main.c
@@ -47,6 +47,7 @@ gboolean opt_halt = FALSE;
 gboolean opt_reboot = FALSE;
 gboolean opt_suspend = FALSE;
 gboolean opt_hibernate = FALSE;
+gboolean opt_switch_user = FALSE;
 gboolean opt_fast = FALSE;
 gboolean opt_version = FALSE;
 
@@ -57,7 +58,8 @@ enum
   XFSM_SHUTDOWN_HALT,
   XFSM_SHUTDOWN_REBOOT,
   XFSM_SHUTDOWN_SUSPEND,
-  XFSM_SHUTDOWN_HIBERNATE
+  XFSM_SHUTDOWN_HIBERNATE,
+  XFSM_SHUTDOWN_SWITCH_USER
 };
 
 static GOptionEntry option_entries[] =
@@ -82,6 +84,10 @@ static GOptionEntry option_entries[] =
     N_("Hibernate without displaying the logout dialog"),
     NULL
   },
+  { "switch-user", 'u', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_switch_user,
+    N_("Switch user without displaying the logout dialog"),
+    NULL
+  },
   { "fast", 'f', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &opt_fast,
     N_("Log out quickly; don't save the session"),
     NULL
@@ -194,6 +200,15 @@ main (int argc, char **argv)
                                        NULL,
                                        &err);
     }
+  else if (opt_switch_user)
+    {
+      result = g_dbus_proxy_call_sync (proxy, "SwitchUser",
+                                       g_variant_new("()"),
+                                       G_DBUS_CALL_FLAGS_NONE,
+                                       -1,
+                                       NULL,
+                                       &err);
+    }
   else
     {
       show_dialog = !opt_logout;
@@ -225,6 +240,8 @@ main (int argc, char **argv)
         shutdown_type = XFSM_SHUTDOWN_SUSPEND;
       else if (opt_hibernate)
         shutdown_type = XFSM_SHUTDOWN_HIBERNATE;
+      else if (opt_switch_user)
+        shutdown_type = XFSM_SHUTDOWN_SWITCH_USER;
       else
         shutdown_type = XFSM_SHUTDOWN_ASK;
 
diff --git a/xfce4-session/xfsm-manager-dbus.xml b/xfce4-session/xfsm-manager-dbus.xml
index 9c0aa67..73dd663 100644
--- a/xfce4-session/xfsm-manager-dbus.xml
+++ b/xfce4-session/xfsm-manager-dbus.xml
@@ -149,6 +149,11 @@
         </method>
 
         <!--
+             void org.Xfce.Session.Manager.SwitchUser
+        -->
+        <method name="SwitchUser" />
+
+        <!--
              ObjectPath[] org.Xfce.Session.Manager.RegisterClient
 
              @app_id: The application identifier
diff --git a/xfce4-session/xfsm-manager.c b/xfce4-session/xfsm-manager.c
index 6cb18a4..c9ed0e3 100644
--- a/xfce4-session/xfsm-manager.c
+++ b/xfce4-session/xfsm-manager.c
@@ -1201,10 +1201,11 @@ xfsm_manager_save_yourself_global (XfsmManager     *manager,
         manager->shutdown_type = shutdown_type;
 
       /* we only save the session and quit if we're actually shutting down;
-       * suspend and hibernate will (if successful) return us to
+       * suspend, hibernate, and switch user will (if successful) return us to
        * exactly the same state, so there's no need to save session */
       if (manager->shutdown_type == XFSM_SHUTDOWN_SUSPEND
-          || manager->shutdown_type == XFSM_SHUTDOWN_HIBERNATE)
+          || manager->shutdown_type == XFSM_SHUTDOWN_HIBERNATE
+          || manager->shutdown_type == XFSM_SHUTDOWN_SWITCH_USER)
         {
           if (!xfsm_shutdown_try_type (manager->shutdown_helper,
                                        manager->shutdown_type,
@@ -1215,16 +1216,18 @@ xfsm_manager_save_yourself_global (XfsmManager     *manager,
                                    "dialog-error",
                                    manager->shutdown_type == XFSM_SHUTDOWN_SUSPEND
                                    ? _("Failed to suspend session")
-                                   : _("Failed to hibernate session"),
+                                   : manager->shutdown_type == XFSM_SHUTDOWN_HIBERNATE
+                                   ? _("Failed to hibernate session")
+                                   : _("Failed to switch user"),
                                    error->message,
                                    XFCE_BUTTON_TYPE_MIXED, "window-close", _("_Close"), GTK_RESPONSE_ACCEPT,
                                    NULL);
               g_error_free (error);
             }
 
-          /* at this point, either we failed to suspend/hibernate, or we
-           * successfully suspended/hibernated, and we've been woken back
-           * up, so return control to the user */
+          /* at this point, either we failed to suspend/hibernate/switch user,
+           * or we successfully did and we've been woken back
+           * up or returned to the session, so return control to the user */
           return;
         }
     }
@@ -1967,6 +1970,8 @@ static gboolean xfsm_manager_dbus_hibernate (XfsmDbusManager *object,
                                              GDBusMethodInvocation *invocation);
 static gboolean xfsm_manager_dbus_can_hibernate (XfsmDbusManager *object,
                                                  GDBusMethodInvocation *invocation);
+static gboolean xfsm_manager_dbus_switch_user (XfsmDbusManager *object,
+                                               GDBusMethodInvocation *invocation);
 static gboolean xfsm_manager_dbus_register_client (XfsmDbusManager *object,
                                                    GDBusMethodInvocation *invocation,
                                                    const gchar *arg_app_id,
@@ -2073,6 +2078,7 @@ xfsm_manager_iface_init (XfsmDbusManagerIface *iface)
   iface->handle_get_info = xfsm_manager_dbus_get_info;
   iface->handle_get_state = xfsm_manager_dbus_get_state;
   iface->handle_hibernate = xfsm_manager_dbus_hibernate;
+  iface->handle_switch_user = xfsm_manager_dbus_switch_user;
   iface->handle_list_clients = xfsm_manager_dbus_list_clients;
   iface->handle_logout = xfsm_manager_dbus_logout;
   iface->handle_restart = xfsm_manager_dbus_restart;
@@ -2231,6 +2237,8 @@ xfsm_manager_dbus_logout (XfsmDbusManager *object,
 {
   XfsmShutdownType type;
 
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
 
   type = arg_show_dialog ? XFSM_SHUTDOWN_ASK : XFSM_SHUTDOWN_LOGOUT;
@@ -2251,6 +2259,8 @@ xfsm_manager_dbus_shutdown (XfsmDbusManager *object,
                             GDBusMethodInvocation *invocation,
                             gboolean arg_allow_save)
 {
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
   if (xfsm_manager_save_yourself_dbus (XFSM_MANAGER (object), XFSM_SHUTDOWN_SHUTDOWN, arg_allow_save) == FALSE)
     {
@@ -2271,6 +2281,8 @@ xfsm_manager_dbus_can_shutdown (XfsmDbusManager *object,
   gboolean can_shutdown = FALSE;
   GError *error = NULL;
 
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
 
   xfsm_shutdown_can_shutdown (XFSM_MANAGER (object)->shutdown_helper, &can_shutdown, &error);
@@ -2292,6 +2304,8 @@ xfsm_manager_dbus_restart (XfsmDbusManager *object,
                            GDBusMethodInvocation *invocation,
                            gboolean arg_allow_save)
 {
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
   if (xfsm_manager_save_yourself_dbus (XFSM_MANAGER (object), XFSM_SHUTDOWN_RESTART, arg_allow_save) == FALSE)
     {
@@ -2312,6 +2326,8 @@ xfsm_manager_dbus_can_restart (XfsmDbusManager *object,
   gboolean can_restart = FALSE;
   GError *error = NULL;
 
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
 
   xfsm_shutdown_can_restart (XFSM_MANAGER (object)->shutdown_helper, &can_restart, &error);
@@ -2334,6 +2350,8 @@ xfsm_manager_dbus_suspend (XfsmDbusManager *object,
 {
   GError *error = NULL;
 
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
   if (xfsm_shutdown_try_suspend (XFSM_MANAGER (object)->shutdown_helper, &error) == FALSE)
     {
@@ -2355,6 +2373,8 @@ xfsm_manager_dbus_can_suspend (XfsmDbusManager *object,
   gboolean can_suspend = FALSE;
   GError *error = NULL;
 
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
 
   xfsm_shutdown_can_suspend (XFSM_MANAGER (object)->shutdown_helper, &can_suspend, &auth_suspend, &error);
@@ -2379,6 +2399,8 @@ xfsm_manager_dbus_hibernate (XfsmDbusManager *object,
 {
   GError *error = NULL;
 
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
   if (xfsm_shutdown_try_hibernate (XFSM_MANAGER (object)->shutdown_helper, &error) == FALSE)
     {
@@ -2391,7 +2413,6 @@ xfsm_manager_dbus_hibernate (XfsmDbusManager *object,
   return TRUE;
 }
 
-
 static gboolean
 xfsm_manager_dbus_can_hibernate (XfsmDbusManager *object,
                                  GDBusMethodInvocation *invocation)
@@ -2400,6 +2421,8 @@ xfsm_manager_dbus_can_hibernate (XfsmDbusManager *object,
   gboolean can_hibernate = FALSE;
   GError *error = NULL;
 
+  xfsm_verbose ("entering\n");
+
   g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
 
   xfsm_shutdown_can_hibernate (XFSM_MANAGER (object)->shutdown_helper, &can_hibernate, &auth_hibernate, &error);
@@ -2418,6 +2441,26 @@ xfsm_manager_dbus_can_hibernate (XfsmDbusManager *object,
   return TRUE;
 }
 
+static gboolean
+xfsm_manager_dbus_switch_user (XfsmDbusManager *object,
+                               GDBusMethodInvocation *invocation)
+{
+  GError *error = NULL;
+
+  xfsm_verbose ("entering\n");
+
+  g_return_val_if_fail (XFSM_IS_MANAGER (object), FALSE);
+  if (xfsm_shutdown_try_switch_user (XFSM_MANAGER (object)->shutdown_helper, &error) == FALSE)
+    {
+      throw_error (invocation, XFSM_ERROR_BAD_STATE, error->message);
+      g_clear_error (&error);
+      return TRUE;
+    }
+
+  xfsm_dbus_manager_complete_switch_user (object, invocation);
+  return TRUE;
+}
+
 
 
 /* adapted from ConsoleKit2 whch was adapted from PolicyKit */
diff --git a/xfce4-session/xfsm-shutdown.c b/xfce4-session/xfsm-shutdown.c
index e015323..5690176 100644
--- a/xfce4-session/xfsm-shutdown.c
+++ b/xfce4-session/xfsm-shutdown.c
@@ -209,6 +209,9 @@ xfsm_shutdown_try_type (XfsmShutdown      *shutdown,
     case XFSM_SHUTDOWN_HIBERNATE:
       return xfsm_shutdown_try_hibernate (shutdown, error);
 
+    case XFSM_SHUTDOWN_SWITCH_USER:
+      return xfsm_shutdown_try_switch_user (shutdown, error);
+
     default:
       g_set_error (error, 1, 0, _("Unknown shutdown method %d"), type);
       break;
@@ -338,7 +341,9 @@ xfsm_shutdown_try_switch_user (XfsmShutdown  *shutdown,
   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";
+  const gchar *DBUS_OBJECT_PATH = g_getenv ("XDG_SEAT_PATH");
+
+  xfsm_verbose ("entering\n");
 
   g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE);
 
@@ -351,11 +356,13 @@ xfsm_shutdown_try_switch_user (XfsmShutdown  *shutdown,
                                                  NULL,
                                                  error);
 
-  if (display_proxy == NULL || error != NULL)
+  if (display_proxy == NULL || *error != NULL)
     {
+      xfsm_verbose ("display proxy == NULL or an error was set\n");
       return FALSE;
     }
 
+  xfsm_verbose ("calling SwitchToGreeter\n");
   unused = g_dbus_proxy_call_sync (display_proxy,
                                   "SwitchToGreeter",
                                   g_variant_new ("()"),
@@ -371,7 +378,7 @@ xfsm_shutdown_try_switch_user (XfsmShutdown  *shutdown,
 
   g_object_unref (display_proxy);
 
-  return (error == NULL);
+  return (*error == NULL);
 }
 
 

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


More information about the Xfce4-commits mailing list