Hi,

this little patch adds the possibility of mrxvt to paste a certain
x selection buffer to the terminal.
(documentation included)

Example: The following statement enables mrxvt to paste the secondary
clipboard x selection buffer to the current tab.
---
Mrxvt.macro.Ctrl+Shift+x:        Paste SECONDARY
Mrxvt.macro.Ctrl+Shift+y:        Paste CLIPBOARD
---

I added this feature because i`m a sysadmin and I own logins to hundreds of
systems. I add a 20 lines bash profile to the secondary x selection
buffer using "cat ~/ms-env/data/cut-and-paste-profile|xsel -i -s", and i paste 
this 
profile everytime i login to a server or change a user with "su - <user>".

This is also pretty useful for users which use the clipboard buffer in
kde and gnome.
(i.e. perform a copy-operation in openoffice and a paste it into mrxvt)

I would be happy to see this modification in mrxvt-head.

Apply this patch by executing:
---
cd mrxvt05b
patch -p0 -u < ../define_selection_for_paste.patch
---

Best regards
Marc Schöchlin
Index: src/screen.c
===================================================================
--- src/screen.c	(revision 261)
+++ src/screen.c	(working copy)
@@ -4932,6 +4932,39 @@
 
 /* ------------------------------------------------------------------------- */
 /*
+ * Request the content of a selection buffer: 
+ *
+ * EXT: button 2 release
+ */
+/* EXTPROTO */
+void
+rxvt_selection_request_by_sel(rxvt_t* r, int page, Time tm, int x, int y,int sel)
+{
+    rxvt_dbgmsg ((DBG_DEBUG, DBG_SCREEN, "rxvt_selection_request %d (%lu, %d, %d)\n", page, tm, x, y ));
+
+    if (x < 0 || x >= VT_WIDTH(r) || y < 0 || y >= VT_HEIGHT(r))
+	return;		/* outside window */
+
+	r->h->selection_request_time = tm;
+	r->h->selection_wait = Sel_normal;
+
+#ifdef MULTICHAR_SET
+   r->h->selection_type = Sel_CompoundText;
+#else
+   r->h->selection_type = 0;
+#endif
+   rxvt_selection_request_other(r, page,
+#ifdef MULTICHAR_SET
+	 r->h->xa[XA_COMPOUND_TEXT],
+#else
+	 XA_STRING,
+#endif
+		 sel);
+}
+
+
+/* ------------------------------------------------------------------------- */
+/*
  * Request the current selection: 
  * Order: > internal selection if available
  *	> PRIMARY, SECONDARY, CLIPBOARD if ownership is claimed (+)
Index: src/macros.c
===================================================================
--- src/macros.c	(revision 261)
+++ src/macros.c	(working copy)
@@ -996,11 +996,29 @@
 	case MacroFnCopy:
 #endif
 	case MacroFnPaste:
-	    if (NOT_NULL(ev))
-		rxvt_selection_request (r, ATAB(r), ev->xkey.time, 0, 0);
-	    else
-		retval = -1;
+  {
+      int sel = 1;
+
+	    if (NOT_NULL(ev)){
+        if( NOT_NULL(astr) && *astr ){
+           if(strcmp ("PRIMARY", astr) == 0)
+             sel=XA_PRIMARY;
+           else if (strcmp ("SECONDARY", astr) == 0)
+             sel=XA_SECONDARY;
+           else if (strcmp ("CLIPBOARD", astr) == 0)
+             sel=XA_CLIPBOARD;
+           else
+	           break;
+          rxvt_selection_request_by_sel (r, ATAB(r), ev->xkey.time, 0, 0, sel);
+        }
+        else
+		      rxvt_selection_request (r, ATAB(r), ev->xkey.time, 0, 0);
+      }
+	    else{
+		    retval = -1;
+      }
 	    break;
+  }
 
 	case MacroFnToggleSubwin:
 	    rxvt_toggle_subwin( r, (unsigned char*) astr);
Index: src/protos.h
===================================================================
--- src/protos.h	(revision 261)
+++ src/protos.h	(working copy)
@@ -274,6 +274,7 @@
 int              rxvt_selection_paste             __PROTO((rxvt_t* r, Window win, Atom prop, Bool delete_prop));
 void             rxvt_selection_property          __PROTO((rxvt_t* r, Window win, Atom prop));
 void             rxvt_selection_request           __PROTO((rxvt_t* r, int page, Time tm, int x, int y));
+void             rxvt_selection_request_by_sel    __PROTO((rxvt_t* r, int page, Time tm, int x, int y, int sel));
 void             rxvt_process_selectionclear      __PROTO((rxvt_t* r, int page));
 void             rxvt_selection_make              __PROTO((rxvt_t* r, int page, Time tm));
 void             rxvt_selection_click             __PROTO((rxvt_t* r, int page, int clicks, int x, int y));
Index: share/mrxvtrc
===================================================================
--- share/mrxvtrc	(revision 261)
+++ share/mrxvtrc	(working copy)
@@ -182,7 +182,11 @@
 Mrxvt.macro.Primary+Shift+Home:		Scroll -1000000
 Mrxvt.macro.Primary+Shift+End:		Scroll +1000000
 
+# Pasting
 Mrxvt.macro.Ctrl+Shift+v:		Paste
+# A slection buffer can be added as an argument (PRIMARY,SECONDARY, CLIPBOARD)
+Mrxvt.macro.Ctrl+Shift+x:		Paste SECONDARY
+
 Mrxvt.macro.Shift+Delete:		SetTitle
 
 #
Index: share/default.menu
===================================================================
--- share/default.menu	(revision 261)
+++ share/default.menu	(working copy)
@@ -40,6 +40,8 @@
 {Toggle Macros}				ToggleMacros
 {-}
 {Paste}					Paste
+{Paste secondary buffer}					Paste SECONDRAY
+{Paste clipboard buffer}					Paste CLIPBOARD
 [read:submenus;selection]
 {-}
 [read:submenus;tabsmenu]
Index: doc/mrxvt.1
===================================================================
--- doc/mrxvt.1	(revision 261)
+++ doc/mrxvt.1	(working copy)
@@ -1690,8 +1690,10 @@
 .It Ic Copy
 Copy selection into clipboard (not implemented).
 .\" ------------------------------------------------------------
-.It Ic Paste
-Pasete selection into active tab.
+.It Ic Paste Op Ar selection-buffer
+Paste selection into active tab. The value
+.Ar selection-buffer 
+specifies the name of the buffer to be pasted. If not specified the first used buffer in the order PRIMARY, SECONDARY and CLIPBOARD  will be used.
 .It Ic ToggleSubwin Op Oo Ar + Ns | Ns Ar - Oc Ns Op Ar b Ns | Ns Ar m Ns | Ns Ar s Ns | Ns Ar t
 Toggle visibility of sub-windows. If the argument begins with a
 .Sq +
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Materm-devel mailing list
Materm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/materm-devel
mrxvt home page: http://materm.sourceforge.net

Reply via email to