mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-11-21 07:35:08 +00:00
X11: Support wheel events from sources without smooth scrolling when smooth scrolling sources are also present
Fixes #10575
This commit is contained in:
parent
ab08ba80ec
commit
8a390c5062
3 changed files with 40 additions and 14 deletions
|
|
@ -221,6 +221,10 @@ Detailed list of changes
|
|||
- Fix the padding beside window title bars not being drawn when
|
||||
:opt:`padding_fill_strategy` is set to :code:`neighboring_cell`
|
||||
|
||||
- X11: Fix mouse wheel events from sources without smooth scrolling, such as
|
||||
x11vnc, being ignored when a smooth scrolling device is present. Also pick up
|
||||
smooth scrolling devices that are added or enabled after kitty starts
|
||||
|
||||
0.49.2 [2026-10-01]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
|
|
|||
4
glfw/x11_platform.h
vendored
4
glfw/x11_platform.h
vendored
|
|
@ -493,6 +493,10 @@ typedef struct _GLFWlibraryX11 {
|
|||
PFN_XIGetProperty GetProperty;
|
||||
XIScrollDevice scroll_devices[16];
|
||||
unsigned num_scroll_devices;
|
||||
// Server timestamp of the last XI_Motion event that carried scroll
|
||||
// valuators. The X server stamps the wheel button events it emulates
|
||||
// from those valuators with the same time.
|
||||
Time last_smooth_scroll_time;
|
||||
int master_pointer_id;
|
||||
Atom LIBINPUT_SCROLL_METHOD_ENABLED, LIBINPUT_TAPPING;
|
||||
} xi;
|
||||
|
|
|
|||
46
glfw/x11_window.c
vendored
46
glfw/x11_window.c
vendored
|
|
@ -457,11 +457,12 @@ disableRawMouseMotion(_GLFWwindow *window UNUSED) {
|
|||
XISelectEvents(_glfw.x11.display, _glfw.x11.root, &em, 1);
|
||||
}
|
||||
|
||||
// Enable XI2 smooth scrolling events on a window
|
||||
// Select XI2 smooth scrolling events on a window if there are scroll devices,
|
||||
// otherwise deselect them
|
||||
//
|
||||
static void
|
||||
enableSmoothScrolling(_GLFWwindow *window) {
|
||||
if (!_glfw.x11.xi.num_scroll_devices) return;
|
||||
updateSmoothScrolling(_GLFWwindow *window) {
|
||||
if (!_glfw.x11.xi.available) return;
|
||||
// Select XI_Motion events on the window
|
||||
XIEventMask em;
|
||||
unsigned char mask[XIMaskLen(XI_Motion)] = {0};
|
||||
|
|
@ -469,11 +470,19 @@ enableSmoothScrolling(_GLFWwindow *window) {
|
|||
em.deviceid = XIAllDevices;
|
||||
em.mask_len = sizeof(mask);
|
||||
em.mask = mask;
|
||||
XISetMask(mask, XI_Motion);
|
||||
if (_glfw.x11.xi.num_scroll_devices) XISetMask(mask, XI_Motion);
|
||||
|
||||
XISelectEvents(_glfw.x11.display, window->x11.handle, &em, 1);
|
||||
}
|
||||
|
||||
// Return true if the core wheel button event was emulated by the X server from
|
||||
// smooth scroll valuators that have already been handled via XI_Motion
|
||||
//
|
||||
static bool
|
||||
isEmulatedScrollButton(const XButtonEvent *event) {
|
||||
return _glfw.x11.xi.num_scroll_devices && _glfw.x11.xi.last_smooth_scroll_time != CurrentTime && event->time == _glfw.x11.xi.last_smooth_scroll_time;
|
||||
}
|
||||
|
||||
static void
|
||||
resetScrollValuators(void) {
|
||||
for (unsigned i = 0; i < _glfw.x11.xi.num_scroll_devices; i++) {
|
||||
|
|
@ -854,7 +863,7 @@ createNativeWindow(_GLFWwindow *window, const _GLFWwndconfig *wndconfig, Visual
|
|||
if (_glfw.hints.window.blur_radius > 0) _glfwPlatformSetWindowBlur(window, _glfw.hints.window.blur_radius);
|
||||
|
||||
// Enable XI2 smooth scrolling if available
|
||||
enableSmoothScrolling(window);
|
||||
updateSmoothScrolling(window);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1392,7 +1401,8 @@ handle_xi_motion_event(_GLFWwindow *window, XIDeviceEvent *de) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!scroll_valuator_found) {
|
||||
if (scroll_valuator_found) _glfw.x11.xi.last_smooth_scroll_time = de->time;
|
||||
else {
|
||||
x11_cancel_momentum_scroll_timer();
|
||||
glfw_cancel_momentum_scroll();
|
||||
handle_mouse_move_event(window, (int)de->event_x, (int)de->event_y);
|
||||
|
|
@ -1823,9 +1833,13 @@ processEvent(XEvent *event) {
|
|||
XIHierarchyEvent *he = (XIHierarchyEvent *)event->xcookie.data;
|
||||
// Check if any devices were added or removed
|
||||
for (int i = 0; i < he->num_info; i++) {
|
||||
if (he->info[i].flags & (XISlaveAdded | XISlaveRemoved | XIMasterAdded | XIMasterRemoved)) {
|
||||
// Re-read scroll devices when devices are added or removed
|
||||
if (he->info[i].flags & (XISlaveAdded | XISlaveRemoved | XIMasterAdded | XIMasterRemoved | XIDeviceEnabled | XIDeviceDisabled)) {
|
||||
// Re-read scroll devices when devices are added, removed, enabled or disabled
|
||||
// and update the smooth scrolling event selection on existing windows
|
||||
read_xi_scroll_devices();
|
||||
for (_GLFWwindow *w = _glfw.windowListHead; w; w = w->next) {
|
||||
if (w->x11.handle) updateSmoothScrolling(w);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -1956,17 +1970,21 @@ processEvent(XEvent *event) {
|
|||
_glfwInputMouseClick(window, GLFW_MOUSE_BUTTON_RIGHT, GLFW_PRESS, mods);
|
||||
}
|
||||
|
||||
// Modern X provides scroll events as mouse button presses
|
||||
// Only use these if smooth scrolling is not available
|
||||
// Modern X provides scroll events as mouse button presses. Ignore
|
||||
// the ones the server emulated from smooth scroll valuators, as those
|
||||
// have already been handled via XI_Motion. Other wheel button presses,
|
||||
// such as from XTEST (x11vnc, xdotool) are handled normally.
|
||||
else if (event->xbutton.button == Button4) {
|
||||
if (!_glfw.x11.xi.num_scroll_devices) _glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers = mods, .y_offset = 1, .unscaled.y = 1});
|
||||
if (!isEmulatedScrollButton(&event->xbutton))
|
||||
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers = mods, .y_offset = 1, .unscaled.y = 1});
|
||||
} else if (event->xbutton.button == Button5) {
|
||||
if (!_glfw.x11.xi.num_scroll_devices)
|
||||
if (!isEmulatedScrollButton(&event->xbutton))
|
||||
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers = mods, .y_offset = -1, .unscaled.y = -1});
|
||||
} else if (event->xbutton.button == Button6) {
|
||||
if (!_glfw.x11.xi.num_scroll_devices) _glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers = mods, .x_offset = 1, .unscaled.x = 1});
|
||||
if (!isEmulatedScrollButton(&event->xbutton))
|
||||
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers = mods, .x_offset = 1, .unscaled.x = 1});
|
||||
} else if (event->xbutton.button == Button7) {
|
||||
if (!_glfw.x11.xi.num_scroll_devices)
|
||||
if (!isEmulatedScrollButton(&event->xbutton))
|
||||
_glfwInputScroll(window, &(GLFWScrollEvent){.keyboard_modifiers = mods, .x_offset = -1, .unscaled.x = -1});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue