[Goodies-commits] r3866 - xfce4-clipman-plugin/trunk/panel-plugin

Mike Massonnet mmassonnet at xfce.org
Thu Jan 24 14:09:16 CET 2008


Author: mmassonnet
Date: 2008-01-24 13:09:16 +0000 (Thu, 24 Jan 2008)
New Revision: 3866

Added:
   xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.c
   xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.h
Modified:
   xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
   xfce4-clipman-plugin/trunk/panel-plugin/clipman.c
Log:
* panel-plugin/Makefile.am,
  panel-plugin/xfce4-popup-clipman.c,
  panel-plugin/xfce4-popup-clipman.h,
  panel-plugin/clipman.c: Add popup command.


Modified: xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2008-01-24 13:09:09 UTC (rev 3865)
+++ xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2008-01-24 13:09:16 UTC (rev 3866)
@@ -1,3 +1,18 @@
+bin_PROGRAMS = xfce4-popup-clipman
+
+xfce4_popup_clipman_SOURCES =						\
+	xfce4-popup-clipman.h						\
+	xfce4-popup-clipman.c
+
+xfce4_popup_clipman_CFLAGS =						\
+	@LIBX11_CFLAGS@							\
+	@GTK_CFLAGS@
+
+xfce4_popup_clipman_LDADD =						\
+	@LIBX11_LDFLAGS@						\
+	@LIBX11_LIBS@							\
+	@GTK_LIBS@
+	
 plugindir = $(libexecdir)/xfce4/panel-plugins
 plugin_PROGRAMS = xfce4-clipman-plugin
 

Modified: xfce4-clipman-plugin/trunk/panel-plugin/clipman.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/clipman.c	2008-01-24 13:09:09 UTC (rev 3865)
+++ xfce4-clipman-plugin/trunk/panel-plugin/clipman.c	2008-01-24 13:09:16 UTC (rev 3866)
@@ -27,6 +27,7 @@
 
 #include "clipman.h"
 #include "clipman-dialogs.h"
+#include "xfce4-popup-clipman.h"
 
 
 
@@ -68,9 +69,13 @@
                                                                      const gchar *text);
 static void                     clipman_plugin_delete               (ClipmanPlugin *clipman_plugin,
                                                                      ClipmanClip *clip);
+static gboolean                 clipman_plugin_message_received     (ClipmanPlugin *clipman_plugin,
+                                                                     GdkEventClient *ev);
+static gboolean                 clipman_plugin_set_selection        (ClipmanPlugin *clipman_plugin);
 
 
 
+
 static ClipmanClips *           clipman_clips_new                   (ClipmanPlugin *clipman_plugin);
 
 static void                     clipman_clips_clear_history         (ClipmanClips *clipman_clips);
@@ -125,6 +130,7 @@
 
   xfce_panel_plugin_menu_show_configure (panel_plugin);
   xfce_panel_plugin_add_action_widget (panel_plugin, clipman_plugin->button);
+  clipman_plugin_set_selection (clipman_plugin);
 
   gtk_widget_show_all (clipman_plugin->button);
 }
@@ -861,8 +867,62 @@
   clipman_clips_delete (clipman_clips, clip);
 }
 
+static gboolean
+clipman_plugin_message_received (ClipmanPlugin *clipman_plugin,
+                                 GdkEventClient *ev)
+{
+  DBG ("Message received");
+  if (G_LIKELY (ev->data_format == 8 && *(ev->data.b) != '\0'))
+    {
+      if (!g_ascii_strcasecmp (XFCE_CLIPMAN_MESSAGE, ev->data.b))
+        {
+          DBG ("`%s'", ev->data.b);
+          xfce_panel_plugin_set_panel_hidden (clipman_plugin->panel_plugin, FALSE);
+          while (gtk_events_pending ())
+            gtk_main_iteration ();
+          gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (clipman_plugin->button), TRUE);
+          return TRUE;
+        }
+    }
+  return FALSE;
+}
 
+static gboolean
+clipman_plugin_set_selection (ClipmanPlugin *clipman_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 (clipman_plugin_message_received),
+                            clipman_plugin);
+
+  return TRUE;
+}
+
+
+
 static ClipmanClips *
 clipman_clips_new (ClipmanPlugin *clipman_plugin)
 {

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	2008-01-24 13:09:16 UTC (rev 3866)
@@ -0,0 +1,82 @@
+/*
+ *  Clipman - panel plugin for Xfce Desktop Environment
+ *            popup command to show the clipman menu
+ *  Copyright (C) 2002-2006  Olivier Fourdan
+ *                2008  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 <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include <X11/Xlib.h>
+
+#include "xfce4-popup-clipman.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;
+}
+

Added: xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.h
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.h	                        (rev 0)
+++ xfce4-clipman-plugin/trunk/panel-plugin/xfce4-popup-clipman.h	2008-01-24 13:09:16 UTC (rev 3866)
@@ -0,0 +1,29 @@
+/*
+ *  Clipman - panel plugin for Xfce Desktop Environment
+ *            popup command to show the clipman menu
+ *  Copyright (C) 2002-2006  Olivier Fourdan
+ *                2008  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.
+ */
+
+#ifndef __XFCE4_POPUP_CLIPMAN_H__
+#define __XFCE4_POPUP_CLIPMAN_H__
+
+#define XFCE_CLIPMAN_SELECTION    "XFCE_NOTES_SELECTION"
+#define XFCE_CLIPMAN_MESSAGE      "MENU"
+
+#endif
+




More information about the Goodies-commits mailing list