Wayland: a touch makes its window Device::focusedWindow and nothing puts the pointer's window back, so the mouse's events go to the touched window #194

Open
opened 2026-11-17 06:45:38 +00:00 by jorijnvdgraaf · 0 comments

Summary

For the first finger, touch_down makes the touched window Device::focusedWindow, and nothing puts the previous one back when the finger lifts. wl_pointer's motion, button and axis events carry no surface and go to focusedWindow. So with two windows, a touch on one while the pointer is over the other sends the mouse's events to the touched window, in the other window's coordinates. Line numbers refer to c006519.

Details

  • implementations/Crafter.Graphics-Device.cpp:737: focusedWindow = window in touch_down. touch_up (:749-768) and touch_cancel (:792-803) leave it as it is.
  • pointer_handle_button (:484-508), PointerListenerHandleMotion (:510-517) and PointerListenerHandleAxis (:549-563) all act on focusedWindow.
  • Only PointerListenerHandleEnter (:528) and PointerListenerHandleLeave (:545) set it otherwise.
  • Why the touch sets it: the comment at :715-718, "so the clipboard has a serial and Device::focusedWindow a window". The clipboard takes its serial from Device::focusedWindow->lastPointerSerial_ (implementations/Crafter.Graphics-Clipboard.cpp:238-239).

Concrete case

The pointer is over window A, so focusedWindow is A. A finger taps window B: focusedWindow is B, and stays B after the up. The mouse moves within A. wl_pointer.motion is relative to A's surface, and B gets PointerMove with those coordinates, then the clicks and the wheel. It lasts until the pointer leaves A, when B gets the PointerLeave call and focusedWindow becomes null, and enters a surface again.

With one window there is little to see: after a touch the window is focusedWindow without mouseInside, which is what the comment intends.

Found by reading the code, in the pre-push review of 364d210..c006519. It is older than that range. Not reproduced. Whether a compositor sends the pointer a new enter after a touch elsewhere, which would repair it, was not checked.

Suggested fix

Keep the pointer's window and the touch's apart. Either let the stand-in events use the touch's own window without writing focusedWindow, and give the clipboard another way to the touched window's serial (touchWindow, or the window the last serial came from); or remember the pointer's window in touch_down and put it back when the primary finger lifts or is cancelled.

## Summary For the first finger, `touch_down` makes the touched window `Device::focusedWindow`, and nothing puts the previous one back when the finger lifts. `wl_pointer`'s motion, button and axis events carry no surface and go to `focusedWindow`. So with two windows, a touch on one while the pointer is over the other sends the mouse's events to the touched window, in the other window's coordinates. Line numbers refer to `c006519`. ## Details - `implementations/Crafter.Graphics-Device.cpp:737`: `focusedWindow = window` in `touch_down`. `touch_up` (`:749-768`) and `touch_cancel` (`:792-803`) leave it as it is. - `pointer_handle_button` (`:484-508`), `PointerListenerHandleMotion` (`:510-517`) and `PointerListenerHandleAxis` (`:549-563`) all act on `focusedWindow`. - Only `PointerListenerHandleEnter` (`:528`) and `PointerListenerHandleLeave` (`:545`) set it otherwise. - Why the touch sets it: the comment at `:715-718`, "so the clipboard has a serial and Device::focusedWindow a window". The clipboard takes its serial from `Device::focusedWindow->lastPointerSerial_` (`implementations/Crafter.Graphics-Clipboard.cpp:238-239`). ## Concrete case The pointer is over window A, so `focusedWindow` is A. A finger taps window B: `focusedWindow` is B, and stays B after the up. The mouse moves within A. `wl_pointer.motion` is relative to A's surface, and B gets `PointerMove` with those coordinates, then the clicks and the wheel. It lasts until the pointer leaves A, when B gets the `PointerLeave` call and `focusedWindow` becomes null, and enters a surface again. With one window there is little to see: after a touch the window is `focusedWindow` without `mouseInside`, which is what the comment intends. Found by reading the code, in the pre-push review of 364d210..c006519. It is older than that range. Not reproduced. Whether a compositor sends the pointer a new enter after a touch elsewhere, which would repair it, was not checked. ## Suggested fix Keep the pointer's window and the touch's apart. Either let the stand-in events use the touch's own window without writing `focusedWindow`, and give the clipboard another way to the touched window's serial (`touchWindow`, or the window the last serial came from); or remember the pointer's window in `touch_down` and put it back when the primary finger lifts or is cancelled.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Graphics#194
No description provided.