xdg_popup support: right-click menus in client apps (Konsole etc.)
CI / test (push) Failing after 37s
CI / test (push) Failing after 37s
- server: xdg_positioner state, get_popup placement + configure, popup commits, popup_done; popups share the toplevel table so pointer/keyboard routing is reused - compositor: popups drawn above windows and panel, input goes to the popup under the pointer, keyboard focus follows the popup, a click outside dismisses them - test: a client opens a popup, clicks inside it, and is told to dismiss it Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3b2e19ace5
commit
bc1e3dfdbd
5 files changed
+491
-5
No files matched your search
@@ -14,8 +14,22 @@ pub(all) struct HostWindow {
|
||||
mut cfg_dirty : Bool
|
||||
}
|
||||
|
||||
///| A client popup (xdg_popup): menus, combo lists, tooltips.
|
||||
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 surface : @scene.ShmBufferSnapshot?
|
||||
}
|
||||
|
||||
///|
|
||||
pub(all) struct MoonPlasmaCompositor {
|
||||
/// Open popups, oldest first (the last is topmost).
|
||||
popups : Array[HostPopup]
|
||||
server : @wayland.WaylandServer
|
||||
wm : @wm.WmState
|
||||
theme : @scene.ThemeTokens
|
||||
@@ -77,6 +91,7 @@ pub fn MoonPlasmaCompositor::new(
|
||||
shell,
|
||||
ptr_x: 0.0,
|
||||
ptr_y: 0.0,
|
||||
popups: [],
|
||||
ptr_win: None,
|
||||
split_drag: None,
|
||||
press_fwd: false,
|
||||
@@ -230,7 +245,23 @@ pub fn MoonPlasmaCompositor::step(self : MoonPlasmaCompositor) -> 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))
|
||||
}
|
||||
@wayland.CompositorEvent::PopupCommitted(wid, snap) =>
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
match snap {
|
||||
Some(_) => p.surface = snap
|
||||
None => ()
|
||||
}
|
||||
self.damage.mark_full()
|
||||
}
|
||||
}
|
||||
@wayland.CompositorEvent::PopupClosed(wid) => self.close_popup(wid)
|
||||
@wayland.CompositorEvent::ToplevelClosed(wid) => {
|
||||
self.close_popup(wid)
|
||||
ignore(self.windows.remove(wid))
|
||||
if self.ptr_win == Some(wid) {
|
||||
self.ptr_win = None
|
||||
@@ -316,6 +347,13 @@ pub fn MoonPlasmaCompositor::compose_frame(
|
||||
}
|
||||
}
|
||||
|
||||
for p in self.popups {
|
||||
match p.surface {
|
||||
Some(snap) => scene.popups.push((self.popup_rect(p), snap))
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
|
||||
self.shell.layout_sel = match self.layout_mode {
|
||||
@wm.LayoutMode::Tiling => 0
|
||||
@wm.LayoutMode::Monocle => 1
|
||||
@@ -414,6 +452,127 @@ pub fn MoonPlasmaCompositor::handle_gfx_events(
|
||||
}
|
||||
|
||||
|
||||
///| Content origin of a window or popup.
|
||||
fn MoonPlasmaCompositor::origin_of(self : MoonPlasmaCompositor, wid : UInt64) -> (Int, Int) {
|
||||
match self.windows.get(wid) {
|
||||
Some(win) => (win.geometry.x, win.geometry.y)
|
||||
None => {
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
let r = self.popup_rect(p)
|
||||
return (r.x, r.y)
|
||||
}
|
||||
}
|
||||
(0, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Absolute rectangle of a popup, nudged to stay on screen.
|
||||
fn MoonPlasmaCompositor::popup_rect(self : MoonPlasmaCompositor, 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)
|
||||
}
|
||||
|
||||
///|
|
||||
fn MoonPlasmaCompositor::origin_of_parent(self : MoonPlasmaCompositor, p : HostPopup) -> (Int, Int) {
|
||||
if p.parent == p.id {
|
||||
(0, 0)
|
||||
} else {
|
||||
self.origin_of(p.parent)
|
||||
}
|
||||
}
|
||||
|
||||
///| Top-most popup under (x, y).
|
||||
fn MoonPlasmaCompositor::popup_at(self : MoonPlasmaCompositor, x : Int, y : Int) -> HostPopup? {
|
||||
let mut i = self.popups.length() - 1
|
||||
while i >= 0 {
|
||||
let p = self.popups[i]
|
||||
let r = self.popup_rect(p)
|
||||
if p.surface is Some(_) && x >= r.x && x < r.x + r.w && y >= r.y && y < r.y + r.h {
|
||||
return Some(p)
|
||||
}
|
||||
i = i - 1
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///| The toplevel a popup chain hangs off (for returning keyboard focus).
|
||||
fn MoonPlasmaCompositor::popup_root(self : MoonPlasmaCompositor, wid : UInt64) -> UInt64? {
|
||||
let mut cur = wid
|
||||
let mut n = 0
|
||||
while n < 16 {
|
||||
if self.windows.contains(cur) {
|
||||
return Some(cur)
|
||||
}
|
||||
let mut next : UInt64? = None
|
||||
for p in self.popups {
|
||||
if p.id == cur {
|
||||
next = Some(p.parent)
|
||||
}
|
||||
}
|
||||
match next {
|
||||
Some(x) => cur = x
|
||||
None => return None
|
||||
}
|
||||
n = n + 1
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
///| Forget a popup (and any popups hanging off it); give keyboard focus back to its window.
|
||||
fn MoonPlasmaCompositor::close_popup(self : MoonPlasmaCompositor, wid : UInt64) -> Unit {
|
||||
let mut found = false
|
||||
for p in self.popups {
|
||||
if p.id == wid {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return
|
||||
}
|
||||
let root = self.popup_root(wid)
|
||||
let keep = self.popups.filter(p => p.id != wid)
|
||||
self.popups.clear()
|
||||
for p in keep {
|
||||
self.popups.push(p)
|
||||
}
|
||||
self.damage.mark_full()
|
||||
if self.ptr_win == Some(wid) {
|
||||
self.ptr_win = None
|
||||
}
|
||||
if self.kbd_win == Some(wid) {
|
||||
self.kbd_win = None
|
||||
match self.popups.last() {
|
||||
Some(top) => self.set_kbd_focus(Some(top.id))
|
||||
None => self.set_kbd_focus(root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///| Send pointer enter/motion for a popup under the pointer.
|
||||
fn MoonPlasmaCompositor::pointer_into_popup(self : MoonPlasmaCompositor, p : HostPopup, time_ms : UInt, motion : Bool) -> Unit {
|
||||
let r = self.popup_rect(p)
|
||||
let lx = self.ptr_x - r.x.to_double()
|
||||
let ly = self.ptr_y - r.y.to_double()
|
||||
if self.ptr_win != Some(p.id) {
|
||||
self.leave_pointer()
|
||||
self.ptr_win = Some(p.id)
|
||||
self.server.pointer_enter(p.id, lx, ly)
|
||||
}
|
||||
if motion {
|
||||
self.server.pointer_motion(p.id, time_ms, lx, ly)
|
||||
}
|
||||
}
|
||||
|
||||
///| Move keyboard focus (wl_keyboard leave/enter + current modifiers).
|
||||
fn MoonPlasmaCompositor::set_kbd_focus(self : MoonPlasmaCompositor, wid : UInt64?) -> Unit {
|
||||
if self.kbd_win == wid {
|
||||
@@ -630,6 +789,13 @@ pub fn MoonPlasmaCompositor::handle_input(
|
||||
self.ptr_y = y
|
||||
let xi = x.to_int()
|
||||
let yi = y.to_int()
|
||||
match self.popup_at(xi, yi) {
|
||||
Some(p) => {
|
||||
self.pointer_into_popup(p, time_ms, true)
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if self.shell.inspecting() {
|
||||
self.leave_pointer()
|
||||
let id = match self.shell.component_at(xi, yi) {
|
||||
@@ -696,6 +862,29 @@ pub fn MoonPlasmaCompositor::handle_input(
|
||||
PointerButton(button, pressed) => {
|
||||
let xi = self.ptr_x.to_int()
|
||||
let yi = self.ptr_y.to_int()
|
||||
match self.popup_at(xi, yi) {
|
||||
Some(p) => {
|
||||
self.pointer_into_popup(p, time_ms, false)
|
||||
if pressed {
|
||||
self.press_fwd = true
|
||||
self.server.pointer_button(p.id, time_ms, button, true)
|
||||
} else if self.press_fwd {
|
||||
self.press_fwd = false
|
||||
self.server.pointer_button(p.id, time_ms, button, false)
|
||||
}
|
||||
return
|
||||
}
|
||||
None => ()
|
||||
}
|
||||
if pressed && self.popups.length() > 0 {
|
||||
// A click outside the open popups dismisses them (the click is swallowed).
|
||||
let mut i = self.popups.length() - 1
|
||||
while i >= 0 {
|
||||
self.server.popup_done(self.popups[i].id)
|
||||
i = i - 1
|
||||
}
|
||||
return
|
||||
}
|
||||
if !pressed && self.shell.pointer_up() {
|
||||
self.run_shell_actions()
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user