Commit graph

213 commits

Author SHA1 Message Date
Kovid Goyal
b069fa5674
Add a mode to report scroll events to programs in full detail
Mode 5523, while mouse tracking is on, makes kitty report each scroll event
as a single CSI > ... M escape code instead of as button 4-7 presses. It
carries integer deltas in v120 units or pixels, with fractions carried
over, the user's scroll multiplier as a hint, the kind of device, the
gesture phase, and flags for momentum and inverted (natural) scrolling,
and the full set of modifiers. Only the sign of the multipliers is applied.

To support this GLFW scroll events now carry the source device, the
gesture phase and whether the direction is inverted, on Wayland, X11 and
macOS. The momentum scroller now forwards the gesture end before starting
momentum and no longer reports a cancel for momentum that never began.
2026-11-19 19:57:38 +05:30
Kovid Goyal
ab98897710
Move OpenGL context creation from glfw into the GPU driver
glfw is now a windowing only library. It no longer creates OpenGL
contexts and contains no GLX, EGL, NSGL or OSMesa code. Instead it
exposes native window handles, and the GPU driver creates surfaces that
render into them, owning everything needed to render and present, such
as OpenGL contexts or, in future, Vulkan swapchains.

The GPU driver API (now version 2) gains surfaces: creation from native
X11, Wayland and Cocoa windows, making current, resizing, presenting,
swap interval, handling native view changes and recreation (macOS) and
choosing the X11 visual before window creation. The OpenGL driver
implements them with GLX on X11, EGL on Wayland and NSGL on macOS, all
ported from glfw, loading every library at runtime.

glfw gains a GLFW_X11_VISUAL_ID window hint, a native surface changed
callback (used on macOS where the NSOpenGLContext must be updated) and
glfwWindowContentsPresented(), which on Wayland commits surface state
after a frame is presented. The OpenGL context API, hints and the
share parameter of glfwCreateWindow() are removed.

The macOS (NSGL) code is untested as it could not be built.
2026-11-19 19:57:33 +05:30
Kovid Goyal
2b260d8d67
Wayland CSD: Re-render on keyboard focus changes
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
The focus state of the decorations comes only from keyboard enter/leave
events, but the decorations were only re-rendered on configure events and
title changes. So they showed a stale focus state whenever focus changed
without a following configure, for example, when switching between tabbed
windows in niri, which keeps all tabs activated.

Re-render the decorations on keyboard enter/leave, looking up the window
again after the focus callbacks have run, since they can close it.

Also:
- Ignore the activated state in the change detection, as focus is tracked
  separately, to avoid rendering twice per focus change.
- Never create decoration surfaces in ensure_csd_resources() for windows
  that should not be decorated, such as fullscreen windows. Title changes
  while fullscreen could previously create them from a stale state.
- Recreate the decoration surfaces when they are missing even if the
  window state is unchanged, otherwise the resize borders were not
  restored after leaving fullscreen with hide_window_decorations
  titlebar-only.

Based on the patch by Ole Jørgen Brønner.

Closes #10873
2026-11-15 20:06:45 +05:30
Kovid Goyal
3fe8677c4d
Cleanup previous PR
Do not track decoration touches that start an interactive move or resize,
the compositor takes the contact over and need not send its up event, which
left the contact active and caused the next decoration touch to be ignored.
Drop a stale tracked contact whenever a new down arrives with the same id,
wherever it lands. A titlebar button held down by one finger no longer
blocks moving or resizing windows with another.

Restore the old mouse behavior of hit testing titlebar buttons only by x, so
that a button is still activated when released after dragging the pointer
below the titlebar.

Update the input serials only for decoration touches that are handled,
including their up events. Share the titlebar commit code between the
pointer and touch paths, remove checks that can no longer fail, fix
indentation in decoration_surface() and add a changelog entry.
2026-11-13 19:44:02 +05:30
Cryolitia PukNgae
d370da8bdf
Wayland: Handle touch input on client-side decorations
Touch events on decoration surfaces are discarded, leaving the titlebar
buttons and interactive window moves and resizes unavailable on touch
screens.

Share decoration hit testing and button actions with the pointer path.
Track the decoration contact separately from application touch points,
use its down serial for move and resize requests, and activate a button
only when the same contact is released over it.

Clear the contact on cancellation, seat capability loss and surface
destruction, and clear it before invoking a close callback.
2026-11-13 19:44:02 +05:30
Kovid Goyal
7f8020faa2
Wayland: Fix unbounded wait for xdg_output geometry
glfwGetWaylandCurrentMonitorFractionalScale() looped on
wl_display_roundtrip() until every monitor had received xdg_output
logical size and position, with no limit. Compositors do not send
these for an xdg_output created on an output whose global has
just been removed, so kitty would hang forever when creating a new OS
window after output churn.

Bound the wait to a few roundtrips and remember monitors for which we
gave up so we dont wait on them again. Re-lookup monitors after each
roundtrip, since a dispatched global_remove can free them.

Also track outputs that have been bound but not yet announced via
wl_output.done, so that a global_remove arriving before done frees them
instead of the dead output being announced later and living in the
monitor list forever.
2026-11-05 08:52:20 +05:30
Kovid Goyal
a7c64b5b09
Wayland: Fix frame callbacks accumulating in the compositor for occluded windows
Fixes #10597
2026-10-04 14:14:36 +05:30
Kovid Goyal
3f0af8942e
Wayland: Support touchscreens
Turn glfw touch events into mouse and scroll events. A tap is a left
click where the finger landed, a finger that moves scrolls through the
glfw momentum scroller so it coasts like touchpad scrolling, and a
finger held still before it moves drags the left button, selecting
text. Only the first finger of a sequence is used. Touch events are
printed by --debug-input.
2026-10-02 11:28:30 +05:30
Kovid Goyal
8d7c77038f
Cleanup previous PR
Improve the touch event API and expose the momentum scroller

- Add a timestamp to GLFWTouchEvent, converted from the wl_touch event
  time to the monotonic() clock
- Cancel momentum scrolling when a finger touches the screen and add
  glfwFeedMomentumScroller() and glfwCancelMomentumScroll() so that
  applications can drive touch scrolling through the momentum scroller
- Report every touch point as pressed before it is reported as
  released, so GLFW_TOUCH_BEGIN never carries a released point
- Replace the as_state sentinel with an explicit report mode
- Update pointer_serial from touch so the primary selection can be set
  after a touch selection
- Document the guarantees of the touch API
2026-10-02 11:27:41 +05:30
rokokol
ee45ed2306 glfw: Report touch events
Add a touch callback that reports abstract touch events. The design
follows QTouchEvent and NSTouch. A sequence opens with GLFW_TOUCH_BEGIN,
goes on with GLFW_TOUCH_UPDATE and closes with GLFW_TOUCH_END or
GLFW_TOUCH_CANCEL. Each event carries every point that is down on the
window, with its id, its state and its position.

The Wayland backend binds wl_touch and collects the down, motion and up
events until the frame event. It then sends one event to each window
that has a changed point. A point belongs to the window it first
touched, because wl_touch gives its position relative to that surface.
A cancel from the compositor reaches only the windows that were told
that the sequence began. Touches on client-side decorations are not
reported.

glfw does not turn these events into mouse events. That is left to the
application.

Assisted-by: Claude Code:claude-opus-5-5 (mostly)
2026-09-26 15:05:51 +03:00
Kovid Goyal
df00dd1cec
Fix #10448
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
2026-09-07 20:51:54 +05:30
Kovid Goyal
17d2814b4d
Fix #10383 2026-08-21 20:38:38 +05:30
Kovid Goyal
49ee9c4a7b
handle no keymap message from compositor correctly 2026-08-10 15:36:27 +05:30
Kovid Goyal
278016cabb
Add API to glfw to inject key and mouse events into wlr supporting Wayland compositors
Used by the demo script to automate interaction
2026-08-10 15:13:54 +05:30
Kovid Goyal
2af2d313de
autoformat c/objc code, using clang-format with left alignment for line continuation chars 2026-08-05 19:37:00 +05:30
Kovid Goyal
4c6467814b
autoformat c/objc code, using clang-format 2026-08-05 19:10:55 +05:30
Kovid Goyal
e36f6ac1b8
Use most recently focused OS Window when available to guess the monitor to use for fractional scale
Some checks are pending
CI / Linux (python=3.14 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.13 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Slight improvement in odds of guessing right for subsequent OS Windows.
2026-07-21 13:02:23 +05:30
Kovid Goyal
6ed833e163
Wayland: get initial window size in cells working in most cases on hyprland/sway with fractional scaling by using the fractional scale of the primary monitor 2026-07-21 10:03:40 +05:30
ttyS3
98366076e1
fix(wayland): detect start_drag silently ignored by the compositor
The pointer_button_count check added in dc36e2165 uses the client side
view of the implicit grab, which is stale when the button release is
still in flight: glfwStartDrag passes the check, but by the time the
compositor processes wl_data_device.start_drag the implicit grab is
gone and the request is silently dropped. The data source then never
receives any event, so the tab drag state leaks forever, hijacking
mouse handling again, and the already created xdg_toplevel_drag
toplevel gets mapped as a stray undecorated window showing the drag
thumbnail that nothing ever destroys.

Detect this deterministically using protocol ordering: issue a
wl_display.sync right after start_drag. An accepted start_drag
synchronously produces events (wl_pointer.leave from the DND grab
taking over, wl_data_device.enter, wl_data_source events) that are
ordered before the sync callback. If the callback fires with none of
them seen, the request was dropped: cancel the drag, which notifies
the application (clearing the tab drag state) and destroys the drag
toplevel and data source.

Also defer mapping the drag toplevel until the session is confirmed,
so the stray window can never appear, not even for one frame.

Verified against headless GNOME Shell 50.2 (mutter) with injected
pointer timing scans: the unpatched build deadlocks with an orphaned
drag toplevel within ~13 fast flicks, the patched build catches every
race hit and cancels cleanly, with no deadlock, no stray window, and
normal slow drag/reorder/detach behaviour preserved.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-12 14:16:22 +08:00
ttyS3
dc36e21654
fix(tabs): mouse handling stuck after aborted tab drag on Wayland
A quick click-and-flick on a tab could leave all of kitty with mouse
input permanently redirected to the tab bar, making every window
unclickable and text selection impossible.

Starting a tab drag is asynchronous: the drag thumbnail is rendered on
the next frame before glfwStartDrag is called. If the button is
released in that window, wl_data_device_start_drag is sent with a stale
serial that no longer matches an active pointer implicit grab, so the
compositor silently ignores it. The wl_data_source then never receives
any event, on_drag_source_finished never runs, and the
tab_being_dragged state is stuck forever, hijacking all mouse events.

Fix in layers:
- glfw/Wayland: track the implicit grab (serial of the first button
  press and pressed-button count), use that serial for start_drag and
  refuse with EAGAIN when there is no active implicit grab instead of
  letting the compositor silently drop the request
- mouse.c: a left button release arriving while a tab drag is marked
  started but no system DND is active means the drag never launched
  (an active DND consumes the release on all platforms), so clear the
  drag state instead of waiting for DND events that will never come
- tabs.py: handle OSError from start_drag_with_data for tab drags the
  same way window drags already do; clear the potential-drag state when
  the release lands on the new-tab button or empty tab bar area
- tabs.py/boss.py: clear drag state on drag finish/drop even when the
  dragged tab has already been closed

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 03:43:25 +00:00
Kovid Goyal
2096948cbc
Wayland: Only use key repeat events from server is repeat rate == 0
Some checks are pending
CI / Linux (python=3.13 cc=clang sanitize=1) (push) Waiting to run
CI / Linux (python=3.11 cc=gcc sanitize=0) (push) Waiting to run
CI / Linux (python=3.12 cc=gcc sanitize=1) (push) Waiting to run
CI / Linux package (push) Waiting to run
CI / Bundle test (macos-latest) (push) Waiting to run
CI / Bundle test (ubuntu-latest) (push) Waiting to run
CI / macOS Brew (push) Waiting to run
CI / Test ./dev.sh and benchmark (push) Waiting to run
CodeQL / CodeQL-Build (actions, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, macos-latest) (push) Waiting to run
CodeQL / CodeQL-Build (c, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (go, ubuntu-latest) (push) Waiting to run
CodeQL / CodeQL-Build (python, ubuntu-latest) (push) Waiting to run
Depscan / Scan dependencies for vulnerabilities (push) Waiting to run
Fixes #10070
2026-05-26 08:31:52 +05:30
Kovid Goyal
4076c43783
Report missing pointer-gestures protocol 2026-04-14 09:44:48 +05:30
Kovid Goyal
95593ef008
Wayland: Allow holding momentum scroll by putting two finger on touchpad. Fixes #9863 2026-04-14 09:39:57 +05:30
Kovid Goyal
98931d99b0
Wayland: Fix momentum scrolling not working on compositors that send a stop frame with no axis information
Fixes #9653
2026-03-13 08:47:45 +05:30
Kovid Goyal
9f2a4ad2dd
Wayland: Implement ridiculous workaround for broken dnd
Wayland is *the worst* window system I have ever had the
displeasure of trying to support.
2026-02-22 16:24:46 +05:30
copilot-swe-agent[bot]
accee908aa
Implement Wayland xdg-toplevel-drag protocol for make_toplevel in _glfwPlatformChangeDragImage
Fixes #9544
2026-02-22 14:53:34 +05:30
copilot-swe-agent[bot]
bcba8fc04c
Wayland: Add support for ext-background-effects
Fixes #9536
Fixes #9534
2026-02-21 20:56:40 +05:30
Kovid Goyal
3cf24afdc0
Refactor drop API and implement it on Wayland 2026-02-08 22:05:14 +05:30
Kovid Goyal
07a9f2bcaa
API to start a drag 2026-02-07 13:50:16 +05:30
Kovid Goyal
9ef934cf54
Wayland: Remove usage of the Wayland color management protocol to inform compositors of the color space used by kitty
As is typical with Wayland, the protocol is poorly designed and
implemented even worse. Hyprland 0.53 has completely broken color
management.
https://github.com/hyprwm/Hyprland/discussions/12788
In addition it and mangowc crash when using color management with nouveau drivers.
https://github.com/kovidgoyal/kitty/issues/9030

KDE kwin does not support the sRGB transfer function. And the geniuses
at Wayland are any way planning to deprecate sRGB as a transfer function.

Only GNOME mutter seems to get it right.

Then there are people that are likely going to shoehorn this into EGL
instead of leaving it under application control via the protocol anyway.
https://github.com/KhronosGroup/EGL-Registry/issues/197

Sigh. Wayland.
2026-01-15 09:53:09 +05:30
Kovid Goyal
c389f4d5b8
Wayland: Fix doubled key repeat events when compositor sends repeat events
Fixes #9374
2026-01-15 08:13:37 +05:30
Kovid Goyal
779fb0d5c5
Cancel momentum scroll on button and key events 2026-01-09 13:15:37 +05:30
Kovid Goyal
3c250a741d
Wayland: Fix line and v120 scroll event types being multiplied by screen scale
This does not match X11/macOS behavior. And I see no logical reason why
it should be so. The wheel_scroll_multiplier should be used to adjust
this by end users.
2026-01-09 12:50:07 +05:30
Kovid Goyal
32f7f8d321
Remove unneeded axis event timestamp 2026-01-05 20:13:33 +05:30
Kovid Goyal
e1199bcee2
Initial implementation of momentum for finger based scrolling on Wayland
Needs configuration and possibly the parameter adjustment once pixel
scrolling is merged.
2026-01-05 19:52:44 +05:30
Kovid Goyal
0f1362524b
Store more information about axis events from Wayland 2026-01-01 13:25:30 +05:30
Kovid Goyal
ba3af8f2c3
Refactor GLFW scroll event callback to use a proper event struct 2025-12-31 23:40:34 +05:30
Kovid Goyal
71a7dda522
... 2025-12-05 07:51:04 +05:30
Kovid Goyal
16008b950a
Wayland: Fix spurious key repeat events when some user defined callback takes a long time to execute
On compositors that support compositor key repeat events, use those, for
complete robustness. Sadly no actual compositor implements these yet.

Otherwise use a timer fd/pipe to queue the repeat events and only
dispatch them after events from the compositor are handled. This means
release events from the compositor will prevent spurious repeat events.
One can, in the worst case lose some repeat events if there is a very
large interval between the start of the timer and the next poll, but
that is unavoidable and is why repeat events should come from the compositor
in the first place.

Fixes #9224
2025-12-03 22:26:09 +05:30
Kovid Goyal
ca945563bb
Wayland: add support for compositor provided key repeat events
Far more robust. Sadly no actual compositors yet support this. Fifteen
years it takes Wayland developers to correct their most basic mistakes.

See #9224
2025-12-03 20:02:46 +05:30
Kovid Goyal
94f3da53aa
Cleanup previous PR 2025-10-21 09:44:41 +05:30
Evan Goode
80a9bdb999 Smoothly handle VALUE120 scroll events 2025-10-20 09:32:59 -04:00
Kovid Goyal
2ffa8cd7c2
Apparently gamma22 gives incorrect colors or at least colors different from rendering without color management. srgb transfer function gives expected colors. 2025-07-31 19:07:28 +05:30
Kovid Goyal
caa654b6b8
Also track needed color manager features 2025-07-31 18:53:24 +05:30
Kovid Goyal
d37bd7afcf
Create the sRGB colorspace description we need 2025-07-31 18:30:47 +05:30
Kovid Goyal
df22e8c9b7
Only report missing features when color manager itself is supported 2025-07-31 15:41:17 +05:30
Kovid Goyal
fe860d170f
Track that the compositor supports the sRGB primary 2025-07-31 15:39:55 +05:30
Kovid Goyal
77106b1035
DRYer 2025-07-31 15:15:49 +05:30
Kovid Goyal
8762576a5b
Also track support for extlinear transfer function 2025-07-31 15:12:26 +05:30
Kovid Goyal
d0a862bedb
Get the color manager capabilities from the compositor 2025-07-31 15:09:18 +05:30