From aa9c3cd63468d0cef475ecae6517af94770ba4b7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 29 Apr 2020 20:02:55 +0530 Subject: [PATCH] Report modifier key state when sending wheel events to the terminal program --- docs/changelog.rst | 2 ++ glfw/cocoa_window.m | 2 +- glfw/glfw3.h | 3 ++- glfw/input.c | 4 ++-- glfw/internal.h | 2 +- glfw/wl_init.c | 2 +- glfw/x11_window.c | 8 ++++---- kitty/data-types.h | 2 +- kitty/glfw-wrapper.h | 3 ++- kitty/glfw.c | 4 ++-- kitty/mouse.c | 4 ++-- 11 files changed, 20 insertions(+), 16 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 7e15f0a96..8e0eb9934 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -19,6 +19,8 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: Fix a regression that broke drag and drop (:iss:`2605`) +- Report modifier key state when sending wheel events to the terminal program + 0.17.3 [2020-04-23] -------------------- diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index b343a917e..374f0683b 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1133,7 +1133,7 @@ is_ascii_control_char(char x) { break; } - _glfwInputScroll(window, deltaX, deltaY, flags); + _glfwInputScroll(window, deltaX, deltaY, flags, translateFlags([event modifierFlags])); } - (NSDragOperation)draggingEntered:(id )sender diff --git a/glfw/glfw3.h b/glfw/glfw3.h index b60b2630d..8c0135b66 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -1550,6 +1550,7 @@ typedef void (* GLFWcursorenterfun)(GLFWwindow*,int); * value 2 for stationary momentum scrolling, value 3 for momentum scrolling * in progress, value 4 for momentum scrolling ended, value 5 for momentum * scrolling cancelled and value 6 if scrolling may begin soon. + * @param[int] mods The keyboard modifiers * * @sa @ref scrolling * @sa @ref glfwSetScrollCallback @@ -1559,7 +1560,7 @@ typedef void (* GLFWcursorenterfun)(GLFWwindow*,int); * * @ingroup input */ -typedef void (* GLFWscrollfun)(GLFWwindow*,double,double,int); +typedef void (* GLFWscrollfun)(GLFWwindow*,double,double,int,int); /*! @brief The function pointer type for key callbacks. * diff --git a/glfw/input.c b/glfw/input.c index 0ae33ec44..6b451aaff 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -300,10 +300,10 @@ void _glfwInputKeyboard(_GLFWwindow* window, GLFWkeyevent* ev) // Notifies shared code of a scroll event // -void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags) +void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags, int mods) { if (window->callbacks.scroll) - window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset, flags); + window->callbacks.scroll((GLFWwindow*) window, xoffset, yoffset, flags, mods); } // Notifies shared code of a mouse button click event diff --git a/glfw/internal.h b/glfw/internal.h index ac2190fb0..fb7b402bc 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -755,7 +755,7 @@ void _glfwInputWindowMonitor(_GLFWwindow* window, _GLFWmonitor* monitor); void _glfwInitializeKeyEvent(GLFWkeyevent *ev, int key, int native_key, int action, int mods); void _glfwInputKeyboard(_GLFWwindow *window, GLFWkeyevent *ev); -void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags); +void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset, int flags, int mods); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods); void _glfwInputCursorPos(_GLFWwindow* window, double xpos, double ypos); void _glfwInputCursorEnter(_GLFWwindow* window, bool entered); diff --git a/glfw/wl_init.c b/glfw/wl_init.c index 5d0fe8c4b..49136bf03 100644 --- a/glfw/wl_init.c +++ b/glfw/wl_init.c @@ -334,7 +334,7 @@ static void pointerHandleAxis(void* data UNUSED, else if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) y = wl_fixed_to_double(value) * -1; - _glfwInputScroll(window, x, y, 1); + _glfwInputScroll(window, x, y, 1, _glfw.wl.xkb.states.modifiers); } static const struct wl_pointer_listener pointerListener = { diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 997f235fe..ec5e4c1ca 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -1265,13 +1265,13 @@ static void processEvent(XEvent *event) // Modern X provides scroll events as mouse button presses else if (event->xbutton.button == Button4) - _glfwInputScroll(window, 0.0, 1.0, 0); + _glfwInputScroll(window, 0.0, 1.0, 0, mods); else if (event->xbutton.button == Button5) - _glfwInputScroll(window, 0.0, -1.0, 0); + _glfwInputScroll(window, 0.0, -1.0, 0, mods); else if (event->xbutton.button == Button6) - _glfwInputScroll(window, 1.0, 0.0, 0); + _glfwInputScroll(window, 1.0, 0.0, 0, mods); else if (event->xbutton.button == Button7) - _glfwInputScroll(window, -1.0, 0.0, 0); + _glfwInputScroll(window, -1.0, 0.0, 0, mods); else { diff --git a/kitty/data-types.h b/kitty/data-types.h index de2663ff0..65d5a60f3 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -313,7 +313,7 @@ void set_mouse_cursor(MouseShape); void enter_event(void); void mouse_event(int, int, int); void focus_in_event(void); -void scroll_event(double, double, int); +void scroll_event(double, double, int, int); void fake_scroll(int, bool); void set_special_key_combo(int glfw_key, int mods, bool is_native); void on_key_input(GLFWkeyevent *ev); diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index b7a816761..b3a4a05b5 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1313,6 +1313,7 @@ typedef void (* GLFWcursorenterfun)(GLFWwindow*,int); * value 2 for stationary momentum scrolling, value 3 for momentum scrolling * in progress, value 4 for momentum scrolling ended, value 5 for momentum * scrolling cancelled and value 6 if scrolling may begin soon. + * @param[int] mods The keyboard modifiers * * @sa @ref scrolling * @sa @ref glfwSetScrollCallback @@ -1322,7 +1323,7 @@ typedef void (* GLFWcursorenterfun)(GLFWwindow*,int); * * @ingroup input */ -typedef void (* GLFWscrollfun)(GLFWwindow*,double,double,int); +typedef void (* GLFWscrollfun)(GLFWwindow*,double,double,int,int); /*! @brief The function pointer type for key callbacks. * diff --git a/kitty/glfw.c b/kitty/glfw.c index 4672f1b1a..5ac8e33ea 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -287,12 +287,12 @@ cursor_pos_callback(GLFWwindow *w, double x, double y) { } static void -scroll_callback(GLFWwindow *w, double xoffset, double yoffset, int flags) { +scroll_callback(GLFWwindow *w, double xoffset, double yoffset, int flags, int mods) { if (!set_callback_window(w)) return; show_mouse_cursor(w); monotonic_t now = monotonic(); global_state.callback_os_window->last_mouse_activity_at = now; - if (is_window_ready_for_callbacks()) scroll_event(xoffset, yoffset, flags); + if (is_window_ready_for_callbacks()) scroll_event(xoffset, yoffset, flags, mods); request_tick_callback(); global_state.callback_os_window = NULL; } diff --git a/kitty/mouse.c b/kitty/mouse.c index a81dd7c55..dae9a853d 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -613,7 +613,7 @@ mouse_event(int button, int modifiers, int action) { } void -scroll_event(double UNUSED xoffset, double yoffset, int flags) { +scroll_event(double UNUSED xoffset, double yoffset, int flags, int modifiers) { bool in_tab_bar; static id_type window_for_momentum_scroll = 0; static bool main_screen_for_momentum_scroll = false; @@ -690,7 +690,7 @@ scroll_event(double UNUSED xoffset, double yoffset, int flags) { screen_history_scroll(screen, abs(s), upwards); } else { if (screen->modes.mouse_tracking_mode) { - int sz = encode_mouse_event(w, upwards ? GLFW_MOUSE_BUTTON_4 : GLFW_MOUSE_BUTTON_5, PRESS, 0); + int sz = encode_mouse_event(w, upwards ? GLFW_MOUSE_BUTTON_4 : GLFW_MOUSE_BUTTON_5, PRESS, modifiers); if (sz > 0) { mouse_event_buf[sz] = 0; for (s = abs(s); s > 0; s--) {