[libegg] smclient: Add ability to connect lately to the session manager



commit dc8db697dfaf8e57fbc9fe5251675a27e8c54f44
Author: Vincent Untz <vuntz gnome org>
Date:   Tue Jan 12 22:54:41 2010 +0100

    smclient: Add ability to connect lately to the session manager
    
    For this, the mode should be set to EGG_SM_CLIENT_MODE_DISABLED early in
    the application, and then setting the mode to
    EGG_SM_CLIENT_MODE_NO_RESTART or EGG_SM_CLIENT_MODE_NORMAL will make the
    registration occur if needed. This is useful for applications that need
    to control how the session registration is done, like gnome-panel.
    
    Internally, this means that instead of creating a dummy EggSMClient
    object when the mode is EGG_SM_CLIENT_MODE_DISABLED, we directly create
    the right object, but we don't connect to the session manager when
    parsing the options.
    
    Also, some checks are now done in egg_sm_client_set_mode() so that the
    mode cannot be changed in ways that wouldn't work (eg: changing the
    state to EGG_SM_CLIENT_MODE_DISABLED while the client has already
    connected to the sessio manager).

 libegg/smclient/eggsmclient.c |   29 ++++++++++++++++++++++-------
 1 files changed, 22 insertions(+), 7 deletions(-)
---
diff --git a/libegg/smclient/eggsmclient.c b/libegg/smclient/eggsmclient.c
index efa901d..92be8a7 100644
--- a/libegg/smclient/eggsmclient.c
+++ b/libegg/smclient/eggsmclient.c
@@ -202,7 +202,8 @@ sm_client_post_parse_func (GOptionContext  *context,
    * use the same client id. */
   g_unsetenv ("DESKTOP_AUTOSTART_ID");
 
-  if (EGG_SM_CLIENT_GET_CLASS (client)->startup)
+  if (global_client_mode != EGG_SM_CLIENT_MODE_DISABLED &&
+      EGG_SM_CLIENT_GET_CLASS (client)->startup)
     EGG_SM_CLIENT_GET_CLASS (client)->startup (client, sm_client_id);
   return TRUE;
 }
@@ -265,9 +266,9 @@ egg_sm_client_get_option_group (void)
  * Sets the "mode" of #EggSMClient as follows:
  *
  *    %EGG_SM_CLIENT_MODE_DISABLED: Session management is completely
- *    disabled. The application will not even connect to the session
- *    manager. (egg_sm_client_get() will still return an #EggSMClient,
- *    but it will just be a dummy object.)
+ *    disabled, until the mode is changed again. The application will
+ *    not even connect to the session manager. (egg_sm_client_get()
+ *    will still return an #EggSMClient object.)
  *
  *    %EGG_SM_CLIENT_MODE_NO_RESTART: The application will connect to
  *    the session manager (and thus will receive notification when the
@@ -277,12 +278,27 @@ egg_sm_client_get_option_group (void)
  *    %EGG_SM_CLIENT_MODE_NORMAL: The default. #EggSMCLient will
  *    function normally.
  *
- * This must be called before the application's main loop begins.
+ * This must be called before the application's main loop begins and
+ * before any call to egg_sm_client_get(), unless the mode was set
+ * earlier to %EGG_SM_CLIENT_MODE_DISABLED and this call enables
+ * session management. Note that option parsing will call
+ * egg_sm_client_get().
  **/
 void
 egg_sm_client_set_mode (EggSMClientMode mode)
 {
+  EggSMClientMode old_mode = global_client_mode;
+
+  g_return_if_fail (global_client == NULL || global_client_mode == EGG_SM_CLIENT_MODE_DISABLED);
+  g_return_if_fail (!(global_client != NULL && mode == EGG_SM_CLIENT_MODE_DISABLED));
+
   global_client_mode = mode;
+
+  if (global_client != NULL && old_mode == EGG_SM_CLIENT_MODE_DISABLED)
+    {
+      if (EGG_SM_CLIENT_GET_CLASS (global_client)->startup)
+        EGG_SM_CLIENT_GET_CLASS (global_client)->startup (global_client, sm_client_id);
+    }
 }
 
 /**
@@ -317,8 +333,7 @@ egg_sm_client_get (void)
 {
   if (!global_client)
     {
-      if (global_client_mode != EGG_SM_CLIENT_MODE_DISABLED &&
-	  !sm_client_disable)
+      if (!sm_client_disable)
 	{
 #if defined (GDK_WINDOWING_WIN32)
 	  global_client = egg_sm_client_win32_new ();



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