Simple program to load panel plugin

Jean-François Wauthy pollux at xfce.org
Sat Aug 16 21:42:42 CEST 2008


Hi all,

It has been a while since I have contributed some useful code to one of
the core component, so here is my latest "production".

I've written a simple program that can load a panel plugin and send
events like the panel does. I came to writing this code because it
really bothers me of having to add, then to remove a plugin under
development to a panel in order to try and debug it. Also it creates
only one rc file in the panel config directory because it keeps using
the same identifier for the plugin.

I've attached the patch, the patch modifies configure.in.in but not
Makefile.am in the source code root of the panel. So it is ready to be
built but not automatically with a simple make so far.

Feedback is more than welcome. Also it does not support internal plugins
at this point but if there is interest for that it won't be a problem
for me to write the need code.

Cheers
-- 
Jean-François Wauthy <pollux at xfce.org>
-------------- next part --------------
diff --git a/configure.in.in b/configure.in.in
index ef403f9..e958692 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -267,6 +267,7 @@ plugins/showdesktop/Makefile
 plugins/systray/Makefile
 plugins/tasklist/Makefile
 plugins/windowlist/Makefile
+plugin-dev-container/Makefile
 mcs-plugin/Makefile
 po/Makefile.in
 docs/Makefile
diff --git a/plugin-dev-container/Makefile.am b/plugin-dev-container/Makefile.am
new file mode 100644
index 0000000..5c06495
--- /dev/null
+++ b/plugin-dev-container/Makefile.am
@@ -0,0 +1,41 @@
+# $Id$
+
+INCLUDES = 								\
+	-I$(top_srcdir)							\
+	-I$(top_builddir)						\
+	-DG_LOG_DOMAIN=\"plugin-dev-container\"				\
+	-DDATADIR=\"$(datadir)\"					\
+	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
+	$(PLATFORM_CPPFLAGS)
+
+bin_PROGRAMS = 								\
+	plugin-dev-container
+
+plugin_dev_container_headers =						\
+	container-window.h
+
+plugin_dev_container_SOURCES =						\
+	$(plugin_dev_container_headers)					\
+	container-window.c						\
+	main.c								
+
+plugin_dev_container_CFLAGS =						\
+	$(GMODULE_CFLAGS)						\
+	$(LIBXFCE4UTIL_CFLAGS)                                          \
+	$(LIBXFCEGUI4_CFLAGS)						\
+	$(PLATFORM_CFLAGS)
+
+plugin_dev_container_LDFLAGS =						\
+	-no-undefined							\
+	$(PLATFORM_LDFLAGS)
+
+plugin_dev_container_LDADD =						\
+	$(top_builddir)/libxfce4panel/libxfce4panel.la			\
+	$(LIBXFCE4UTIL_LIBS)                                            \
+	$(LIBXFCEGUI4_LIBS)                                             \
+	$(GMODULE_LIBS)							
+
+plugin_dev_container_DEPENDENCIES =					\
+	$(top_builddir)/libxfce4panel/libxfce4panel.la
+
+# vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/plugin-dev-container/container-window.c b/plugin-dev-container/container-window.c
new file mode 100644
index 0000000..19f9485
--- /dev/null
+++ b/plugin-dev-container/container-window.c
@@ -0,0 +1,198 @@
+/* $Id$
+ *
+ * Copyright (c) 2008 Jean-François Wauthy <pollux 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 Library 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/xfce-panel-enums.h>
+#include <libxfce4panel/xfce-panel-external-item.h>
+#include <libxfce4panel/xfce-panel-item-iface.h>
+
+#include "container-window.h"
+
+#define CONTAINER_WINDOW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TYPE_CONTAINER_WINDOW, ContainerWindowPrivate))
+
+typedef struct {
+  GtkWidget *spin;
+  GtkWidget *container;
+  GtkWidget *plugin;
+} ContainerWindowPrivate;
+
+/* prototypes */
+static void container_window_class_init (ContainerWindowClass *);
+static void container_window_init (ContainerWindow *);
+
+static gboolean cb_delete_window (ContainerWindow * win, GdkEvent * event, ContainerWindowPrivate *priv);
+static void cb_button_resize_clicked (GtkButton *button, ContainerWindowPrivate *priv);
+static void cb_button_save_clicked (GtkButton *button, ContainerWindowPrivate *priv);
+
+/* global */
+static GtkWindowClass *parent_class = NULL;
+
+/*************************/
+/* ContainerWindow class */
+/*************************/
+GtkType
+container_window_get_type (void)
+{
+  static GtkType container_window_type = 0;
+
+  if (!container_window_type) {
+    static const GTypeInfo container_window_info = {
+      sizeof (ContainerWindowClass),
+      NULL,
+      NULL,
+      (GClassInitFunc) container_window_class_init,
+      NULL,
+      NULL,
+      sizeof (ContainerWindow),
+      0,
+      (GInstanceInitFunc) container_window_init
+    };
+
+    container_window_type = g_type_register_static (GTK_TYPE_WINDOW, "ContainerWindow", &container_window_info, 0);
+  }
+
+  return container_window_type;
+}
+
+static void
+container_window_class_init (ContainerWindowClass * klass)
+{
+  g_type_class_add_private (klass, sizeof (ContainerWindowPrivate));
+
+  parent_class = g_type_class_peek_parent (klass);
+}
+
+static void
+container_window_init (ContainerWindow * window)
+{
+  ContainerWindowPrivate *priv = CONTAINER_WINDOW_GET_PRIVATE (window);
+
+  GtkWidget *hbox, *vbox, *button, *separator;
+  GtkWidget *hbox2, *image;
+
+  gtk_window_set_title (GTK_WINDOW (window), "Panel-plugin development container");
+  g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (cb_delete_window), priv);
+
+  hbox = gtk_hbox_new (FALSE, 5);
+  gtk_widget_show (hbox);
+
+  vbox = gtk_vbox_new (TRUE, 0);
+  gtk_widget_show (vbox);
+
+  /* resize button */
+  hbox2 = gtk_hbox_new (FALSE, 0);
+  gtk_widget_show (hbox2);
+
+  priv->spin = gtk_spin_button_new_with_range (1, 5000, 1);
+  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (priv->spin), FALSE);
+  gtk_widget_show (priv->spin);
+  gtk_box_pack_start (GTK_BOX (hbox2), priv->spin, FALSE, FALSE, 0);
+
+  button = gtk_button_new_with_label ("_Resize");
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cb_button_resize_clicked), priv);
+
+  image = gtk_image_new_from_stock (GTK_STOCK_FULLSCREEN, GTK_ICON_SIZE_BUTTON);
+  gtk_widget_show (image);
+  gtk_button_set_image (GTK_BUTTON (button), image);
+
+  gtk_box_pack_start (GTK_BOX (hbox2), button, TRUE, TRUE, 0);
+  gtk_widget_show (button); 
+
+  gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 2);
+
+  /* save button */
+  button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (cb_button_save_clicked), priv);
+  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+  gtk_widget_show (button);
+  
+  gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 2);
+
+  /* separator */
+  separator = gtk_vseparator_new ();
+  gtk_widget_show (separator);
+  gtk_box_pack_start (GTK_BOX (hbox), separator, FALSE, FALSE, 0);
+
+  /* container */
+  priv->container = gtk_alignment_new (0.5, 0.5, 0, 0);
+  gtk_widget_show (priv->container);
+  gtk_box_pack_start (GTK_BOX (hbox), priv->container, FALSE, FALSE, 0);
+
+  gtk_container_add (GTK_CONTAINER (window), hbox);
+}
+
+/*************/
+/* Callbacks */
+/*************/
+static gboolean
+cb_delete_window (ContainerWindow * win, GdkEvent * event, ContainerWindowPrivate *priv)
+{
+  gtk_main_quit ();
+
+  return FALSE;
+}
+
+static void
+cb_button_resize_clicked (GtkButton *button, ContainerWindowPrivate *priv)
+{
+  xfce_panel_item_set_size (XFCE_PANEL_ITEM (priv->plugin), gtk_spin_button_get_value (GTK_SPIN_BUTTON (priv->spin)));
+}
+
+static void
+cb_button_save_clicked (GtkButton *button, ContainerWindowPrivate *priv)
+{
+  xfce_panel_item_save (XFCE_PANEL_ITEM (priv->plugin));
+}
+
+/***************/
+/* Public API */
+/**************/
+
+GtkWidget *
+container_window_new (gboolean is_external, const gchar *name, const gchar *file, gint size)
+{
+  GtkWidget *obj = NULL;
+
+  obj = g_object_new (container_window_get_type (), NULL);
+
+  if (obj) {
+    ContainerWindowPrivate *priv = CONTAINER_WINDOW_GET_PRIVATE (obj);
+
+    if (is_external) {
+      priv->plugin = xfce_external_panel_item_new (name, "container-dev-plugin", "Plugin in development container", file, size, XFCE_SCREEN_POSITION_NONE);
+    } else {
+      g_warning ("Internal plugins are not yet supported.");
+    }
+
+    gtk_spin_button_set_value (GTK_SPIN_BUTTON (priv->spin), size);
+
+    if (priv->plugin) {
+      gtk_container_add (GTK_CONTAINER (priv->container), priv->plugin);
+      gtk_widget_show (priv->plugin);
+    }
+  }
+
+  return obj;
+}
+
diff --git a/plugin-dev-container/container-window.h b/plugin-dev-container/container-window.h
new file mode 100644
index 0000000..75fe91e
--- /dev/null
+++ b/plugin-dev-container/container-window.h
@@ -0,0 +1,53 @@
+/* $Id$
+ *
+ * Copyright (c) 2008 Jean-François Wauthy <pollux 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 Library 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 __CONTAINER_WINDOW_H__
+#define __CONTAINER_WINDOW_H__
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define TYPE_CONTAINER_WINDOW            (container_window_get_type ())
+#define CONTAINER_WINDOW(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_CONTAINER_WINDOW, ContainerWindow))
+#define CONTAINER_WINDOW_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_CONTAINER_WINDOW, ContainerWindowClass))
+#define IS_CONTAINER_WINDOW(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_CONTAINER_WINDOW))
+#define IS_CONTAINER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_CONTAINER_WINDOW))
+#define CONTAINER_WINDOW_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_CONTAINER_WINDOW, ContainerWindowClass))
+
+typedef struct 
+{
+  GtkWindow window;
+} ContainerWindow;
+
+typedef struct 
+{
+  GtkWindowClass parent_class;
+} ContainerWindowClass;
+
+GtkType container_window_get_type (void);
+
+GtkWidget *container_window_new (gboolean is_external, const gchar *name, const gchar *file, gint size);
+
+G_END_DECLS
+#endif
diff --git a/plugin-dev-container/main.c b/plugin-dev-container/main.c
new file mode 100644
index 0000000..b8a853e
--- /dev/null
+++ b/plugin-dev-container/main.c
@@ -0,0 +1,94 @@
+/* $Id$
+ *
+ * Copyright (c) 2008 Jean-François Wauthy <pollux 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 Library 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
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <libxfce4util/libxfce4util.h>
+
+#include "container-window.h"
+
+/* globals */
+static gboolean opt_internal = FALSE;
+static gchar *opt_file = NULL;
+static gint opt_size = 24;
+
+/* command line options */
+static GOptionEntry option_entries[] =
+{
+    { "internal", 'i', 0, G_OPTION_ARG_NONE, &opt_internal, "The plugin is an internal plugin", NULL },
+    { "file",     'f', 0, G_OPTION_ARG_FILENAME, &opt_file, "The path to the plugin binary file", NULL },
+    { "size",     's', 0, G_OPTION_ARG_INT, &opt_size,      "The size of the panel plugin at startup", NULL},
+    { NULL }
+};
+
+/* main program */
+gint
+main (gint argc, gchar **argv)
+{
+  GtkWidget *mainwin;
+  GError *error = NULL;
+
+  /* translation domain */
+  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
+
+  /* application name */
+  g_set_application_name (PACKAGE_NAME);
+
+  /* initialize gtk */
+  if (!gtk_init_with_args (&argc, &argv, "", option_entries, GETTEXT_PACKAGE, &error)) {
+    g_print ("%s: %s\n", PACKAGE_NAME, error ? error->message : _("Failed to open display"));
+    
+    if (error != NULL)
+      g_error_free (error);
+    
+    return EXIT_FAILURE;
+  }
+
+  if (G_UNLIKELY (opt_file == NULL)) {
+    g_error ("A path to a plugin must be provided");
+
+    return EXIT_FAILURE;
+  }
+  
+  mainwin = container_window_new (!opt_internal, "test", opt_file, opt_size);
+
+  gtk_widget_show (mainwin);
+
+  gtk_main ();
+
+  g_free (opt_file);
+
+  return EXIT_SUCCESS;
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Ceci est une partie de message num?riquement sign?e
URL: <http://mail.xfce.org/pipermail/xfce4-dev/attachments/20080816/47fa23aa/attachment.pgp>


More information about the Xfce4-dev mailing list