Use PopupKind instead of PopupSurface
Browse files at this commitc2d03d82ceb47322fbe0d93af5a452a83de3b1e1Parent: 52995903 changed files +30 -20
- src/handlers/layer_shell.rs +2 -2
- src/handlers/mod.rs +1 -0
- src/handlers/xdg_shell.rs +27 -18
src/handlers/layer_shell.rsmodified+2 -2
| @@ -1,5 +1,5 @@ | |||
| 1 | use smithay::delegate_layer_shell; | 1 | use smithay::delegate_layer_shell; |
| 2 | -use smithay::desktop::{layer_map_for_output, LayerSurface, WindowSurfaceType}; | 2 | +use smithay::desktop::{layer_map_for_output, LayerSurface, PopupKind, WindowSurfaceType}; |
| 3 | use smithay::output::Output; | 3 | use smithay::output::Output; |
| 4 | use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; | 4 | use smithay::reexports::wayland_server::protocol::wl_output::WlOutput; |
| 5 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 5 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| @@ -55,7 +55,7 @@ impl WlrLayerShellHandler for State { | |||
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | fn new_popup(&mut self, _parent: WlrLayerSurface, popup: PopupSurface) { | 57 | fn new_popup(&mut self, _parent: WlrLayerSurface, popup: PopupSurface) { |
| 58 | - self.unconstrain_popup(&popup); | 58 | + self.unconstrain_popup(&PopupKind::Xdg(popup)); |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | delegate_layer_shell!(State); | 61 | delegate_layer_shell!(State); |
src/handlers/mod.rsmodified+1 -0
| @@ -142,6 +142,7 @@ impl InputMethodHandler for State { | |||
| 142 | send_surface_state(wl_surface, data, scale, transform); | 142 | send_surface_state(wl_surface, data, scale, transform); |
| 143 | }); | 143 | }); |
| 144 | } | 144 | } |
| 145 | + | ||
| 145 | if let Err(err) = self.niri.popups.track_popup(popup) { | 146 | if let Err(err) = self.niri.popups.track_popup(popup) { |
| 146 | warn!("error tracking ime popup {err:?}"); | 147 | warn!("error tracking ime popup {err:?}"); |
| 147 | } | 148 | } |
src/handlers/xdg_shell.rsmodified+27 -18
| @@ -47,9 +47,10 @@ impl XdgShellHandler for State { | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) { | 49 | fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) { |
| 50 | - self.unconstrain_popup(&surface); | 50 | + let popup = PopupKind::Xdg(surface); |
| 51 | + self.unconstrain_popup(&popup); | ||
| 51 | 52 | ||
| 52 | - if let Err(err) = self.niri.popups.track_popup(PopupKind::Xdg(surface)) { | 53 | + if let Err(err) = self.niri.popups.track_popup(popup) { |
| 53 | warn!("error tracking popup: {err:?}"); | 54 | warn!("error tracking popup: {err:?}"); |
| 54 | } | 55 | } |
| 55 | } | 56 | } |
| @@ -79,7 +80,7 @@ impl XdgShellHandler for State { | |||
| 79 | state.geometry = geometry; | 80 | state.geometry = geometry; |
| 80 | state.positioner = positioner; | 81 | state.positioner = positioner; |
| 81 | }); | 82 | }); |
| 82 | - self.unconstrain_popup(&surface); | 83 | + self.unconstrain_popup(&PopupKind::Xdg(surface.clone())); |
| 83 | surface.send_repositioned(token); | 84 | surface.send_repositioned(token); |
| 84 | } | 85 | } |
| 85 | 86 | ||
| @@ -659,12 +660,12 @@ impl State { | |||
| 659 | self.niri.output_for_root(&root) | 660 | self.niri.output_for_root(&root) |
| 660 | } | 661 | } |
| 661 | 662 | ||
| 662 | - pub fn unconstrain_popup(&self, popup: &PopupSurface) { | 663 | + pub fn unconstrain_popup(&self, popup: &PopupKind) { |
| 663 | let _span = tracy_client::span!("Niri::unconstrain_popup"); | 664 | let _span = tracy_client::span!("Niri::unconstrain_popup"); |
| 664 | 665 | ||
| 665 | // Popups with a NULL parent will get repositioned in their respective protocol handlers | 666 | // Popups with a NULL parent will get repositioned in their respective protocol handlers |
| 666 | // (i.e. layer-shell). | 667 | // (i.e. layer-shell). |
| 667 | - let Ok(root) = find_popup_root_surface(&PopupKind::Xdg(popup.clone())) else { | 668 | + let Ok(root) = find_popup_root_surface(popup) else { |
| 668 | return; | 669 | return; |
| 669 | }; | 670 | }; |
| 670 | 671 | ||
| @@ -680,7 +681,7 @@ impl State { | |||
| 680 | } | 681 | } |
| 681 | } | 682 | } |
| 682 | 683 | ||
| 683 | - fn unconstrain_window_popup(&self, popup: &PopupSurface, window: &Window, output: &Output) { | 684 | + fn unconstrain_window_popup(&self, popup: &PopupKind, window: &Window, output: &Output) { |
| 684 | let window_geo = window.geometry(); | 685 | let window_geo = window.geometry(); |
| 685 | let output_geo = self.niri.global_space.output_geometry(output).unwrap(); | 686 | let output_geo = self.niri.global_space.output_geometry(output).unwrap(); |
| 686 | 687 | ||
| @@ -693,16 +694,21 @@ impl State { | |||
| 693 | let mut target = | 694 | let mut target = |
| 694 | Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h)); | 695 | Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h)); |
| 695 | target.loc.y -= self.niri.layout.window_y(window).unwrap(); | 696 | target.loc.y -= self.niri.layout.window_y(window).unwrap(); |
| 696 | - target.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(popup.clone())); | 697 | + target.loc -= get_popup_toplevel_coords(popup); |
| 697 | 698 | ||
| 698 | - popup.with_pending_state(|state| { | 699 | + match popup { |
| 699 | - state.geometry = unconstrain_with_padding(state.positioner, target); | 700 | + PopupKind::Xdg(popup) => { |
| 700 | - }); | 701 | + popup.with_pending_state(|state| { |
| 702 | + state.geometry = unconstrain_with_padding(state.positioner, target); | ||
| 703 | + }); | ||
| 704 | + } | ||
| 705 | + PopupKind::InputMethod(_) => todo!(), | ||
| 706 | + } | ||
| 701 | } | 707 | } |
| 702 | 708 | ||
| 703 | pub fn unconstrain_layer_shell_popup( | 709 | pub fn unconstrain_layer_shell_popup( |
| 704 | &self, | 710 | &self, |
| 705 | - popup: &PopupSurface, | 711 | + popup: &PopupKind, |
| 706 | layer_surface: &LayerSurface, | 712 | layer_surface: &LayerSurface, |
| 707 | output: &Output, | 713 | output: &Output, |
| 708 | ) { | 714 | ) { |
| @@ -716,11 +722,14 @@ impl State { | |||
| 716 | // we will compute that here. | 722 | // we will compute that here. |
| 717 | let mut target = Rectangle::from_loc_and_size((0, 0), output_geo.size); | 723 | let mut target = Rectangle::from_loc_and_size((0, 0), output_geo.size); |
| 718 | target.loc -= layer_geo.loc; | 724 | target.loc -= layer_geo.loc; |
| 719 | - target.loc -= get_popup_toplevel_coords(&PopupKind::Xdg(popup.clone())); | 725 | + target.loc -= get_popup_toplevel_coords(popup); |
| 720 | 726 | ||
| 721 | - popup.with_pending_state(|state| { | 727 | + match popup { |
| 722 | - state.geometry = unconstrain_with_padding(state.positioner, target); | 728 | + PopupKind::Xdg(popup) => popup.with_pending_state(|state| { |
| 723 | - }); | 729 | + state.geometry = unconstrain_with_padding(state.positioner, target); |
| 730 | + }), | ||
| 731 | + PopupKind::InputMethod(_) => todo!(), | ||
| 732 | + } | ||
| 724 | } | 733 | } |
| 725 | 734 | ||
| 726 | pub fn update_reactive_popups(&self, window: &Window, output: &Output) { | 735 | pub fn update_reactive_popups(&self, window: &Window, output: &Output) { |
| @@ -729,10 +738,10 @@ impl State { | |||
| 729 | for (popup, _) in PopupManager::popups_for_surface( | 738 | for (popup, _) in PopupManager::popups_for_surface( |
| 730 | window.toplevel().expect("no x11 support").wl_surface(), | 739 | window.toplevel().expect("no x11 support").wl_surface(), |
| 731 | ) { | 740 | ) { |
| 732 | - match popup { | 741 | + match &popup { |
| 733 | - PopupKind::Xdg(ref popup) => { | 742 | + xdg_popup @ PopupKind::Xdg(popup) => { |
| 734 | if popup.with_pending_state(|state| state.positioner.reactive) { | 743 | if popup.with_pending_state(|state| state.positioner.reactive) { |
| 735 | - self.unconstrain_window_popup(popup, window, output); | 744 | + self.unconstrain_window_popup(xdg_popup, window, output); |
| 736 | if let Err(err) = popup.send_pending_configure() { | 745 | if let Err(err) = popup.send_pending_configure() { |
| 737 | warn!("error re-configuring reactive popup: {err:?}"); | 746 | warn!("error re-configuring reactive popup: {err:?}"); |
| 738 | } | 747 | } |