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

Mike Massonnet mmassonnet at xfce.org
Mon Apr 13 16:26:20 CEST 2009


Author: mmassonnet
Date: 2009-04-13 14:26:19 +0000 (Mon, 13 Apr 2009)
New Revision: 7177

Modified:
   xfce4-clipman-plugin/trunk/ChangeLog
   xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
   xfce4-clipman-plugin/trunk/panel-plugin/main.c
Log:
Set ownership on CLIPBOARD_MANAGER

Modified: xfce4-clipman-plugin/trunk/ChangeLog
===================================================================
--- xfce4-clipman-plugin/trunk/ChangeLog	2009-04-13 11:40:26 UTC (rev 7176)
+++ xfce4-clipman-plugin/trunk/ChangeLog	2009-04-13 14:26:19 UTC (rev 7177)
@@ -1,4 +1,17 @@
-2009-04-02	Mike Massonnet
+2009-04-13	Mike Massonnet
+Set ownership on CLIPBOARD_MANAGER
+
+	- panel-plugin/main.c:
+		Add a panel plugin check function and acquire ownership on the
+		X11 Selection CLIPBOARD_MANAGER. Quit the application if there
+		is an application already with the ownership. This part follows
+		the "clipboard manager spec" from freedesktop, but it doesn't
+		implement the possibility to be replaced by another manager.
+	- panel-plugin/main.c(plugin_preinit):
+		Set human readable name for the application if run in the
+		notification area.
+
+2009-04-13	Mike Massonnet
 Make the plugin run as a standalone application
 
 	- panel-plugin/main.c:
@@ -11,7 +24,7 @@
 	- Makefile.am, xfce4-clipman-plugin.desktop.in:
 		Install a desktop entry file for the menu.
 
-2009-04-02	Mike Massonnet
+2009-04-11	Mike Massonnet
 Set Clipman the owner of a text content only on specific target
 
 	- panel-plugin/collector.c(cb_clipboard_owner_change):
@@ -21,7 +34,7 @@
 		Useless call to clipman_history_add_text() as the text is going
 		into the default clipboard.
 
-2009-04-02	Mike Massonnet
+2009-04-10	Mike Massonnet
 New test program to report targets
 
 2009-04-02	Mike Massonnet

Modified: xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-04-13 11:40:26 UTC (rev 7176)
+++ xfce4-clipman-plugin/trunk/panel-plugin/Makefile.am	2009-04-13 14:26:19 UTC (rev 7177)
@@ -54,6 +54,8 @@
 	$(NULL)
 
 xfce4_clipman_plugin_CFLAGS =						\
+	@LIBX11_CFLAGS@							\
+	@GDKX_CFLAGS@							\
 	@GTK_CFLAGS@							\
 	@EXO_CFLAGS@							\
 	@LIBXFCE4UTIL_CFLAGS@						\
@@ -64,6 +66,8 @@
 	$(NULL)
 
 xfce4_clipman_plugin_LDADD =						\
+	@LIBX11_LIBS@							\
+	@GDKX_LIBS@							\
 	@GTK_LIBS@							\
 	@EXO_LIBS@							\
 	@LIBXFCE4UTIL_LIBS@						\

Modified: xfce4-clipman-plugin/trunk/panel-plugin/main.c
===================================================================
--- xfce4-clipman-plugin/trunk/panel-plugin/main.c	2009-04-13 11:40:26 UTC (rev 7176)
+++ xfce4-clipman-plugin/trunk/panel-plugin/main.c	2009-04-13 14:26:19 UTC (rev 7177)
@@ -21,6 +21,8 @@
 #endif
 
 #include <glib/gstdio.h>
+#include <X11/Xlib.h>
+#include <gdk/gdkx.h>
 #include <gtk/gtk.h>
 #include <libxfce4util/libxfce4util.h>
 #include <libxfcegui4/libxfcegui4.h>
@@ -85,7 +87,9 @@
 
 static gboolean         plugin_preinit                  (gint argc,
                                                          gchar *argv[]);
-XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL (panel_plugin_register, plugin_preinit, NULL);
+static gboolean         plugin_check                    (GdkScreen *screen);
+XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL_FULL (panel_plugin_register,
+                                          plugin_preinit, plugin_check);
 
 /*
  * Plugin Functions
@@ -107,6 +111,12 @@
                                                          MyPlugin *plugin);
 
 /*
+ * X11 Selection on CLIPBOARD_MANAGER
+ */
+
+static gboolean         my_plugin_take_ownership        ();
+
+/*
  * X11 Selection for the popup command
  */
 
@@ -170,10 +180,13 @@
 
   if (argc == 1)
     {
-      /* 
-       * Consider the plugin to be run by command line
-       */
+      /* Consider the plugin to be run by command line */
       gtk_init (&argc, &argv);
+
+      if (!plugin_check (NULL))
+        return FALSE;
+
+      g_set_application_name (_("Clipman"));
       plugin = status_icon_register ();
       gtk_main ();
       plugin_save (plugin);
@@ -184,6 +197,13 @@
   return TRUE;
 }
 
+static gboolean
+plugin_check (GdkScreen *screen)
+{
+  /* Take Ownership on CLIPBOARD_MANAGER */
+  return my_plugin_take_ownership ();
+}
+
 static MyPlugin *
 plugin_register ()
 {
@@ -674,6 +694,37 @@
 }
 
 /*
+ * X11 Selection on CLIPBOARD_MANAGER
+ */
+
+static gboolean
+my_plugin_take_ownership ()
+{
+  Display      *display;
+  Window        root;
+  Atom          atom;
+  GtkWidget    *dialog;
+
+  display = GDK_DISPLAY ();
+  root = XDefaultRootWindow (display);
+
+  atom = XInternAtom (display, "CLIPBOARD_MANAGER", FALSE);
+  if (XGetSelectionOwner (display, atom))
+    {
+      dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+                                       _("There is already a clipboard manager running"),
+                                       NULL);
+      gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);
+      gtk_dialog_run (GTK_DIALOG (dialog));
+      gtk_widget_destroy (dialog);
+      return FALSE;
+    }
+  XSetSelectionOwner (display, atom, root, GDK_CURRENT_TIME);
+
+  return TRUE;
+}
+
+/*
  * X11 Selection for the popup command
  */
 
@@ -688,7 +739,7 @@
 
   win = gtk_invisible_new ();
   gtk_widget_realize (win);
-  id = GDK_WINDOW_XID (GTK_WIDGET (win)->window);
+  id = GDK_WINDOW_XID (win->window);
 
   gscreen = gtk_widget_get_screen (win);
   selection_name = g_strdup_printf (XFCE_CLIPMAN_SELECTION"%d",




More information about the Goodies-commits mailing list