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.