[Xfce4-commits] <xfdesktop:master> Apply wallpaper to all workspaces option

Eric Koegel noreply at xfce.org
Sun Aug 4 10:36:06 CEST 2013


Updating branch refs/heads/master
         to f51d49ec663ae59c3c5c357eedd9c378a1fdfd13 (commit)
       from c4a10cc1524490d35a6afd7aa67cdd57c59729b8 (commit)

commit f51d49ec663ae59c3c5c357eedd9c378a1fdfd13
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Sun Mar 10 11:31:45 2013 +0300

    Apply wallpaper to all workspaces option

 common/xfdesktop-common.h                          |    3 +
 settings/main.c                                    |   83 ++++++++++--
 .../xfdesktop-settings-appearance-frame-ui.glade   |   15 +++
 src/xfce-desktop.c                                 |  132 ++++++++++++++++++--
 4 files changed, 214 insertions(+), 19 deletions(-)

diff --git a/common/xfdesktop-common.h b/common/xfdesktop-common.h
index 5334ba8..b34d7b5 100644
--- a/common/xfdesktop-common.h
+++ b/common/xfdesktop-common.h
@@ -49,6 +49,9 @@
 #define ARRANGE_MESSAGE    "arrange"
 #define QUIT_MESSAGE       "quit"
 
+#define SINGLE_WORKSPACE_MODE     "/backdrop/single-workspace-mode"
+#define SINGLE_WORKSPACE_NUMBER   "/backdrop/single-workspace-number"
+
 /**
  * File information namespaces queried for #GFileInfo objects.
  */
diff --git a/settings/main.c b/settings/main.c
index f82bd7c..95ced14 100644
--- a/settings/main.c
+++ b/settings/main.c
@@ -96,6 +96,8 @@ typedef struct
     gchar *monitor_name;
     gulong image_list_loaded:1;
 
+    WnckWindow *wnck_window;
+
     GtkWidget *frame_image_list;
     GtkWidget *image_iconview;
     GtkWidget *btn_folder;
@@ -674,6 +676,35 @@ cb_image_selection_changed(GtkIconView *icon_view,
     g_free(buf);
 }
 
+static gint
+xfdesktop_settings_get_active_workspace(AppearancePanel *panel,
+                                        WnckWindow *wnck_window)
+{
+    WnckWorkspace *wnck_workspace;
+    gboolean single_workspace;
+    gint workspace_num, active_workspace;
+
+    wnck_workspace = wnck_window_get_workspace(wnck_window);
+
+    workspace_num = wnck_workspace_get_number(wnck_workspace);
+
+    single_workspace = xfconf_channel_get_bool(panel->channel,
+                                               SINGLE_WORKSPACE_MODE,
+                                               TRUE);
+
+    /* If we're in single_workspace mode we need to return the workspace that
+     * it was set to, otherwise return the current workspace */
+    if(single_workspace) {
+        active_workspace = xfconf_channel_get_int(panel->channel,
+                                                  SINGLE_WORKSPACE_NUMBER,
+                                                  0);
+    } else {
+        active_workspace = workspace_num;
+    }
+
+    return active_workspace;
+}
+
 static void
 cb_xfdesktop_chk_custom_font_size_toggled(GtkCheckButton *button,
                                           gpointer user_data)
@@ -1013,7 +1044,7 @@ cb_update_background_tab(WnckWindow *wnck_window,
     screen = gtk_widget_get_screen(panel->image_iconview);
     wnck_workspace = wnck_window_get_workspace(wnck_window);
 
-    workspace_num = wnck_workspace_get_number(wnck_workspace);
+    workspace_num = xfdesktop_settings_get_active_workspace(panel, wnck_window);
     screen_num = gdk_screen_get_number(screen);
     monitor_num = gdk_screen_get_monitor_at_window(screen,
                                                    gtk_widget_get_window(panel->image_iconview));
@@ -1062,6 +1093,29 @@ cb_update_background_tab(WnckWindow *wnck_window,
 }
 
 static void
+cb_xfdesktop_chk_apply_to_all(GtkCheckButton *button,
+                              gpointer user_data)
+{
+    AppearancePanel *panel = user_data;
+    gboolean active;
+    active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
+
+    TRACE("entering");
+
+    xfconf_channel_set_bool(panel->channel,
+                            SINGLE_WORKSPACE_MODE,
+                            active);
+
+    if(active) {
+        xfconf_channel_set_int(panel->channel,
+                               SINGLE_WORKSPACE_NUMBER,
+                               panel->workspace);
+    } else {
+        cb_update_background_tab(panel->wnck_window, panel);
+    }
+}
+
+static void
 xfdesktop_settings_setup_image_iconview(AppearancePanel *panel)
 {
     GtkIconView *iconview = GTK_ICON_VIEW(panel->image_iconview);
@@ -1093,13 +1147,12 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
     GtkWidget *appearance_container, *chk_custom_font_size,
               *spin_font_size, *w, *box, *spin_icon_size,
               *chk_show_thumbnails, *chk_single_click, *appearance_settings,
-              *bnt_exit;
+              *bnt_exit, *chk_apply_to_all;
     GtkBuilder *appearance_gxml;
     AppearancePanel *panel = g_new0(AppearancePanel, 1);
     GError *error = NULL;
     GtkFileFilter *filter;
     WnckScreen *wnck_screen;
-    WnckWindow *wnck_window = NULL;
 
     TRACE("entering");
 
@@ -1156,16 +1209,16 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
     /* We have to force wnck to initialize */
     wnck_screen = wnck_screen_get(panel->screen);
     wnck_screen_force_update(wnck_screen);
-    wnck_window = wnck_window_get(window_xid);
+    panel->wnck_window = wnck_window_get(window_xid);
 
-    if(wnck_window == NULL)
-        wnck_window = wnck_screen_get_active_window(wnck_screen);
+    if(panel->wnck_window == NULL)
+        panel->wnck_window = wnck_screen_get_active_window(wnck_screen);
 
     /* These callbacks are for updating the image_iconview when the window
      * moves to another monitor or workspace */
-    g_signal_connect(wnck_window, "geometry-changed",
+    g_signal_connect(panel->wnck_window, "geometry-changed",
                      G_CALLBACK(cb_update_background_tab), panel);
-    g_signal_connect(wnck_window, "workspace-changed",
+    g_signal_connect(panel->wnck_window, "workspace-changed",
                      G_CALLBACK(cb_update_background_tab), panel);
 
     /* send invalid numbers so that the update_background_tab will update everything */
@@ -1236,6 +1289,18 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
     gtk_combo_box_set_active(GTK_COMBO_BOX(panel->image_style_combo), 0);
     gtk_combo_box_set_active(GTK_COMBO_BOX(panel->color_style_combo), 0);
 
+    /* Use these settings for all workspaces checkbox */
+    chk_apply_to_all =  GTK_WIDGET(gtk_builder_get_object(appearance_gxml,
+                                                          "chk_apply_to_all"));
+
+    if(xfconf_channel_get_bool(channel, SINGLE_WORKSPACE_MODE, TRUE)) {
+        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_apply_to_all), TRUE);
+    }
+
+    g_signal_connect(G_OBJECT(chk_apply_to_all), "toggled",
+                    G_CALLBACK(cb_xfdesktop_chk_apply_to_all),
+                    panel);
+
     /* background cycle timer */
     panel->backdrop_cycle_chkbox = GTK_WIDGET(gtk_builder_get_object(appearance_gxml,
                                                                      "chk_cycle_backdrop"));
@@ -1318,7 +1383,7 @@ xfdesktop_settings_dialog_setup_tabs(GtkBuilder *main_gxml,
                            "active");
 
     setup_special_icon_list(main_gxml, channel);
-    cb_update_background_tab(wnck_window, panel);
+    cb_update_background_tab(panel->wnck_window, panel);
 }
 
 static void
diff --git a/settings/xfdesktop-settings-appearance-frame-ui.glade b/settings/xfdesktop-settings-appearance-frame-ui.glade
index ee8e334..b928932 100644
--- a/settings/xfdesktop-settings-appearance-frame-ui.glade
+++ b/settings/xfdesktop-settings-appearance-frame-ui.glade
@@ -215,6 +215,21 @@
                 <property name="expand">False</property>
               </packing>
             </child>
+            <child>
+              <object class="GtkCheckButton" id="chk_apply_to_all">
+                <property name="visible">True</property>
+                <property name="sensitive">True</property>
+                <property name="can_focus">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="label" translatable="yes">_Use these settings for all workspaces</property>
+                <property name="use_underline">True</property>
+                <property name="draw_indicator">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="pack-type">GTK_PACK_END</property>
+              </packing>
+            </child>
           </object>
           <packing>
             <property name="expand">False</property>
diff --git a/src/xfce-desktop.c b/src/xfce-desktop.c
index 6e12456..11df13d 100644
--- a/src/xfce-desktop.c
+++ b/src/xfce-desktop.c
@@ -101,7 +101,10 @@ struct _XfceDesktopPriv
     gint nworkspaces;
     XfceWorkspace **workspaces;
     gint current_workspace;
-    
+
+    gboolean single_workspace_mode;
+    gint single_workspace_num;
+
     SessionLogoutFunc session_logout_func;
     
 #ifdef ENABLE_DESKTOP_ICONS
@@ -130,6 +133,8 @@ enum
     PROP_ICON_FONT_SIZE,
     PROP_ICON_FONT_SIZE_SET,
 #endif
+    PROP_SINGLE_WORKSPACE_MODE,
+    PROP_SINGLE_WORKSPACE_NUMBER,
 };
 
 
@@ -156,6 +161,12 @@ static gboolean xfce_desktop_delete_event(GtkWidget *w,
 static void xfce_desktop_style_set(GtkWidget *w,
                                    GtkStyle *old_style);
 
+static void xfce_desktop_set_single_workspace_mode(XfceDesktop *desktop,
+                                                   gboolean single_workspace);
+static void xfce_desktop_set_single_workspace_number(XfceDesktop *desktop,
+                                                     gint workspace_num);
+
+static gboolean xfce_desktop_get_single_workspace_mode(XfceDesktop *desktop);
 static gint xfce_desktop_get_current_workspace(XfceDesktop *desktop);
 
 static guint signals[N_SIGNALS] = { 0, };
@@ -471,7 +482,7 @@ workspace_backdrop_changed_cb(XfceWorkspace *workspace,
 
     g_return_if_fail(XFCE_IS_WORKSPACE(workspace) && XFCE_IS_BACKDROP(backdrop));
 
-    if(desktop->priv->current_workspace == xfce_workspace_get_workspace_num(workspace))
+    if(xfce_desktop_get_current_workspace(desktop) == xfce_workspace_get_workspace_num(workspace))
         backdrop_changed_cb(backdrop, user_data);
 }
 
@@ -481,15 +492,17 @@ workspace_changed_cb(WnckScreen *wnck_screen,
                      gpointer user_data)
 {
     XfceDesktop *desktop = XFCE_DESKTOP(user_data);
-    WnckWorkspace *wnck_workspace = wnck_screen_get_active_workspace(wnck_screen);
     gint current_workspace, new_workspace, i;
     XfceBackdrop *current_backdrop, *new_backdrop;
 
     TRACE("entering");
 
     current_workspace = desktop->priv->current_workspace;
-    new_workspace = wnck_workspace_get_number(wnck_workspace);
-    desktop->priv->current_workspace = new_workspace;
+    desktop->priv->current_workspace = xfce_desktop_get_current_workspace(desktop);
+    new_workspace = desktop->priv->current_workspace;
+
+    DBG("current_workspace %d, new_workspace %d",
+        current_workspace, new_workspace);
 
     /* special case for the spanning screen option */
     if(xfce_workspace_get_xinerama_stretch(desktop->priv->workspaces[new_workspace])) {
@@ -711,6 +724,20 @@ xfce_desktop_class_init(XfceDesktopClass *klass)
                                                          "icon font size set",
                                                          FALSE,
                                                          XFDESKTOP_PARAM_FLAGS));
+
+    g_object_class_install_property(gobject_class, PROP_SINGLE_WORKSPACE_MODE,
+                                    g_param_spec_boolean("single-workspace-mode",
+                                                         "single-workspace-mode",
+                                                         "single-workspace-mode",
+                                                         TRUE,
+                                                         XFDESKTOP_PARAM_FLAGS));
+
+    g_object_class_install_property(gobject_class, PROP_SINGLE_WORKSPACE_NUMBER,
+                                    g_param_spec_int("single-workspace-number",
+                                                     "single-workspace-number",
+                                                     "single-workspace-number",
+                                                     0, 31, 0,
+                                                     XFDESKTOP_PARAM_FLAGS));
 #endif
 #undef XFDESKTOP_PARAM_FLAGS
 }
@@ -768,6 +795,16 @@ xfce_desktop_set_property(GObject *object,
             break;
 
 #endif
+        case PROP_SINGLE_WORKSPACE_MODE:
+            xfce_desktop_set_single_workspace_mode(desktop,
+                                                   g_value_get_boolean(value));
+            break;
+
+        case PROP_SINGLE_WORKSPACE_NUMBER:
+            xfce_desktop_set_single_workspace_number(desktop,
+                                                     g_value_get_int(value));
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
             break;
@@ -801,6 +838,14 @@ xfce_desktop_get_property(GObject *object,
             break;
 
 #endif
+        case PROP_SINGLE_WORKSPACE_MODE:
+            g_value_set_boolean(value, desktop->priv->single_workspace_mode);
+            break;
+
+        case PROP_SINGLE_WORKSPACE_NUMBER:
+            g_value_set_int(value, desktop->priv->single_workspace_num);
+            break;
+
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
             break;
@@ -816,7 +861,6 @@ xfce_desktop_realize(GtkWidget *widget)
     Window xid;
     GdkWindow *groot;
     WnckScreen *wnck_screen;
-    WnckWorkspace *wnck_workspace;
     
     TRACE("entering");
 
@@ -866,9 +910,16 @@ xfce_desktop_realize(GtkWidget *widget)
     wnck_screen_force_update(wnck_screen);
     desktop->priv->wnck_screen = wnck_screen;
 
+    xfconf_g_property_bind(desktop->priv->channel,
+                           SINGLE_WORKSPACE_MODE, G_TYPE_BOOLEAN,
+                           G_OBJECT(desktop), "single-workspace-mode");
+
+    xfconf_g_property_bind(desktop->priv->channel,
+                           SINGLE_WORKSPACE_NUMBER, G_TYPE_INT,
+                           G_OBJECT(desktop), "single-workspace-number");
+
     /* Get the current workspace number */
-    wnck_workspace = wnck_screen_get_active_workspace(wnck_screen);
-    desktop->priv->current_workspace = wnck_workspace_get_number(wnck_workspace);
+    desktop->priv->current_workspace = xfce_desktop_get_current_workspace(desktop);
     desktop->priv->nworkspaces = wnck_screen_get_workspace_count(wnck_screen);
 
     desktop->priv->workspaces = g_realloc(desktop->priv->workspaces,
@@ -1113,12 +1164,37 @@ xfce_desktop_connect_settings(XfceDesktop *desktop)
     xfce_desktop_thaw_updates(desktop);
 }
 
+static gboolean
+xfce_desktop_get_single_workspace_mode(XfceDesktop *desktop)
+{
+    g_return_val_if_fail(XFCE_IS_DESKTOP(desktop), TRUE);
+
+    return desktop->priv->single_workspace_mode;
+}
+
 static gint
 xfce_desktop_get_current_workspace(XfceDesktop *desktop)
 {
+    WnckWorkspace *wnck_workspace;
+    gint workspace_num, current_workspace;
+
     g_return_val_if_fail(XFCE_IS_DESKTOP(desktop), -1);
 
-    return desktop->priv->current_workspace;
+    wnck_workspace = wnck_screen_get_active_workspace(desktop->priv->wnck_screen);
+    workspace_num = wnck_workspace_get_number(wnck_workspace);
+
+    /* If we're in single_workspace mode we need to return the workspace that
+     * it was set to, otherwise return the current workspace */
+    if(xfce_desktop_get_single_workspace_mode(desktop)) {
+        current_workspace = desktop->priv->single_workspace_num;
+    } else {
+        current_workspace = workspace_num;
+    }
+
+    DBG("workspace_num %d, single_workspace_num %d, current_workspace %d",
+        workspace_num, desktop->priv->single_workspace_num, current_workspace);
+
+    return current_workspace;
 }
 
 /* public api */
@@ -1279,6 +1355,42 @@ xfce_desktop_set_use_icon_font_size(XfceDesktop *desktop,
 #endif
 }
 
+static void
+xfce_desktop_set_single_workspace_mode(XfceDesktop *desktop,
+                                       gboolean single_workspace)
+{
+    g_return_if_fail(XFCE_IS_DESKTOP(desktop));
+
+    if(single_workspace == desktop->priv->single_workspace_mode)
+        return;
+
+    desktop->priv->single_workspace_mode = single_workspace;
+
+    DBG("single_workspace_mode now %s", single_workspace ? "TRUE" : "FALSE");
+
+    /* Fake a screen size changed to update the backdrop */
+    screen_size_changed_cb(desktop->priv->gscreen, desktop);
+}
+
+static void
+xfce_desktop_set_single_workspace_number(XfceDesktop *desktop,
+                                         gint workspace_num)
+{
+    g_return_if_fail(XFCE_IS_DESKTOP(desktop));
+
+    if(workspace_num == desktop->priv->single_workspace_num)
+        return;
+
+    DBG("single_workspace_num now %d", workspace_num);
+
+    desktop->priv->single_workspace_num = workspace_num;
+
+    if(xfce_desktop_get_single_workspace_mode(desktop)) {
+        /* Fake a screen size changed to update the backdrop */
+        screen_size_changed_cb(desktop->priv->gscreen, desktop);
+    }
+}
+
 void
 xfce_desktop_set_session_logout_func(XfceDesktop *desktop,
                                      SessionLogoutFunc logout_func)
@@ -1386,7 +1498,7 @@ xfce_desktop_refresh(XfceDesktop *desktop)
     if(!gtk_widget_get_realized(GTK_WIDGET(desktop)))
         return;
 
-    current_workspace = desktop->priv->current_workspace;
+    current_workspace = xfce_desktop_get_current_workspace(desktop);
 
     /* reload backgrounds */
     for(i = 0; i < xfce_desktop_get_n_monitors(desktop); i++) {


More information about the Xfce4-commits mailing list