diff --git a/docs/changelog.rst b/docs/changelog.rst index b7d44f24e..a4c67e39c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -306,8 +306,9 @@ Detailed list of changes moves it, so it no longer briefly appears at the previous position at the start of the next composition (:pull:`10644`) -- :ref:`mouse_map ` can now map the scroll wheel, via the :code:`wheel_up` and - :code:`wheel_down` buttons, for example, to change the font size with +- :ref:`mouse_map ` can now map the scroll wheel, via + the :code:`wheel_up`, :code:`wheel_down`, :code:`wheel_left` and + :code:`wheel_right` buttons, for example, to change the font size with :kbd:`Ctrl+scroll` - Fix closing an unfocused window that comes before the focused window in the diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index fbbeb42e3..6babadb27 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -63,6 +63,8 @@ MOUSE_SELECTION_WORD_AND_LINE_FROM_POINT: int MOUSE_SELECTION_MOVE_END: int MOUSE_WHEEL_UP: int MOUSE_WHEEL_DOWN: int +MOUSE_WHEEL_LEFT: int +MOUSE_WHEEL_RIGHT: int KITTY_VCS_REV: str NO_CLOSE_REQUESTED: int IMPERATIVE_CLOSE_REQUESTED: int diff --git a/kitty/mouse.c b/kitty/mouse.c index d78b85ee2..1af5f737c 100644 --- a/kitty/mouse.c +++ b/kitty/mouse.c @@ -207,6 +207,8 @@ set_currently_hovered_window(id_type window_id, int modifiers, bool focus_follow // these, count is the number of wheel steps, which is always positive. #define MOUSE_WHEEL_UP (GLFW_MOUSE_BUTTON_LAST + 1) #define MOUSE_WHEEL_DOWN (GLFW_MOUSE_BUTTON_LAST + 2) +#define MOUSE_WHEEL_LEFT (GLFW_MOUSE_BUTTON_LAST + 3) +#define MOUSE_WHEEL_RIGHT (GLFW_MOUSE_BUTTON_LAST + 4) static bool dispatch_mouse_event(Window *w, int button, int count, int modifiers, bool grabbed) { @@ -233,13 +235,13 @@ dispatch_mouse_event(Window *w, int button, int count, int modifiers, bool grabb const char *evname = "move"; if (button > GLFW_MOUSE_BUTTON_LAST) evname = "press"; else switch (count) { - case -3: evname = "doubleclick"; break; - case -2: evname = "click"; break; - case -1: evname = "release"; break; - case 1: evname = "press"; break; - case 2: evname = "doublepress"; break; - case 3: evname = "triplepress"; break; - } + case -3: evname = "doubleclick"; break; + case -2: evname = "click"; break; + case -1: evname = "release"; break; + case 1: evname = "press"; break; + case 2: evname = "doublepress"; break; + case 3: evname = "triplepress"; break; + } const char *bname = "unknown"; switch (button) { case GLFW_MOUSE_BUTTON_LEFT: bname = "left"; break; @@ -252,6 +254,8 @@ dispatch_mouse_event(Window *w, int button, int count, int modifiers, bool grabb case GLFW_MOUSE_BUTTON_8: bname = "b8"; break; case MOUSE_WHEEL_UP: bname = "wheel_up"; break; case MOUSE_WHEEL_DOWN: bname = "wheel_down"; break; + case MOUSE_WHEEL_LEFT: bname = "wheel_left"; break; + case MOUSE_WHEEL_RIGHT: bname = "wheel_right"; break; } debug("\x1b[33mon_mouse_input\x1b[m: %s button: %s %sgrabbed: %d handled_in_kitty: %d\n", evname, bname, format_mods(modifiers), grabbed, handled); } @@ -1582,14 +1586,14 @@ mapped_scroll_steps(GLFWOffsetType offset_type, double offset, double *pending, const int s = (int)round(offset); return s ? s : *direction; } - if (*pending * offset < 0) *pending = 0; // direction reversed, start a fresh step + if (*pending * offset < 0) *pending = 0; // direction reversed, start a fresh step *pending += offset; const int s = (int)(*pending / step_size); *pending -= s * step_size; return s; } -// Bit i of wheel_mappings[direction][grabbed] is set when the wheel is mapped +// Bit i of wheel_mappings[button - MOUSE_WHEEL_UP][grabbed] is set when the wheel is mapped // with the modifiers i, so that unmapped scrolling never calls into Python. #define WHEEL_MAPPING_MODS_MASK (GLFW_MOD_SHIFT | GLFW_MOD_ALT | GLFW_MOD_CONTROL | GLFW_MOD_SUPER | GLFW_MOD_HYPER | GLFW_MOD_META) static_assert(WHEEL_MAPPING_MODS_MASK < 64, "wheel mapping modifiers must fit in a uint64_t bitmap"); @@ -1614,35 +1618,65 @@ set_wheel_mappings(PyObject *py_opts, Options *opts) { const long button = PyLong_AsLong(PyTuple_GET_ITEM(key, 0)), mods = PyLong_AsLong(PyTuple_GET_ITEM(key, 1)); if (PyErr_Occurred()) return false; // modifiers outside the mask are stripped from events, so such a mapping can never match - if ((button != MOUSE_WHEEL_UP && button != MOUSE_WHEEL_DOWN) || (mods & ~WHEEL_MAPPING_MODS_MASK)) continue; + if (button < MOUSE_WHEEL_UP || button > MOUSE_WHEEL_RIGHT || (mods & ~WHEEL_MAPPING_MODS_MASK)) continue; const int grabbed = PyObject_IsTrue(PyTuple_GET_ITEM(key, 3)); if (grabbed < 0) return false; - opts->wheel_mappings[button == MOUSE_WHEEL_UP ? 0 : 1][grabbed] |= 1ull << mods; + opts->wheel_mappings[button - MOUSE_WHEEL_UP][grabbed] |= 1ull << mods; } return true; } -// Fires the wheel_up/wheel_down mouse_map actions for vertical scrolling. -// Returns true if the wheel is mapped for this event, in which case the event -// is consumed even if it does not complete a step, so the screen does not -// also scroll. static bool -dispatch_mapped_scroll(OSWindow *osw, Window *w, const GLFWScrollEvent *ev) { - const bool grabbed = w->render_data.screen->modes.mouse_tracking_mode != NO_TRACKING; - const int mods = ev->keyboard_modifiers & WHEEL_MAPPING_MODS_MASK; - // A partial step does not carry over to a different window or mapping - double pending = osw->scroll.mapped_window_id == w->id && osw->scroll.mapped_modifiers == mods ? osw->scroll.mapped_pending_pixels_y : 0; +wheel_is_mapped(int button, bool grabbed, int mods) { + return OPT(wheel_mappings)[button - MOUSE_WHEEL_UP][grabbed] & (1ull << mods); +} + +// Fires the wheel mouse_map actions for one axis of a scroll event. Returns +// true if the wheel is mapped for it, in which case the event is consumed even +// if it does not complete a step, so the screen does not also scroll. +static bool +dispatch_mapped_scroll_axis(OSWindow *osw, Window *w, const GLFWScrollEvent *ev, bool vertical, int mods, bool grabbed) { + double *pending = vertical ? &osw->scroll.mapped_pending_pixels_y : &osw->scroll.mapped_pending_pixels_x; + double p = *pending; int direction; - // unscaled is in logical pixels for touchpads and equal to y_offset otherwise - const int steps = mapped_scroll_steps(ev->offset_type, ev->unscaled.y, &pending, &direction); - if (!direction || !(OPT(wheel_mappings)[direction > 0 ? 0 : 1][grabbed] & (1ull << mods))) { - osw->scroll.mapped_pending_pixels_y = 0; + // unscaled is in logical pixels for touchpads and equal to the offset otherwise + const int steps = mapped_scroll_steps(ev->offset_type, vertical ? ev->unscaled.y : ev->unscaled.x, &p, &direction); + // positive offsets are upwards and leftwards + const int button = vertical ? (direction > 0 ? MOUSE_WHEEL_UP : MOUSE_WHEEL_DOWN) : (direction > 0 ? MOUSE_WHEEL_LEFT : MOUSE_WHEEL_RIGHT); + if (!direction || !wheel_is_mapped(button, grabbed, mods)) { + *pending = 0; return false; } - osw->scroll.mapped_pending_pixels_y = pending; + *pending = p; + if (steps) dispatch_mouse_event(w, button, abs(steps), ev->keyboard_modifiers, grabbed); + return true; +} + +// Returns true if either axis of the scroll event is mapped, in which case the +// whole event is consumed. +static bool +dispatch_mapped_scroll(OSWindow *osw, Window *w, const GLFWScrollEvent *ev, int mods, bool grabbed) { + // A partial step does not carry over to a different window or modifiers + if (osw->scroll.mapped_window_id != w->id || osw->scroll.mapped_modifiers != mods) + osw->scroll.mapped_pending_pixels_x = osw->scroll.mapped_pending_pixels_y = 0; + // Both axes are always dispatched, so that a diagonal gesture can fire both + const bool consumed_y = ev->y_offset != 0.0 && dispatch_mapped_scroll_axis(osw, w, ev, true, mods, grabbed); + const bool consumed_x = ev->x_offset != 0.0 && dispatch_mapped_scroll_axis(osw, w, ev, false, mods, grabbed); + if (!consumed_x && !consumed_y) return false; osw->scroll.mapped_window_id = w->id; osw->scroll.mapped_modifiers = mods; - if (steps) dispatch_mouse_event(w, direction > 0 ? MOUSE_WHEEL_UP : MOUSE_WHEEL_DOWN, abs(steps), ev->keyboard_modifiers, grabbed); + return true; +} + +// An unmapped event continues a mapped gesture only if it is in the same window +// with the same modifiers and only scrolls along axes that have no mappings at +// all, for example, horizontal jitter during a vertical gesture. Otherwise the +// momentum of a following, unmapped gesture would be swallowed. +static bool +continues_mapped_gesture(const OSWindow *osw, const Window *w, const GLFWScrollEvent *ev, int mods, bool grabbed) { + if (osw->scroll.mapped_window_id != w->id || osw->scroll.mapped_modifiers != mods) return false; + if (ev->y_offset != 0.0 && (wheel_is_mapped(MOUSE_WHEEL_UP, grabbed, mods) || wheel_is_mapped(MOUSE_WHEEL_DOWN, grabbed, mods))) return false; + if (ev->x_offset != 0.0 && (wheel_is_mapped(MOUSE_WHEEL_LEFT, grabbed, mods) || wheel_is_mapped(MOUSE_WHEEL_RIGHT, grabbed, mods))) return false; return true; } @@ -1698,16 +1732,14 @@ scroll_event_in_window(OSWindow *osw, Window *w, const GLFWScrollEvent *ev, unsi case GLFW_MOMENTUM_PHASE_MAY_BEGIN: break; } if (ev->momentum_type == GLFW_NO_MOMENTUM_DATA) { - if (ev->y_offset != 0.0) osw->scroll.mapped_gesture = dispatch_mapped_scroll(osw, w, ev); - // Horizontal only events continue a mapped gesture, but not one in a - // different window or with different modifiers, so that its momentum - // is not swallowed - else if (osw->scroll.mapped_window_id != w->id || osw->scroll.mapped_modifiers != (ev->keyboard_modifiers & WHEEL_MAPPING_MODS_MASK)) - osw->scroll.mapped_gesture = false; + const bool grabbed = screen->modes.mouse_tracking_mode != NO_TRACKING; + const int mods = ev->keyboard_modifiers & WHEEL_MAPPING_MODS_MASK; + if (dispatch_mapped_scroll(osw, w, ev, mods, grabbed)) osw->scroll.mapped_gesture = true; + else if (osw->scroll.mapped_gesture) osw->scroll.mapped_gesture = continues_mapped_gesture(osw, w, ev, mods, grabbed); if (osw->scroll.mapped_gesture) return; } else if (osw->scroll.mapped_gesture) { - // Inertial scrolling after a mapped gesture neither fires the mapping nor scrolls - osw->scroll.mapped_pending_pixels_y = 0; + // Inertial scrolling after a mapped gesture neither fires the mappings nor scrolls + osw->scroll.mapped_pending_pixels_x = osw->scroll.mapped_pending_pixels_y = 0; return; } finish_scroll_animation(screen); @@ -1725,12 +1757,7 @@ scroll_event_in_window(OSWindow *osw, Window *w, const GLFWScrollEvent *ev, unsi if (screen_apply_pixel_scroll(screen, delta_pixels) && screen->selections.in_progress) update_drag(w); } else { int s = scale_scroll( - screen->modes.mouse_tracking_mode, - ev->y_offset, - ev->offset_type, - &osw->scroll.pending_pixels_y, - cell_height, - &osw->scroll.last_v120_dir_y); + screen->modes.mouse_tracking_mode, ev->y_offset, ev->offset_type, &osw->scroll.pending_pixels_y, cell_height, &osw->scroll.last_v120_dir_y); if (s) { bool upwards = s > 0; if (screen->modes.mouse_tracking_mode) { @@ -1750,12 +1777,7 @@ scroll_event_in_window(OSWindow *osw, Window *w, const GLFWScrollEvent *ev, unsi } if (ev->x_offset != 0.0) { int s = scale_scroll( - screen->modes.mouse_tracking_mode, - ev->x_offset, - ev->offset_type, - &osw->scroll.pending_pixels_x, - cell_width, - &osw->scroll.last_v120_dir_x); + screen->modes.mouse_tracking_mode, ev->x_offset, ev->offset_type, &osw->scroll.pending_pixels_x, cell_width, &osw->scroll.last_v120_dir_x); if (s) { if (screen->modes.mouse_tracking_mode) { int sz = encode_mouse_scroll(w, s > 0 ? 6 : 7, ev->keyboard_modifiers); @@ -1968,8 +1990,7 @@ send_mock_scroll_event_to_window(PyObject *self UNUSED, PyObject *args) { PyObject *capsule; GLFWScrollEvent ev = {0}; int offset_type, momentum_type = GLFW_NO_MOMENTUM_DATA; - if (!PyArg_ParseTuple( - args, "O!iddi|i", &PyCapsule_Type, &capsule, &offset_type, &ev.x_offset, &ev.y_offset, &ev.keyboard_modifiers, &momentum_type)) + if (!PyArg_ParseTuple(args, "O!iddi|i", &PyCapsule_Type, &capsule, &offset_type, &ev.x_offset, &ev.y_offset, &ev.keyboard_modifiers, &momentum_type)) return NULL; Window *w = PyCapsule_GetPointer(capsule, "Window"); if (!w) return NULL; @@ -2013,6 +2034,8 @@ init_mouse(PyObject *module) { PyModule_AddIntMacro(module, MOUSE_SELECTION_UPTO_SURROUNDING_WHITESPACE); PyModule_AddIntMacro(module, MOUSE_WHEEL_UP); PyModule_AddIntMacro(module, MOUSE_WHEEL_DOWN); + PyModule_AddIntMacro(module, MOUSE_WHEEL_LEFT); + PyModule_AddIntMacro(module, MOUSE_WHEEL_RIGHT); if (PyModule_AddFunctions(module, module_methods) != 0) return false; return true; } diff --git a/kitty/options/definition.py b/kitty/options/definition.py index dd40e0889..14a03e62d 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -1227,13 +1227,14 @@ Mouse buttons can be mapped to perform arbitrary actions. The syntax is: mouse_map button-name event-type modes action Where :code:`button-name` is one of :code:`left`, :code:`middle`, :code:`right`, -:code:`b1` ... :code:`b8`, :code:`wheel_up`, :code:`wheel_down` with added -keyboard modifiers. For example: :code:`ctrl+shift+left` refers to holding the +:code:`b1` ... :code:`b8`, :code:`wheel_up`, :code:`wheel_down`, +:code:`wheel_left`, :code:`wheel_right` with added keyboard modifiers. For example: :code:`ctrl+shift+left` refers to holding the :kbd:`Ctrl+Shift` keys while clicking with the left mouse button. The value :code:`b1` ... :code:`b8` can be used to refer to up to eight buttons on a mouse. :code:`wheel_up` and :code:`wheel_down` refer to scrolling the mouse -wheel (or touchpad) vertically and only support the :code:`press` event type, -which is triggered once per wheel step. A step is one click of a classic wheel, +wheel (or touchpad) vertically, :code:`wheel_left` and :code:`wheel_right` +horizontally. They only support the :code:`press` event type, which is triggered +once per wheel step. A step is one click of a classic wheel, one notch of a high resolution wheel or 100 pixels of touchpad travel (scaled by :opt:`touch_scroll_multiplier`). The direction follows the scroll direction of kitty, so a negative :opt:`wheel_scroll_multiplier` or @@ -1246,6 +1247,11 @@ the mouse wheel:: mouse_map ctrl+wheel_up press ungrabbed,grabbed change_font_size all +2 mouse_map ctrl+wheel_down press ungrabbed,grabbed change_font_size all -2 +Or to switch tabs by scrolling horizontally with :kbd:`Ctrl`:: + + mouse_map ctrl+wheel_left press ungrabbed,grabbed previous_tab + mouse_map ctrl+wheel_right press ungrabbed,grabbed next_tab + :code:`event-type` is one of :code:`press`, :code:`release`, :code:`doublepress`, :code:`triplepress`, :code:`click`, :code:`doubleclick`. :code:`modes` indicates whether the action is performed when the mouse is diff --git a/kitty/options/utils.py b/kitty/options/utils.py index dfb73c084..6b9731208 100644 --- a/kitty/options/utils.py +++ b/kitty/options/utils.py @@ -79,7 +79,13 @@ for x in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ': character_key_name_aliases_with_ascii_lowercase[x] = x.lower() sequence_sep = '>' mouse_button_map = {'left': 'b1', 'middle': 'b3', 'right': 'b2'} -mouse_wheel_map = {'wheel_up': defines.MOUSE_WHEEL_UP, 'wheel_down': defines.MOUSE_WHEEL_DOWN} +mouse_wheel_map = { + 'wheel_up': defines.MOUSE_WHEEL_UP, + 'wheel_down': defines.MOUSE_WHEEL_DOWN, + 'wheel_left': defines.MOUSE_WHEEL_LEFT, + 'wheel_right': defines.MOUSE_WHEEL_RIGHT, +} +mouse_wheel_buttons = frozenset(mouse_wheel_map.values()) mouse_trigger_count_map = {'doubleclick': -3, 'click': -2, 'release': -1, 'press': 1, 'doublepress': 2, 'triplepress': 3} FuncArgsType = tuple[str, Sequence[Any]] func_with_args = KeyFuncWrapper[FuncArgsType]() diff --git a/kitty/state.h b/kitty/state.h index aa4d7a513..35940d35d 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -130,9 +130,10 @@ typedef struct Options { // all remapped source bits, used as a fast path. int modifier_remap[8]; int modifier_remap_mask; - // Bit i of wheel_mappings[0 for wheel_up, 1 for wheel_down][grabbed] is set - // when mouse_map maps the wheel with the modifiers i - uint64_t wheel_mappings[2][2]; + // Bit i of wheel_mappings[button][grabbed] is set when mouse_map maps the + // wheel with the modifiers i, button is 0 for wheel_up, 1 for wheel_down, + // 2 for wheel_left and 3 for wheel_right + uint64_t wheel_mappings[4][2]; bool window_alert_on_bell; bool macos_dock_badge_on_bell; bool debug_keyboard; @@ -602,10 +603,10 @@ typedef struct OSWindow { struct { double pending_pixels_x, pending_pixels_y; int last_v120_dir_x, last_v120_dir_y; - // wheel_up/wheel_down mouse_map state: the partial step and the - // window and modifiers it belongs to, and whether the current gesture - // fired a mapping, so that its momentum is swallowed - double mapped_pending_pixels_y; + // mouse_map wheel state: the partial steps and the window and + // modifiers they belong to, and whether the current gesture fired a + // mapping, so that its momentum is swallowed + double mapped_pending_pixels_x, mapped_pending_pixels_y; id_type mapped_window_id; int mapped_modifiers; bool mapped_gesture; diff --git a/kitty/window.py b/kitty/window.py index 3e12ec739..84fe4512a 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -49,8 +49,6 @@ from .fast_data_types import ( GLFW_PRESS, GLFW_RELEASE, GLFW_REPEAT, - MOUSE_WHEEL_DOWN, - MOUSE_WHEEL_UP, NO_CURSOR_SHAPE, NULL_COLOR_VALUE, SCROLL_FULL, @@ -103,6 +101,7 @@ from .fast_data_types import ( from .keys import keyboard_mode_name, mod_mask from .notifications import NotificationManager from .options.types import Options +from .options.utils import mouse_wheel_buttons from .progress import Progress from .rgb import to_color from .terminfo import get_capabilities @@ -1425,7 +1424,7 @@ class Window: def on_mouse_event(self, event: dict[str, Any]) -> bool: event['mods'] = event.get('mods', 0) & mod_mask steps = 1 - if event['button'] in (MOUSE_WHEEL_UP, MOUSE_WHEEL_DOWN): # repeat_count is the number of wheel steps + if event['button'] in mouse_wheel_buttons: # repeat_count is the number of wheel steps steps, event['repeat_count'] = event['repeat_count'], 1 ev = MouseEvent(**event) self.current_mouse_event_button = ev.button diff --git a/kitty_tests/base.py b/kitty_tests/base.py index 2d912d3ee..66f98120d 100644 --- a/kitty_tests/base.py +++ b/kitty_tests/base.py @@ -18,9 +18,10 @@ from pty import CHILD, STDIN_FILENO, STDOUT_FILENO, fork from unittest import TestCase from kitty.config import finalize_keys, finalize_mouse_mappings -from kitty.fast_data_types import MOUSE_WHEEL_DOWN, MOUSE_WHEEL_UP, TEXT_SIZE_CODE, Cursor, HistoryBuf, LineBuf, Screen, get_options, monotonic, set_options +from kitty.fast_data_types import TEXT_SIZE_CODE, Cursor, HistoryBuf, LineBuf, Screen, get_options, monotonic, set_options from kitty.options.parse import merge_result_dicts from kitty.options.types import Options, defaults +from kitty.options.utils import mouse_wheel_buttons from kitty.rgb import to_color from kitty.types import MouseEvent from kitty.utils import read_screen_size @@ -176,7 +177,7 @@ class Callbacks: def on_mouse_event(self, event): steps = 1 - if event['button'] in (MOUSE_WHEEL_UP, MOUSE_WHEEL_DOWN): # repeat_count is the number of wheel steps + if event['button'] in mouse_wheel_buttons: # repeat_count is the number of wheel steps steps, event['repeat_count'] = event['repeat_count'], 1 ev = MouseEvent(**event) opts = get_options() diff --git a/kitty_tests/mouse.py b/kitty_tests/mouse.py index 951220cef..a16fdb780 100644 --- a/kitty_tests/mouse.py +++ b/kitty_tests/mouse.py @@ -6,6 +6,7 @@ from functools import partial from kitty.fast_data_types import ( GLFW_MOD_ALT, GLFW_MOD_CONTROL, + GLFW_MOD_SHIFT, GLFW_MOUSE_BUTTON_LEFT, GLFW_MOUSE_BUTTON_RIGHT, MOUSE_SELECTION_WORD_AND_LINE_FROM_POINT, @@ -493,6 +494,9 @@ class TestMouse(BaseTest): 'mouse_map ctrl+wheel_up press ungrabbed change_font_size all +1', 'mouse_map ctrl+wheel_down press ungrabbed change_font_size all -1', 'mouse_map alt+wheel_up press ungrabbed mouse_selection normal', + 'mouse_map ctrl+wheel_left press ungrabbed previous_tab', + 'mouse_map shift+wheel_left press ungrabbed previous_tab', + 'mouse_map shift+wheel_right press ungrabbed next_tab', ), accumulate_bad_lines=errors, ) @@ -506,6 +510,8 @@ class TestMouse(BaseTest): calls = [] s.callbacks.change_font_size = lambda *a: calls.append(a[1]) s.callbacks.mouse_selection = lambda code: mock_mouse_selection(w, s.callbacks.current_mouse_button, code) + s.callbacks.previous_tab = lambda: calls.append('left') + s.callbacks.next_tab = lambda: calls.append('right') def scroll(y, mods=0, offset_type=LINES, momentum=0, x=0.0): send_mock_scroll_event_to_window(w, offset_type, x, float(y), mods, momentum) @@ -556,3 +562,27 @@ class TestMouse(BaseTest): scroll(1, GLFW_MOD_ALT) self.assertFalse(s.has_selection()) ac([], 2) + # Horizontal scrolling, positive offsets are leftwards + scroll(0, GLFW_MOD_SHIFT, x=1) + ac(['left'], 2) + scroll(0, GLFW_MOD_SHIFT, x=-2) + ac(['right'] * 2, 2) + scroll(0, GLFW_MOD_SHIFT, HIGHRES, x=60) + ac([], 2) + scroll(0, GLFW_MOD_SHIFT, HIGHRES, x=40) + ac(['left'], 2) + # A diagonal event fires the mappings of both axes + scroll(1, GLFW_MOD_CONTROL, x=1) + ac(['+', 'left'], 2) + # Horizontal jitter, without horizontal mappings, continues a mapped + # vertical gesture, so its momentum is still swallowed + scroll(100, GLFW_MOD_ALT, HIGHRES) + scroll(0, GLFW_MOD_ALT, HIGHRES, x=10) + scroll(-200, GLFW_MOD_ALT, HIGHRES, MOMENTUM_BEGAN) + ac([], 2) + # But horizontal scrolling in an unmapped direction, with horizontal + # mappings, ends the gesture, so its momentum scrolls + scroll(100, GLFW_MOD_CONTROL, HIGHRES) + scroll(0, GLFW_MOD_CONTROL, HIGHRES, x=-10) + scroll(-20, GLFW_MOD_CONTROL, HIGHRES, MOMENTUM_BEGAN) + ac(['+'], 1) diff --git a/kitty_tests/options.py b/kitty_tests/options.py index c70442572..98ee9f42c 100644 --- a/kitty_tests/options.py +++ b/kitty_tests/options.py @@ -403,8 +403,15 @@ def conf_parsing(self): self.ae(len(opts.keyboard_modes[''].keymap), 1) opts = p('clear_all_mouse_actions y', 'mouse_map left click ungrabbed mouse_click_url_or_select') self.ae(len(opts.mousemap), 1) - opts = p('clear_all_mouse_actions y', 'mouse_map ctrl+wheel_up press ungrabbed,grabbed change_font_size all +1') - self.ae({k.human_repr() for k in opts.mousemap}, {'ctrl+wheel_up press ungrabbed', 'ctrl+wheel_up press grabbed'}) + opts = p( + 'clear_all_mouse_actions y', + 'mouse_map ctrl+wheel_up press ungrabbed,grabbed change_font_size all +1', + 'mouse_map shift+wheel_right press ungrabbed next_tab', + ) + self.ae( + {k.human_repr() for k in opts.mousemap}, + {'ctrl+wheel_up press ungrabbed', 'ctrl+wheel_up press grabbed', 'shift+wheel_right press ungrabbed'}, + ) opts = p('strip_trailing_spaces always') self.ae(opts.strip_trailing_spaces, 'always') self.assertFalse(bad_lines)