From ea2d7f8b8c5782d422d02058861fa9a754055b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 29 Feb 2020 15:38:04 +0100 Subject: [PATCH] input: start window move right away if user starts dragging the window When the user left-clicks the title-bar, we start a timer. When the timer has elapsed, we initiate a 'move' operation. However, if the user clicked, and then started dragging right away, there was a very visible lag since we waited for the timeout before starting the move. Now, on a pointer motion event we detect a running 'move' timer, and abort it and instead start the 'move' operation right away. --- input.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/input.c b/input.c index 3bb9eaba..b5973364 100644 --- a/input.c +++ b/input.c @@ -758,6 +758,7 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, { struct wayland *wayl = data; struct terminal *term = wayl->mouse_focus; + struct wl_window *win = term->window; /* Workaround buggy Sway 1.2 */ if (term == NULL) { @@ -787,7 +788,17 @@ wl_pointer_motion(void *data, struct wl_pointer *wl_pointer, switch (term->active_surface) { case TERM_SURF_NONE: case TERM_SURF_SEARCH: + break; + case TERM_SURF_TITLE: + /* We've started a 'move' timer, but user started dragging + * right away - abort the timer and initiate the actual move + * right away */ + if (wayl->mouse.button == BTN_LEFT && win->csd.move_timeout_fd != -1) { + fdm_del(wayl->fdm, win->csd.move_timeout_fd); + win->csd.move_timeout_fd = -1; + xdg_toplevel_move(win->xdg_toplevel, wayl->seat, win->csd.serial); + } break; case TERM_SURF_BORDER_LEFT: @@ -922,6 +933,14 @@ wl_pointer_button(void *data, struct wl_pointer *wl_pointer, } } } + + else if (state == WL_POINTER_BUTTON_STATE_RELEASED) { + struct wl_window *win = term->window; + if (win->csd.move_timeout_fd != -1) { + fdm_del(wayl->fdm, win->csd.move_timeout_fd); + win->csd.move_timeout_fd = -1; + } + } return; case TERM_SURF_BORDER_LEFT: