diff options
| author | Kirill Chibisov <contact@kchibisov.com> | 2024-04-19 16:04:41 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-04-23 00:09:42 -0700 |
| commit | c2d03d82ceb47322fbe0d93af5a452a83de3b1e1 (patch) | |
| tree | c991ff06a484bddb6126ccd1c00200b8f272035b | |
| parent | 5299590290880039c733600bea796ce1de055c18 (diff) | |
| download | niri-c2d03d82ceb47322fbe0d93af5a452a83de3b1e1.tar.gz niri-c2d03d82ceb47322fbe0d93af5a452a83de3b1e1.tar.bz2 niri-c2d03d82ceb47322fbe0d93af5a452a83de3b1e1.zip | |
Use PopupKind instead of PopupSurface
| -rw-r--r-- | src/handlers/layer_shell.rs | 4 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 1 | ||||
| -rw-r--r-- | src/handlers/xdg_shell.rs | 45 |
3 files changed, 30 insertions, 20 deletions
diff --git a/src/handlers/layer_shell.rs b/src/handlers/layer_shell.rs index bf1832fb..bd3fbbcd 100644 --- a/src/handlers/layer_shell.rs +++ b/src/handlers/layer_shell.rs @@ -1,5 +1,5 @@ use smithay::delegate_layer_shell; -use smithay::desktop::{layer_map_for_output, LayerSurface, WindowSurfaceType}; +use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType}; use smithay::output::Output; use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; @@ -55,7 +55,7 @@ impl WlrLayerShellHandler for State { } fn new_popup(&mut self, _parent: WlrLayerSurface, popup: PopupSurface) { - self.unconstrain_popup(&popup); + self.unconstrain_popup(&PopupKind::Xdg(popup)); } } delegate_layer_shell!(State); diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index ae2b4499..28b21b9f 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -142,6 +142,7 @@ impl InputMethodHandler for State { send_surface_state(wl_surface, data, scale, transform); }); } + if let Err(err) = self.niri.popups.track_popup(popup) { warn!("error tracking ime popup {err:?}"); } diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 7ebf360a..1fde1eee 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -47,9 +47,10 @@ impl XdgShellHandler for State { } fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) { - self.unconstrain_popup(&surface); + let popup = PopupKind::Xdg(surface); + self.unconstrain_popup(&popup); - if let Err(err) = self.niri.popups.track_popup(PopupKind::Xdg(surface)) { + if let Err(err) = self.niri.popups.track_popup(popup) { warn!("error tracking popup: {err:?}"); } } @@ -79,7 +80,7 @@ impl XdgShellHandler for State { state.geometry = geometry; state.positioner = positioner; }); - self.unconstrain_popup(&surface); + self.unconstrain_popup(&PopupKind::Xdg(surface.clone())); surface.send_repositioned(token); } @@ -659,12 +660,12 @@ impl State { self.niri.output_for_root(&root) } - pub fn unconstrain_popup(&self, popup: &PopupSurface) { + pub fn unconstrain_popup(&self, popup: &PopupKind) { let _span = tracy_client::span!("Niri::unconstrain_popup"); // Popups with a NULL parent will get repositioned in their respective protocol handlers // (i.e. layer-shell). - let Ok(root) = find_popup_root_surface(&PopupKind::Xdg(popup.clone())) else { + let Ok(root) = find_popup_root_surface(popup) else { return; }; @@ -680,7 +681,7 @@ impl State { } } - fn unconstrain_window_popup(&self, popup: &PopupSurface, window: &Window, output: &Output) { + fn unconstrain_window_popup(&self, popup: &PopupKind, window: &Window, output: &Output) { let window_geo = window.geometry(); let output_geo = self.niri.global_space.output_geometry(output).unwrap(); @@ -693,16 +694,21 @@ impl State { let mut target = Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h)); target.loc.y -= self.niri.layout.window_y(window).unwrap(); - target.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(popup.clone())); + target.loc -= get_popup_toplevel_coords(popup); - popup.with_pending_state(|state| { - state.geometry = unconstrain_with_padding(state.positioner, target); - }); + match popup { + PopupKind::Xdg(popup) => { + popup.with_pending_state(|state| { + state.geometry = unconstrain_with_padding(state.positioner, target); + }); + } + PopupKind::InputMethod(_) => todo!(), + } } pub fn unconstrain_layer_shell_popup( &self, - popup: &PopupSurface, + popup: &PopupKind, layer_surface: &LayerSurface, output: &Output, ) { @@ -716,11 +722,14 @@ impl State { // we will compute that here. let mut target = Rectangle::from_loc_and_size((0, 0), output_geo.size); target.loc -= layer_geo.loc; - target.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(popup.clone())); + target.loc -= get_popup_toplevel_coords(popup); - popup.with_pending_state(|state| { - state.geometry = unconstrain_with_padding(state.positioner, target); - }); + match popup { + PopupKind::Xdg(popup) => popup.with_pending_state(|state| { + state.geometry = unconstrain_with_padding(state.positioner, target); + }), + PopupKind::InputMethod(_) => todo!(), + } } pub fn update_reactive_popups(&self, window: &Window, output: &Output) { @@ -729,10 +738,10 @@ impl State { for (popup, _) in PopupManager::popups_for_surface( window.toplevel().expect("no x11 support").wl_surface(), ) { - match popup { - PopupKind::Xdg(ref popup) => { + match &popup { + xdg_popup @ PopupKind::Xdg(popup) => { if popup.with_pending_state(|state| state.positioner.reactive) { - self.unconstrain_window_popup(popup, window, output); + self.unconstrain_window_popup(xdg_popup, window, output); if let Err(err) = popup.send_pending_configure() { warn!("error re-configuring reactive popup: {err:?}"); } |
