Author: kelnos
Date: 2008-09-14 10:19:15 +0000 (Sun, 14 Sep 2008)
New Revision: 27860

Added:
   xfce4-settings/trunk/xfce4-settings-helper/workspaces.c
   xfce4-settings/trunk/xfce4-settings-helper/workspaces.h
Modified:
   xfce4-settings/trunk/configure.ac.in
   xfce4-settings/trunk/xfce4-settings-helper/Makefile.am
   xfce4-settings/trunk/xfce4-settings-helper/main.c
Log:
add workspaces helper to set names of workspaces

Modified: xfce4-settings/trunk/configure.ac.in
===================================================================
--- xfce4-settings/trunk/configure.ac.in        2008-09-14 10:19:02 UTC (rev 
27859)
+++ xfce4-settings/trunk/configure.ac.in        2008-09-14 10:19:15 UTC (rev 
27860)
@@ -83,6 +83,7 @@
 XDT_CHECK_PACKAGE([XI], [xi], [1.0.0])
 XDT_CHECK_PACKAGE([LIBX11], [x11], [1.0.0])
 XDT_CHECK_PACKAGE([XRANDR], [xrandr], [1.1.0])
+XDT_CHECK_PACKAGE([LIBWNCK], [libwnck-1.0], [2.12.0])
 
 dnl **************************************
 dnl *** Optional support for Libnotify ***

Modified: xfce4-settings/trunk/xfce4-settings-helper/Makefile.am
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/Makefile.am      2008-09-14 
10:19:02 UTC (rev 27859)
+++ xfce4-settings/trunk/xfce4-settings-helper/Makefile.am      2008-09-14 
10:19:15 UTC (rev 27860)
@@ -7,6 +7,7 @@
        -DSRCDIR=\"$(top_srcdir)\" \
        -DLOCALEDIR=\"$(localedir)\" \
        -DG_LOG_DOMAIN=\"xfce4-settings-helper\" \
+       -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
        $(PLATFORM_CPPFLAGS)
 
 bin_PROGRAMS = \
@@ -25,7 +26,9 @@
        frap-shortcuts.c \
        frap-shortcuts.h \
        pointers.c \
-       pointers.h
+       pointers.h \
+       workspaces.c \
+       workspaces.h
 
 xfce4_settings_helper_CFLAGS = \
        $(GTK_CFLAGS) \
@@ -38,7 +41,9 @@
        $(XI_CFLAGS) \
        $(LIBX11_CFLAGS) \
        $(XRANDR_CFLAGS) \
-       $(LIBNOTIFY_CFLAGS)
+       $(LIBNOTIFY_CFLAGS) \
+       $(LIBWNCK_CFLAGS) \
+       $(PLATFORM_CFLAGS)
 
 xfce4_settings_helper_LDFLAGS = \
        -no-undefined \
@@ -55,7 +60,8 @@
        $(XI_LIBS) \
        $(LIBX11_LIBS) \
        $(XRANDR_LIBS) \
-       $(LIBNOTIFY_LIBS)
+       $(LIBNOTIFY_LIBS) \
+       $(LIBWNCK_LIBS)
 
 autostartdir = $(sysconfdir)/xdg/autostart
 autostart_DATA = xfce4-settings-helper-autostart.desktop

Modified: xfce4-settings/trunk/xfce4-settings-helper/main.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/main.c   2008-09-14 10:19:02 UTC 
(rev 27859)
+++ xfce4-settings/trunk/xfce4-settings-helper/main.c   2008-09-14 10:19:15 UTC 
(rev 27860)
@@ -47,6 +47,7 @@
 #include "pointers.h"
 #include "keyboards.h"
 #include "keyboard-shortcuts.h"
+#include "workspaces.h"
 
 
 
@@ -79,6 +80,7 @@
     GObject    *accessibility_helper;
     GObject    *shortcuts_helper;
     GObject    *displays_helper;
+    GObject    *workspaces_helper;
     pid_t       pid;
     guint       i;
     const gint  signums[] = { SIGHUP, SIGINT, SIGQUIT, SIGTERM };
@@ -157,6 +159,7 @@
     accessibility_helper = g_object_new (XFCE_TYPE_ACCESSIBILITY_HELPER, NULL);
     shortcuts_helper = g_object_new (XFCE_TYPE_KEYBOARD_SHORTCUTS_HELPER, 
NULL);
     displays_helper = g_object_new (XFCE_TYPE_DISPLAYS_HELPER, NULL);
+    workspaces_helper = g_object_new (XFCE_TYPE_WORKSPACES_HELPER, NULL);
 
     /* setup signal handlers to properly quit the main loop */
     for (i = 0; i < G_N_ELEMENTS (signums); i++)
@@ -171,6 +174,7 @@
     g_object_unref (G_OBJECT (accessibility_helper));
     g_object_unref (G_OBJECT (shortcuts_helper));
     g_object_unref (G_OBJECT (displays_helper));
+    g_object_unref (G_OBJECT (workspaces_helper));
 
     /* shutdown xfconf */
     xfconf_shutdown ();

Added: xfce4-settings/trunk/xfce4-settings-helper/workspaces.c
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/workspaces.c                     
        (rev 0)
+++ xfce4-settings/trunk/xfce4-settings-helper/workspaces.c     2008-09-14 
10:19:15 UTC (rev 27860)
@@ -0,0 +1,199 @@
+/*
+ *  Copyright (c) 2008 Brian Tarricone <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License ONLY.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <dbus/dbus-glib.h>
+#include <xfconf/xfconf.h>
+#include <libxfce4util/libxfce4util.h>
+#include <libwnck/libwnck.h>
+
+#include "workspaces.h"
+
+#define WORKSPACES_CHANNEL    "xfwm4"
+#define WORKSPACE_NAMES_PROP  "/general/workspace_names"
+
+
+struct _XfceWorkspacesHelper
+{
+    GObject parent;
+
+    WnckScreen *screen;
+    XfconfChannel *channel;
+};
+
+typedef struct _XfceWorkspacesHelperClass
+{
+    GObjectClass parent;
+} XfceWorkspacesHelperClass;
+
+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_update_all_names(XfceWorkspacesHelper 
*helper);
+static void xfce_workspaces_helper_prop_changed(XfconfChannel *channel,
+                                                const gchar *property,
+                                                const GValue *value,
+                                                gpointer user_data);
+
+
+G_DEFINE_TYPE(XfceWorkspacesHelper, xfce_workspaces_helper, G_TYPE_OBJECT)
+
+
+static void
+xfce_workspaces_helper_class_init(XfceWorkspacesHelperClass *klass)
+{
+    GObjectClass *gobject_class = (GObjectClass *)klass;
+
+    gobject_class->finalize = xfce_workspaces_helper_finalize;
+}
+
+static void
+xfce_workspaces_helper_init(XfceWorkspacesHelper *helper)
+{
+    WnckWorkspace *space;
+    gint i, n_workspaces;
+    gchar **names;
+
+    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);
+    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);
+
+    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) {
+        /* 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,
+                                       names);
+    }
+
+    g_signal_connect(G_OBJECT(helper->channel),
+                     "property-changed::" WORKSPACE_NAMES_PROP,
+                     G_CALLBACK(xfce_workspaces_helper_prop_changed), helper);
+
+    g_strfreev(names);
+}
+
+static void
+xfce_workspaces_helper_finalize(GObject *obj)
+{
+    XfceWorkspacesHelper *helper = XFCE_WORKSPACES_HELPER(obj);
+
+    g_signal_handlers_disconnect_by_func(G_OBJECT(helper->screen),
+                                         
G_CALLBACK(xfce_workspaces_helper_update_all_names),
+                                         helper);
+
+    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_OBJECT_CLASS(xfce_workspaces_helper_parent_class)->finalize(obj);
+}
+
+
+
+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));
+
+    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,
+                                   (gchar * const *)names);
+
+    g_free(names);
+}
+
+static void
+xfce_workspaces_helper_prop_changed(XfconfChannel *channel,
+                                    const gchar *property,
+                                    const GValue *value,
+                                    gpointer user_data)
+{
+    XfceWorkspacesHelper *helper = user_data;
+    GPtrArray *names;
+    gint i, n_workspaces = wnck_screen_get_workspace_count(helper->screen);
+
+    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)
+        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;
+
+        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;
+        }
+
+        /* 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);
+    }
+}

Added: xfce4-settings/trunk/xfce4-settings-helper/workspaces.h
===================================================================
--- xfce4-settings/trunk/xfce4-settings-helper/workspaces.h                     
        (rev 0)
+++ xfce4-settings/trunk/xfce4-settings-helper/workspaces.h     2008-09-14 
10:19:15 UTC (rev 27860)
@@ -0,0 +1,35 @@
+/*
+ *  Copyright (c) 2008 Brian Tarricone <[EMAIL PROTECTED]>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; version 2 of the License ONLY.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
USA
+ */
+
+#ifndef __WORKSPACES_H__
+#define __WORKSPACES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define XFCE_TYPE_WORKSPACES_HELPER     (xfce_workspaces_helper_get_type())
+#define XFCE_WORKSPACES_HELPER(obj)     (G_TYPE_CHECK_INSTANCE_CAST((obj), 
XFCE_TYPE_WORKSPACES_HELPER, XfceWorkspacesHelper))
+#define XFCE_IS_WORKSPACES_HELPER(obj)  (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
XFCE_TYPE_WORKSPACES_HELPER))
+
+typedef struct _XfceWorkspacesHelper  XfceWorkspacesHelper;
+
+GType xfce_workspaces_helper_get_type() G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __WORKSPACES_H__ */

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to