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.
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.
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.
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
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.
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.
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.
- 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.
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.
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.
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.
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.
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.
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
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
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
- 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.
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.
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
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.
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
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)
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)