[Xfce4-commits] <xfce4-panel:devel> * Add preferences dialog to the pager plugin and make it work.
Nick Schermer
nick at xfce.org
Tue Aug 11 20:26:25 CEST 2009
Updating branch refs/heads/devel
to 40e21cfae3875cca9e1a0c00c34a6c7dafca81b5 (commit)
from 2eeaa3c7f3dbe62fa732c68469bba4eeedd000c1 (commit)
commit 40e21cfae3875cca9e1a0c00c34a6c7dafca81b5
Author: Nick Schermer <nick at xfce.org>
Date: Thu Dec 11 19:42:16 2008 +0100
* Add preferences dialog to the pager plugin and make it work.
plugins/pager/Makefile.am | 16 +++
.../pager-dialog.glade} | 105 +++++++++++------
plugins/pager/pager.c | 126 +++++++++++++++++++-
3 files changed, 208 insertions(+), 39 deletions(-)
diff --git a/plugins/pager/Makefile.am b/plugins/pager/Makefile.am
index 92d9c24..2d26973 100644
--- a/plugins/pager/Makefile.am
+++ b/plugins/pager/Makefile.am
@@ -13,7 +13,11 @@ plugindir = \
plugin_LTLIBRARIES = \
libpager.la
+libpager_built_sources = \
+ pager-dialog_glade.h
+
libpager_la_SOURCES = \
+ $(libpager_built_sources) \
pager.c \
pager.h
@@ -42,6 +46,17 @@ libpager_la_LIBADD = \
libpager_la_DEPENDENCIES = \
$(top_builddir)/libxfce4panel/libxfce4panel.la
+if MAINTAINER_MODE
+BUILT_SOURCES = \
+ $(libpager_built_sources)
+
+DISTCLEANFILES = \
+ $(libpager_built_sources)
+
+pager-dialog_glade.h: pager-dialog.glade
+ exo-csource --static --strip-comments --strip-content --name=pager_dialog_glade $< >$@
+endif
+
#
# .desktop file
#
@@ -54,6 +69,7 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@INTLTOOL_DESKTOP_RULE@
EXTRA_DIST = \
+ pager-dialog.glade \
$(desktop_in_in_files)
DISTCLEANFILES = \
diff --git a/plugins/systray/systray-dialog.glade b/plugins/pager/pager-dialog.glade
similarity index 65%
copy from plugins/systray/systray-dialog.glade
copy to plugins/pager/pager-dialog.glade
index 5dfbbb2..49e58e2 100644
--- a/plugins/systray/systray-dialog.glade
+++ b/plugins/pager/pager-dialog.glade
@@ -1,10 +1,10 @@
<?xml version="1.0"?>
<interface>
- <requires lib="gtk+" version="2.14"/>
+ <!-- interface-requires gtk+ 2.12 -->
<!-- interface-requires xfce4 0.0 -->
<!-- interface-naming-policy toplevel-contextual -->
<object class="XfceTitledDialog" id="dialog">
- <property name="title" translatable="yes">Notification Area Properties</property>
+ <property name="title" translatable="yes">Pager Properties</property>
<property name="icon_name">gtk-properties</property>
<property name="type_hint">normal</property>
<property name="has_separator">False</property>
@@ -13,36 +13,35 @@
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
- <object class="GtkVBox" id="vbox1">
+ <object class="GtkVBox" id="vbox2">
<property name="visible">True</property>
<property name="border_width">6</property>
<property name="spacing">6</property>
<child>
- <object class="GtkFrame" id="frame3">
+ <object class="GtkFrame" id="frame2">
<property name="visible">True</property>
+ <property name="border_width">6</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
- <object class="GtkAlignment" id="alignment3">
+ <object class="GtkAlignment" id="alignment2">
<property name="visible">True</property>
- <property name="bottom_padding">6</property>
- <property name="left_padding">12</property>
+ <property name="top_padding">6</property>
+ <property name="bottom_padding">12</property>
+ <property name="left_padding">18</property>
+ <property name="right_padding">6</property>
<child>
- <object class="GtkVBox" id="vbox2">
+ <object class="GtkVBox" id="vbox4">
<property name="visible">True</property>
- <property name="border_width">6</property>
<property name="spacing">6</property>
<child>
- <object class="GtkHBox" id="hbox1">
+ <object class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
- <object class="GtkLabel" id="label2">
+ <object class="GtkLabel" id="label4">
<property name="visible">True</property>
- <property name="xalign">0</property>
- <property name="label" translatable="yes">_Number of rows:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">style-num-rows</property>
+ <property name="label" translatable="yes">Number of rows:</property>
</object>
<packing>
<property name="expand">False</property>
@@ -50,10 +49,13 @@
</packing>
</child>
<child>
- <object class="GtkSpinButton" id="style-num-rows">
+ <object class="GtkSpinButton" id="spin1">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="adjustment">rows</property>
+ <property name="snap_to_ticks">True</property>
<property name="numeric">True</property>
+ <property name="update_policy">if-valid</property>
</object>
<packing>
<property name="expand">False</property>
@@ -66,24 +68,42 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="style-show-frame">
+ <object class="GtkCheckButton" id="show-names">
+ <property name="label" translatable="yes">Show workspace names</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_underline">True</property>
<property name="draw_indicator">True</property>
- <property name="label" translatable="yes">Show _frame</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkAlignment" id="alignment1">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="xscale">0</property>
+ <child>
+ <object class="GtkButton" id="settings-button">
+ <property name="label" translatable="yes">Workspace Settings...</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="image">image1</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">2</property>
+ </packing>
+ </child>
</object>
</child>
</object>
</child>
<child type="label">
- <object class="GtkLabel" id="label1">
+ <object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="label" translatable="yes"><b>Appearance</b></property>
<property name="use_markup">True</property>
@@ -96,41 +116,39 @@
</packing>
</child>
<child>
- <object class="GtkFrame" id="frame1">
+ <object class="GtkFrame" id="frame3">
<property name="visible">True</property>
+ <property name="border_width">6</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
- <object class="GtkAlignment" id="alignment1">
+ <object class="GtkAlignment" id="alignment3">
<property name="visible">True</property>
<property name="top_padding">6</property>
- <property name="left_padding">12</property>
+ <property name="bottom_padding">12</property>
+ <property name="left_padding">18</property>
+ <property name="right_padding">6</property>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow1">
+ <object class="GtkCheckButton" id="workspace-scrolling">
+ <property name="label" translatable="yes">Switch workspaces using the mouse wheel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="hscrollbar_policy">automatic</property>
- <property name="vscrollbar_policy">automatic</property>
- <property name="shadow_type">in</property>
- <child>
- <object class="GtkTreeView" id="applications-treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- </object>
- </child>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
</object>
</child>
</object>
</child>
<child type="label">
- <object class="GtkLabel" id="label3">
+ <object class="GtkLabel" id="label7">
<property name="visible">True</property>
- <property name="label" translatable="yes"><b>Known Applications</b></property>
+ <property name="label" translatable="yes"><b>Behaviour</b></property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
+ <property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
@@ -145,12 +163,11 @@
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="close-button">
+ <property name="label" translatable="yes">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
- <property name="response_id">0</property>
- <property name="label" translatable="yes">gtk-close</property>
</object>
<packing>
<property name="position">0</property>
@@ -165,5 +182,19 @@
</child>
</object>
</child>
+ <action-widgets>
+ <action-widget response="0">close-button</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="icon_name">xfce4-workspaces</property>
+ </object>
+ <object class="GtkAdjustment" id="rows">
+ <property name="value">1</property>
+ <property name="lower">1</property>
+ <property name="upper">10</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
</object>
</interface>
diff --git a/plugins/pager/pager.c b/plugins/pager/pager.c
index bd8cb20..7c1be93 100644
--- a/plugins/pager/pager.c
+++ b/plugins/pager/pager.c
@@ -25,10 +25,12 @@
#include <gtk/gtk.h>
#include <libxfce4panel/libxfce4panel.h>
#include <libxfce4util/libxfce4util.h>
+#include <libxfce4ui/libxfce4ui.h>
#include <xfconf/xfconf.h>
#include <libwnck/libwnck.h>
#include "pager.h"
+#include "pager-dialog_glade.h"
@@ -183,11 +185,17 @@ pager_plugin_screen_changed (GtkWidget *widget,
/* only update if the screen changed */
if (plugin->wnck_screen != wnck_screen)
{
+ /* destroy the existing pager */
+ if (G_UNLIKELY (plugin->wnck_pager != NULL))
+ gtk_widget_destroy (GTK_WIDGET (plugin->wnck_pager));
+
/* set the new screen */
plugin->wnck_screen = wnck_screen;
/* create the wnck pager */
plugin->wnck_pager = wnck_pager_new (wnck_screen);
+ gtk_container_add (GTK_CONTAINER (widget), plugin->wnck_pager);
+ gtk_widget_show (plugin->wnck_pager);
/* set the pager properties */
wnck_pager_set_display_mode (WNCK_PAGER (plugin->wnck_pager),
@@ -262,7 +270,72 @@ pager_plugin_save (XfcePanelPlugin *panel_plugin)
/* store settings */
xfconf_channel_set_bool (plugin->channel, "/workspace-scrolling", plugin->scrolling);
xfconf_channel_set_bool (plugin->channel, "/show-names", plugin->show_names);
- xfconf_channel_set_int (plugin->channel, "/rows", plugin->rows);
+ xfconf_channel_set_uint (plugin->channel, "/rows", plugin->rows);
+}
+
+
+
+static void
+pager_plugin_configure_workspace_settings (GtkWidget *button)
+{
+ GdkScreen *screen;
+ GError *error = NULL;
+
+ panel_return_if_fail (GTK_IS_WIDGET (button));
+
+ /* get the screen */
+ screen = gtk_widget_get_screen (button);
+ if (G_UNLIKELY (screen == NULL))
+ screen = gdk_screen_get_default ();
+
+ /* try to start the settings dialog */
+ if (!gdk_spawn_command_line_on_screen (screen, "xfwm4-workspace-settings", &error))
+ {
+ /* show an error dialog */
+ xfce_dialog_show_error (button, error, _("Unable to open the Xfce workspace settings"));
+ g_error_free (error);
+ }
+}
+
+
+
+static void
+pager_plugin_configure_n_workspaces_changed (WnckScreen *wnck_screen,
+ WnckWorkspace *workspace,
+ GtkBuilder *builder)
+{
+ GObject *object;
+ gdouble n_worspaces, value;
+
+ panel_return_if_fail (WNCK_IS_SCREEN (wnck_screen));
+ panel_return_if_fail (GTK_IS_BUILDER (builder));
+
+ /* get the rows adjustment */
+ object = gtk_builder_get_object (builder, "rows");
+
+ /* get the number of workspaces and clamp the current value */
+ n_worspaces = wnck_screen_get_workspace_count (wnck_screen);
+ value = MIN (gtk_adjustment_get_value (GTK_ADJUSTMENT (object)), n_worspaces);
+
+ /* update the adjustment */
+ g_object_set (G_OBJECT (object), "upper", n_worspaces, "value", value, NULL);
+}
+
+
+
+static void
+pager_plugin_configure_destroyed (gpointer data,
+ GObject *where_the_object_was)
+{
+ PagerPlugin *plugin = XFCE_PAGER_PLUGIN (data);
+
+ /* disconnect signals */
+ g_signal_handlers_disconnect_by_func (G_OBJECT (plugin->wnck_screen),
+ pager_plugin_configure_n_workspaces_changed,
+ where_the_object_was);
+
+ /* unblock the menu */
+ xfce_panel_plugin_unblock_menu (XFCE_PANEL_PLUGIN (plugin));
}
@@ -271,12 +344,57 @@ static void
pager_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
{
PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
+ GtkBuilder *builder;
+ GObject *dialog, *object;
panel_return_if_fail (XFCE_IS_PAGER_PLUGIN (plugin));
panel_return_if_fail (XFCONF_IS_CHANNEL (plugin->channel));
/* save before we opend the dialog, so all properties exist in xfonf */
pager_plugin_save (panel_plugin);
+
+ /* load the dialog from the glade file */
+ builder = gtk_builder_new ();
+ if (gtk_builder_add_from_string (builder, pager_dialog_glade, pager_dialog_glade_length, NULL))
+ {
+ /* signals to monitor number of workspace changes */
+ g_signal_connect (G_OBJECT (plugin->wnck_screen), "workspace-created",
+ G_CALLBACK (pager_plugin_configure_n_workspaces_changed), builder);
+ g_signal_connect (G_OBJECT (plugin->wnck_screen), "workspace-destroyed",
+ G_CALLBACK (pager_plugin_configure_n_workspaces_changed), builder);
+
+ xfce_panel_plugin_block_menu (panel_plugin);
+ g_object_weak_ref (G_OBJECT (builder), pager_plugin_configure_destroyed, plugin);
+
+ dialog = gtk_builder_get_object (builder, "dialog");
+ g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_object_unref, builder);
+ xfce_panel_plugin_take_window (panel_plugin, GTK_WINDOW (dialog));
+
+ object = gtk_builder_get_object (builder, "close-button");
+ g_signal_connect_swapped (G_OBJECT (object), "clicked", G_CALLBACK (gtk_widget_destroy), dialog);
+
+ object = gtk_builder_get_object (builder, "settings-button");
+ g_signal_connect (G_OBJECT (object), "clicked", G_CALLBACK (pager_plugin_configure_workspace_settings), dialog);
+
+ object = gtk_builder_get_object (builder, "workspace-scrolling");
+ xfconf_g_property_bind (plugin->channel, "/workspace-scrolling", G_TYPE_BOOLEAN, object, "active");
+
+ object = gtk_builder_get_object (builder, "show-names");
+ xfconf_g_property_bind (plugin->channel, "/show-names", G_TYPE_BOOLEAN, object, "active");
+
+ object = gtk_builder_get_object (builder, "rows");
+ xfconf_g_property_bind (plugin->channel, "/rows", G_TYPE_UINT, object, "value");
+
+ /* update the rows limit */
+ pager_plugin_configure_n_workspaces_changed (plugin->wnck_screen, NULL, builder);
+
+ gtk_widget_show (GTK_WIDGET (dialog));
+ }
+ else
+ {
+ /* release the builder */
+ g_object_unref (G_OBJECT (builder));
+ }
}
@@ -287,10 +405,13 @@ pager_plugin_property_changed (XfconfChannel *channel,
const GValue *value,
PagerPlugin *plugin)
{
+ guint n_workspaces;
+
panel_return_if_fail (XFCONF_IS_CHANNEL (channel));
panel_return_if_fail (XFCE_IS_PAGER_PLUGIN (plugin));
panel_return_if_fail (plugin->channel == channel);
panel_return_if_fail (WNCK_IS_PAGER (plugin->wnck_pager));
+ panel_return_if_fail (WNCK_IS_SCREEN (plugin->wnck_screen));
/* update the changed property */
if (strcmp (property_name, "/workspace-scrolling") == 0)
@@ -310,7 +431,8 @@ pager_plugin_property_changed (XfconfChannel *channel,
else if (strcmp (property_name, "/rows") == 0)
{
/* store new value and set wnck pager rows */
- plugin->rows = CLAMP (g_value_get_int (value), 1, 50);
+ n_workspaces = MIN (wnck_screen_get_workspace_count (plugin->wnck_screen), 1);
+ plugin->rows = CLAMP (g_value_get_uint (value), 1, n_workspaces);
wnck_pager_set_n_rows (WNCK_PAGER (plugin->wnck_pager), plugin->rows);
}
}
More information about the Xfce4-commits
mailing list