[Xfce4-commits] <xfce4-panel:master> Add a pager mode with normal buttons.
Nick Schermer
noreply at xfce.org
Tue Jul 20 22:26:01 CEST 2010
Updating branch refs/heads/master
to 1ae6753c76635f62367e0bf16d3657ff805c9942 (commit)
from 93d9e97bd0f3109fbc6978abc5ca089c7db7f1cd (commit)
commit 1ae6753c76635f62367e0bf16d3657ff805c9942
Author: Nick Schermer <nick at xfce.org>
Date: Tue Jul 20 22:21:37 2010 +0200
Add a pager mode with normal buttons.
This removes the old 'Show workspace names' option and adds a
pager with normal buttons and workspace names instead. This
looks much more like the old pager known in pre-4.0 Xfce versions.
plugins/pager/Makefile.am | 4 +-
plugins/pager/pager-buttons.c | 479 ++++++++++++++++++++++++++++++++++++++
plugins/pager/pager-buttons.h | 51 ++++
plugins/pager/pager-dialog.glade | 5 +-
plugins/pager/pager.c | 110 +++++-----
plugins/pager/pager.h | 2 +
6 files changed, 592 insertions(+), 59 deletions(-)
diff --git a/plugins/pager/Makefile.am b/plugins/pager/Makefile.am
index 4d97de7..19a927b 100644
--- a/plugins/pager/Makefile.am
+++ b/plugins/pager/Makefile.am
@@ -16,7 +16,9 @@ libpager_built_sources = \
libpager_la_SOURCES = \
$(libpager_built_sources) \
pager.c \
- pager.h
+ pager.h \
+ pager-buttons.h \
+ pager-buttons.c
libpager_la_CFLAGS = \
$(GTK_CFLAGS) \
diff --git a/plugins/pager/pager-buttons.c b/plugins/pager/pager-buttons.c
new file mode 100644
index 0000000..0e53ebd
--- /dev/null
+++ b/plugins/pager/pager-buttons.c
@@ -0,0 +1,479 @@
+/*
+ * Copyright (c) 2010 Nick Schermer <nick at xfce.org>
+ *
+ * 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; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <exo/exo.h>
+#include <libxfce4panel/libxfce4panel.h>
+#include <common/panel-private.h>
+
+#include "pager-buttons.h"
+
+
+
+static void pager_buttons_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+static void pager_buttons_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void pager_buttons_finalize (GObject *object);
+static void pager_buttons_queue_rebuild (PagerButtons *pager);
+static void pager_buttons_screen_workspace_changed (WnckScreen *screen,
+ WnckWorkspace *previous_workspace,
+ PagerButtons *pager);
+static void pager_buttons_screen_workspace_created (WnckScreen *screen,
+ WnckWorkspace *created_workspace,
+ PagerButtons *pager);
+static void pager_buttons_screen_workspace_destroyed (WnckScreen *screen,
+ WnckWorkspace *destroyed_workspace,
+ PagerButtons *pager);
+static void pager_buttons_workspace_button_toggled (GtkWidget *button,
+ WnckWorkspace *workspace);
+static void pager_buttons_workspace_button_label (WnckWorkspace *workspace,
+ GtkWidget *label);
+
+
+
+struct _PagerButtonsClass
+{
+ GtkTableClass __parent__;
+};
+
+struct _PagerButtons
+{
+ GtkTable __parent__;
+
+ GSList *buttons;
+
+ guint rebuild_id;
+
+ WnckScreen *wnck_screen;
+
+ gint rows;
+ GtkOrientation orientation;
+};
+
+enum
+{
+ PROP_0,
+ PROP_SCREEN,
+ PROP_ROWS,
+ PROP_ORIENTATION
+};
+
+
+
+XFCE_PANEL_DEFINE_TYPE (PagerButtons, pager_buttons, GTK_TYPE_TABLE)
+
+
+
+static void
+pager_buttons_class_init (PagerButtonsClass *klass)
+{
+ GObjectClass *gobject_class;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->get_property = pager_buttons_get_property;
+ gobject_class->set_property = pager_buttons_set_property;
+ gobject_class->finalize = pager_buttons_finalize;
+
+ g_object_class_install_property (gobject_class,
+ PROP_SCREEN,
+ g_param_spec_object ("screen",
+ NULL, NULL,
+ WNCK_TYPE_SCREEN,
+ EXO_PARAM_WRITABLE
+ | G_PARAM_CONSTRUCT_ONLY));
+
+ g_object_class_install_property (gobject_class,
+ PROP_ROWS,
+ g_param_spec_int ("rows",
+ NULL, NULL,
+ 1, 100, 1,
+ EXO_PARAM_READWRITE));
+
+ g_object_class_install_property (gobject_class,
+ PROP_ORIENTATION,
+ g_param_spec_enum ("orientation",
+ NULL, NULL,
+ GTK_TYPE_ORIENTATION,
+ GTK_ORIENTATION_HORIZONTAL,
+ EXO_PARAM_READWRITE));
+}
+
+
+
+static void
+pager_buttons_init (PagerButtons *pager)
+{
+ pager->rows = 1;
+ pager->wnck_screen = NULL;
+ pager->orientation = GTK_ORIENTATION_HORIZONTAL;
+ pager->buttons = NULL;
+ pager->rebuild_id = 0;
+
+ /* although I'd prefer normal allocation, the homogeneous setting
+ * takes care of small panels, while non-homogeneous tables allocate
+ * outside the panel size --nick */
+ gtk_table_set_homogeneous (GTK_TABLE (pager), TRUE);
+}
+
+
+
+static void
+pager_buttons_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PagerButtons *pager = XFCE_PAGER_BUTTONS (object);
+
+ switch (prop_id)
+ {
+ case PROP_ROWS:
+ g_value_set_int (value, pager->rows);
+ break;
+
+ case PROP_ORIENTATION:
+ g_value_set_enum (value, pager->orientation);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+pager_buttons_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PagerButtons *pager = XFCE_PAGER_BUTTONS (object);
+
+ switch (prop_id)
+ {
+ case PROP_SCREEN:
+ pager->wnck_screen = g_value_dup_object (value);
+ panel_return_if_fail (WNCK_IS_SCREEN (pager->wnck_screen));
+
+ g_signal_connect (G_OBJECT (pager->wnck_screen), "active-workspace-changed",
+ G_CALLBACK (pager_buttons_screen_workspace_changed), pager);
+ g_signal_connect (G_OBJECT (pager->wnck_screen), "workspace-created",
+ G_CALLBACK (pager_buttons_screen_workspace_created), pager);
+ g_signal_connect (G_OBJECT (pager->wnck_screen), "workspace-destroyed",
+ G_CALLBACK (pager_buttons_screen_workspace_destroyed), pager);
+
+ pager_buttons_queue_rebuild (pager);
+ break;
+
+ case PROP_ROWS:
+ pager_buttons_set_n_rows (pager, g_value_get_int (value));
+ break;
+
+ case PROP_ORIENTATION:
+ pager_buttons_set_orientation (pager, g_value_get_enum (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+
+
+static void
+pager_buttons_finalize (GObject *object)
+{
+ PagerButtons *pager = XFCE_PAGER_BUTTONS (object);
+
+ if (pager->rebuild_id != 0)
+ g_source_remove (pager->rebuild_id);
+
+ if (G_LIKELY (pager->wnck_screen != NULL))
+ {
+ g_signal_handlers_disconnect_by_func (G_OBJECT (pager->wnck_screen),
+ G_CALLBACK (pager_buttons_screen_workspace_changed), pager);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (pager->wnck_screen),
+ G_CALLBACK (pager_buttons_screen_workspace_created), pager);
+ g_signal_handlers_disconnect_by_func (G_OBJECT (pager->wnck_screen),
+ G_CALLBACK (pager_buttons_screen_workspace_destroyed), pager);
+
+ g_object_unref (G_OBJECT (pager->wnck_screen));
+ }
+
+ g_slist_free (pager->buttons);
+
+ (*G_OBJECT_CLASS (pager_buttons_parent_class)->finalize) (object);
+}
+
+
+
+static gboolean
+pager_buttons_rebuild_idle (gpointer user_data)
+{
+ PagerButtons *pager = XFCE_PAGER_BUTTONS (user_data);
+ GList *li, *workspaces;
+ WnckWorkspace *active_ws;
+ gint n, n_workspaces;
+ gint rows, cols;
+ gint row, col;
+ GtkWidget *button;
+ WnckWorkspace *workspace;
+ GtkWidget *panel_plugin;
+ GtkWidget *label;
+
+ panel_return_val_if_fail (XFCE_IS_PAGER_BUTTONS (pager), FALSE);
+ panel_return_val_if_fail (WNCK_IS_SCREEN (pager->wnck_screen), FALSE);
+
+ gtk_container_foreach (GTK_CONTAINER (pager),
+ (GtkCallback) gtk_widget_destroy, NULL);
+
+ g_slist_free (pager->buttons);
+ pager->buttons = NULL;
+
+ active_ws = wnck_screen_get_active_workspace (pager->wnck_screen);
+ workspaces = wnck_screen_get_workspaces (pager->wnck_screen);
+ if (workspaces == NULL)
+ return FALSE;
+
+ n_workspaces = g_list_length (workspaces);
+
+ rows = CLAMP (1, pager->rows, n_workspaces);
+ cols = n_workspaces / rows;
+ if (cols * rows < n_workspaces)
+ cols++;
+
+ if (pager->orientation != GTK_ORIENTATION_HORIZONTAL)
+ SWAP_INTEGER (rows, cols);
+
+ gtk_table_resize (GTK_TABLE (pager), rows, cols);
+
+ panel_plugin = gtk_widget_get_ancestor (GTK_WIDGET (pager), XFCE_TYPE_PANEL_PLUGIN);
+
+ for (li = workspaces, n = 0; li != NULL; li = li->next, n++)
+ {
+ workspace = WNCK_WORKSPACE (li->data);
+
+ button = xfce_panel_create_toggle_button ();
+ if (workspace == active_ws)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ g_signal_connect (G_OBJECT (button), "toggled",
+ G_CALLBACK (pager_buttons_workspace_button_toggled), workspace);
+ xfce_panel_plugin_add_action_widget (XFCE_PANEL_PLUGIN (panel_plugin), button);
+ gtk_widget_show (button);
+
+ label = gtk_label_new (NULL);
+ g_signal_connect_object (G_OBJECT (workspace), "name-changed",
+ G_CALLBACK (pager_buttons_workspace_button_label), label, 0);
+ pager_buttons_workspace_button_label (workspace, label);
+ gtk_label_set_angle (GTK_LABEL (label),
+ pager->orientation == GTK_ORIENTATION_HORIZONTAL ? 0 : 270);
+ gtk_container_add (GTK_CONTAINER (button), label);
+ gtk_widget_show (label);
+
+ pager->buttons = g_slist_prepend (pager->buttons, button);
+
+ row = n / rows;
+ col = n % rows;
+
+ gtk_table_attach (GTK_TABLE (pager), button,
+ row, row + 1, col, col + 1,
+ GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
+ 0, 0);
+ }
+
+ pager->buttons = g_slist_reverse (pager->buttons);
+
+ return FALSE;
+}
+
+
+
+static void
+pager_buttons_rebuild_idle_destroyed (gpointer user_data)
+{
+ XFCE_PAGER_BUTTONS (user_data)->rebuild_id = 0;
+}
+
+
+
+static void
+pager_buttons_queue_rebuild (PagerButtons *pager)
+{
+ panel_return_if_fail (XFCE_IS_PAGER_BUTTONS (pager));
+
+ if (pager->rebuild_id == 0)
+ {
+ pager->rebuild_id = g_idle_add_full (G_PRIORITY_LOW, pager_buttons_rebuild_idle,
+ pager, pager_buttons_rebuild_idle_destroyed);
+ }
+}
+
+
+
+static void
+pager_buttons_screen_workspace_changed (WnckScreen *screen,
+ WnckWorkspace *previous_workspace,
+ PagerButtons *pager)
+{
+ gint active = -1, n;
+ WnckWorkspace *active_ws;
+ GSList *li;
+
+ panel_return_if_fail (WNCK_IS_SCREEN (screen));
+ panel_return_if_fail (previous_workspace == NULL || WNCK_IS_WORKSPACE (previous_workspace));
+ panel_return_if_fail (XFCE_IS_PAGER_BUTTONS (pager));
+ panel_return_if_fail (pager->wnck_screen == screen);
+
+ active_ws = wnck_screen_get_active_workspace (screen);
+ if (G_LIKELY (active_ws != NULL))
+ active = wnck_workspace_get_number (active_ws);
+
+ for (li = pager->buttons, n = 0; li != NULL; li = li->next, n++)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (li->data), n == active);
+}
+
+
+
+static void
+pager_buttons_screen_workspace_created (WnckScreen *screen,
+ WnckWorkspace *created_workspace,
+ PagerButtons *pager)
+{
+ panel_return_if_fail (WNCK_IS_SCREEN (screen));
+ panel_return_if_fail (WNCK_IS_WORKSPACE (created_workspace));
+ panel_return_if_fail (XFCE_IS_PAGER_BUTTONS (pager));
+ panel_return_if_fail (pager->wnck_screen == screen);
+
+ pager_buttons_queue_rebuild (pager);
+}
+
+
+
+static void
+pager_buttons_screen_workspace_destroyed (WnckScreen *screen,
+ WnckWorkspace *destroyed_workspace,
+ PagerButtons *pager)
+{
+ panel_return_if_fail (WNCK_IS_SCREEN (screen));
+ panel_return_if_fail (WNCK_IS_WORKSPACE (destroyed_workspace));
+ panel_return_if_fail (WNCK_IS_WORKSPACE (destroyed_workspace));
+ panel_return_if_fail (XFCE_IS_PAGER_BUTTONS (pager));
+ panel_return_if_fail (pager->wnck_screen == screen);
+
+ pager_buttons_queue_rebuild (pager);
+}
+
+
+
+static void
+pager_buttons_workspace_button_label (WnckWorkspace *workspace,
+ GtkWidget *label)
+{
+ const gchar *name;
+ gchar *utf8 = NULL, *name_num = NULL;
+
+ panel_return_if_fail (WNCK_IS_WORKSPACE (workspace));
+ panel_return_if_fail (GTK_IS_LABEL (label));
+
+ /* try to get an utf-8 valid name */
+ name = wnck_workspace_get_name (workspace);
+ if (!exo_str_is_empty (name)
+ && !g_utf8_validate (name, -1, NULL))
+ name = utf8 = g_locale_to_utf8 (name, -1, NULL, NULL, NULL);
+
+ if (exo_str_is_empty (name))
+ name = name_num = g_strdup_printf (_("Workspace %d"),
+ wnck_workspace_get_number (workspace) + 1);
+
+ gtk_label_set_text (GTK_LABEL (label), name);
+
+ g_free (utf8);
+ g_free (name_num);
+}
+
+
+
+static void
+pager_buttons_workspace_button_toggled (GtkWidget *button,
+ WnckWorkspace *workspace)
+{
+ WnckWorkspace *active_ws;
+
+ panel_return_if_fail (GTK_IS_TOGGLE_BUTTON (button));
+ panel_return_if_fail (WNCK_IS_WORKSPACE (workspace));
+
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
+ {
+ active_ws = wnck_screen_get_active_workspace (wnck_workspace_get_screen (workspace));
+ if (active_ws != workspace)
+ wnck_workspace_activate (workspace, gtk_get_current_event_time ());
+ }
+}
+
+
+
+GtkWidget *
+pager_buttons_new (WnckScreen *screen)
+{
+ panel_return_val_if_fail (WNCK_IS_SCREEN (screen), NULL);
+
+ return g_object_new (XFCE_TYPE_PAGER_BUTTONS,
+ "screen", screen, NULL);
+}
+
+
+
+void
+pager_buttons_set_orientation (PagerButtons *pager,
+ GtkOrientation orientation)
+{
+ panel_return_if_fail (XFCE_IS_PAGER_BUTTONS (pager));
+
+ if (pager->orientation == orientation)
+ return;
+
+ pager->orientation = orientation;
+ pager_buttons_queue_rebuild (pager);
+}
+
+
+
+void
+pager_buttons_set_n_rows (PagerButtons *pager,
+ gint rows)
+{
+ panel_return_if_fail (XFCE_IS_PAGER_BUTTONS (pager));
+
+ if (pager->rows == rows)
+ return;
+
+ pager->rows = rows;
+ pager_buttons_queue_rebuild (pager);
+}
diff --git a/plugins/pager/pager-buttons.h b/plugins/pager/pager-buttons.h
new file mode 100644
index 0000000..3a5d1db
--- /dev/null
+++ b/plugins/pager/pager-buttons.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010 Nick Schermer <nick at xfce.org>
+ *
+ * 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; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * 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., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef __PAGER_BUTTONS_H__
+#define __PAGER_BUTTONS_H__
+
+#include <gtk/gtk.h>
+#include <libwnck/libwnck.h>
+
+G_BEGIN_DECLS
+
+typedef struct _PagerButtonsClass PagerButtonsClass;
+typedef struct _PagerButtons PagerButtons;
+
+#define XFCE_TYPE_PAGER_BUTTONS (pager_buttons_get_type ())
+#define XFCE_PAGER_BUTTONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_PAGER_BUTTONS, PagerButtons))
+#define XFCE_PAGER_BUTTONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_PAGER_BUTTONS, PagerButtonsClass))
+#define XFCE_IS_PAGER_BUTTONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_PAGER_BUTTONS))
+#define XFCE_IS_PAGER_BUTTONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_PAGER_BUTTONS))
+#define XFCE_PAGER_BUTTONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_PAGER_BUTTONS, PagerButtonsClass))
+
+GType pager_buttons_get_type (void) G_GNUC_CONST;
+
+void pager_buttons_register_type (XfcePanelTypeModule *type_module);
+
+GtkWidget *pager_buttons_new (WnckScreen *screen) G_GNUC_MALLOC;
+
+void pager_buttons_set_orientation (PagerButtons *pager,
+ GtkOrientation orientation);
+
+void pager_buttons_set_n_rows (PagerButtons *pager,
+ gint rows);
+
+G_END_DECLS
+
+#endif /* !__PAGER_BUTTONS_H__ */
diff --git a/plugins/pager/pager-dialog.glade b/plugins/pager/pager-dialog.glade
index 3092d12..bec47f1 100644
--- a/plugins/pager/pager-dialog.glade
+++ b/plugins/pager/pager-dialog.glade
@@ -70,11 +70,12 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="show-names">
- <property name="label" translatable="yes">Show workspace _names</property>
+ <object class="GtkCheckButton" id="miniature-view">
+ <property name="label" translatable="yes">Show mi_niature view</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Show a miniature view of the workspace with rectangles for the visible windows</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
diff --git a/plugins/pager/pager.c b/plugins/pager/pager.c
index a16aecb..d034bd4 100644
--- a/plugins/pager/pager.c
+++ b/plugins/pager/pager.c
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2005-2007 Jasper Huijsmans <jasper at xfce.org>
- * Copyright (c) 2007-2009 Nick Schermer <nick at xfce.org>
+ * Copyright (c) 2007-2010 Nick Schermer <nick at xfce.org>
*
* 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
@@ -32,6 +32,7 @@
#include <exo/exo.h>
#include "pager.h"
+#include "pager-buttons.h"
#include "pager-dialog_ui.h"
@@ -59,6 +60,7 @@ static gboolean pager_plugin_size_changed (XfcePanelPlugin *panel
static void pager_plugin_orientation_changed (XfcePanelPlugin *panel_plugin,
GtkOrientation orientation);
static void pager_plugin_configure_plugin (XfcePanelPlugin *panel_plugin);
+static void pager_plugin_screen_layout_changed (PagerPlugin *plugin);
@@ -71,13 +73,13 @@ struct _PagerPlugin
{
XfcePanelPlugin __parent__;
- GtkWidget *wnck_pager;
+ GtkWidget *pager;
WnckScreen *wnck_screen;
/* settings */
guint scrolling : 1;
- guint show_names : 1;
+ guint miniature_view : 1;
gint rows;
};
@@ -85,14 +87,15 @@ enum
{
PROP_0,
PROP_WORKSPACE_SCROLLING,
- PROP_SHOW_NAMES,
+ PROP_MINIATURE_VIEW,
PROP_ROWS
};
/* define the plugin */
-XFCE_PANEL_DEFINE_PLUGIN_RESIDENT (PagerPlugin, pager_plugin)
+XFCE_PANEL_DEFINE_PLUGIN_RESIDENT (PagerPlugin, pager_plugin,
+ pager_buttons_register_type)
@@ -125,8 +128,8 @@ pager_plugin_class_init (PagerPluginClass *klass)
EXO_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
- PROP_SHOW_NAMES,
- g_param_spec_boolean ("show-names",
+ PROP_MINIATURE_VIEW,
+ g_param_spec_boolean ("miniature-view",
NULL, NULL,
FALSE,
EXO_PARAM_READWRITE));
@@ -146,12 +149,11 @@ pager_plugin_class_init (PagerPluginClass *klass)
static void
pager_plugin_init (PagerPlugin *plugin)
{
- /* init, draw nothing */
plugin->wnck_screen = NULL;
plugin->scrolling = TRUE;
- plugin->show_names = FALSE;
+ plugin->miniature_view = FALSE;
plugin->rows = 1;
- plugin->wnck_pager = NULL;
+ plugin->pager = NULL;
}
@@ -170,8 +172,10 @@ pager_plugin_get_property (GObject *object,
g_value_set_boolean (value, plugin->scrolling);
break;
- case PROP_SHOW_NAMES:
- g_value_set_boolean (value, plugin->show_names);
+ case PROP_MINIATURE_VIEW:
+ g_value_set_boolean (value, plugin->miniature_view);
+
+ pager_plugin_screen_layout_changed (plugin);
break;
case PROP_ROWS:
@@ -200,21 +204,20 @@ pager_plugin_set_property (GObject *object,
plugin->scrolling = g_value_get_boolean (value);
break;
- case PROP_SHOW_NAMES:
- plugin->show_names = g_value_get_boolean (value);
-
- if (plugin->wnck_pager != NULL)
- wnck_pager_set_display_mode (WNCK_PAGER (plugin->wnck_pager),
- plugin->show_names ?
- WNCK_PAGER_DISPLAY_NAME :
- WNCK_PAGER_DISPLAY_CONTENT);
+ case PROP_MINIATURE_VIEW:
+ plugin->miniature_view = g_value_get_boolean (value);
break;
case PROP_ROWS:
plugin->rows = g_value_get_uint (value);
- if (plugin->wnck_pager != NULL)
- wnck_pager_set_n_rows (WNCK_PAGER (plugin->wnck_pager), plugin->rows);
+ if (plugin->pager != NULL)
+ {
+ if (plugin->miniature_view)
+ wnck_pager_set_n_rows (WNCK_PAGER (plugin->pager), plugin->rows);
+ else
+ pager_buttons_set_n_rows (XFCE_PAGER_BUTTONS (plugin->pager), plugin->rows);
+ }
break;
default:
@@ -269,29 +272,35 @@ pager_plugin_scroll_event (GtkWidget *widget,
static void
pager_plugin_screen_layout_changed (PagerPlugin *plugin)
{
+ GtkOrientation orientation;
+
panel_return_if_fail (XFCE_IS_PAGER_PLUGIN (plugin));
panel_return_if_fail (WNCK_IS_SCREEN (plugin->wnck_screen));
- if (G_UNLIKELY (plugin->wnck_pager != NULL))
+ if (G_UNLIKELY (plugin->pager != NULL))
{
- /* destroy the existing pager */
- gtk_widget_destroy (GTK_WIDGET (plugin->wnck_pager));
-
- /* force a screen update */
+ gtk_widget_destroy (GTK_WIDGET (plugin->pager));
wnck_screen_force_update (plugin->wnck_screen);
}
- /* create the wnck pager */
- plugin->wnck_pager = wnck_pager_new (plugin->wnck_screen);
- gtk_container_add (GTK_CONTAINER (plugin), plugin->wnck_pager);
- gtk_widget_show (plugin->wnck_pager);
-
- /* set the pager properties */
- wnck_pager_set_display_mode (WNCK_PAGER (plugin->wnck_pager),
- plugin->show_names ?
- WNCK_PAGER_DISPLAY_NAME :
- WNCK_PAGER_DISPLAY_CONTENT);
- wnck_pager_set_n_rows (WNCK_PAGER (plugin->wnck_pager), plugin->rows);
+ orientation = xfce_panel_plugin_get_orientation (XFCE_PANEL_PLUGIN (plugin));
+
+ if (plugin->miniature_view)
+ {
+ plugin->pager = wnck_pager_new (plugin->wnck_screen);
+ wnck_pager_set_display_mode (WNCK_PAGER (plugin->pager), WNCK_PAGER_DISPLAY_CONTENT);
+ wnck_pager_set_n_rows (WNCK_PAGER (plugin->pager), plugin->rows);
+ wnck_pager_set_orientation (WNCK_PAGER (plugin->pager), orientation);
+ }
+ else
+ {
+ plugin->pager = pager_buttons_new (plugin->wnck_screen);
+ pager_buttons_set_n_rows (XFCE_PAGER_BUTTONS (plugin->pager), plugin->rows);
+ pager_buttons_set_orientation (XFCE_PAGER_BUTTONS (plugin->pager), orientation);
+ }
+
+ gtk_container_add (GTK_CONTAINER (plugin), plugin->pager);
+ gtk_widget_show (plugin->pager);
}
@@ -304,20 +313,15 @@ pager_plugin_screen_changed (GtkWidget *widget,
GdkScreen *screen;
WnckScreen *wnck_screen;
- /* get the active screen */
screen = gtk_widget_get_screen (widget);
wnck_screen = wnck_screen_get (gdk_screen_get_number (screen));
- /* only update if the screen changed */
if (plugin->wnck_screen != wnck_screen)
{
- /* set the new screen */
plugin->wnck_screen = wnck_screen;
- /* rebuild the pager */
pager_plugin_screen_layout_changed (plugin);
- /* watch the screen for changes */
g_signal_connect_swapped (G_OBJECT (screen), "monitors-changed",
G_CALLBACK (pager_plugin_screen_layout_changed), plugin);
g_signal_connect_swapped (G_OBJECT (screen), "size-changed",
@@ -334,20 +338,17 @@ pager_plugin_construct (XfcePanelPlugin *panel_plugin)
const PanelProperty properties[] =
{
{ "workspace-scrolling", G_TYPE_BOOLEAN },
- { "show-names", G_TYPE_BOOLEAN },
+ { "miniature-view", G_TYPE_BOOLEAN },
{ "rows", G_TYPE_UINT },
{ NULL }
};
- /* show the properties dialog */
xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
- /* bind all properties */
panel_properties_bind (NULL, G_OBJECT (plugin),
xfce_panel_plugin_get_property_base (panel_plugin),
properties, FALSE);
- /* create the pager */
g_signal_connect (G_OBJECT (plugin), "screen-changed",
G_CALLBACK (pager_plugin_screen_changed), NULL);
pager_plugin_screen_changed (GTK_WIDGET (plugin), NULL);
@@ -360,7 +361,6 @@ pager_plugin_free_data (XfcePanelPlugin *panel_plugin)
{
PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
- /* disconnect screen changed signal */
g_signal_handlers_disconnect_by_func (G_OBJECT (plugin),
pager_plugin_screen_changed, NULL);
}
@@ -383,7 +383,10 @@ pager_plugin_orientation_changed (XfcePanelPlugin *panel_plugin,
{
PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
- wnck_pager_set_orientation (WNCK_PAGER (plugin->wnck_pager), orientation);
+ if (plugin->miniature_view)
+ wnck_pager_set_orientation (WNCK_PAGER (plugin->pager), orientation);
+ else
+ pager_buttons_set_orientation (XFCE_PAGER_BUTTONS (plugin->pager), orientation);
}
@@ -397,7 +400,6 @@ pager_plugin_configure_workspace_settings (GtkWidget *button)
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 ();
@@ -426,14 +428,11 @@ pager_plugin_configure_n_workspaces_changed (WnckScreen *wnck_screen,
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);
}
@@ -445,7 +444,6 @@ pager_plugin_configure_destroyed (gpointer data,
{
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);
@@ -492,9 +490,9 @@ pager_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
exo_mutual_binding_new (G_OBJECT (plugin), "workspace-scrolling",
G_OBJECT (object), "active");
- object = gtk_builder_get_object (builder, "show-names");
+ object = gtk_builder_get_object (builder, "miniature-view");
panel_return_if_fail (GTK_IS_TOGGLE_BUTTON (object));
- exo_mutual_binding_new (G_OBJECT (plugin), "show-names",
+ exo_mutual_binding_new (G_OBJECT (plugin), "miniature-view",
G_OBJECT (object), "active");
object = gtk_builder_get_object (builder, "rows");
diff --git a/plugins/pager/pager.h b/plugins/pager/pager.h
index 28cbc09..e61883b 100644
--- a/plugins/pager/pager.h
+++ b/plugins/pager/pager.h
@@ -1,4 +1,6 @@
/*
+ * Copyright (c) 2009 Nick Schermer <nick at xfce.org>
+ *
* 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; either version 2 of the License, or (at your option)
More information about the Xfce4-commits
mailing list