fix popup

This commit is contained in:
IoIxD 2026-07-07 16:32:06 -07:00
commit 9268cb0220
2 changed files with 41 additions and 5 deletions

View file

@ -1,6 +1,8 @@
use smithay::{
desktop::{
find_popup_root_surface, get_popup_toplevel_coords, PopupKind, PopupManager, Space, Window,
find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output,
PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Space,
Window, WindowSurfaceType,
},
input::{
pointer::{Focus, GrabStartData as PointerGrabStartData},
@ -42,7 +44,12 @@ impl XdgShellHandler for State {
fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) {
self.unconstrain_popup(&surface);
let _ = self.popups.track_popup(PopupKind::Xdg(surface));
if let Err(err) = self.popups.track_popup(PopupKind::Xdg(surface.clone())) {
println!("Failed to track popup: {err}");
};
if let Err(err) = surface.send_pending_configure() {
println!("Failed to configure popup: {err}");
}
}
fn reposition_request(
@ -128,8 +135,37 @@ impl XdgShellHandler for State {
}
}
fn grab(&mut self, _surface: PopupSurface, _seat: wl_seat::WlSeat, _serial: Serial) {
// TODO popup grabs
fn grab(&mut self, surface: PopupSurface, seat: wl_seat::WlSeat, serial: Serial) {
let seat = Seat::from_resource(&seat).unwrap();
let kind = PopupKind::Xdg(surface);
if let Ok(root) = find_popup_root_surface(&kind) {
let ret = self.popups.grab_popup(root, kind, &seat, serial);
if let Ok(mut grab) = ret {
if let Some(keyboard) = seat.get_keyboard() {
if keyboard.is_grabbed()
&& !(keyboard.has_grab(serial)
|| keyboard.has_grab(grab.previous_serial().unwrap_or(serial)))
{
grab.ungrab(PopupUngrabStrategy::All);
return;
}
keyboard.set_focus(self, grab.current_grab(), serial);
keyboard.set_grab(self, PopupKeyboardGrab::new(&grab), serial);
}
if let Some(pointer) = seat.get_pointer() {
if pointer.is_grabbed()
&& !(pointer.has_grab(serial)
|| pointer
.has_grab(grab.previous_serial().unwrap_or_else(|| grab.serial())))
{
grab.ungrab(PopupUngrabStrategy::All);
return;
}
pointer.set_grab(self, PopupPointerGrab::new(&grab), serial, Focus::Keep);
}
}
}
}
fn title_changed(&mut self, surface: ToplevelSurface) {

View file

@ -259,7 +259,7 @@ impl DecoratedWindow {
impl SpaceElement for DecoratedWindow {
fn bbox(&self) -> smithay::utils::Rectangle<i32, smithay::utils::Logical> {
let mut bbox = self.window.bbox();
let mut bbox = self.window.bbox_with_popups();
if self.decorated() {
bbox.loc.x -= 5;