Text input: don't send leave for destroyed client surfaces
CI / test (push) Failing after 49s

- Drop text-input and keyboard focus references when a client destroys a wl_surface, without sending leave for it
- Skip wl_keyboard.leave and zwp_text_input_v3.leave/enter for surfaces the client no longer has
- Skip pointer enter/leave for missing subsurfaces or toplevels
- Add a regression test: closing a second toplevel (e.g. OAuth popup) must return focus to the main window without leaving stale events
This commit is contained in:
nandi committed 2026-11-28 23:33:17 -08:00
1 parent 444d67ac79
commit aa92aaac6f
3 files changed
+128 -16

No files matched your search

+28 -12
View File
@@ -737,6 +737,10 @@ fn WaylandServer::dispatch_msg(
}
}
self.dnd_icon_gone(c, sid, events)
text_inputs_surface_gone(c, sid)
if self.kbd_surface == Some((c.client_id, sid)) {
self.kbd_surface = None
}
c.surfaces.remove(sid)
c.objects.remove(sid)
send_delete_id(c, sid)
@@ -1974,16 +1978,21 @@ fn fixed(v : Double) -> Int {
pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : Double, y : Double, sub? : UInt = 0U) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, tl)) =>
Some((c, tl)) => {
let target = if sub != 0U && c.surfaces.contains(sub) { sub } else { tl.wl_surface_id }
if !c.surfaces.contains(target) {
return
}
for pid in c.pointer_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(if sub != 0U && c.surfaces.contains(sub) { sub } else { tl.wl_surface_id })
w.u32(target)
w.i32(fixed(x))
w.i32(fixed(y))
c.send_msg(w.finish_msg(pid, 0U))
self.pointer_frame(c, pid)
}
}
}
}
@@ -1991,17 +2000,19 @@ pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : D
pub fn WaylandServer::pointer_leave(self : WaylandServer, win_id : UInt64, sub? : UInt = 0U) -> Unit {
match self.win_client(win_id) {
None => ()
Some((c, tl)) =>
Some((c, tl)) => {
let target = if sub != 0U { sub } else { tl.wl_surface_id }
if !c.surfaces.contains(target) {
return
}
for pid in c.pointer_ids {
if sub != 0U && !c.surfaces.contains(sub) {
continue // the subsurface is gone: nothing to leave
}
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(if sub != 0U { sub } else { tl.wl_surface_id })
w.u32(target)
c.send_msg(w.finish_msg(pid, 1U))
self.pointer_frame(c, pid)
}
}
}
}
@@ -2089,6 +2100,9 @@ pub fn WaylandServer::keyboard_enter(self : WaylandServer, win_id : UInt64) -> U
match self.win_client(win_id) {
None => ()
Some((c, tl)) => {
if !c.surfaces.contains(tl.wl_surface_id) {
return
}
self.kbd_client = Some(c.client_id)
self.kbd_surface = Some((c.client_id, tl.wl_surface_id))
self.send_selection(c)
@@ -2110,11 +2124,13 @@ pub fn WaylandServer::keyboard_leave(self : WaylandServer, win_id : UInt64) -> U
match self.win_client(win_id) {
None => ()
Some((c, tl)) => {
for kid in c.keyboard_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(tl.wl_surface_id)
c.send_msg(w.finish_msg(kid, 2U))
if c.surfaces.contains(tl.wl_surface_id) {
for kid in c.keyboard_ids {
let w = WireWriter::new()
w.u32(self.next_serial())
w.u32(tl.wl_surface_id)
c.send_msg(w.finish_msg(kid, 2U))
}
}
text_inputs_leave(c, tl.wl_surface_id)
if self.kbd_surface == Some((c.client_id, tl.wl_surface_id)) {
+28 -4
View File
@@ -113,11 +113,21 @@ fn send_text_input_surface(c : ClientConn, id : UInt, opcode : UInt, surface : U
fn text_inputs_enter(c : ClientConn, surface : UInt) -> Unit {
for id, ti in c.text_inputs {
if ti.surface != 0U && ti.surface != surface {
send_text_input_surface(c, id, 1U, ti.surface)
if c.surfaces.contains(ti.surface) {
send_text_input_surface(c, id, 1U, ti.surface)
}
ti.enabled = false
ti.cursor = None
}
if ti.surface != surface {
ti.surface = surface
send_text_input_surface(c, id, 0U, surface)
if c.surfaces.contains(surface) {
ti.surface = surface
send_text_input_surface(c, id, 0U, surface)
} else {
ti.surface = 0U
ti.enabled = false
ti.cursor = None
}
}
}
}
@@ -129,7 +139,21 @@ fn text_inputs_leave(c : ClientConn, surface : UInt) -> Unit {
ti.surface = 0U
// The client disables it in answer; until it commits that, it can't take text anyway.
ti.enabled = false
send_text_input_surface(c, id, 1U, surface)
ti.cursor = None
if c.surfaces.contains(surface) {
send_text_input_surface(c, id, 1U, surface)
}
}
}
}
///| A wl_surface was destroyed by the client: drop text-input references without sending `leave`.
fn text_inputs_surface_gone(c : ClientConn, surface : UInt) -> Unit {
for _, ti in c.text_inputs {
if ti.surface == surface {
ti.surface = 0U
ti.enabled = false
ti.cursor = None
}
}
}