--- src/command.C.mdr	2012-05-14 15:41:28.000000000 +1000
+++ src/command.C	2012-05-15 11:56:19.000000000 +1000
@@ -1363,10 +1380,12 @@
         break;
 
       case ButtonPress:
+        swap_mouse_buttons (ev.xbutton);
         button_press (ev.xbutton);
         break;
 
       case ButtonRelease:
+        swap_mouse_buttons (ev.xbutton);
         button_release (ev.xbutton);
         break;
 
--- src/optinc.h.mdr	2012-05-14 16:45:18.000000000 +1000
+++ src/optinc.h	2012-05-15 14:21:46.000000000 +1000
@@ -18,6 +18,7 @@
  def(jumpScroll)
  def(skipScroll)
  def(mouseWheelScrollPage)
+ def(swapMouseButtons)
 #if POINTER_BLANK
  def(pointerBlank)
 #else
--- src/rsinc.h.mdr	2012-05-14 16:47:00.000000000 +1000
+++ src/rsinc.h	2012-05-15 14:21:29.000000000 +1000
@@ -36,6 +36,7 @@
   def (saveLines)
   def (utmpInhibit)
   def (visualBell)
+  def (swapMouseButtons)
 #if ! defined(NO_MAPALERT) && defined(MAPALERT_OPTION)
   def (mapAlert)
 #endif
--- src/rxvt.h.mdr	2012-05-14 15:38:52.000000000 +1000
+++ src/rxvt.h	2012-05-15 11:55:06.000000000 +1000
@@ -1340,6 +1341,15 @@
   void key_press (XKeyEvent &ev);
   void key_release (XKeyEvent &ev);
 
+  void swap_mouse_buttons(XButtonEvent &ev)
+	{
+		if (option (Opt_swapMouseButtons))
+			if (ev.button == Button2)
+				ev.button = Button3;
+			else if (ev.button == Button3)
+				ev.button = Button2;
+	}
+
   wchar_t next_char () NOTHROW;
   wchar_t cmd_getc () THROW ((class out_of_input));
   uint32_t next_octet () NOTHROW;
--- src/xdefaults.C.mdr	2012-05-14 16:29:15.000000000 +1000
+++ src/xdefaults.C	2012-05-14 17:03:01.000000000 +1000
@@ -281,6 +281,7 @@
 #ifdef KEYSYM_RESOURCE
               RINFO ("keysym.sym", "keysym"),
 #endif
+	      BOOL (Rs_swapMouseButtons, "swapMouseButtons", "smb", Opt_swapMouseButtons, 0, "swap middle and right mouse buttons"),
               INFO ("e", "command arg ...", "command to execute")
             };
 
--- doc/rxvt.1.pod.mdr	2012-05-15 15:10:43.000000000 +1000
+++ doc/rxvt.1.pod	2012-05-15 14:50:07.000000000 +1000
@@ -456,6 +456,11 @@
 Turn on/off secondary screen scroll (default enabled); resource
 B<secondaryScroll>.
 
+=item B<-smb>|B<+smb>
+
+Turn on/off swap middle and right mouse buttons (default disabled); resource
+B<swapMouseButtons>.
+
 =item B<-hold>|B<+hold>
 
 Turn on/off hold window after exit support. If enabled, @@RXVT_NAME@@
@@ -1168,6 +1173,14 @@
 scrollback buffer and, when secondaryScreen is off, switching
 to/from the secondary screen will instead scroll the screen up.
 
+=item B<swapMouseButtons:> I<boolean>
+
+Turn on/off swap middle and right mouse buttons (default disabled).
+Trying to paste with a click of the scroll-wheel/middle button can
+sometimes result in an inadvertent scroll event; enabling this option
+removes that possibility.  Selections can still be extended with
+shift-left-click.
+
 =item B<hold>: I<boolean>
 
 Turn on/off hold window after exit support. If enabled, @@RXVT_NAME@@
