[Xfce4-commits] <libxfce4ui:new-sm-client> be a bit smarter when dealing with --sm-client-id substitution

Brian J. Tarricone brian at tarricone.org
Tue Sep 15 13:42:01 CEST 2009


Updating branch refs/heads/kelnos/new-sm-client
         to 38ec38a0732dd9c99395d47705d6e78930be6340 (commit)
       from 468f6a5855029a46f7e789ee2dd8f6ee0c72a441 (commit)

commit 38ec38a0732dd9c99395d47705d6e78930be6340
Author: Brian J. Tarricone <brian at tarricone.org>
Date:   Tue Sep 15 04:41:40 2009 -0700

    be a bit smarter when dealing with --sm-client-id substitution

 libxfce4ui/xfce-sm-client.c |   46 +++++++++++++++++++++++++++++++++---------
 1 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/libxfce4ui/xfce-sm-client.c b/libxfce4ui/xfce-sm-client.c
index 10a8f69..bfec8f6 100644
--- a/libxfce4ui/xfce-sm-client.c
+++ b/libxfce4ui/xfce-sm-client.c
@@ -1228,22 +1228,47 @@ xfce_sm_client_set_property_from_command(XfceSMClient *sm_client,
                                          gint alter_sm_id)
 {
     SmProp prop, *props[1];
-    gchar **args;
-    gint i;
-    gint argc;
+    gint i, argc;
     SmPropValue *vals;
 
     if(!command || !sm_client->session_connection)
         return;
 
-    args = command;
-    for(argc = 0; *args; args++) {
+    if(G_UNLIKELY(alter_sm_id == SM_ARG_APPEND && !sm_client->client_id)) {
+        g_warning("Trying to add client ID to %s without having a client ID yet",
+                  property_name);
+        return;
+    }
+
+    for(argc = 0; command[argc]; ++argc) {
         if(alter_sm_id == SM_ARG_APPEND
-           && !g_ascii_strncasecmp(*args, SM_ID_ARG, strlen(SM_ID_ARG)))
+           && !strncmp(command[argc], SM_ID_ARG, strlen(SM_ID_ARG)))
         {
+            /* if we have SM_ID_ARG in the command, we still have to
+             * make sure the command contains the *correct* client ID */
+            gchar *cur_client_id = NULL;
+
+            if(command[argc][strlen(SM_ID_ARG)] == '=')
+                cur_client_id = &(command[argc][strlen(SM_ID_ARG)+1]);
+            else
+                cur_client_id = command[argc+1];
+
+            /* if the client IDs don't match, we need to replace it, and
+             * we'll do it in the same form (either 2 arg, or 1 arg with
+             * the '=' separator) to avoid shifting the array around */
+            if(strcmp(cur_client_id, sm_client->client_id)) {
+                if(cur_client_id == command[argc+1]) {
+                    g_free(command[argc+1]);
+                    command[argc+1] = g_strdup(sm_client->client_id);
+                } else {
+                    g_free(command[argc]);
+                    command[argc] = g_strdup_printf("%s=%s", SM_ID_ARG,
+                                                    sm_client->client_id);
+                }
+            }
+
             alter_sm_id = FALSE;
         }
-        argc++;
     }
 
     if(alter_sm_id == SM_ARG_APPEND)
@@ -1253,11 +1278,12 @@ xfce_sm_client_set_property_from_command(XfceSMClient *sm_client,
     i = 0;
     while(*command) {
         if(alter_sm_id == SM_ARG_REMOVE
-           && !g_ascii_strncasecmp(*command, SM_ID_ARG, strlen(SM_ID_ARG)))
+           && !strncmp(*command, SM_ID_ARG, strlen(SM_ID_ARG)))
         {
-            /* skip the argument after SM_ID_ARG */
-            if(command[1])
+            if((*command)[strlen(SM_ID_ARG)] != '=' && *(command+1)) {
+                /* also skip the argument after SM_ID_ARG */
                 command++;
+            }
         } else {
             vals[i].length = strlen(*command);
             vals[i++].value = *command;



More information about the Xfce4-commits mailing list