From 847ce371606c8e284859f2a1b63186ecf8fd02ef Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 4 Jan 2018 12:34:31 +0530 Subject: [PATCH] Take the mouse wheel multiplier into account when generating keypresses for mouse wheel events. Fixes #262 --- kitty/data-types.h | 2 +- kitty/keys.c | 8 +++++--- kitty/mouse.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/kitty/data-types.h b/kitty/data-types.h index 7d981ee52..9f9392f6c 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -278,7 +278,7 @@ void mouse_event(int, int); void focus_in_event(); void wakeup_io_loop(bool); void scroll_event(double, double); -void fake_scroll(bool); +void fake_scroll(int, bool); void set_special_key_combo(int glfw_key, int mods); void on_text_input(unsigned int codepoint, int mods); void on_key_input(int key, int scancode, int action, int mods); diff --git a/kitty/keys.c b/kitty/keys.c index 2992ceaea..00f08e059 100644 --- a/kitty/keys.c +++ b/kitty/keys.c @@ -188,12 +188,14 @@ on_key_input(int key, int scancode, int action, int mods) { } void -fake_scroll(bool upwards) { +fake_scroll(int amount, bool upwards) { Window *w = active_window(); if (!w) return; Screen *screen = w->render_data.screen; - send_key_to_child(w, upwards ? GLFW_KEY_UP : GLFW_KEY_DOWN, 0, GLFW_PRESS); - if (screen->modes.mEXTENDED_KEYBOARD) send_key_to_child(w, upwards ? GLFW_KEY_UP : GLFW_KEY_DOWN, 0, GLFW_RELEASE); + while (amount-- > 0) { + send_key_to_child(w, upwards ? GLFW_KEY_UP : GLFW_KEY_DOWN, 0, GLFW_PRESS); + if (screen->modes.mEXTENDED_KEYBOARD) send_key_to_child(w, upwards ? GLFW_KEY_UP : GLFW_KEY_DOWN, 0, GLFW_RELEASE); + } } #define PYWRAP1(name) static PyObject* py##name(PyObject UNUSED *self, PyObject *args) diff --git a/kitty/mouse.c b/kitty/mouse.c index a48748c6a..69aa61211 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -375,7 +375,7 @@ scroll_event(double UNUSED xoffset, double yoffset) { int sz = encode_mouse_event(w, upwards ? GLFW_MOUSE_BUTTON_4 : GLFW_MOUSE_BUTTON_5, PRESS, 0); if (sz > 0) { mouse_event_buf[sz] = 0; write_escape_code_to_child(screen, CSI, mouse_event_buf); } } else { - fake_scroll(upwards); + fake_scroll(abs(s), upwards); } } }