All,

I'm not sure if there's broad interest in this, but if there is I'd like to
submit this patch for inclusion in rxvt-unicode.  What it does is optionally
add two new options to the program:

* selectClipboard (-/+clip) -- This reverses the treatment of the PRIMARY
and CLIPBOARD selections.
* twoButtonMouse (-/+tbm) -- This switches Button3 to paste from the
clipboard, rather than copy to it.

These address two issues I encountered when I switched my laptop from
gnome-terminal to uxvt-unicode. The default selection behavior made it
difficult to interoprate with other applications (mainly Firefox). The use
of mouse buttons on a two-button laptop then meant that pasting required
faking a Button2 click by simultaneously pressing Buttons 1 and 3. These
options are enabled by a new configure option that defaults to 'yes'.

If there are any questions, fixes, or suggestions, please let me know.

Thanks,
Mike
diff -rupN rxvt-unicode-original/configure.ac rxvt-unicode-modified/configure.ac
--- rxvt-unicode-original/configure.ac	2008-01-27 17:48:31.000000000 -0500
+++ rxvt-unicode-modified/configure.ac	2008-05-15 17:54:26.000000000 -0400
@@ -102,6 +102,7 @@ support_unicode3=no
 support_combining=yes
 support_8bitctrls=no
 support_iso14755=yes
+support_selection_options=yes
 support_styles=yes
 support_perl=yes
 codesets=all
@@ -138,6 +139,7 @@ AC_ARG_ENABLE(everything,
        support_combining=no
        support_8bitctrls=no
        support_iso14755=no
+       support_selection_options=no
        support_styles=no
        support_perl=no
        codesets=
@@ -166,6 +168,7 @@ AC_ARG_ENABLE(everything,
        support_combining=yes
        #support_8bitctrls=yes
        support_iso14755=yes
+       support_selection_options=yes
        support_styles=yes
        support_perl=yes
        codesets=all
@@ -346,6 +349,12 @@ AC_ARG_ENABLE(iso14755,
     support_iso14755=$enableval
   fi])
 
+AC_ARG_ENABLE(selection_options,
+  [  --enable-selection-options       enable support for selection options],
+  [if test x$enableval = xyes -o x$enableval = xno; then
+    support_selection_options=$enableval
+  fi])
+
 AC_ARG_ENABLE(frills,
   [  --enable-frills         enable support for rarely used features],
   [if test x$enableval = xyes -o x$enableval = xno; then
@@ -606,6 +615,9 @@ fi
 if test x$support_iso14755 = xyes; then
   AC_DEFINE(ISO_14755, 1, Define if you want ISO 14755 extended support)
 fi
+if test x$support_selection_options = xyes; then
+  AC_DEFINE(SELECTION_OPTIONS, 1, Define if you want support for selection options)
+fi
 if test x$support_8bitctrls = xyes; then
   AC_DEFINE(EIGHT_BIT_CONTROLS, 1, Define if you want 8 bit control sequences)
 fi
diff -rupN rxvt-unicode-original/README.configure rxvt-unicode-modified/README.configure
--- rxvt-unicode-original/README.configure	2008-01-29 06:00:49.000000000 -0500
+++ rxvt-unicode-modified/README.configure	2008-05-19 09:38:33.000000000 -0400
@@ -253,3 +253,6 @@ CONFIGURE OPTIONS
     --with-x
         Use the X Window System (pretty much default, eh?).
 
+    --enable-selection-options (default: on)
+        Enable support for options that support two button mice and
+        swapping the CLIPBOARD and PRIMARY selectitons.
diff -rupN rxvt-unicode-original/src/command.C rxvt-unicode-modified/src/command.C
--- rxvt-unicode-original/src/command.C	2008-04-25 23:37:18.000000000 -0400
+++ rxvt-unicode-modified/src/command.C	2008-05-19 09:41:18.000000000 -0400
@@ -2122,13 +2122,28 @@ rxvt_term::button_release (XButtonEvent 
       switch (ev.button)
         {
           case Button1:
-          case Button3:
             selection_make (ev.time);
             break;
 
+
+          case Button3:
+            if (!option (Opt_twoButtonMouse) )
+              {
+                selection_make (ev.time);
+                break;
+              }
+            /* FALL THROUGH to paste if twoButtonMouse is enabled. */
+
           case Button2:
             if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
-	      selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
+              {
+                int selnum = ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary;
+
+                if (option (Opt_selectClipboard))
+                  selnum = ev.state & ModMetaMask ? Sel_Primary : Sel_Clipboard;
+
+                selection_request (ev.time, selnum);
+              }
             break;
 
 #ifdef MOUSE_WHEEL
diff -rupN rxvt-unicode-original/src/optinc.h rxvt-unicode-modified/src/optinc.h
--- rxvt-unicode-original/src/optinc.h	2008-01-28 05:44:21.000000000 -0500
+++ rxvt-unicode-modified/src/optinc.h	2008-05-15 17:49:50.000000000 -0400
@@ -62,4 +62,10 @@
 #else
  nodef(buffered)
 #endif
-
+#ifdef SELECTION_OPTIONS
+ def (selectClipboard,     35)
+ def (twoButtonMouse,      36)
+#else
+ nodef (selectClipboard)
+ nodef (twoButtonMouse)
+#endif
diff -rupN rxvt-unicode-original/src/rsinc.h rxvt-unicode-modified/src/rsinc.h
--- rxvt-unicode-original/src/rsinc.h	2008-01-27 17:48:33.000000000 -0500
+++ rxvt-unicode-modified/src/rsinc.h	2008-05-15 17:49:51.000000000 -0400
@@ -116,3 +116,7 @@
   def (blendtype)
   def (blurradius)
 #endif
+#ifdef SELECTION_OPTIONS
+  def (selectClipboard)
+  def (twoButtonMouse)
+#endif
diff -rupN rxvt-unicode-original/src/screen.C rxvt-unicode-modified/src/screen.C
--- rxvt-unicode-original/src/screen.C	2008-02-21 05:30:24.000000000 -0500
+++ rxvt-unicode-modified/src/screen.C	2008-05-19 09:41:29.000000000 -0400
@@ -2852,7 +2852,7 @@ rxvt_term::selection_property (Window wi
  *        > CUT_BUFFER0
  * (+) if ownership is claimed but property is empty, rxvt_selection_paste ()
  *     will auto fallback to CUT_BUFFER0
- * EXT: button 2 release
+ * EXT: button 2 release (or Button 3 release if Opt_twoButtonMouse)
  */
 void
 rxvt_term::selection_request (Time tm, int selnum) NOTHROW
@@ -2930,7 +2930,7 @@ rxvt_term::selection_clear () NOTHROW
 /* ------------------------------------------------------------------------- */
 /*
  * Copy a selection into the cut buffer
- * EXT: button 1 or 3 release
+ * EXT: button 1 (or 3 release if not Opt_twoButtonMouse)
  */
 void
 rxvt_term::selection_make (Time tm)
@@ -3064,8 +3064,10 @@ rxvt_term::selection_grab (Time tm) NOTH
 {
   selection_time = tm;
 
-  XSetSelectionOwner (dpy, XA_PRIMARY, vt, tm);
-  if (XGetSelectionOwner (dpy, XA_PRIMARY) == vt)
+  Atom sel = option (Opt_selectClipboard) ? xa[XA_CLIPBOARD] : XA_PRIMARY;
+
+  XSetSelectionOwner (dpy, sel, vt, tm);
+  if (XGetSelectionOwner (dpy, sel) == vt)
     {
       display->set_selection_owner (this);
       return true;
diff -rupN rxvt-unicode-original/src/xdefaults.C rxvt-unicode-modified/src/xdefaults.C
--- rxvt-unicode-original/src/xdefaults.C	2008-02-16 10:56:41.000000000 -0500
+++ rxvt-unicode-modified/src/xdefaults.C	2008-05-15 18:04:50.000000000 -0400
@@ -264,6 +264,10 @@ optList[] = {
               STRG (Rs_blendtype, "blendType", "blt", "string", "background image blending type - alpha, tint, etc..."),
               STRG (Rs_blurradius, "blurRadius", "blr", "HxV", "Gaussian Blur radii to apply to the root background"),
 #endif
+#ifdef SELECTION_OPTIONS
+              BOOL (Rs_selectClipboard, "selectClipboard", "clip", Opt_selectClipboard, 0, "default to the CLIPBOARD selection rather than the PRIMARY"),
+              BOOL (Rs_twoButtonMouse, "twoButtonMouse", "tbm", Opt_twoButtonMouse, 0, "use two buttons for copy/paste"),
+#endif
               INFO ("e", "command arg ...", "command to execute")
             };
 
_______________________________________________
rxvt-unicode mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/rxvt-unicode

Reply via email to