Commit graph

421 commits

Author SHA1 Message Date
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
Connor Welsh
fb4d05f7e8
Wayland: Fix crash hiding titlebar on layer-shell windows
inform_compositor_of_window_geometry() calls xdg_surface_set_window_geometry()
unconditionally, but layer-shell surfaces (e.g. those from `kitten panel`) have
no xdg_surface. With hide_window_decorations set to titlebar-only, the panel hits
this geometry call during creation and dereferences the NULL proxy, crashing in
wl_proxy_get_version() with SIGSEGV.

Guard on window->wl.xdg.surface: layer-shell surfaces manage geometry via the
layer surface, so the xdg call is skipped. Normal toplevels are unaffected.
2026-05-30 16:14:55 -04:00
Kovid Goyal
75b99a3cbf
Fix drop state update on move incorrect when transitioning between windows 2026-05-17 07:50:41 +05:30
Kovid Goyal
6d4371f596
Properly pass source actions to drop events
Implemented for Wayland. Needs implementation for X11 and macOS
2026-05-14 11:07:52 +05:30
Kovid Goyal
c909809bb4
More work on DnD kitten 2026-05-13 08:25:14 +05:30
Kovid Goyal
021377c1b6
Yet another workaround for Wayland's awful design 2026-05-04 22:53:05 +05:30
Kovid Goyal
1c4097edde
Remove unnecessary event pump when attaching top level drag surface 2026-04-07 17:25:18 +05:30
Kovid Goyal
837f55fe21
... 2026-04-07 13:47:47 +05:30
copilot-swe-agent[bot]
a90b8470ac
Fix drag icon not visible under GNOME Wayland
Fixes #9823
2026-04-07 13:31:04 +05:30
Kovid Goyal
cd3860817b
... 2026-04-07 11:47:58 +05:30
Kovid Goyal
9fbb079ad6
Add logging for DnD events on Wayland 2026-04-07 11:32:12 +05:30
Kovid Goyal
dc55052f0c
Wayland: set drop accepted operations 2026-04-07 10:40:14 +05:30
copilot-swe-agent[bot]
2f33460864
Add operations==-3 cancel drag support to glfwStartDrag
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/eff7e2c8-ab7a-4967-95b5-e65631245701

Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
2026-04-02 07:14:36 +00:00
copilot-swe-agent[bot]
6b86e7db5d Extend glfwGetKeyboardRepeatDelay() to return both initial delay and repeat interval
Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/bde9bf2e-a0dd-4ccd-8385-6a37be1e025f
2026-03-23 11:58:48 +00:00
copilot-swe-agent[bot]
998ee22ecb Add glfwGetKeyboardRepeatDelay() to the GLFW API for X11, Wayland and Cocoa
Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/4765810b-ecf5-4348-ae3a-ff0ff481aaae
2026-03-23 11:46:35 +00:00
copilot-swe-agent[bot]
877be65447
Fix crashes when moving tab between OS windows (issue #9677)
Wayland (glfw/wl_window.c):
- Fix out-of-bounds access in send_drag_data: look up item by MIME type
  instead of using the data-request index i to index _glfw.drag.items[].
  The compositor calls drag_source_send once per target window entered,
  so _glfw.wl.drag.count grows independently of item_count, causing
  _glfw.drag.items[i] to be out-of-bounds on the second drag, yielding a
  garbage optional_data pointer that made write() fail with EFAULT.
- Fix protocol error "Drag has not ended": change on_fail and the
  GLFW_DRAG_DATA_REQUEST error path to call finish_drag_write(i)+return
  instead of cancel_drag(), which was calling wl_data_source_destroy()
  before the compositor ended the drag, violating the Wayland protocol.
- Fix double-free of dr.pending_data: null the pointer after free and
  add cleanup to finish_drag_write().
- Fix missing finish_drag_write() after a full write in data-request
  mode, which left the pipe open causing the target to wait for EOF.

X11 (glfw/x11_window.c):
- Wrap XSendEvent() calls in send_xdnd_enter/position/leave/drop with
  _glfwGrabErrorHandlerX11()/_glfwReleaseErrorHandlerX11(). A target
  window destroyed between discovery and message delivery produced a
  BadWindow error that hit the default X11 abort handler. Now handled
  gracefully by clearing current_target or cancelling the drag."

Fixes #9677
Fixes #9683
2026-03-17 08:53:17 +05:30
Kovid Goyal
ddfd8d7f45
Wayland: Dont set window icons on layer shell windows as some compositors complain about them 2026-03-16 08:28:36 +05:30
Kovid Goyal
e72f49952d
Linux: Fix regression that broke drag and drop from GTK applications
Fixes #9656
2026-03-13 20:19:33 +05:30
copilot-swe-agent[bot]
4706243380
Fix GLFW drop API to always present full original MIME type list to callbacks
Fixes #9633
2026-03-10 20:10:44 +05:30
Kovid Goyal
5cc510dea4
Merge branch 'titlebar-only-wayland' of https://github.com/antoinecellerier/kitty 2026-02-23 19:19:30 +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
Kovid Goyal
b737eaad65
Cleanup previous PR
Use a single wl_surface for the drag icon. Whther it is attached to the
top level drag or not is determined based on availability.
2026-02-22 15:36:10 +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
Kovid Goyal
531fb3e1b1
Change drag thumbnail when in detach/move modes 2026-02-22 13:09:56 +05:30
Kovid Goyal
449abb69bc
Cleanup previous PR 2026-02-22 11:13:57 +05:30
copilot-swe-agent[bot]
0c0c5a62f7
Implement changing drag image in the various backends
Fixes #9542
2026-02-22 09:26:14 +05:30
Kovid Goyal
6506ce1e91
API to change image for drag in progress 2026-02-22 09:10:26 +05:30
Kovid Goyal
8ad22e7859
On Wayland detach even on drag cancel
Wayland compositors contravene their own spec and make it impossible to
distinguish between drop-but-not-accept and drag-cancel cases.
https://gitlab.freedesktop.org/wayland/wayland/-/issues/140
2026-02-22 08:19:31 +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
96c01b74d8
Detach tab via drag and drop now implemented 2026-02-21 15:15:33 +05:30
Kovid Goyal
a2b7a0cd6d
Port Cocoa drag source backend to new API 2026-02-18 11:20:17 +05:30
Kovid Goyal
e5eb63fcd0
Refactor drag source API to be async
Wayland implementation done. Other two backends remain.
2026-02-17 13:07:55 +05:30
Kovid Goyal
a99103d9a1
Drop events should use same co-ordinate system as mouse events 2026-02-13 10:08:25 +05:30
Antoine Cellerier
ef4574ae97 Support hide_window_decorations titlebar-only on Wayland
Hide the CSD titlebar subsurface while keeping shadow borders for
resizing. On SSD compositors (GNOME), forces CSD mode to draw
kitty's own shadows without a titlebar.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-02-08 19:49:44 +01:00
Kovid Goyal
08217c949d
Fix crash on self drop 2026-02-08 22:05:15 +05:30
Kovid Goyal
af4f3969b7
remove watch after all data is received on pipe 2026-02-08 22:05:14 +05:30
Kovid Goyal
5db41c7ba4
Remove remaining code for the old drop API
X11 and cocoa need to be ported to the new API
2026-02-08 22:05:14 +05:30
Kovid Goyal
f3cda7e828
Have mimes_count be always accurate 2026-02-08 22:05:14 +05:30
Kovid Goyal
3cf24afdc0
Refactor drop API and implement it on Wayland 2026-02-08 22:05:14 +05:30
copilot-swe-agent[bot]
7ca6fd66f8
Fix self drag not working under Wayland
Fixes #9483
2026-02-07 15:10:54 +05:30
Kovid Goyal
07a9f2bcaa
API to start a drag 2026-02-07 13:50:16 +05:30
copilot-swe-agent[bot]
5ea35cbbfc
Refactor drag API to make it asynchronous
Fixes #9477
2026-02-07 08:59:34 +05:30
Kovid Goyal
d51dec8187
When dropping, paste into window under mouse cursor rather than active window 2026-02-04 21:21:25 +05:30
Kovid Goyal
9a2ddc887b
Cleanup new chunked drop code and use it in kitty
Currently the chunking is useful but it will become useful for a future
drag and drop TUI protocol
2026-02-04 20:34:10 +05:30
copilot-swe-agent[bot]
ed5eb8f45c
Allow reading dropped data in chunks
Fixes #9470
2026-02-04 14:18:28 +05:30
copilot-swe-agent[bot]
fac4420804
Simplify new drag/drop API
Fixes #9466
2026-02-03 22:02:51 +05:30
copilot-swe-agent[bot]
9b35c1b535
Allow changing drag acceptance asynchronously
Fixes #9465
2026-02-03 14:43:44 +05:30
copilot-swe-agent[bot]
6744183027
Accept drags based on mime types in drag event callback
Fixes #9456
2026-02-02 21:30:25 +05:30
copilot-swe-agent[bot]
fa6c76d3e3
Add a GLFW API to support starting drag operations
Fixes #9454
Fixes #9455
2026-02-02 20:49:00 +05:30