From 8fea6f85eedfa24d481f9f5b1bd2935bf17b9535 Mon Sep 17 00:00:00 2001 From: Samuel Onoja Date: Thu, 24 Sep 2026 06:03:38 +0100 Subject: [PATCH] feat: enforce xdg popup grabs --- compositor/src/handlers/xdg_shell.rs | 32 ++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/compositor/src/handlers/xdg_shell.rs b/compositor/src/handlers/xdg_shell.rs index 4142d41..cc4b698 100644 --- a/compositor/src/handlers/xdg_shell.rs +++ b/compositor/src/handlers/xdg_shell.rs @@ -1,6 +1,7 @@ use smithay::{ desktop::{ - PopupKind, PopupManager, Space, Window, find_popup_root_surface, get_popup_toplevel_coords, + PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, Space, Window, + find_popup_root_surface, get_popup_toplevel_coords, }, input::{ Seat, @@ -135,7 +136,34 @@ impl XdgShellHandler for Ferese { ); } - fn grab(&mut self, _: PopupSurface, _: wl_seat::WlSeat, _: Serial) {} + fn grab(&mut self, surface: PopupSurface, seat: wl_seat::WlSeat, serial: Serial) { + let Some(seat) = Seat::from_resource(&seat) else { + return; + }; + let popup = PopupKind::Xdg(surface); + let Ok(root) = find_popup_root_surface(&popup) else { + return; + }; + let popup_grab = match self.popups.grab_popup(root, popup, &seat, serial) { + Ok(grab) => grab, + Err(error) => { + tracing::debug!(?error, "rejected xdg popup grab"); + return; + } + }; + + if let Some(pointer) = seat.get_pointer() { + pointer.set_grab( + self, + PopupPointerGrab::new(&popup_grab), + serial, + Focus::Keep, + ); + } + if let Some(keyboard) = seat.get_keyboard() { + keyboard.set_grab(self, PopupKeyboardGrab::new(&popup_grab), serial); + } + } } fn check_grab(