On Mon, May 12, 2014 at 2:39 PM, Hiltjo Posthuma <[email protected]> wrote:
> Attached is the fixed-up patch.

So will this patch be included upstream? It adds no lines to st.c
(only changes 4 lines).

I attached the updated patch so in config.def.h forceselmod is by
default set to 0, so the behaviour is exactly the same as without the
patch by default.

Kind regards,
Hiltjo
From b51abb3233c7bf1217d8bc6c18975ca97b0d1a90 Mon Sep 17 00:00:00 2001
From: Hiltjo Posthuma <[email protected]>
Date: Wed, 14 May 2014 10:28:32 +0000
Subject: [PATCH] Allow forced mouse selection using ShiftMask

Similar to xterm or urxvt holding ShiftMask before selecting text with the
mouse allows to override copying text. For example in tmux with
"mode-mouse on" or vim (compiled with --with-x), mc, htop, etc.

forceselmod in config.h sets the mask to use this mode, by default
disabled (set to 0), but can be set to ShiftMask to use the behaviour
described above.

Signed-off-by: Hiltjo Posthuma <[email protected]>
---
 config.def.h | 8 +++++++-
 st.c         | 8 ++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/config.def.h b/config.def.h
index 646a88a..6212f04 100644
--- a/config.def.h
+++ b/config.def.h
@@ -154,6 +154,13 @@ static KeySym mappedkeys[] = { -1 };
  */
 static uint ignoremod = Mod2Mask|XK_SWITCH_MOD;
 
+/*
+ * Override mouse-select while mask is active (when MODE_MOUSE is set).
+ * Set to ShiftMask to be able to override mouse-selection behaviour similar
+ * to xterm or urxvt. By default this is disabled (set to 0).
+ */
+static uint forceselmod = 0;
+
 static Key key[] = {
 	/* keysym           mask            string      appkey appcursor crlf */
 	{ XK_KP_Home,       ShiftMask,      "\033[2J",       0,   -1,    0},
@@ -357,7 +364,6 @@ static Key key[] = {
  * ButtonRelease and MotionNotify.
  * If no match is found, regular selection is used.
  */
-
 static uint selmasks[] = {
 	[SEL_RECTANGULAR] = Mod1Mask,
 };
diff --git a/st.c b/st.c
index 5946c7c..78d8a01 100644
--- a/st.c
+++ b/st.c
@@ -765,7 +765,7 @@ selsnap(int mode, int *x, int *y, int direction) {
 void
 getbuttoninfo(XEvent *e) {
 	int type;
-	uint state = e->xbutton.state &~Button1Mask;
+	uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
 
 	sel.alt = IS_SET(MODE_ALTSCREEN);
 
@@ -858,7 +858,7 @@ bpress(XEvent *e) {
 	struct timeval now;
 	Mousekey *mk;
 
-	if(IS_SET(MODE_MOUSE)) {
+	if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
 		mousereport(e);
 		return;
 	}
@@ -1090,7 +1090,7 @@ xsetsel(char *str) {
 
 void
 brelease(XEvent *e) {
-	if(IS_SET(MODE_MOUSE)) {
+	if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
 		mousereport(e);
 		return;
 	}
@@ -1113,7 +1113,7 @@ void
 bmotion(XEvent *e) {
 	int oldey, oldex, oldsby, oldsey;
 
-	if(IS_SET(MODE_MOUSE)) {
+	if(IS_SET(MODE_MOUSE) && !(e->xbutton.state & forceselmod)) {
 		mousereport(e);
 		return;
 	}
-- 
1.9.2

Reply via email to