Commit graph

1654 commits

Author SHA1 Message Date
Kovid Goyal
8e73e474b0
X11: Use a single process wide X error handler
Replace the grab/release error handler pattern with a process wide
handler that is installed for the lifetime of the display. Errors are
captured by nestable traps identified by request serial numbers, so
traps only capture errors from requests made while they are open, and
errors from requests not covered by any trap are reported rather than
exiting the process.

Requests to windows owned by other clients (selection requestors, drag
and drop peers) are trapped individually, without waiting for a round
trip to the server, and without covering calls into the application.

Also fix reading uninitialized memory when handling a MULTIPLE
selection request whose requestor window has been destroyed, trap
errors when replying to drag sources, report failure to deliver drag
data, and fix detectEWMH() leaving the error handler installed on an
early return.
2026-11-09 09:01:19 +05:30
Johannes Wüller
b2f1bd6ebf X11: Don't exit when a selection requestor's window disappears
Answering a SelectionRequest writes a property on the requestor's window
and sends it a SelectionNotify. The requestor may destroy that window at
any time, for example right after issuing ConvertSelection. The reply
then fails with BadWindow, and without an error handler installed,
Xlib's default handler exits the whole process:

    X Error of failed request:  BadWindow (invalid Window parameter)
      Major opcode of failed request:  18 (X_ChangeProperty)

This happens in practice with clipboard-syncing clients such as the
Looking Glass client, which request PRIMARY while the user drag-selects
text in kitty, and takes down every window of a --single-instance kitty.

Trap X errors while replying to selection requests, for both the
synchronous path and the asynchronous drag-and-drop data reply.
2026-11-08 18:50:43 +01:00
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
7670f895a6
IME: Show the cursor at the position reported by the input method in the pre-edit text
Previously the cursor was always drawn after the pre-edit text, as the
cursor position sent by the input method was ignored, so one could not see
which character was being edited when moving inside the pre-edit text, as
with Chewing. Pass the pre-edit cursor from IBus, Wayland text-input and
macOS to kitty, in code points, and place the cursor there. On Wayland, do
not drop pre-edit updates that only move the cursor.

Also use the pre-edit cells rather than the original line under them to
size and color the cursor, so that it covers wide pre-edit characters.

The IME candidate window remains anchored at the start of the pre-edit text.

Fixes #10807
2026-11-05 08:26:34 +05:30
Kovid Goyal
1b2ea883b0
Make CodeQL happy 2026-11-03 13:40:34 +05:30
Kovid Goyal
b8a70cf3d0
Desktop settings: Avoid duplicate portal queries and coalesce titlebar redraws
When the color scheme is queried at startup, wait for the reply to the
pending ReadAll request instead of making a second blocking ReadOne call,
only falling back to ReadOne if ReadAll failed or did not reply in time.
Session bus dispatching is now guarded against re-entrancy so this wait is
safe even when called from inside a DBus callback.

Coalesce titlebar redraws: settings changes only mark the titlebar dirty,
redrawing once after the initial ReadAll reply and once per burst of
SettingChanged signals via a short one-shot timer.

Fix the legacy Read color-scheme handler checking a stale type for the
nested variant and reading the value without verifying it is a uint32.
2026-10-30 10:07:13 +05:30
Kovid Goyal
51fae4211c
Wayland CSD: Guard against zero sized buffers and shadows at tiny scales
wl_shm buffers must have non-zero size and at scales below 1/24 the
shadow margin rounds to zero, which led to out of bounds reads when
compositing the shadow into the titlebar corners.
2026-10-30 09:22:13 +05:30
Kovid Goyal
2e71520e56
Wayland CSD: Track buffer release instead of recreating all buffers on every release
Previously, every time the compositor released a decoration buffer it was
destroyed and all decoration buffers, for all nine surfaces, were
recreated on the next update. In addition, the titlebar could be
rendered into a buffer the compositor had not yet released. Now buffers
are marked busy while attached and kept when released. The titlebar is
never rendered into a busy buffer, instead the render is done when the
buffer is released. Busy buffers are still not destroyed when freeing
buffers, to avoid flicker, they are destroyed when released.
2026-10-30 09:22:10 +05:30
Kovid Goyal
0c87f8ce94
Wayland CSD: Fix various correctness issues
- Dont re-render the titlebar on every pointer motion event. This both
  wasted CPU re-shaping the title and rendered into the buffer last
  attached to the titlebar surface without attaching the result.
- Notify of the window size change when the titlebar height changes in a
  docked window, as is done for configure events, and never set a non
  positive content height.
- Only wait for the desktop settings when creating the first window, since
  dispatching DBus from inside a DBus callback is not re-entrant.
- Apply cursor theme changes received via SettingChanged instead of
  silently updating the theme name.
2026-10-30 09:14:43 +05:30
Kovid Goyal
0331c873f9
Run autoformat 2026-10-30 09:07:45 +05:30
Kovid Goyal
84b93bd01c
Wayland CSD: Document the new decorations and remove the standalone tests
The standalone C tests compiled the glfw sources by including them and
stubbing internals and were not run by the test suite. Move the useful
parts of the markdown docs into the option docs and changelog.
2026-10-30 09:07:45 +05:30
Kovid Goyal
e37f4cd223
Wayland CSD: Cleanup titlebar rendering and button handling
Use enums for titlebar buttons and gestures instead of magic numbers
shared between files. Split up the titlebar renderer. Derive button
colors from the titlebar color so they fit in with custom titlebar
colors. Parse button layouts without a colon the way GTK does, all
buttons on the left. Restore the error message when the compositor
does not support showing the window menu.
2026-10-30 09:06:15 +05:30
Kovid Goyal
a2aa9b739d
Wayland CSD: Parse the titlebar font description once in glfw
Replace glfwGetSystemFont(), which returned a raw Pango font description
that was parsed separately in glfw and kitty, with glfwGetTitlebarFont()
that returns the parsed family, size and style. The parser now handles
font family lists, pixel sizes and the full set of Pango weight and style
names. A text scale less than one is now applied to the header height as
well. The FreeType context for the title font is released on exit and
failures to create it are not retried and reported on every redraw.
2026-10-30 09:03:46 +05:30
Kovid Goyal
53ba16881d
Wayland CSD: Wait briefly for desktop settings before creating a decorated window
On compositors without xdg-decoration, such as mutter, the titlebar height
depends on desktop settings that arrive asynchronously from the portal. If
they arrive after the window is mapped, the window visibly resizes. Wait
up to 200ms for the reply before creating the first such window.
2026-10-30 09:01:46 +05:30
Kovid Goyal
a5c48a3644
Wayland CSD: With system titlebar color and no desktop preference follow the window background
This was the behavior before the GNOME style CSD changes. Also restore
the previous semantics of the initial color scheme notification.
2026-10-30 08:59:34 +05:30
Kovid Goyal
6d6134ce16
Wayland CSD: Move titlebar settings handling into the Wayland backend
The desktop settings module is shared with X11 and should not walk the
window list and poke at Wayland decoration state. Use a platform hook
like the existing one for cursor theme changes. Also dont recompute
metrics and change window geometry on every title change, only when the
titlebar settings actually change.
2026-10-30 08:59:11 +05:30
Kovid Goyal
8853163337
Merge branch 'feature/wayland-gnome-csd' of https://github.com/acid0ikario/kitty 2026-10-30 08:57:46 +05:30
Manuel Villanueva
401d8795f3
Wayland: default CSD to dark when desktop appearance is unavailable 2026-10-29 15:53:45 -06:00
Manuel Villanueva
0753e82dbf
Wayland: treat the default desktop appearance as light 2026-10-29 15:41:39 -06:00
Manuel Villanueva
45282eef7d
Wayland: inherit GNOME titlebar preferences through the desktop portal 2026-10-29 15:35:48 -06:00
Manuel Villanueva
c28c460e34
Wayland: use GNOME CSD by default and follow desktop appearance 2026-10-29 15:16:12 -06:00
Kovid Goyal
e5d78ce8fc
macOS: Commit in-progress IME text when the OS window loses focus
Previously the pre-edit text was discarded on any focus loss, losing
composed or dictated text when switching to another application. Now when
the OS window loses focus the pre-edit text is committed, as native macOS
applications do, preferring any final result the input method delivers
when it is reset. Focus changes between kitty windows and closing windows
still cancel the composition.

Closes #10771
2026-10-29 19:07:16 +05:30
Manuel Villanueva
96976d85b6
Wayland: add opt-in built-in GNOME-style window decorations 2026-10-28 23:01:00 -06:00
Kovid Goyal
ad451c720f
Fix #10759 2026-10-28 17:25:46 +05:30
Kovid Goyal
b5adf1de0e
Linux: Send kitty's .desktop file name to notification servers for grouping
Closes #10721
2026-10-23 08:47:19 +05:30
Kovid Goyal
72ffcb5733
macOS: Fix a possible use-after-free of the tick lock when quitting
The I/O and talk threads can call glfwPostEmptyEvent() until
Boss.destroy() joins them, which is after the main loop has returned and
released the NSLock, so they could message a freed lock. The lock only
guarded a single flag, so replace it with an atomic exchange. This
removes the lifetime problem entirely, is cheaper than locking on every
wakeup, also fixes the unsynchronized access of the flag from the main
thread and no longer drops wakeups posted before the main loop starts.

Closes #10705
2026-10-20 09:20:58 +05:30
Kovid Goyal
24201d3080
Implement session saving on Logout for Linux as well 2026-10-19 10:49:22 +05:30
Kovid Goyal
7e88f51ed7
Some minor robustness fixes to glfw cocoa backend 2026-10-16 14:02:01 +05:30
Kovid Goyal
76a00e5142
macOS: Optionally restore kitty, including scrollback, after logging out
A new option restore_session_after_logout. When macOS asks kitty to quit
because the user is logging out, restarting or shutting down, every kitty
instance saves a snapshot: its session, including OS Window geometry, the
scrollback of every window and the command line, working directory and
environment of the instance.

The next kitty started without a session or command to run claims all
snapshots, restores the one saved by an instance with the same command
line itself and starts a separate kitty instance for each of the others,
so every instance keeps its own command line arguments and environment.
Snapshots are deleted only after their windows have been created. A
snapshot that fails to restore twice, for example because kitty crashed,
is deleted. Snapshots from an earlier logout that were never restored are
deleted when saving, using the wall clock start time of the process.

Restored scrollback is parsed before the child is allowed to run, after
the window has its final size. Only the scrollback and screen are saved,
not the scrollback pager history. Before parsing, everything except SGR,
OSC 8 and OSC 66 is removed, so a modified snapshot cannot run escape
codes such as OSC 52, and the restored output has no shell integration
marks. Programs other than the shell are not started again.

A quit is treated as being for a logout only if it is confirmed within
LOGOUT_CONFIRMATION_TIMEOUT of the logout request, and not if the quit
was cancelled in between.

Fixes #1197
2026-10-16 11:41:27 +05:30
Kovid Goyal
42eb2a1c3b
Cleanup previous PR
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
- Anchor the IME cursor rectangle at the column the pre-edit text is
  actually drawn at, which is shifted left of the cursor when the text
  would not otherwise fit on the line, instead of at the cursor column.
- Store the IBus cursor geometry cache per input context rather than in
  a function static, only update it after a successful send and reset it
  whenever a new input context is created.
- Add a test and a changelog entry.
2026-10-10 12:45:19 +05:30
Wanten
3bce8cdc36
Anchor IME cursor rectangle to pre-edit start
During IME composition kitty reported the cursor rectangle at the end
of the pre-edit text (overlay_line.cursor_x), so every keystroke that
grew the pre-edit moved the rectangle and the IME candidate window
jumped horizontally.

Report the start of the pre-edit text (overlay_line.xstart) instead,
which is stable for the whole composition, and only send position
updates when it changes. Also deduplicate IBus SetCursorLocation the
same way the Wayland text-input path already does.
2026-10-10 14:37:23 +08:00
rudolf-blue
4d2a12df72 Fix lazy drag data being cut off after the first chunk on Wayland 2026-10-08 23:59:56 -04:00
rudolf-blue
dcac4bb35f Fix partial drag data writes and a NULL mime_type dereference on Wayland 2026-10-08 23:59:56 -04:00
rudolf-blue
eff37ff291 Fix drop data buffer overflow and unchecked mmap on Wayland 2026-10-08 23:59:56 -04:00
Kovid Goyal
f021526205
Fix #10628 2026-10-08 22:08:13 +05:30
Kovid Goyal
51aa327be1
Fix momentum scroll scale not being set for negative deltas
The scale between scaled and unscaled offsets was only calculated for
positive deltas, so when scrolling up or left it stayed at zero (or stale from
a previous scroll), causing momentum events to have zero offsets.

Closes #10610
2026-10-05 20:42:16 +05:30
Kovid Goyal
643f18f292
Fix #10604
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-10-05 04:49:44 +05:30
Kovid Goyal
83e5692817
Fix #10602 2026-10-05 03:50:54 +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
Kovid Goyal
8da7732ca6 Merge branch 'pr10551' 2026-10-02 11:12:37 +05:30
Kovid Goyal
62c73ac988
Fix #10581
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-10-01 19:29:33 +05:30
Kovid Goyal
8a390c5062
X11: Support wheel events from sources without smooth scrolling when smooth scrolling sources are also present
Fixes #10575
2026-10-01 19:02:59 +05:30
Kovid Goyal
3435aeccdb
Fix #10567 2026-09-28 14:53:48 +05:30
Kovid Goyal
dc37ed4c6a
macOS: Fix a regression in the previous release causing :opt:background_opacity less than one with no :opt:background_blur making the titlebar transparent
Fixes #10540
Fixes #10547
2026-09-28 08:51:38 +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
Jeff Quast
aaab61a87b ignore NotifyPointer as focus events
Problem: On X11/KDE, with two kitty windows on different virtual
desktops, switching desktops with the keyboard while the mouse pointer
sits still caused both windows to report as "focused". Keyboard input
still went to visible window, but paste and other actions went to the
other window. Fixed by ignoring FocusIn/FocusOut when ``detail ==
NotifyPointer``.

Logfile before::

    0x2 focused: 0   0x2 focused: 1   0x1 focused: 1

Logfile after::

    0x2 focused: 0   0x1 focused: 1

Video attached.  This same approach is used by Qt and Wine,

148bc4bc05/src/plugins/platforms/xcb/qxcbwindow.cpp (L2292-L2312)
9d17984f27/dlls/winex11.drv/event.c (L697)
2026-09-25 05:17:28 -04:00
Kovid Goyal
a1d2e5942b
autoformat 2026-09-19 15:23:24 +05:30
Kovid Goyal
41b7959675
Fix #10492 2026-09-19 15:21:29 +05:30