Author: kelnos
Date: 2009-01-27 07:51:59 +0000 (Tue, 27 Jan 2009)
New Revision: 29403

Modified:
   xfce4-settings/trunk/xfce4-settings-helper/workspaces.c
Log:
revert nick's broken commit from r39342.  it breaks workspace name
setting, breaks libwnck api compat, and wasn't necessary anyway.

Modified: xfce4-settings/trunk/xfce4-settings-helper/workspaces.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/workspaces.c     2009-01-27 
00:53:45 UTC (rev 29402)
+++ xfce4-settings/trunk/xfce4-settings-helper/workspaces.c     2009-01-27 
07:51:59 UTC (rev 29403)
@@ -38,8 +38,7 @@
 {
     GObject parent;
 
-    WnckScreen *screen;
-
+    WnckScreen **screens;
     XfconfChannel *channel;
 };
 
@@ -51,7 +50,10 @@
 static void xfce_workspaces_helper_class_init(XfceWorkspacesHelperClass 
*klass);
 static void xfce_workspaces_helper_init(XfceWorkspacesHelper *helper);
 static void xfce_workspaces_helper_finalize(GObject *obj);
-static void xfce_workspaces_helper_set_workspace_names(XfceWorkspacesHelper 
*helper);
+
+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,
@@ -73,18 +75,55 @@
 static void
 xfce_workspaces_helper_init(XfceWorkspacesHelper *helper)
 {
+    gint w, s, n_screens, 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);
 
-    xfce_workspaces_helper_set_workspace_names(helper);
+    /* FIXME: need to do this for all screens? */
+    display = gdk_display_get_default();
+    n_screens = gdk_display_get_n_screens(display);
+    helper->screens = g_new0(WnckScreen *, n_screens + 1);
+    for(s = 0; s < n_screens; ++s) {
+        helper->screens[s] = wnck_screen_get(s);
+        wnck_screen_force_update(helper->screens[s]);
 
-    helper->screen = wnck_screen_get_default();
-    g_signal_connect_swapped(G_OBJECT(helper->screen), "workspace-created",
-                             
G_CALLBACK(xfce_workspaces_helper_update_all_names),
-                             helper);
-    g_signal_connect_swapped(G_OBJECT(helper->screen), "workspace-destroyed",
-                             
G_CALLBACK(xfce_workspaces_helper_update_all_names),
-                             helper);
+        if(s == 0) {
+            /* here we assume that all screens will always have the same
+             * number of workspaces, and any changes to this number will
+             * occur at the same time.  this may not be a great assumption,
+             * but it'll do. */
+            g_signal_connect_swapped(G_OBJECT(helper->screens[s]), 
"workspace-created",
+                                     
G_CALLBACK(xfce_workspaces_helper_update_all_names),
+                                     helper);
+            g_signal_connect_swapped(G_OBJECT(helper->screens[s]), 
"workspace-destroyed",
+                                     
G_CALLBACK(xfce_workspaces_helper_update_all_names),
+                                     helper);
+        }
 
+        n_workspaces = wnck_screen_get_workspace_count(helper->screens[s]);
+        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(w = g_strv_length(names); w < n_workspaces; ++w) {
+            /* some of them may not have been set in xfconf */
+            names[w] = g_strdup_printf(_("Workspace %d"), w + 1);
+        }
+        names[w] = NULL;
+
+        screen = gdk_display_get_screen(display, s);
+        xfce_workspaces_helper_set_names_prop(helper, screen, names);
+
+    }
+
+    g_strfreev(names);
+
     g_signal_connect(G_OBJECT(helper->channel),
                      "property-changed::" WORKSPACE_NAMES_PROP,
                      G_CALLBACK(xfce_workspaces_helper_prop_changed), helper);
@@ -95,82 +134,59 @@
 {
     XfceWorkspacesHelper *helper = XFCE_WORKSPACES_HELPER(obj);
 
-    g_signal_handlers_disconnect_by_func(G_OBJECT(helper->screen),
+    g_signal_handlers_disconnect_by_func(G_OBJECT(helper->channel),
+                                         
G_CALLBACK(xfce_workspaces_helper_prop_changed),
+                                         helper);
+    g_object_unref(G_OBJECT(helper->channel));
+
+    g_signal_handlers_disconnect_by_func(G_OBJECT(helper->screens[0]),
                                          
G_CALLBACK(xfce_workspaces_helper_update_all_names),
                                          helper);
+    g_free(helper->screens);
 
-    g_object_unref(G_OBJECT(helper->channel));
-
     G_OBJECT_CLASS(xfce_workspaces_helper_parent_class)->finalize(obj);
 }
 
+
+
 static void
-xfce_workspaces_helper_set_workspace_names(XfceWorkspacesHelper *helper)
+xfce_workspaces_helper_set_names_prop(XfceWorkspacesHelper *helper,
+                                      GdkScreen *screen,
+                                      gchar **names)
 {
-    WnckWorkspace *workspace;
-    WnckScreen *screen;
-    GList *li, *workspaces;
-    guint i, n_names;
-    gchar **names;
-    gint n_screens, n;
-    const gchar *name, *old_name;
-    gchar *tmp_name;
-    
-    /* get the workspace names */
-    names = xfconf_channel_get_string_list(helper->channel, 
WORKSPACE_NAMES_PROP);
-    n_names = names ? g_strv_length(names) : 0;
+    GString *names_str;
+    gint i;
 
-    /* walk all the displays on this screen */
-    /* FIXME? Is this really needed? */
-    n_screens = gdk_display_get_n_screens(gdk_display_get_default());
-    for(n = 0; n < n_screens; n++) {
-        /* get the wnck screen and force an update */
-        screen = wnck_screen_get(n);
-        wnck_screen_force_update(screen);
+    names_str = g_string_new(NULL);
 
-        /* walk all the workspaces on this screen */
-        workspaces = wnck_screen_get_workspaces(screen);
-        for(li = workspaces, i = 0; li != NULL; li = li->next, i++) {
-            workspace = WNCK_WORKSPACE(li->data);
+    for(i = 0; names[i]; ++i)
+        g_string_append_len(names_str, names[i], strlen(names[i]) + 1);
 
-            /* check if we have a valid name in the array */
-            if(n_names > i && names[i] != NULL && names[i] != '\0') {
-                name = names[i];
-                tmp_name = NULL;
-            } else {
-                tmp_name = g_strdup_printf(_("Workspace %d"), i + 1);
-                name = tmp_name;
-            }
+    gdk_error_trap_push();
 
-            /* update the workspace name if it has changed */
-            old_name = wnck_workspace_get_name(workspace);
-            if(old_name == NULL || strcmp(old_name, name) != 0)
-                wnck_workspace_change_name(workspace, name);
+    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();
 
-            /* cleanup */
-            g_free(tmp_name);
-        }
-    }
-    
-    /* cleanup */
-    g_strfreev(names);
+    gdk_error_trap_pop();
+
+    g_string_free(names_str, TRUE);
 }
 
 static void
 xfce_workspaces_helper_update_all_names(XfceWorkspacesHelper *helper)
 {
-    gint i, n_workspaces;
+    gint i, n_workspaces = wnck_screen_get_workspace_count(helper->screens[0]);
     gchar const **names;
-    WnckWorkspace *workspace;
 
-    g_return_if_fail (XFCE_IS_WORKSPACES_HELPER (helper));
-
-    n_workspaces = wnck_screen_get_workspace_count(helper->screen);
     names = g_new0(gchar const *, n_workspaces + 1);
 
     for(i = 0; i < n_workspaces; ++i) {
-        workspace = wnck_screen_get_workspace(helper->screen, i);
-        names[i] = wnck_workspace_get_name(workspace);
+        WnckWorkspace *space = wnck_screen_get_workspace(helper->screens[0], 
i);
+        names[i] = wnck_workspace_get_name(space);
     }
 
     xfconf_channel_set_string_list(helper->channel, WORKSPACE_NAMES_PROP,
@@ -186,6 +202,49 @@
                                     const GValue *value,
                                     gpointer user_data)
 {
-    g_return_if_fail (XFCE_IS_WORKSPACES_HELPER (user_data));
-    
xfce_workspaces_helper_set_workspace_names(XFCE_WORKSPACES_HELPER(user_data));
+    XfceWorkspacesHelper *helper = user_data;
+    GPtrArray *names_arr;
+    gint s, i, n_workspaces;
+    gchar **names;
+    GdkDisplay *display;
+    GdkScreen *screen;
+
+    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_arr = g_value_get_boxed(value);
+    if(!names_arr)
+        return;
+
+    display = gdk_display_get_default();
+
+    for(s = 0; helper->screens[s]; ++s) {
+        wnck_screen_force_update(helper->screens[s]);
+        n_workspaces = wnck_screen_get_workspace_count(helper->screens[s]);
+        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;
+        }
+
+        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);
+        }
+
+        screen = gdk_display_get_screen(display, s);
+        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