[Goodies-commits] r7094 - in xfce4-clipman-plugin/trunk: . panel-plugin

Mike Massonnet mmassonnet at xfce.org
Thu Apr 2 13:09:43 CEST 2009


Author: mmassonnet
Date: 2009-04-02 11:09:43 +0000 (Thu, 02 Apr 2009)
New Revision: 7094

Added:
   xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.c
Modified:
   xfce4-clipman-plugin/trunk/ChangeLog
   xfce4-clipman-plugin/trunk/configure.ac.in
   xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
   xfce4-clipman-plugin/trunk/panel-plugin/common.h
   xfce4-clipman-plugin/trunk/panel-plugin/panel-plugin.c
Log:
Install a popup command

Modified: xfce4-clipman-plugin/trunk/ChangeLog
===================================================================
--- xfce4-clipman-plugin/trunk/ChangeLog	2009-04-02 10:46:59 UTC (rev 7093)
+++ xfce4-clipman-plugin/trunk/ChangeLog	2009-04-02 11:09:43 UTC (rev 7094)
@@ -1,3 +1,14 @@
+2009-04-02	Mike Massonnet
+Install a popup command
+
+	- configure.ac.in, panel-plugin/Makefile.am:
+		Install the new binary xfce4-popup-clipman.
+	- panel-plugin/panel-plugin.c, panel-plugin/common.h:
+		Add an X11 selection on the panel plugin and listen to it.
+	- panel-plugin/xfce4-popup-clipman.c:
+		New binary that sends a message to the X11 selection installed
+		in the panel plugin.
+
 2009-04-01	Mike Massonnet
 Set long URLs to 120 characters at least
 

Modified: xfce4-clipman-plugin/trunk/configure.ac.in
===================================================================
--- xfce4-clipman-plugin/trunk/configure.ac.in	2009-04-02 10:46:59 UTC (rev 7093)
+++ xfce4-clipman-plugin/trunk/configure.ac.in	2009-04-02 11:09:43 UTC (rev 7094)
@@ -58,6 +58,7 @@
 dnl *** Check for required packages ***
 dnl ***********************************
 XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.14.0])
+XDT_CHECK_PACKAGE([GDKX], [gdk-x11-2.0], [2.10.0])
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.10.0])
 XDT_CHECK_PACKAGE([EXO], [exo-0.3], [0.3.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.4.0])

Modified: xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-04-02 10:46:59 UTC (rev 7093)
+++ xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-04-02 11:09:43 UTC (rev 7094)
@@ -9,6 +9,39 @@
 	-DLOCALEDIR=\"$(localedir)\"					\
 	$(NULL)
 
+EXTRA_DIST =								\
+	settings-dialog.glade						\
+	$(NULL)
+
+CLEANFILES =								\
+	$(desktop_DATA)							\
+	$(NULL)
+
+#
+# Popup Command
+#
+
+bin_PROGRAMS = xfce4-popup-clipman
+
+xfce4_popup_clipman_SOURCES =						\
+	xfce4-popup-clipman.c						\
+	$(NULL)
+
+xfce4_popup_clipman_CFLAGS =                                            \
+	@LIBX11_CFLAGS@							\
+	@GTK_CFLAGS@							\
+	@GTK_CFLAGS@							\
+	$(NULL)
+
+xfce4_popup_clipman_LDADD =						\
+	@LIBX11_LIBS@							\
+	@GTK_LIBS@							\
+	$(NULL)
+
+#
+# Plugin
+#
+
 plugindir = $(libexecdir)/xfce4/panel-plugins
 plugin_PROGRAMS = xfce4-clipman-plugin
 
@@ -47,11 +80,19 @@
 	exo-csource --static --strip-comments --strip-content --name=settings_dialog_glade $< >$@
 endif
 
+#
+# Actions
+#
+
 actionsdir = $(sysconfdir)/xdg/xfce4/panel
 actions_in_files = xfce4-clipman-actions.xml.in
 actions_DATA = $(actions_in_files:.xml.in=.xml)
 @INTLTOOL_XML_RULE@
 
+#
+# Desktop Entry File
+#
+
 desktopdir = $(datadir)/xfce4/panel-plugins
 desktop_in_in_files = xfce4-clipman-plugin.desktop.in.in
 desktop_in_files = $(desktop_in_in_files:.desktop.in.in=.desktop.in)
@@ -62,11 +103,3 @@
 	sed -e "s^@EXTERNAL_PLUGIN_PATH@^$(libexecdir)/xfce4/panel-plugins^" \
 		$< > $@
 
-EXTRA_DIST =								\
-	settings-dialog.glade						\
-	$(NULL)
-
-CLEANFILES =								\
-	$(desktop_DATA)							\
-	$(NULL)
-

Modified: xfce4-clipman-plugin/trunk/panel-plugin/common.h
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/common.h	2009-04-02 10:46:59 UTC (rev 7093)
+++ xfce4-clipman-plugin/trunk/panel-plugin/common.h	2009-04-02 11:09:43 UTC (rev 7094)
@@ -31,3 +31,10 @@
 #define DEFAULT_ADD_PRIMARY_CLIPBOARD           FALSE
 #define DEFAULT_ENABLE_ACTIONS                  FALSE
 
+/*
+ * Selection for the popup command
+ */
+
+#define XFCE_CLIPMAN_SELECTION    "XFCE_CLIPMAN_SELECTION"
+#define XFCE_CLIPMAN_MESSAGE      "MENU"
+

Modified: xfce4-clipman-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/panel-plugin.c	2009-04-02 10:46:59 UTC (rev 7093)
+++ xfce4-clipman-plugin/trunk/panel-plugin/panel-plugin.c	2009-04-02 11:09:43 UTC (rev 7094)
@@ -89,6 +89,14 @@
                                                          MyPlugin *plugin);
 
 /*
+ * Selection for the popup command declarations
+ */
+
+static gboolean         my_plugin_set_selection         (MyPlugin *plugin);
+static gboolean         cb_message_received             (MyPlugin *plugin,
+                                                         GdkEventClient *ev);
+
+/*
  * Settings Dialog functions declarations
  */
 
@@ -206,6 +214,9 @@
   /* Load the data */
   panel_plugin_load (panel_plugin, plugin);
 
+  /* Set the selection for the popup command */
+  my_plugin_set_selection (plugin);
+
   gtk_widget_show_all (GTK_WIDGET (panel_plugin));
 }
 
@@ -518,6 +529,62 @@
 }
 
 /*
+ * Selection for the popup command
+ */
+
+static gboolean
+my_plugin_set_selection (MyPlugin *plugin)
+{
+  GdkScreen          *gscreen;
+  gchar              *selection_name;
+  Atom                selection_atom;
+  GtkWidget          *win;
+  Window              id;
+
+  win = gtk_invisible_new ();
+  gtk_widget_realize (win);
+  id = GDK_WINDOW_XID (GTK_WIDGET (win)->window);
+
+  gscreen = gtk_widget_get_screen (win);
+  selection_name = g_strdup_printf (XFCE_CLIPMAN_SELECTION"%d",
+                                    gdk_screen_get_number (gscreen));
+  selection_atom = XInternAtom (GDK_DISPLAY(), selection_name, FALSE);
+
+  if (XGetSelectionOwner (GDK_DISPLAY(), selection_atom))
+    {
+      gtk_widget_destroy (win);
+      return FALSE;
+    }
+
+  XSelectInput (GDK_DISPLAY(), id, PropertyChangeMask);
+  XSetSelectionOwner (GDK_DISPLAY(), selection_atom, id, GDK_CURRENT_TIME);
+
+  g_signal_connect_swapped (win, "client-event",
+                            G_CALLBACK (cb_message_received), plugin);
+
+  return TRUE;
+}
+
+static gboolean
+cb_message_received (MyPlugin *plugin,
+                     GdkEventClient *ev)
+{
+  if (G_LIKELY (ev->data_format == 8 && *(ev->data.b) != '\0'))
+    {
+      if (!g_ascii_strcasecmp (XFCE_CLIPMAN_MESSAGE, ev->data.b))
+        {
+          DBG ("Message received: %s", ev->data.b);
+          xfce_panel_plugin_set_panel_hidden (plugin->panel_plugin, FALSE);
+          while (gtk_events_pending ())
+            gtk_main_iteration ();
+          gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (plugin->button), TRUE);
+          return TRUE;
+        }
+    }
+  return FALSE;
+}
+
+/*
  * Settings Dialog functions
  */
 

Added: xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.c	                        (rev 0)
+++ xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.c	2009-04-02 11:09:43 UTC (rev 7094)
@@ -0,0 +1,80 @@
+/*
+ *  Clipman - panel plugin for Xfce Desktop Environment
+ *            popup command to show the clipman menu
+ *  Copyright (C) 2002-2006  Olivier Fourdan
+ *                2008-2009  Mike Massonnet <mmassonnet 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 <X11/Xlib.h>
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+
+#include "common.h"
+
+static gboolean
+clipman_plugin_check_is_running (GtkWidget *widget,
+                                 Window *xid)
+{
+  GdkScreen          *gscreen;
+  gchar              *selection_name;
+  Atom                selection_atom;
+
+  gscreen = gtk_widget_get_screen (widget);
+  selection_name = g_strdup_printf (XFCE_CLIPMAN_SELECTION"%d",
+                                    gdk_screen_get_number (gscreen));
+  selection_atom = XInternAtom (GDK_DISPLAY(), selection_name, FALSE);
+
+  if ((*xid = XGetSelectionOwner (GDK_DISPLAY(), selection_atom)))
+    return TRUE;
+
+  return FALSE;
+}
+
+gint
+main (gint argc, gchar *argv[])
+{
+  GdkEventClient        gev;
+  GtkWidget            *win;
+  Window                id;
+
+  gtk_init (&argc, &argv);
+
+  win = gtk_invisible_new ();
+  gtk_widget_realize (win);
+
+  gev.type              = GDK_CLIENT_EVENT;
+  gev.window            = win->window;
+  gev.send_event        = TRUE;
+  gev.message_type      = gdk_atom_intern ("STRING", FALSE);
+  gev.data_format       = 8;
+  g_snprintf (gev.data.b, sizeof (gev.data.b), XFCE_CLIPMAN_MESSAGE);
+
+  if (clipman_plugin_check_is_running (win, &id))
+    gdk_event_send_client_message ((GdkEvent *)&gev, (GdkNativeWindow)id);
+  else
+    g_warning ("Can't find the xfce4-clipman-plugin.\n");
+  gdk_flush ();
+
+  gtk_widget_destroy (win);
+
+  return FALSE;
+}
+




More information about the Goodies-commits mailing list