[Xfce4-commits] <xfce4-panel:devel> * Partly import the pager plugin.

Nick Schermer nick at xfce.org
Tue Aug 11 20:26:21 CEST 2009


Updating branch refs/heads/devel
         to aab284b08cf31164855f09b31c33f400f3c13566 (commit)
       from cbe0a689ba86ee7b86ba94cc7c32039282dfce42 (commit)

commit aab284b08cf31164855f09b31c33f400f3c13566
Author: Nick Schermer <nick at xfce.org>
Date:   Wed Nov 12 21:38:05 2008 +0100

    * Partly import the pager plugin.

 plugins/{showdesktop => pager}/Makefile.am         |   31 +-
 plugins/pager/pager.c                              |  316 ++++++++++++++++++++
 .../pager.desktop.in.in}                           |    8 +-
 plugins/pager/pager.h                              |   39 +++
 4 files changed, 376 insertions(+), 18 deletions(-)

diff --git a/plugins/showdesktop/Makefile.am b/plugins/pager/Makefile.am
similarity index 70%
copy from plugins/showdesktop/Makefile.am
copy to plugins/pager/Makefile.am
index 74b3651..92d9c24 100644
--- a/plugins/showdesktop/Makefile.am
+++ b/plugins/pager/Makefile.am
@@ -2,50 +2,53 @@
 
 INCLUDES = \
 	-I$(top_srcdir) \
-	-DBINDIR=\"$(bindir)\" \
-	-DG_LOG_DOMAIN=\"libshowdesktop\" \
-	-DWNCK_I_KNOW_THIS_IS_UNSTABLE \
+	-DG_LOG_DOMAIN=\"libpager\" \
 	-DLOCALEDIR=\"$(localedir)\" \
+	-DWNCK_I_KNOW_THIS_IS_UNSTABLE \
 	$(PLATFORM_CPPFLAGS)
 
 plugindir = \
 	$(libdir)/xfce4/panel-plugins
 
 plugin_LTLIBRARIES = \
-	libshowdesktop.la
+	libpager.la
 
-libshowdesktop_la_SOURCES = \
-	showdesktop.c \
-	showdesktop.h
+libpager_la_SOURCES = \
+	pager.c \
+	pager.h
 
-libshowdesktop_la_CFLAGS = \
+libpager_la_CFLAGS = \
 	$(GTK_CFLAGS) \
 	$(LIBXFCE4UTIL_CFLAGS) \
 	$(LIBWNCK_CFLAGS) \
+	$(XFCONF_CFLAGS) \
+	$(LIBXFCE4UI_CFLAGS) \
 	$(PLATFORM_CFLAGS)
 
-libshowdesktop_la_LDFLAGS = \
+libpager_la_LDFLAGS = \
 	-avoid-version \
 	-module \
 	-no-undefined \
 	$(PLATFORM_LDFLAGS)
 
-libshowdesktop_la_LIBADD = \
+libpager_la_LIBADD = \
 	$(top_builddir)/libxfce4panel/libxfce4panel.la \
 	$(GTK_LIBS) \
 	$(LIBXFCE4UTIL_LIBS) \
-	$(LIBWNCK_LIBS)
+	$(LIBWNCK_LIBS) \
+	$(XFCONF_LIBS) \
+	$(LIBXFCE4UI_LIBS)
 
-libshowdesktop_la_DEPENDENCIES = \
+libpager_la_DEPENDENCIES = \
 	$(top_builddir)/libxfce4panel/libxfce4panel.la
 
 #
 # .desktop file
 #
 desktopdir = $(datadir)/xfce4/panel-plugins
-desktop_in_in_files = showdesktop.desktop.in.in
+desktop_in_in_files = pager.desktop.in.in
 desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in)
-showdesktop.desktop.in: $(desktop_in_in_files)
+pager.desktop.in: $(desktop_in_in_files)
 	sed -e "s,\@libdir\@,$(libdir),g" < $< > $@
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 @INTLTOOL_DESKTOP_RULE@
diff --git a/plugins/pager/pager.c b/plugins/pager/pager.c
new file mode 100644
index 0000000..bd8cb20
--- /dev/null
+++ b/plugins/pager/pager.c
@@ -0,0 +1,316 @@
+/* $Id$ */
+/*
+ * Copyright (c) 2005-2007 Jasper Huijsmans <jasper at xfce.org>
+ * Copyright (c) 2007-2008 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 <libxfce4panel/libxfce4panel.h>
+#include <libxfce4util/libxfce4util.h>
+#include <xfconf/xfconf.h>
+#include <libwnck/libwnck.h>
+
+#include "pager.h"
+
+
+
+static void     pager_plugin_class_init                (PagerPluginClass  *klass);
+static void     pager_plugin_init                      (PagerPlugin       *pager);
+static gboolean pager_plugin_scroll_event              (GtkWidget         *widget,
+                                                        GdkEventScroll    *event);
+static void     pager_plugin_screen_changed            (GtkWidget         *widget,
+                                                        GdkScreen         *previous_screen);
+static void     pager_plugin_construct                 (XfcePanelPlugin   *panel_plugin);
+static void     pager_plugin_free_data                 (XfcePanelPlugin   *panel_plugin);
+static gboolean pager_plugin_size_changed              (XfcePanelPlugin   *panel_plugin,
+                                                        gint               size);
+static void     pager_plugin_save                      (XfcePanelPlugin   *panel_plugin);
+static void     pager_plugin_configure_plugin          (XfcePanelPlugin   *panel_plugin);
+static void     pager_plugin_property_changed          (XfconfChannel     *channel,
+                                                        const gchar       *property_name,
+                                                        const GValue      *value,
+                                                        PagerPlugin       *plugin);
+
+
+
+struct _PagerPluginClass
+{
+  /* parent class */
+  XfcePanelPluginClass __parent__;
+};
+
+struct _PagerPlugin
+{
+  /* parent type */
+  XfcePanelPlugin __parent__;
+
+  /* the wnck pager */
+  GtkWidget     *wnck_pager;
+
+  /* xfconf channel */
+  XfconfChannel *channel;
+
+  /* the active wnck screen */
+  WnckScreen    *wnck_screen;
+
+  /* settings */
+  guint          scrolling : 1;
+  guint          show_names : 1;
+  gint           rows;
+};
+
+
+
+G_DEFINE_TYPE (PagerPlugin, pager_plugin, XFCE_TYPE_PANEL_PLUGIN);
+
+
+
+/* register the panel plugin */
+XFCE_PANEL_PLUGIN_REGISTER_OBJECT (XFCE_TYPE_PAGER_PLUGIN);
+
+
+
+static void
+pager_plugin_class_init (PagerPluginClass *klass)
+{
+  XfcePanelPluginClass *plugin_class;
+  GtkWidgetClass       *widget_class;
+
+  widget_class = GTK_WIDGET_CLASS (klass);
+  widget_class->scroll_event = pager_plugin_scroll_event;
+  widget_class->screen_changed = pager_plugin_screen_changed;
+
+  plugin_class = XFCE_PANEL_PLUGIN_CLASS (klass);
+  plugin_class->construct = pager_plugin_construct;
+  plugin_class->free_data = pager_plugin_free_data;
+  plugin_class->save = pager_plugin_save;
+  plugin_class->size_changed = pager_plugin_size_changed;
+  plugin_class->configure_plugin = pager_plugin_configure_plugin;
+}
+
+
+
+static void
+pager_plugin_init (PagerPlugin *plugin)
+{
+  /* init, draw nothing */
+  plugin->wnck_screen = NULL;
+  plugin->scrolling = FALSE;
+  plugin->show_names = FALSE;
+  plugin->rows = 1;
+  plugin->wnck_pager = NULL;
+  plugin->channel = NULL;
+
+  /* show the properties dialog */
+  xfce_panel_plugin_menu_show_configure (XFCE_PANEL_PLUGIN (plugin));
+
+  /* initialize xfconf */
+  xfconf_init (NULL);
+}
+
+
+
+static gboolean
+pager_plugin_scroll_event (GtkWidget      *widget,
+                           GdkEventScroll *event)
+{
+  PagerPlugin         *plugin = XFCE_PAGER_PLUGIN (widget);
+  WnckWorkspace       *active, *neighbor;
+  WnckMotionDirection  direction;
+
+  panel_return_val_if_fail (WNCK_IS_SCREEN (plugin->wnck_screen), FALSE);
+
+  /* leave when scrolling is not enabled */
+  if (plugin->scrolling == FALSE)
+    return TRUE;
+
+  /* translate the gdk scroll direction into a wnck motion direction */
+  switch (event->direction)
+    {
+      case GDK_SCROLL_UP:   direction = WNCK_MOTION_UP;    break;
+      case GDK_SCROLL_DOWN: direction = WNCK_MOTION_DOWN;  break;
+      case GDK_SCROLL_LEFT: direction = WNCK_MOTION_LEFT;  break;
+      default:              direction = WNCK_MOTION_RIGHT; break;
+    }
+
+  /* get the active workspace's neighbor */
+  active = wnck_screen_get_active_workspace (plugin->wnck_screen);
+  neighbor = wnck_workspace_get_neighbor (active, direction);
+
+  /* if there is a neighbor, move to it */
+  if (neighbor != NULL)
+    wnck_workspace_activate (neighbor, event->time);
+
+  return TRUE;
+}
+
+
+
+static void
+pager_plugin_screen_changed (GtkWidget *widget,
+                             GdkScreen *previous_screen)
+{
+  PagerPlugin *plugin = XFCE_PAGER_PLUGIN (widget);
+  GdkScreen   *screen;
+  WnckScreen  *wnck_screen;
+
+  /* do nothing until the xfconf properties are initialized */
+  if (plugin->channel == NULL)
+    return;
+
+  /* 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;
+
+      /* create the wnck pager */
+      plugin->wnck_pager = wnck_pager_new (wnck_screen);
+
+      /* 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);
+    }
+}
+
+
+
+static void
+pager_plugin_construct (XfcePanelPlugin *panel_plugin)
+{
+  PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
+
+  /* set the xfconf channel */
+  plugin->channel = xfce_panel_plugin_xfconf_channel_new (panel_plugin);
+  g_signal_connect (G_OBJECT (plugin->channel), "property-changed",
+                    G_CALLBACK (pager_plugin_property_changed), plugin);
+
+  /* read xfconf settings */
+  plugin->scrolling = xfconf_channel_get_bool (plugin->channel, "/workspace-scrolling", FALSE);
+  plugin->show_names = xfconf_channel_get_bool (plugin->channel, "/show-names", FALSE);
+  plugin->rows = CLAMP (xfconf_channel_get_int (plugin->channel, "/rows", 1), 1, 50);\
+
+  /* create the pager */
+  pager_plugin_screen_changed (GTK_WIDGET (panel_plugin), NULL);
+}
+
+
+
+static void
+pager_plugin_free_data (XfcePanelPlugin *panel_plugin)
+{
+  PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
+
+  panel_return_if_fail (XFCONF_IS_CHANNEL (plugin->channel));
+
+  /* release the xfonf channel */
+  g_object_unref (G_OBJECT (plugin->channel));
+
+  /* shutdown xfconf */
+  xfconf_shutdown ();
+}
+
+
+
+static gboolean
+pager_plugin_size_changed (XfcePanelPlugin *panel_plugin,
+                           gint             size)
+{
+  if (xfce_panel_plugin_get_orientation (panel_plugin) ==
+      GTK_ORIENTATION_HORIZONTAL)
+    gtk_widget_set_size_request (GTK_WIDGET (panel_plugin), -1, size);
+  else
+    gtk_widget_set_size_request (GTK_WIDGET (panel_plugin), size, -1);
+
+  return TRUE;
+}
+
+
+
+static void
+pager_plugin_save (XfcePanelPlugin *panel_plugin)
+{
+  PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
+
+  panel_return_if_fail (XFCONF_IS_CHANNEL (plugin->channel));
+
+  /* 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);
+}
+
+
+
+static void
+pager_plugin_configure_plugin (XfcePanelPlugin *panel_plugin)
+{
+  PagerPlugin *plugin = XFCE_PAGER_PLUGIN (panel_plugin);
+
+  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);
+}
+
+
+
+static void
+pager_plugin_property_changed (XfconfChannel *channel,
+                               const gchar   *property_name,
+                               const GValue  *value,
+                               PagerPlugin   *plugin)
+{
+  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));
+
+  /* update the changed property */
+  if (strcmp (property_name, "/workspace-scrolling") == 0)
+    {
+      /* store new setting */
+      plugin->scrolling = g_value_get_boolean (value);
+    }
+  else if (strcmp (property_name, "/show-names") == 0)
+    {
+      /* store new value and set wnck pager display mode */
+      plugin->show_names = g_value_get_boolean (value);
+      wnck_pager_set_display_mode (WNCK_PAGER (plugin->wnck_pager),
+                                   plugin->show_names ?
+                                   WNCK_PAGER_DISPLAY_NAME :
+                                   WNCK_PAGER_DISPLAY_CONTENT);
+    }
+  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);
+      wnck_pager_set_n_rows (WNCK_PAGER (plugin->wnck_pager), plugin->rows);
+    }
+}
diff --git a/plugins/clock/clock.desktop.in.in b/plugins/pager/pager.desktop.in.in
similarity index 54%
copy from plugins/clock/clock.desktop.in.in
copy to plugins/pager/pager.desktop.in.in
index 7298d4a..d71cda1 100644
--- a/plugins/clock/clock.desktop.in.in
+++ b/plugins/pager/pager.desktop.in.in
@@ -1,9 +1,9 @@
 [Xfce Panel]
 Type=X-XFCE-PanelPlugin
 Encoding=UTF-8
-_Name=Clock
-_Comment=What time is it?
-Icon=office-calendar
-X-XFCE-Module=clock
+_Name=Pager
+_Comment=Miniature view of all virtual desktops
+Icon=xfce4-workspaces
+X-XFCE-Module=pager
 X-XFCE-Module-Path=@libdir@/xfce4/panel-plugins
 X-XFCE-External=FALSE
diff --git a/plugins/pager/pager.h b/plugins/pager/pager.h
new file mode 100644
index 0000000..05da29e
--- /dev/null
+++ b/plugins/pager/pager.h
@@ -0,0 +1,39 @@
+/* $Id$ */
+/*
+ * 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_H__
+#define __PAGER_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _PagerPluginClass PagerPluginClass;
+typedef struct _PagerPlugin      PagerPlugin;
+
+#define XFCE_TYPE_PAGER_PLUGIN            (pager_plugin_get_type ())
+#define XFCE_PAGER_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_PAGER_PLUGIN, PagerPlugin))
+#define XFCE_PAGER_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_PAGER_PLUGIN, PagerPluginClass))
+#define XFCE_IS_PAGER_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_PAGER_PLUGIN))
+#define XFCE_IS_PAGER_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_PAGER_PLUGIN))
+#define XFCE_PAGER_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_PAGER_PLUGIN, PagerPluginClass))
+
+GType pager_plugin_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* !__PAGER_H__ */



More information about the Xfce4-commits mailing list