- 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:
1 parent
444d67ac79
commit
aa92aaac6f
3 files changed
+119
-7
No files matched your search
@@ -0,0 +1,72 @@
|
|||||||
|
///| Destroying a client's second wl_surface (e.g. an OAuth popup closing) must not send
|
||||||
|
///| zwp_text_input_v3.leave or wl_keyboard.leave referencing the destroyed surface when focus
|
||||||
|
///| returns to the client's remaining window.
|
||||||
|
|
||||||
|
///|
|
||||||
|
test "destroying a second toplevel surface on the same client never sends leave for the gone surface" {
|
||||||
|
let socket_path = "/tmp/wayland-moon-ti-destroy-" + @sys.getpid().to_string() + ".sock"
|
||||||
|
let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap()
|
||||||
|
let (a, shm_a, surf_a, xdg_a, _, _) = open_and_configure_client(comp, socket_path, "Main", "main")
|
||||||
|
commit_shm_frame(comp, a, shm_a, surf_a, xdg_a, 1UL)
|
||||||
|
assert_eq(comp.kbd_win, Some(1UL))
|
||||||
|
let (ti, kbd) = text_input_for(comp, a)
|
||||||
|
ignore(drain_args(a))
|
||||||
|
|
||||||
|
// Open a second toplevel on the same client (simulating an OAuth popup).
|
||||||
|
let comp_b = bind_global(a, 2U, "wl_compositor", 5U)
|
||||||
|
let xdg_wm_b = bind_global(a, 2U, "xdg_wm_base", 5U)
|
||||||
|
let surf_b = a.alloc_id()
|
||||||
|
let w_cs = @wayland.WireWriter::new()
|
||||||
|
w_cs.u32(surf_b)
|
||||||
|
a.send(w_cs.finish_msg(comp_b, 0U))
|
||||||
|
let xdg_b = a.alloc_id()
|
||||||
|
let w_xs = @wayland.WireWriter::new()
|
||||||
|
w_xs.u32(xdg_b)
|
||||||
|
w_xs.u32(surf_b)
|
||||||
|
a.send(w_xs.finish_msg(xdg_wm_b, 2U))
|
||||||
|
let tl_b = a.alloc_id()
|
||||||
|
let w_tl = @wayland.WireWriter::new()
|
||||||
|
w_tl.u32(tl_b)
|
||||||
|
a.send(w_tl.finish_msg(xdg_b, 1U))
|
||||||
|
let w_t = @wayland.WireWriter::new()
|
||||||
|
w_t.str("Popup")
|
||||||
|
a.send(w_t.finish_msg(tl_b, 2U))
|
||||||
|
let w_a = @wayland.WireWriter::new()
|
||||||
|
w_a.str("popup")
|
||||||
|
a.send(w_a.finish_msg(tl_b, 3U))
|
||||||
|
a.configure_serial = None
|
||||||
|
a.configured_w = 0
|
||||||
|
a.configured_h = 0
|
||||||
|
a.send(@wayland.WireWriter::new().finish_msg(surf_b, 6U))
|
||||||
|
for _i = 0; _i < 20; _i = _i + 1 {
|
||||||
|
comp.step()
|
||||||
|
a.read_events(xdg_b, tl_b, 0U)
|
||||||
|
if a.configure_serial is Some(_) && a.configured_w > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
@sys.sleep_ms(2)
|
||||||
|
}
|
||||||
|
commit_shm_frame(comp, a, shm_a, surf_b, xdg_b, 2UL)
|
||||||
|
assert_eq(comp.kbd_win, Some(2UL))
|
||||||
|
text_input_state(comp, a, ti, true, 10, 10, 16)
|
||||||
|
ignore(drain_args(a))
|
||||||
|
|
||||||
|
// Destroy the popup toplevel + xdg_surface + wl_surface together, as Electron/Ozone does on close.
|
||||||
|
a.send(@wayland.WireWriter::new().finish_msg(tl_b, 0U))
|
||||||
|
a.send(@wayland.WireWriter::new().finish_msg(xdg_b, 0U))
|
||||||
|
a.send(@wayland.WireWriter::new().finish_msg(surf_b, 0U))
|
||||||
|
for _i = 0; _i < 5; _i = _i + 1 {
|
||||||
|
comp.step()
|
||||||
|
@sys.sleep_ms(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq(comp.kbd_win, Some(1UL))
|
||||||
|
let msgs = drain_args(a)
|
||||||
|
let ti_leaves_gone = msgs.filter(m => m.0 == ti && m.1 == 1U && m.2.length() > 0 && m.2[0] == surf_b)
|
||||||
|
let kbd_leaves_gone = msgs.filter(m => m.0 == kbd && m.1 == 2U && m.2.length() > 1 && m.2[1] == surf_b)
|
||||||
|
let ti_enters_main = msgs.filter(m => m.0 == ti && m.1 == 0U && m.2.length() > 0 && m.2[0] == surf_a)
|
||||||
|
assert_eq(ti_leaves_gone.length(), 0)
|
||||||
|
assert_eq(kbd_leaves_gone.length(), 0)
|
||||||
|
assert_true(ti_enters_main.length() >= 1)
|
||||||
|
comp.close()
|
||||||
|
}
|
||||||
@@ -737,6 +737,10 @@ fn WaylandServer::dispatch_msg(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.dnd_icon_gone(c, sid, events)
|
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.surfaces.remove(sid)
|
||||||
c.objects.remove(sid)
|
c.objects.remove(sid)
|
||||||
send_delete_id(c, sid)
|
send_delete_id(c, sid)
|
||||||
@@ -1974,35 +1978,42 @@ fn fixed(v : Double) -> Int {
|
|||||||
pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : Double, y : Double, sub? : UInt = 0U) -> Unit {
|
pub fn WaylandServer::pointer_enter(self : WaylandServer, win_id : UInt64, x : Double, y : Double, sub? : UInt = 0U) -> Unit {
|
||||||
match self.win_client(win_id) {
|
match self.win_client(win_id) {
|
||||||
None => ()
|
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 {
|
for pid in c.pointer_ids {
|
||||||
let w = WireWriter::new()
|
let w = WireWriter::new()
|
||||||
w.u32(self.next_serial())
|
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(x))
|
||||||
w.i32(fixed(y))
|
w.i32(fixed(y))
|
||||||
c.send_msg(w.finish_msg(pid, 0U))
|
c.send_msg(w.finish_msg(pid, 0U))
|
||||||
self.pointer_frame(c, pid)
|
self.pointer_frame(c, pid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///|
|
///|
|
||||||
pub fn WaylandServer::pointer_leave(self : WaylandServer, win_id : UInt64, sub? : UInt = 0U) -> Unit {
|
pub fn WaylandServer::pointer_leave(self : WaylandServer, win_id : UInt64, sub? : UInt = 0U) -> Unit {
|
||||||
match self.win_client(win_id) {
|
match self.win_client(win_id) {
|
||||||
None => ()
|
None => ()
|
||||||
Some((c, tl)) =>
|
Some((c, tl)) => {
|
||||||
for pid in c.pointer_ids {
|
let target = if sub != 0U { sub } else { tl.wl_surface_id }
|
||||||
if sub != 0U && !c.surfaces.contains(sub) {
|
if !c.surfaces.contains(target) {
|
||||||
continue // the subsurface is gone: nothing to leave
|
return
|
||||||
}
|
}
|
||||||
|
for pid in c.pointer_ids {
|
||||||
let w = WireWriter::new()
|
let w = WireWriter::new()
|
||||||
w.u32(self.next_serial())
|
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))
|
c.send_msg(w.finish_msg(pid, 1U))
|
||||||
self.pointer_frame(c, pid)
|
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) {
|
match self.win_client(win_id) {
|
||||||
None => ()
|
None => ()
|
||||||
Some((c, tl)) => {
|
Some((c, tl)) => {
|
||||||
|
if !c.surfaces.contains(tl.wl_surface_id) {
|
||||||
|
return
|
||||||
|
}
|
||||||
self.kbd_client = Some(c.client_id)
|
self.kbd_client = Some(c.client_id)
|
||||||
self.kbd_surface = Some((c.client_id, tl.wl_surface_id))
|
self.kbd_surface = Some((c.client_id, tl.wl_surface_id))
|
||||||
self.send_selection(c)
|
self.send_selection(c)
|
||||||
@@ -2110,12 +2124,14 @@ pub fn WaylandServer::keyboard_leave(self : WaylandServer, win_id : UInt64) -> U
|
|||||||
match self.win_client(win_id) {
|
match self.win_client(win_id) {
|
||||||
None => ()
|
None => ()
|
||||||
Some((c, tl)) => {
|
Some((c, tl)) => {
|
||||||
|
if c.surfaces.contains(tl.wl_surface_id) {
|
||||||
for kid in c.keyboard_ids {
|
for kid in c.keyboard_ids {
|
||||||
let w = WireWriter::new()
|
let w = WireWriter::new()
|
||||||
w.u32(self.next_serial())
|
w.u32(self.next_serial())
|
||||||
w.u32(tl.wl_surface_id)
|
w.u32(tl.wl_surface_id)
|
||||||
c.send_msg(w.finish_msg(kid, 2U))
|
c.send_msg(w.finish_msg(kid, 2U))
|
||||||
}
|
}
|
||||||
|
}
|
||||||
text_inputs_leave(c, tl.wl_surface_id)
|
text_inputs_leave(c, tl.wl_surface_id)
|
||||||
if self.kbd_surface == Some((c.client_id, tl.wl_surface_id)) {
|
if self.kbd_surface == Some((c.client_id, tl.wl_surface_id)) {
|
||||||
self.kbd_surface = None
|
self.kbd_surface = None
|
||||||
|
|||||||
@@ -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 {
|
fn text_inputs_enter(c : ClientConn, surface : UInt) -> Unit {
|
||||||
for id, ti in c.text_inputs {
|
for id, ti in c.text_inputs {
|
||||||
if ti.surface != 0U && ti.surface != surface {
|
if ti.surface != 0U && ti.surface != surface {
|
||||||
|
if c.surfaces.contains(ti.surface) {
|
||||||
send_text_input_surface(c, id, 1U, ti.surface)
|
send_text_input_surface(c, id, 1U, ti.surface)
|
||||||
}
|
}
|
||||||
|
ti.enabled = false
|
||||||
|
ti.cursor = None
|
||||||
|
}
|
||||||
if ti.surface != surface {
|
if ti.surface != surface {
|
||||||
|
if c.surfaces.contains(surface) {
|
||||||
ti.surface = surface
|
ti.surface = surface
|
||||||
send_text_input_surface(c, id, 0U, surface)
|
send_text_input_surface(c, id, 0U, surface)
|
||||||
|
} else {
|
||||||
|
ti.surface = 0U
|
||||||
|
ti.enabled = false
|
||||||
|
ti.cursor = None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,9 +139,23 @@ fn text_inputs_leave(c : ClientConn, surface : UInt) -> Unit {
|
|||||||
ti.surface = 0U
|
ti.surface = 0U
|
||||||
// The client disables it in answer; until it commits that, it can't take text anyway.
|
// The client disables it in answer; until it commits that, it can't take text anyway.
|
||||||
ti.enabled = false
|
ti.enabled = false
|
||||||
|
ti.cursor = None
|
||||||
|
if c.surfaces.contains(surface) {
|
||||||
send_text_input_surface(c, id, 1U, 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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///| The enabled text inputs on window `win_id`'s surface: (client, ids).
|
///| The enabled text inputs on window `win_id`'s surface: (client, ids).
|
||||||
|
|||||||
Reference in new issue
Block a user