Author: kelnos
Date: 2008-11-11 05:14:42 +0000 (Tue, 11 Nov 2008)
New Revision: 28722

Modified:
   xfce4-settings/trunk/xfce4-settings-helper/workspaces.c
Log:
fix workspace names setting... seems wnck_workspace_change_name() is
broken if you call it several times in succession for different
workspaces

Modified: xfce4-settings/trunk/xfce4-settings-helper/workspaces.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/workspaces.c     2008-11-11 
05:14:24 UTC (rev 28721)
+++ xfce4-settings/trunk/xfce4-settings-helper/workspaces.c     2008-11-11 
05:14:42 UTC (rev 28722)
@@ -51,6 +51,9 @@
 static void xfce_workspaces_helper_init(XfceWorkspacesHelper *helper);
 static void xfce_workspaces_helper_finalize(GObject *obj);
 
+static void xfce_workspaces_helper_set_names_prop(XfceWorkspacesHelper *helper,
+                                                  GdkScreen *screen,
+                                                  gchar **names);
 static void xfce_workspaces_helper_update_all_names(XfceWorkspacesHelper 
*helper);
 static void xfce_workspaces_helper_prop_changed(XfconfChannel *channel,
                                                 const gchar *property,
@@ -72,14 +75,11 @@
 static void
 xfce_workspaces_helper_init(XfceWorkspacesHelper *helper)
 {
-    WnckWorkspace *space;
     gint i, n_workspaces;
     gchar **names;
+    GdkDisplay *display;
+    GdkScreen *screen;
 
-    helper->channel = xfconf_channel_new(WORKSPACES_CHANNEL);
-    names = xfconf_channel_get_string_list(helper->channel,
-                                           WORKSPACE_NAMES_PROP);
-
     /* FIXME: need to do this for all screens? */
     helper->screen = wnck_screen_get_default();
     wnck_screen_force_update(helper->screen);
@@ -90,27 +90,26 @@
                              
G_CALLBACK(xfce_workspaces_helper_update_all_names),
                              helper);
 
+    helper->channel = xfconf_channel_new(WORKSPACES_CHANNEL);
+    names = xfconf_channel_get_string_list(helper->channel,
+                                           WORKSPACE_NAMES_PROP);
+
     n_workspaces = wnck_screen_get_workspace_count(helper->screen);
-    i = 0;
-    if(names) {
-        for(; i < n_workspaces && names[i]; ++i) {
-            space = wnck_screen_get_workspace(helper->screen, i);
-            wnck_workspace_change_name(space, names[i]);
-        }
-    }
-    if(i != n_workspaces) {
+    if(G_UNLIKELY(!names))
+        names = g_new0(gchar *, n_workspaces + 1);
+    else if(g_strv_length(names) < n_workspaces)
+        names = g_renew(gchar *, names, n_workspaces + 1);
+
+    for(i = g_strv_length(names); i < n_workspaces; ++i) {
         /* some of them may not have been set in xfconf */
-        names = g_realloc(names, sizeof(gchar *) * (n_workspaces + 1));
-        for(; i < n_workspaces; ++i) {
-            names[i] = g_strdup_printf(_("Workspace %d"), i + 1);
-            space = wnck_screen_get_workspace(helper->screen, i);
-            wnck_workspace_change_name(space, names[i]);
-        }
-        names[i] = NULL;
-        xfconf_channel_set_string_list(helper->channel, WORKSPACE_NAMES_PROP,
-                                       (const gchar **)names);
+        names[i] = g_strdup_printf(_("Workspace %d"), i + 1);
     }
+    names[i] = NULL;
 
+    display = gdk_display_get_default();
+    screen = gdk_display_get_screen(display, 
wnck_screen_get_number(helper->screen));
+    xfce_workspaces_helper_set_names_prop(helper, screen, names);
+
     g_signal_connect(G_OBJECT(helper->channel),
                      "property-changed::" WORKSPACE_NAMES_PROP,
                      G_CALLBACK(xfce_workspaces_helper_prop_changed), helper);
@@ -138,18 +137,44 @@
 
 
 static void
+xfce_workspaces_helper_set_names_prop(XfceWorkspacesHelper *helper,
+                                      GdkScreen *screen,
+                                      gchar **names)
+{
+    GString *names_str;
+    gint i;
+
+    names_str = g_string_new(NULL);
+
+    for(i = 0; names[i]; ++i)
+        g_string_append_len(names_str, names[i], strlen(names[i]) + 1);
+
+    gdk_error_trap_push();
+
+    gdk_property_change(gdk_screen_get_root_window(screen),
+                        gdk_atom_intern_static_string("_NET_DESKTOP_NAMES"),
+                        gdk_atom_intern_static_string("UTF8_STRING"),
+                        8, GDK_PROP_MODE_REPLACE,
+                        (guchar *)names_str->str, names_str->len + 1);
+    gdk_flush();
+
+    gdk_error_trap_pop();
+
+    g_string_free(names_str, TRUE);
+}
+
+static void
 xfce_workspaces_helper_update_all_names(XfceWorkspacesHelper *helper)
 {
     gint i, n_workspaces = wnck_screen_get_workspace_count(helper->screen);
     gchar const **names;
 
-    names = g_malloc(sizeof(gchar *) * (n_workspaces + 1));
+    names = g_new0(gchar *, n_workspaces + 1);
 
     for(i = 0; i < n_workspaces; ++i) {
         WnckWorkspace *space = wnck_screen_get_workspace(helper->screen, i);
         names[i] = wnck_workspace_get_name(space);
     }
-    names[n_workspaces] = NULL;
 
     xfconf_channel_set_string_list(helper->channel, WORKSPACE_NAMES_PROP,
                                    (const gchar **)names);
@@ -164,36 +189,45 @@
                                     gpointer user_data)
 {
     XfceWorkspacesHelper *helper = user_data;
-    GPtrArray *names;
-    guint i, n_workspaces = wnck_screen_get_workspace_count(helper->screen);
+    GPtrArray *names_arr;
+    gint i, n_workspaces;
+    gchar **names;
+    GdkDisplay *display;
+    GdkScreen *screen;
 
-    if(G_VALUE_TYPE(value) !=  dbus_g_type_get_collection("GPtrArray",
-                                                          G_TYPE_VALUE))
+    if(G_VALUE_TYPE(value) == G_TYPE_INVALID)
+        return;
+
+    if(G_VALUE_TYPE(value) != dbus_g_type_get_collection("GPtrArray",
+                                                         G_TYPE_VALUE))
     {
         g_warning("(workspace names) Expected boxed GPtrArray property, got 
%s",
                   G_VALUE_TYPE_NAME(value));
         return;
     }
 
-    names = g_value_get_boxed(value);
-    if(!names)
+    names_arr = g_value_get_boxed(value);
+    if(!names_arr)
         return;
 
-    for(i = 0; i < n_workspaces && i < names->len; ++i) {
-        WnckWorkspace *space = wnck_screen_get_workspace(helper->screen, i);
-        GValue *val = g_ptr_array_index(names, i);
-        const gchar *old_name, *new_name;
+    wnck_screen_force_update(helper->screen);
+    n_workspaces = wnck_screen_get_workspace_count(helper->screen);
+    if(n_workspaces > names_arr->len)
+        names = g_new0(gchar *, n_workspaces + 1);
+    else {
+        names = g_new0(gchar *, names_arr->len + 1);
+        n_workspaces = names_arr->len;
+    }
 
-        if(!G_VALUE_HOLDS_STRING(val)) {
-            g_warning("(workspace names) Expected string but got %s for item 
%d",
-                      G_VALUE_TYPE_NAME(val), i);
-            continue;
-        }
+    for(i = 0; i < n_workspaces; ++i) {
+        if(i < names_arr->len && 
G_VALUE_HOLDS_STRING(g_ptr_array_index(names_arr, i)))
+            names[i] = g_value_dup_string(g_ptr_array_index(names_arr, i));
+        else
+            names[i] = g_strdup_printf(_("Workspace %d"), i + 1);
+    }
 
-        /* only update the names that have actually changed */
-        old_name = wnck_workspace_get_name(space);
-        new_name = g_value_get_string(val);
-        if(strcmp(old_name, new_name))
-            wnck_workspace_change_name(space, new_name);
-    }
+    display = gdk_display_get_default();
+    screen = gdk_display_get_screen(display, 
wnck_screen_get_number(helper->screen));
+    xfce_workspaces_helper_set_names_prop(helper, screen, names);
+    g_strfreev(names);
 }

_______________________________________________
Xfce4-commits mailing list
Xfce4-commits@xfce.org
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to