Chrome's context menu opened and closed at once: when a client created an xdg_popup the compositor moved keyboard focus to it straight away, and the wl_keyboard.leave on the window made Chrome dismiss the menu. Popups now only take the keyboard when they ask for a grab (xdg_popup.grab, as Qt menus do) and once they have a buffer; Chrome's grab-less menus leave focus on the window. Also: - honour xdg_positioner constraint adjustment (flip, slide, resize) so the configure tells the client where its menu really is, instead of the host silently nudging it on screen (Chrome then took the button release as a click on a menu item); - answer xdg_popup.reposition with repositioned + configure (it was ignored, so clients waiting for it stalled); - place popups by their window geometry, so Chrome's client-drawn menu shadow no longer shifts the menu right and down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hikqzveCoytgF4Uyvh
This commit is contained in:
3 files changed
+563
-20
No files matched your search
@@ -19,11 +19,17 @@ pub(all) struct HostPopup {
|
||||
id : UInt64
|
||||
parent : UInt64
|
||||
/// Position relative to the parent's content origin.
|
||||
rx : Int
|
||||
ry : Int
|
||||
w : Int
|
||||
h : Int
|
||||
mut rx : Int
|
||||
mut ry : Int
|
||||
mut w : Int
|
||||
mut h : Int
|
||||
mut surface : @scene.ShmBufferSnapshot?
|
||||
/// The client asked for an explicit grab (xdg_popup.grab): it takes keyboard focus once mapped.
|
||||
mut grab : Bool
|
||||
/// Window-geometry origin inside the buffer (client-drawn shadow); the buffer is drawn
|
||||
/// this much up/left so the visible menu lands where the positioner put it.
|
||||
mut geo_x : Int
|
||||
mut geo_y : Int
|
||||
}
|
||||
|
||||
///|
|
||||
@@ -111,7 +117,7 @@ pub fn ChandraCompositor::new(
|
||||
let work_area = work_area_for(output_w, output_h, theme)
|
||||
let shell = @shell.DesktopShell::new(socket_path)
|
||||
shell.set_output(theme, output_w, output_h)
|
||||
Some({
|
||||
let comp : ChandraCompositor = {
|
||||
server,
|
||||
wm,
|
||||
theme,
|
||||
@@ -154,7 +160,14 @@ pub fn ChandraCompositor::new(
|
||||
session_seen: "",
|
||||
session_seen_at: 0UL,
|
||||
session_check_at: 0UL,
|
||||
})
|
||||
}
|
||||
// Client popups (menus) are placed to stay on screen: the server asks for the output's
|
||||
// rectangle relative to the parent's content origin when it applies constraint adjustment.
|
||||
server.popup_bounds = fn(parent) {
|
||||
let (ox, oy) = comp.origin_of(parent)
|
||||
(-ox, -oy, comp.output_w, comp.output_h)
|
||||
}
|
||||
Some(comp)
|
||||
}
|
||||
|
||||
///| The part of a `w` x `h` output windows are laid out in.
|
||||
@@ -364,16 +377,48 @@ pub fn ChandraCompositor::step(self : ChandraCompositor) -> Unit {
|
||||
None => ()
|
||||
}
|
||||
@wayland.CompositorEvent::PopupOpened(wid, parent, rx, ry, w, h) => {
|
||||
self.popups.push({ id: wid, parent, rx, ry, w, h, surface: None })
|
||||
self.set_kbd_focus(Some(wid))
|
||||
// Keyboard focus stays on the parent until the popup grabs and maps: moving it away
|
||||
// early makes clients (Chrome, Qt) take the keyboard leave as "dismiss the menu".
|
||||
self.popups.push({ id: wid, parent, rx, ry, w, h, surface: None, grab: false, geo_x: 0, geo_y: 0 })
|
||||
}
|
||||
@wayland.CompositorEvent::PopupGeometry(wid, gx, gy) =>
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
p.geo_x = gx
|
||||
p.geo_y = gy
|
||||
self.damage.mark_full()
|
||||
}
|
||||
}
|
||||
@wayland.CompositorEvent::PopupMoved(wid, rx, ry, w, h) =>
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
p.rx = rx
|
||||
p.ry = ry
|
||||
p.w = w
|
||||
p.h = h
|
||||
self.damage.mark_full()
|
||||
}
|
||||
}
|
||||
@wayland.CompositorEvent::PopupGrabbed(wid) =>
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
p.grab = true
|
||||
if p.surface is Some(_) {
|
||||
self.set_kbd_focus(Some(wid))
|
||||
}
|
||||
}
|
||||
}
|
||||
@wayland.CompositorEvent::PopupCommitted(wid, snap) =>
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
match snap {
|
||||
Some(_) => {
|
||||
let first_map = p.surface is None
|
||||
release_snapshot(p.surface)
|
||||
p.surface = snap
|
||||
if first_map && p.grab {
|
||||
self.set_kbd_focus(Some(wid))
|
||||
}
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
@@ -655,7 +700,8 @@ pub fn ChandraCompositor::handle_gfx_events(
|
||||
}
|
||||
|
||||
|
||||
///| Content origin of a window or popup.
|
||||
///| Content origin of a window or popup (a popup's window geometry, which child popups'
|
||||
/// positioners are relative to).
|
||||
fn ChandraCompositor::origin_of(self : ChandraCompositor, wid : UInt64) -> (Int, Int) {
|
||||
match self.windows.get(wid) {
|
||||
Some(win) => (win.geometry.x, win.geometry.y)
|
||||
@@ -663,7 +709,7 @@ fn ChandraCompositor::origin_of(self : ChandraCompositor, wid : UInt64) -> (Int,
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
let r = self.popup_rect(p)
|
||||
return (r.x, r.y)
|
||||
return (r.x + p.geo_x, r.y + p.geo_y)
|
||||
}
|
||||
}
|
||||
(0, 0)
|
||||
@@ -671,18 +717,23 @@ fn ChandraCompositor::origin_of(self : ChandraCompositor, wid : UInt64) -> (Int,
|
||||
}
|
||||
}
|
||||
|
||||
///| Absolute rectangle of a popup, nudged to stay on screen.
|
||||
///| Absolute rectangle of a popup's buffer. Its visible part (the window geometry the
|
||||
/// positioner placed, `p.w` x `p.h`) is nudged to stay on screen as a safety net; the server
|
||||
/// already keeps adjustable popups inside the output, and then no nudge is needed, so the
|
||||
/// client's idea of where its menu is matches what is drawn.
|
||||
fn ChandraCompositor::popup_rect(self : ChandraCompositor, p : HostPopup) -> @scene.Rect {
|
||||
let (w, h) = match p.surface {
|
||||
Some(s) => (s.width, s.height)
|
||||
None => (p.w, p.h)
|
||||
}
|
||||
let (bx, by) = self.origin_of_parent(p)
|
||||
let x = bx + p.rx
|
||||
let y = by + p.ry
|
||||
let x = if x + w > self.output_w { self.output_w - w } else { x }
|
||||
let y = if y + h > self.output_h { self.output_h - h } else { y }
|
||||
@scene.Rect::new(if x < 0 { 0 } else { x }, if y < 0 { 0 } else { y }, w, h)
|
||||
let vx = bx + p.rx
|
||||
let vy = by + p.ry
|
||||
let vx = if vx + p.w > self.output_w { self.output_w - p.w } else { vx }
|
||||
let vy = if vy + p.h > self.output_h { self.output_h - p.h } else { vy }
|
||||
let vx = if vx < 0 { 0 } else { vx }
|
||||
let vy = if vy < 0 { 0 } else { vy }
|
||||
@scene.Rect::new(vx - p.geo_x, vy - p.geo_y, w, h)
|
||||
}
|
||||
|
||||
///|
|
||||
|
||||
Reference in new issue
Block a user