forge
Explore
Log in

Don't you dare go Hollow

Pass Un/Mapped to window rule resolution

Browse files at this commit

354f0b039a768c77e9c703cbcbca693f0b8c6f96Ivan MolodetskikhParent: d120e0c
src/handlers/xdg_shell.rsmodified+13 -8
@@ -28,7 +28,7 @@ use smithay::{
28 28
29 use crate::layout::workspace::ColumnWidth;29 use crate::layout::workspace::ColumnWidth;
30 use crate::niri::{PopupGrabState, State};30 use crate::niri::{PopupGrabState, State};
31-use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped};31+use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef};
32 32
33 impl XdgShellHandler for State {33 impl XdgShellHandler for State {
34 fn xdg_shell_state(&mut self) -> &mut XdgShellState {34 fn xdg_shell_state(&mut self) -> &mut XdgShellState {
@@ -489,6 +489,10 @@ impl State {
489 return;489 return;
490 };490 };
491 491
492+ let config = self.niri.config.borrow();
493+ let rules =
494+ ResolvedWindowRules::compute(&config.window_rules, WindowRef::Unmapped(unmapped));
495+
492 let Unmapped { window, state } = unmapped;496 let Unmapped { window, state } = unmapped;
493 497
494 let InitialConfigureState::NotConfigured { wants_fullscreen } = state else {498 let InitialConfigureState::NotConfigured { wants_fullscreen } = state else {
@@ -496,9 +500,6 @@ impl State {
496 return;500 return;
497 };501 };
498 502
499- let config = self.niri.config.borrow();
500- let rules = ResolvedWindowRules::compute(&config.window_rules, toplevel);
501-
502 // Pick the target monitor. First, check if we had an output set in the window rules.503 // Pick the target monitor. First, check if we had an output set in the window rules.
503 let mon = rules504 let mon = rules
504 .open_on_output505 .open_on_output
@@ -730,19 +731,23 @@ impl State {
730 }731 }
731 732
732 pub fn update_window_rules(&mut self, toplevel: &ToplevelSurface) {733 pub fn update_window_rules(&mut self, toplevel: &ToplevelSurface) {
733- let resolve =734+ let config = self.niri.config.borrow();
734- || ResolvedWindowRules::compute(&self.niri.config.borrow().window_rules, toplevel);735+ let window_rules = &config.window_rules;
735 736
736 if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) {737 if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) {
738+ let new_rules =
739+ ResolvedWindowRules::compute(window_rules, WindowRef::Unmapped(unmapped));
737 if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {740 if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {
738- *rules = resolve();741+ *rules = new_rules;
739 }742 }
740 } else if let Some((mapped, output)) = self743 } else if let Some((mapped, output)) = self
741 .niri744 .niri
742 .layout745 .layout
743 .find_window_and_output_mut(toplevel.wl_surface())746 .find_window_and_output_mut(toplevel.wl_surface())
744 {747 {
745- let new_rules = resolve();748+ let new_rules = ResolvedWindowRules::compute(window_rules, WindowRef::Mapped(mapped));
749+ drop(config);
750+
746 if mapped.rules != new_rules {751 if mapped.rules != new_rules {
747 mapped.rules = new_rules;752 mapped.rules = new_rules;
748 753
src/niri.rsmodified+6 -6
@@ -115,7 +115,7 @@ use crate::utils::{
115 center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8,115 center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8,
116 };116 };
117 use crate::wheel_tracker::WheelTracker;117 use crate::wheel_tracker::WheelTracker;
118-use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped};118+use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef};
119 use crate::{animation, niri_render_elements};119 use crate::{animation, niri_render_elements};
120 120
121 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];121 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
@@ -880,17 +880,17 @@ impl State {
880 let window_rules = &self.niri.config.borrow().window_rules;880 let window_rules = &self.niri.config.borrow().window_rules;
881 881
882 for unmapped in self.niri.unmapped_windows.values_mut() {882 for unmapped in self.niri.unmapped_windows.values_mut() {
883+ let new_rules =
884+ ResolvedWindowRules::compute(window_rules, WindowRef::Unmapped(unmapped));
883 if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {885 if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {
884- *rules = ResolvedWindowRules::compute(886+ *rules = new_rules;
885- window_rules,
886- unmapped.window.toplevel().expect("no X11 support"),
887- );
888 }887 }
889 }888 }
890 889
891 let mut windows = vec![];890 let mut windows = vec![];
892 self.niri.layout.with_windows_mut(|mapped, _| {891 self.niri.layout.with_windows_mut(|mapped, _| {
893- mapped.rules = ResolvedWindowRules::compute(window_rules, mapped.toplevel());892+ mapped.rules =
893+ ResolvedWindowRules::compute(window_rules, WindowRef::Mapped(mapped));
894 windows.push(mapped.window.clone());894 windows.push(mapped.window.clone());
895 });895 });
896 for win in windows {896 for win in windows {
src/window/mod.rsmodified+18 -1
@@ -12,6 +12,13 @@ pub use mapped::Mapped;
12 pub mod unmapped;12 pub mod unmapped;
13 pub use unmapped::{InitialConfigureState, Unmapped};13 pub use unmapped::{InitialConfigureState, Unmapped};
14 14
15+/// Reference to a mapped or unmapped window.
16+#[derive(Debug, Clone, Copy)]
17+pub enum WindowRef<'a> {
18+ Unmapped(&'a Unmapped),
19+ Mapped(&'a Mapped),
20+}
21+
15 /// Rules fully resolved for a window.22 /// Rules fully resolved for a window.
16 #[derive(Debug, PartialEq)]23 #[derive(Debug, PartialEq)]
17 pub struct ResolvedWindowRules {24 pub struct ResolvedWindowRules {
@@ -46,6 +53,15 @@ pub struct ResolvedWindowRules {
46 pub draw_border_with_background: Option<bool>,53 pub draw_border_with_background: Option<bool>,
47 }54 }
48 55
56+impl<'a> WindowRef<'a> {
57+ pub fn toplevel(self) -> &'a ToplevelSurface {
58+ match self {
59+ WindowRef::Unmapped(unmapped) => unmapped.toplevel(),
60+ WindowRef::Mapped(mapped) => mapped.toplevel(),
61+ }
62+ }
63+}
64+
49 impl ResolvedWindowRules {65 impl ResolvedWindowRules {
50 pub const fn empty() -> Self {66 pub const fn empty() -> Self {
51 Self {67 Self {
@@ -61,11 +77,12 @@ impl ResolvedWindowRules {
61 }77 }
62 }78 }
63 79
64- pub fn compute(rules: &[WindowRule], toplevel: &ToplevelSurface) -> Self {80+ pub fn compute(rules: &[WindowRule], window: WindowRef) -> Self {
65 let _span = tracy_client::span!("ResolvedWindowRules::compute");81 let _span = tracy_client::span!("ResolvedWindowRules::compute");
66 82
67 let mut resolved = ResolvedWindowRules::empty();83 let mut resolved = ResolvedWindowRules::empty();
68 84
85+ let toplevel = window.toplevel();
69 with_states(toplevel.wl_surface(), |states| {86 with_states(toplevel.wl_surface(), |states| {
70 let role = states87 let role = states
71 .data_map88 .data_map
src/window/unmapped.rsmodified+5 -0
@@ -1,5 +1,6 @@
1 use smithay::desktop::Window;1 use smithay::desktop::Window;
2 use smithay::output::Output;2 use smithay::output::Output;
3+use smithay::wayland::shell::xdg::ToplevelSurface;
3 4
4 use super::ResolvedWindowRules;5 use super::ResolvedWindowRules;
5 use crate::layout::workspace::ColumnWidth;6 use crate::layout::workspace::ColumnWidth;
@@ -58,4 +59,8 @@ impl Unmapped {
58 pub fn needs_initial_configure(&self) -> bool {59 pub fn needs_initial_configure(&self) -> bool {
59 matches!(self.state, InitialConfigureState::NotConfigured { .. })60 matches!(self.state, InitialConfigureState::NotConfigured { .. })
60 }61 }
62+
63+ pub fn toplevel(&self) -> &ToplevelSurface {
64+ self.window.toplevel().expect("no X11 support")
65+ }
61 }66 }