diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-13 17:46:37 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-14 08:32:14 +0400 |
| commit | befdebfa03399eeed7869fb0788d553f7aa4dcdb (patch) | |
| tree | 4b59f51b62611570f7c92227ce8f6836ab06dab9 /src/layout/mod.rs | |
| parent | 7960a73e9dda9f82c67e2f7b37766c88f5889c14 (diff) | |
| download | niri-befdebfa03399eeed7869fb0788d553f7aa4dcdb.tar.gz niri-befdebfa03399eeed7869fb0788d553f7aa4dcdb.tar.bz2 niri-befdebfa03399eeed7869fb0788d553f7aa4dcdb.zip | |
Add the beginnings of window rules
Diffstat (limited to 'src/layout/mod.rs')
| -rw-r--r-- | src/layout/mod.rs | 71 |
1 files changed, 63 insertions, 8 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index dfc7ee0a..947b8cea 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -531,12 +531,15 @@ impl<W: LayoutElement> Layout<W> { pub fn add_window( &mut self, window: W, - width: Option<ColumnWidth>, + width: Option<Option<ColumnWidth>>, is_full_width: bool, ) -> Option<&Output> { - let width = width - .or(self.options.default_width) - .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w)); + let width = match width { + Some(Some(width)) => Some(width), + Some(None) => None, + None => self.options.default_width, + } + .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w)); match &mut self.monitor_set { MonitorSet::Normal { @@ -584,12 +587,15 @@ impl<W: LayoutElement> Layout<W> { &mut self, right_of: &W, window: W, - width: Option<ColumnWidth>, + width: Option<Option<ColumnWidth>>, is_full_width: bool, ) -> Option<&Output> { - let width = width - .or(self.options.default_width) - .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w)); + let width = match width { + Some(Some(width)) => Some(width), + Some(None) => None, + None => self.options.default_width, + } + .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w)); match &mut self.monitor_set { MonitorSet::Normal { monitors, .. } => { @@ -612,6 +618,55 @@ impl<W: LayoutElement> Layout<W> { } } + /// Adds a new window to the layout on a specific output. + pub fn add_window_on_output( + &mut self, + output: &Output, + window: W, + width: Option<Option<ColumnWidth>>, + is_full_width: bool, + ) { + let width = match width { + Some(Some(width)) => Some(width), + Some(None) => None, + None => self.options.default_width, + } + .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w)); + + let MonitorSet::Normal { + monitors, + active_monitor_idx, + .. + } = &mut self.monitor_set + else { + panic!() + }; + + let (mon_idx, mon) = monitors + .iter_mut() + .enumerate() + .find(|(_, mon)| mon.output == *output) + .unwrap(); + + // Don't steal focus from an active fullscreen window. + let mut activate = true; + let ws = &mon.workspaces[mon.active_workspace_idx]; + if mon_idx == *active_monitor_idx + && !ws.columns.is_empty() + && ws.columns[ws.active_column_idx].is_fullscreen + { + activate = false; + } + + mon.add_window( + mon.active_workspace_idx, + window, + activate, + width, + is_full_width, + ); + } + pub fn remove_window(&mut self, window: &W) { match &mut self.monitor_set { MonitorSet::Normal { monitors, .. } => { |
