C- or M- MouseDragEnd1Pane ?

30 views
Skip to first unread message

M Kelly

unread,
Feb 18, 2020, 3:33:58 PM2/18/20
to tmux-users
Hi,

I am trying to use C- or M- MouseDragEnd1Pane but cannot seem to get it to work.
It does not highlight / select anything, as tho it were a no-op.
MouseDragEnd1Pane works fine on its own, just not with C- or M- modifiers
M-MouseUp1Pane works fine, if that reveals anything.

I can get it to work in vim so I don't think it's a case of my terminal (terminator) not supporting it.

thx for any advice,
-m

Nicholas Marriott

unread,
Feb 18, 2020, 3:35:23 PM2/18/20
to M Kelly, tmux-users
You want to start the drag without ctrl and then press it when you release?

--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/32154492-2e02-48de-bd22-99415048c18c%40googlegroups.com.

M Kelly

unread,
Feb 18, 2020, 4:40:13 PM2/18/20
to tmux-users
Hi,

I guess I didn't think about it like that.
I doubt I can control it tightly enough, but in essence I hold C- or M- and Mouse button down and drag .... then release both the C-/M- and the Mouse1.
Perhaps I need to notice the start of it (ensuring C-/M- is pressed first) and then deal with that at the end of the drag ??

thx,
-m

Nicholas Marriott

unread,
Feb 18, 2020, 4:41:19 PM2/18/20
to M Kelly, tmux-users
So do you want C-MouseDrag1Pane not MouseDragEnd1Pane?



--
You received this message because you are subscribed to the Google Groups "tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.

Nicholas Marriott

unread,
Feb 18, 2020, 4:42:45 PM2/18/20
to M Kelly, tmux-users
Oh you want different commands to run at End based on whether you started the drag with Ctrl or Meta? I don't know if that is possible, I'll have to look tomorrow.

M Kelly

unread,
Feb 18, 2020, 4:58:41 PM2/18/20
to tmux-users
Hi,

>> want different commands to run at End based on whether you started the drag with Ctrl or Meta?

Exactly :-)

thx,
-m

Nicholas Marriott

unread,
Feb 19, 2020, 2:46:48 AM2/19/20
to M Kelly, tmux-users
OK so I first thought you'd be able to do this by setting a user option
for C-MouseDrag1Pane and MouseDrag1Pane and using it to tell the
difference in MouseDragEnd, but that doesn't work because tmux doesn't
copy the modifier keys to the in between dragging state.

That's easy to fix, but if I'm going to make code changes, why not just
fix it so that C-MouseDragEnd1 works?

Please try this (also attached).

You can now bind both keys with modifiers (in fact you have to if you
want them to do anything):

bind -Tcopy-mode C-MouseDrag1Pane select-pane \; send -X begin-selection
bind -Tcopy-mode C-MouseDragEnd1Pane send -X copy-pipe-and-cancel 'cat >/tmp/copy'


Index: key-string.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/key-string.c,v
retrieving revision 1.52
diff -u -p -r1.52 key-string.c
--- key-string.c 14 Nov 2019 07:55:01 -0000 1.52
+++ key-string.c 19 Feb 2020 07:45:05 -0000
@@ -242,53 +242,90 @@ key_string_lookup_string(const char *str
const char *
key_string_lookup_key(key_code key)
{
- static char out[32];
- char tmp[8];
- u_int i;
- struct utf8_data ud;
- size_t off;
+ static char out[32];
+ char tmp[8];
+ const char *s;
+ u_int i;
+ struct utf8_data ud;
+ size_t off;

*out = '\0';

+ /* Literal keys are themselves. */
+ if (key & KEYC_LITERAL) {
+ snprintf(out, sizeof out, "%c", (int)(key & 0xff));
+ return (out);
+ }
+
+ /* Fill in the modifiers. */
+ if (key & KEYC_CTRL)
+ strlcat(out, "C-", sizeof out);
+ if (key & KEYC_ESCAPE)
+ strlcat(out, "M-", sizeof out);
+ if (key & KEYC_SHIFT)
+ strlcat(out, "S-", sizeof out);
+ key &= KEYC_MASK_KEY;
+
/* Handle no key. */
if (key == KEYC_NONE)
return ("None");

/* Handle special keys. */
- if (key == KEYC_UNKNOWN)
- return ("Unknown");
- if (key == KEYC_ANY)
- return ("Any");
- if (key == KEYC_FOCUS_IN)
- return ("FocusIn");
- if (key == KEYC_FOCUS_OUT)
- return ("FocusOut");
- if (key == KEYC_PASTE_START)
- return ("PasteStart");
- if (key == KEYC_PASTE_END)
- return ("PasteEnd");
- if (key == KEYC_MOUSE)
- return ("Mouse");
- if (key == KEYC_DRAGGING)
- return ("Dragging");
- if (key == KEYC_MOUSEMOVE_PANE)
- return ("MouseMovePane");
- if (key == KEYC_MOUSEMOVE_STATUS)
- return ("MouseMoveStatus");
- if (key == KEYC_MOUSEMOVE_STATUS_LEFT)
- return ("MouseMoveStatusLeft");
- if (key == KEYC_MOUSEMOVE_STATUS_RIGHT)
- return ("MouseMoveStatusRight");
- if (key == KEYC_MOUSEMOVE_BORDER)
- return ("MouseMoveBorder");
- if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) {
- snprintf(out, sizeof out, "User%u", (u_int)(key - KEYC_USER));
- return (out);
+ if (key == KEYC_UNKNOWN) {
+ s = "Unknown";
+ goto append;
+ }
+ if (key == KEYC_ANY) {
+ s = "Any";
+ goto append;
+ }
+ if (key == KEYC_FOCUS_IN) {
+ s = "FocusIn";
+ goto append;
+ }
+ if (key == KEYC_FOCUS_OUT) {
+ s = "FocusOut";
+ goto append;
+ }
+ if (key == KEYC_PASTE_START) {
+ s = "PasteStart";
+ goto append;
+ }
+ if (key == KEYC_PASTE_END) {
+ s = "PasteEnd";
+ goto append;
+ }
+ if (key == KEYC_MOUSE) {
+ s = "Mouse";
+ goto append;
+ }
+ if (key == KEYC_DRAGGING) {
+ s = "Dragging";
+ goto append;
+ }
+ if (key == KEYC_MOUSEMOVE_PANE) {
+ s = "MouseMovePane";
+ goto append;
+ }
+ if (key == KEYC_MOUSEMOVE_STATUS) {
+ s = "MouseMoveStatus";
+ goto append;
+ }
+ if (key == KEYC_MOUSEMOVE_STATUS_LEFT) {
+ s = "MouseMoveStatusLeft";
+ goto append;
+ }
+ if (key == KEYC_MOUSEMOVE_STATUS_RIGHT) {
+ s = "MouseMoveStatusRight";
+ goto append;
+ }
+ if (key == KEYC_MOUSEMOVE_BORDER) {
+ s = "MouseMoveBorder";
+ goto append;
}
-
- /* Literal keys are themselves. */
- if (key & KEYC_LITERAL) {
- snprintf(out, sizeof out, "%c", (int)(key & 0xff));
+ if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) {
+ snprintf(tmp, sizeof tmp, "User%u", (u_int)(key - KEYC_USER));
+ strlcat(out, tmp, sizeof out);
return (out);
}

@@ -301,15 +338,6 @@ key_string_lookup_key(key_code key)
if ((key & KEYC_MASK_KEY) == 0)
key = ' ' | KEYC_CTRL | (key & KEYC_MASK_MOD);

- /* Fill in the modifiers. */
- if (key & KEYC_CTRL)
- strlcat(out, "C-", sizeof out);
- if (key & KEYC_ESCAPE)
- strlcat(out, "M-", sizeof out);
- if (key & KEYC_SHIFT)
- strlcat(out, "S-", sizeof out);
- key &= KEYC_MASK_KEY;
-
/* Try the key against the string table. */
for (i = 0; i < nitems(key_string_table); i++) {
if (key == key_string_table[i].key)
@@ -351,5 +379,9 @@ key_string_lookup_key(key_code key)
xsnprintf(tmp, sizeof tmp, "\\%llo", key);

strlcat(out, tmp, sizeof out);
+ return (out);
+
+append:
+ strlcat(out, s, sizeof out);
return (out);
}
Index: server-client.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/server-client.c,v
retrieving revision 1.304
diff -u -p -r1.304 server-client.c
--- server-client.c 11 Feb 2020 07:01:08 -0000 1.304
+++ server-client.c 19 Feb 2020 07:45:05 -0000
@@ -662,8 +662,7 @@ have_event:
break;
}
c->tty.mouse_drag_flag = 0;
-
- return (key);
+ goto out;
}

/* Convert to a key binding. */
@@ -958,6 +957,7 @@ have_event:
if (key == KEYC_UNKNOWN)
return (KEYC_UNKNOWN);

+out:
/* Apply modifiers if any. */
if (b & MOUSE_MASK_META)
key |= KEYC_ESCAPE;
@@ -966,6 +966,8 @@ have_event:
if (b & MOUSE_MASK_SHIFT)
key |= KEYC_SHIFT;

+ if (log_get_level() != 0)
+ log_debug("mouse key is %s", key_string_lookup_key (key));
return (key);
}

@@ -1059,7 +1061,7 @@ server_client_key_callback(struct cmdq_i
* Mouse drag is in progress, so fire the callback (now that
* the mouse event is valid).
*/
- if (key == KEYC_DRAGGING) {
+ if ((key & KEYC_MASK_KEY) == KEYC_DRAGGING) {
c->tty.mouse_drag_update(c, m);
goto out;
> --
> You received this message because you are subscribed to the Google Groups
> "tmux-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to tmux-users+...@googlegroups.com.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/tmux-users/feadb55c-80b4-4dbc-a5e5-b9dce96b91ba%40googlegroups.com.

tmux-mouse-modifiers.diff

M Kelly

unread,
Feb 19, 2020, 9:22:59 AM2/19/20
to tmux-users
Hi,

Yes!, this works fine in my testing.
Exactly what I wanted, a way to copy the selection and cancel for quick drags.

thx again,
-m

Nicholas Marriott

unread,
Feb 19, 2020, 9:39:46 AM2/19/20
to M Kelly, tmux-users
OK great, I have applied to OpenBSD now, will be in GitHub later on.

Thanks!
> --
> You received this message because you are subscribed to the Google Groups "tmux-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to tmux-users+...@googlegroups.com.
> To view this discussion on the web, visit https://groups.google.com/d/msgid/tmux-users/cf6ef1b4-cc97-4c6c-8bd7-815efb6b81bb%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages