From 0d1be2e32838cfb4f4b528fc3f94ef850b47eda7 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 24 Nov 2016 13:46:50 +0000 Subject: Fix so that we work out the right pane from mouse events - we were doing so too early, before the mouse event was necessarily valid, so could end up using the pane from the previous mouse event, or the active pane. It is important that we use the right pane now that different panes can have different key tables (for copy mode). Fixes problem reported by Greg Hurrell. --- server-client.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'server-client.c') diff --git a/server-client.c b/server-client.c index fbe14e82..dd2a274a 100644 --- a/server-client.c +++ b/server-client.c @@ -698,10 +698,6 @@ server_client_handle_key(struct client *c, key_code key) if (s == NULL || (c->flags & (CLIENT_DEAD|CLIENT_SUSPENDED)) != 0) return; w = s->curw->window; - if (KEYC_IS_MOUSE(key)) - wp = cmd_mouse_pane(m, NULL, NULL); - else - wp = w->active; /* Update the activity timer. */ if (gettimeofday(&c->activity_time, NULL) != 0) @@ -742,12 +738,19 @@ server_client_handle_key(struct client *c, key_code key) m->valid = 1; m->key = key; - - if (!options_get_number(s->options, "mouse")) - goto forward; } else m->valid = 0; + /* Find affected pane. */ + if (KEYC_IS_MOUSE(key) && m->valid) + wp = cmd_mouse_pane(m, NULL, NULL); + else + wp = w->active; + + /* Forward mouse keys if disabled. */ + if (key == KEYC_MOUSE && !options_get_number(s->options, "mouse")) + goto forward; + /* Treat everything as a regular key when pasting is detected. */ if (!KEYC_IS_MOUSE(key) && server_client_assume_paste(s)) goto forward; @@ -764,6 +767,10 @@ retry: table = c->keytable; else table = key_bindings_get_table(name, 1); + if (wp == NULL) + log_debug("key table %s (no pane)", table->name); + else + log_debug("key table %s (pane %%%u)", table->name, wp->id); /* Try to see if there is a key binding in the current table. */ bd_find.key = key; -- cgit From 84319aa8f013238ccc1bbd6ea44b9e6be7c58db2 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 24 Nov 2016 14:38:55 +0000 Subject: If in the middle of a drag, don't use an invalid key, just use KEYC_MOUSE as a placeholder. Reported by Artem Fokin. --- server-client.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'server-client.c') diff --git a/server-client.c b/server-client.c index dd2a274a..ff43f73d 100644 --- a/server-client.c +++ b/server-client.c @@ -474,9 +474,10 @@ have_event: case NOTYPE: break; case DRAG: - if (c->tty.mouse_drag_update != NULL) + if (c->tty.mouse_drag_update != NULL) { c->tty.mouse_drag_update(c, m); - else { + key = KEYC_MOUSE; + } else { switch (MOUSE_BUTTONS(b)) { case 0: if (where == PANE) @@ -738,6 +739,13 @@ server_client_handle_key(struct client *c, key_code key) m->valid = 1; m->key = key; + + /* + * A mouse event that continues to be valid but that we do not + * want to pass through. + */ + if (key == KEYC_MOUSE) + return; } else m->valid = 0; -- cgit