aboutsummaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-02-13 17:46:37 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-02-14 08:32:14 +0400
commitbefdebfa03399eeed7869fb0788d553f7aa4dcdb (patch)
tree4b59f51b62611570f7c92227ce8f6836ab06dab9 /src/layout
parent7960a73e9dda9f82c67e2f7b37766c88f5889c14 (diff)
downloadniri-befdebfa03399eeed7869fb0788d553f7aa4dcdb.tar.gz
niri-befdebfa03399eeed7869fb0788d553f7aa4dcdb.tar.bz2
niri-befdebfa03399eeed7869fb0788d553f7aa4dcdb.zip
Add the beginnings of window rules
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/mod.rs71
-rw-r--r--src/layout/monitor.rs4
-rw-r--r--src/layout/workspace.rs21
3 files changed, 84 insertions, 12 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, .. } => {
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index cb99279a..ff63ed4f 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -76,6 +76,10 @@ impl<W: LayoutElement> Monitor<W> {
}
}
+ pub fn active_workspace_ref(&self) -> &Workspace<W> {
+ &self.workspaces[self.active_workspace_idx]
+ }
+
pub fn active_workspace(&mut self) -> &mut Workspace<W> {
&mut self.workspaces[self.active_workspace_idx]
}
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 64bc4bc7..7c9b68fc 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -321,8 +321,17 @@ impl<W: LayoutElement> Workspace<W> {
))
}
- pub fn new_window_size(&self) -> Size<i32, Logical> {
- let width = if let Some(width) = self.options.default_width {
+ pub fn new_window_size(
+ &self,
+ default_width: Option<Option<ColumnWidth>>,
+ ) -> Size<i32, Logical> {
+ let default_width = match default_width {
+ Some(Some(width)) => Some(width),
+ Some(None) => None,
+ None => self.options.default_width,
+ };
+
+ let width = if let Some(width) = default_width {
let mut width = width.resolve(&self.options, self.working_area.size.w);
if !self.options.border.off {
width -= self.options.border.width as i32 * 2;
@@ -340,8 +349,12 @@ impl<W: LayoutElement> Workspace<W> {
Size::from((width, max(height, 1)))
}
- pub fn configure_new_window(&self, window: &Window) {
- let size = self.new_window_size();
+ pub fn configure_new_window(
+ &self,
+ window: &Window,
+ default_width: Option<Option<ColumnWidth>>,
+ ) {
+ let size = self.new_window_size(default_width);
let bounds = self.toplevel_bounds();
if let Some(output) = self.output.as_ref() {