[Xfce4-commits] <xfce4-clipman-plugin:master> New feature "paste-on-activate"

Mike Massonnet noreply at xfce.org
Thu Oct 20 11:42:07 CEST 2011


Updating branch refs/heads/master
         to 6167c3a5bae9dfcce3710127ae28d14b66e02f46 (commit)
       from d97d667412dc240909891b98b69e7c8ff89bd6c5 (commit)

commit 6167c3a5bae9dfcce3710127ae28d14b66e02f46
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Wed Oct 19 19:39:09 2011 +0200

    New feature "paste-on-activate"
    
    There is a new property in the ClipmanMenu class "paste-on-activate" that
    is bound to the xfconf property "/tweaks/paste-on-activate". This new
    property gives the possibility to paste a content that has been selected
    in the history.
    
    Currently the default value is off, there are two possible values to
    paste the content with Ctrl+V or Shift+Insert.

 panel-plugin/Makefile.am |    4 ++
 panel-plugin/collector.c |    1 -
 panel-plugin/common.h    |    7 +++
 panel-plugin/menu.c      |  102 +++++++++++++++++++++++++++++++++++++++++++---
 panel-plugin/plugin.c    |    2 +
 5 files changed, 109 insertions(+), 7 deletions(-)

diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am
index 88fef2d..75c354b 100644
--- a/panel-plugin/Makefile.am
+++ b/panel-plugin/Makefile.am
@@ -95,6 +95,7 @@ xfce4_clipman_CFLAGS =							\
 	@GIO_CFLAGS@							\
 	@EXO_CFLAGS@							\
 	@LIBX11_CFLAGS@							\
+	@LIBXTST_CFLAGS@						\
 	@GDKX_CFLAGS@							\
 	@GTK_CFLAGS@							\
 	@LIBXFCE4UTIL_CFLAGS@						\
@@ -107,6 +108,7 @@ xfce4_clipman_LDADD =							\
 	@GIO_LIBS@							\
 	@EXO_LIBS@							\
 	@LIBX11_LIBS@							\
+	@LIBXTST_LIBS@							\
 	@GDKX_LIBS@							\
 	@GTK_LIBS@							\
 	@LIBXFCE4UTIL_LIBS@						\
@@ -136,6 +138,7 @@ xfce4_clipman_plugin_CFLAGS =						\
 	@GIO_CFLAGS@							\
 	@EXO_CFLAGS@							\
 	@LIBX11_CFLAGS@							\
+	@LIBXTST_CFLAGS@						\
 	@GDKX_CFLAGS@							\
 	@GTK_CFLAGS@							\
 	@LIBXFCE4UTIL_CFLAGS@						\
@@ -149,6 +152,7 @@ xfce4_clipman_plugin_LDADD =						\
 	@GIO_LIBS@							\
 	@EXO_LIBS@							\
 	@LIBX11_LIBS@							\
+	@LIBXTST_LIBS@							\
 	@GDKX_LIBS@							\
 	@GTK_LIBS@							\
 	@LIBXFCE4UTIL_LIBS@						\
diff --git a/panel-plugin/collector.c b/panel-plugin/collector.c
index e758cfa..a2705d0 100644
--- a/panel-plugin/collector.c
+++ b/panel-plugin/collector.c
@@ -22,7 +22,6 @@
 
 #include <gtk/gtk.h>
 #include <libxfce4util/libxfce4util.h>
-#include <xfconf/xfconf.h>
 
 #include "common.h"
 #include "actions.h"
diff --git a/panel-plugin/common.h b/panel-plugin/common.h
index 633f019..76fa9c5 100644
--- a/panel-plugin/common.h
+++ b/panel-plugin/common.h
@@ -34,6 +34,13 @@
 #define DEFAULT_ENABLE_ACTIONS                          FALSE
 
 /*
+ * Modes for paste-on-activate
+ */
+#define PASTE_INACTIVE  0
+#define PASTE_CTRL_V    1
+#define PASTE_SHIFT_INS 2
+
+/*
  * Selection for the popup command
  */
 
diff --git a/panel-plugin/menu.c b/panel-plugin/menu.c
index 0b0596f..1d11593 100644
--- a/panel-plugin/menu.c
+++ b/panel-plugin/menu.c
@@ -24,6 +24,13 @@
 #include <libxfce4ui/libxfce4ui.h>
 #include <libxfce4util/libxfce4util.h>
 
+#ifdef HAVE_LIBXTST
+#include <X11/Xlib.h>
+#include <X11/extensions/XTest.h>
+#include <X11/keysym.h>
+#endif
+
+#include "common.h"
 #include "collector.h"
 #include "history.h"
 
@@ -44,12 +51,18 @@ struct _ClipmanMenuPrivate
   ClipmanHistory       *history;
   GSList               *list;
   gboolean              reverse_order;
+#ifdef HAVE_LIBXTST
+  guint                 paste_on_activate;
+#endif
 };
 
 enum
 {
   REVERSE_ORDER = 1,
   INHIBIT_MENU_ITEM,
+#ifdef HAVE_LIBXTST
+  PASTE_ON_ACTIVATE,
+#endif
 };
 
 static void             clipman_menu_finalize           (GObject *object);
@@ -72,7 +85,8 @@ static void            _clipman_menu_free_list          (ClipmanMenu *menu);
  * Callbacks declarations
  */
 
-static void             cb_set_clipboard                (const ClipmanHistoryItem *item);
+static void             cb_set_clipboard                (GtkMenuItem *mi,
+                                                         const ClipmanHistoryItem *item);
 static void             cb_clear_history                (ClipmanMenu *menu);
 static void             cb_toggle_inhibit_mi            (ClipmanMenu *menu);
 
@@ -83,7 +97,7 @@ static void             cb_toggle_inhibit_mi            (ClipmanMenu *menu);
  */
 
 static void
-cb_set_clipboard (const ClipmanHistoryItem *item)
+cb_set_clipboard (GtkMenuItem *mi, const ClipmanHistoryItem *item)
 {
   GtkClipboard *clipboard;
   ClipmanCollector *collector;
@@ -117,6 +131,63 @@ cb_set_clipboard (const ClipmanHistoryItem *item)
     default:
       g_assert_not_reached ();
     }
+
+#ifdef HAVE_LIBXTST
+  {
+    int dummyi;
+    KeySym key_sym;
+    KeyCode key_code;
+
+    Display *display = XOpenDisplay (NULL);
+    if (display == NULL)
+      {
+        return;
+      }
+    else if (!XQueryExtension (display, "XTEST", &dummyi, &dummyi, &dummyi))
+      {
+        XCloseDisplay (display);
+        return;
+      }
+
+    switch (GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (mi), "paste-on-activate")))
+      {
+      case PASTE_INACTIVE:
+        break;
+
+      case PASTE_CTRL_V:
+        key_sym = XK_Control_L;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, True, CurrentTime);
+        key_sym = XK_v;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, True, CurrentTime);
+        key_sym = XK_v;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, False, CurrentTime);
+        key_sym = XK_Control_L;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, False, CurrentTime);
+        break;
+
+      case PASTE_SHIFT_INS:
+        key_sym = XK_Shift_L;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, True, CurrentTime);
+        key_sym = XK_Insert;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, True, CurrentTime);
+        key_sym = XK_Insert;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, False, CurrentTime);
+        key_sym = XK_Shift_L;
+        key_code = XKeysymToKeycode (display, key_sym);
+        XTestFakeKeyEvent (display, key_code, False, CurrentTime);
+        break;
+      }
+
+    XCloseDisplay (display);
+  }
+#endif
 }
 
 static void
@@ -177,20 +248,23 @@ _clipman_menu_update_list (ClipmanMenu *menu)
         {
         case CLIPMAN_HISTORY_TYPE_TEXT:
           mi = gtk_image_menu_item_new_with_label (item->preview.text);
-          g_signal_connect_swapped (mi, "activate", G_CALLBACK (cb_set_clipboard), item);
           break;
 
         case CLIPMAN_HISTORY_TYPE_IMAGE:
           mi = gtk_image_menu_item_new ();
           image = gtk_image_new_from_pixbuf (item->preview.image);
           gtk_container_add (GTK_CONTAINER (mi), image);
-          g_signal_connect_swapped (mi, "activate", G_CALLBACK (cb_set_clipboard), item);
           break;
 
         default:
           g_assert_not_reached ();
         }
 
+      g_signal_connect (mi, "activate", G_CALLBACK (cb_set_clipboard), item);
+#ifdef HAVE_LIBXTST
+      g_object_set_data (G_OBJECT (mi), "paste-on-activate", GUINT_TO_POINTER (menu->priv->paste_on_activate));
+#endif
+
       if (item == item_to_restore)
         {
           image = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_MENU);
@@ -268,6 +342,14 @@ clipman_menu_class_init (ClipmanMenuClass *klass)
                                                          "Toggle the inhibit menu item to TRUE or FALSE",
                                                          FALSE,
                                                          G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
+#ifdef HAVE_LIBXTST
+  g_object_class_install_property (object_class, PASTE_ON_ACTIVATE,
+                                   g_param_spec_uint ("paste-on-activate",
+                                                      "PasteOnActivate",
+                                                      "Paste the content of a menu item when it is activated",
+                                                      0, 2, 0,
+                                                      G_PARAM_CONSTRUCT|G_PARAM_READWRITE));
+#endif
 }
 
 static void
@@ -324,7 +406,11 @@ clipman_menu_set_property (GObject *object,
       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (priv->mi_inhibit),
                                       g_value_get_boolean (value));
       break;
-
+#ifdef HAVE_LIBXTST
+    case PASTE_ON_ACTIVATE:
+      priv->paste_on_activate = g_value_get_uint (value);
+      break;
+#endif
     default:
       break;
     }
@@ -347,7 +433,11 @@ clipman_menu_get_property (GObject *object,
     case INHIBIT_MENU_ITEM:
       g_value_set_boolean (value, gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (priv->mi_inhibit)));
       break;
-
+#ifdef HAVE_LIBXTST
+    case PASTE_ON_ACTIVATE:
+      g_value_set_uint (value, priv->paste_on_activate);
+      break;
+#endif
     default:
       break;
     }
diff --git a/panel-plugin/plugin.c b/panel-plugin/plugin.c
index 2dccfea..64132e1 100644
--- a/panel-plugin/plugin.c
+++ b/panel-plugin/plugin.c
@@ -113,6 +113,8 @@ plugin_register (void)
                           G_TYPE_BOOLEAN, plugin->menu, "reverse-order");
   xfconf_g_property_bind (plugin->channel, "/tweaks/inhibit",
                           G_TYPE_BOOLEAN, plugin->menu, "inhibit-menu-item");
+  xfconf_g_property_bind (plugin->channel, "/tweaks/paste-on-activate",
+                          G_TYPE_UINT, plugin->menu, "paste-on-activate");
 
   /* Load the data */
   plugin_load (plugin);


More information about the Xfce4-commits mailing list