Add open-maximized window rule

This commit is contained in:
Ivan Molodetskikh
2024-02-23 14:24:39 +04:00
parent 2317021a7c
commit 6a587245eb
5 changed files with 41 additions and 8 deletions
+4
View File
@@ -583,6 +583,8 @@ pub struct WindowRule {
pub default_column_width: Option<DefaultColumnWidth>, pub default_column_width: Option<DefaultColumnWidth>,
#[knuffel(child, unwrap(argument))] #[knuffel(child, unwrap(argument))]
pub open_on_output: Option<String>, pub open_on_output: Option<String>,
#[knuffel(child, unwrap(argument))]
pub open_maximized: Option<bool>,
} }
#[derive(knuffel::Decode, Debug, Default, Clone)] #[derive(knuffel::Decode, Debug, Default, Clone)]
@@ -1062,6 +1064,7 @@ mod tests {
exclude title="~" exclude title="~"
open-on-output "eDP-1" open-on-output "eDP-1"
open-maximized true
} }
binds { binds {
@@ -1221,6 +1224,7 @@ mod tests {
title: Some(Regex::new("~").unwrap()), title: Some(Regex::new("~").unwrap()),
}], }],
open_on_output: Some("eDP-1".to_owned()), open_on_output: Some("eDP-1".to_owned()),
open_maximized: Some(true),
..Default::default() ..Default::default()
}], }],
binds: Binds(vec![ binds: Binds(vec![
+3
View File
@@ -305,6 +305,9 @@ animations {
// If such an output does not exist, it will open on the currently // If such an output does not exist, it will open on the currently
// focused output as usual. // focused output as usual.
open-on-output "eDP-1" open-on-output "eDP-1"
// Make this window open as a maximized column.
open-maximized true
} }
// Here's a useful example. Work around WezTerm's initial configure bug // Here's a useful example. Work around WezTerm's initial configure bug
+15 -7
View File
@@ -109,16 +109,22 @@ impl CompositorHandler for State {
window.on_commit(); window.on_commit();
let (width, output) = let (width, is_full_width, output) =
if let InitialConfigureState::Configured { width, output, .. } = state { if let InitialConfigureState::Configured {
width,
is_full_width,
output,
..
} = state
{
// Check that the output is still connected. // Check that the output is still connected.
let output = let output =
output.filter(|o| self.niri.layout.monitor_for_output(o).is_some()); output.filter(|o| self.niri.layout.monitor_for_output(o).is_some());
(width, output) (width, is_full_width, output)
} else { } else {
error!("window map must happen after initial configure"); error!("window map must happen after initial configure");
(None, None) (None, false, None)
}; };
let parent = window let parent = window
@@ -140,14 +146,16 @@ impl CompositorHandler for State {
let output = if let Some(p) = parent { let output = if let Some(p) = parent {
// Open dialogs immediately to the right of their parent window. // Open dialogs immediately to the right of their parent window.
self.niri.layout.add_window_right_of(&p, win, width, false) self.niri
.layout
.add_window_right_of(&p, win, width, is_full_width)
} else if let Some(output) = &output { } else if let Some(output) = &output {
self.niri self.niri
.layout .layout
.add_window_on_output(output, win, width, false); .add_window_on_output(output, win, width, is_full_width);
Some(output) Some(output)
} else { } else {
self.niri.layout.add_window(win, width, false) self.niri.layout.add_window(win, width, is_full_width)
}; };
if let Some(output) = output.cloned() { if let Some(output) = output.cloned() {
+13 -1
View File
@@ -89,6 +89,10 @@ pub fn resolve_window_rules(
if let Some(x) = rule.open_on_output.as_deref() { if let Some(x) = rule.open_on_output.as_deref() {
open_on_output = Some(x); open_on_output = Some(x);
} }
if let Some(x) = rule.open_maximized {
resolved.open_maximized = Some(x);
}
} }
resolved.open_on_output = open_on_output.map(|x| x.to_owned()); resolved.open_on_output = open_on_output.map(|x| x.to_owned());
@@ -503,6 +507,7 @@ impl State {
let mon = mon.map(|(mon, _)| mon); let mon = mon.map(|(mon, _)| mon);
let mut width = None; let mut width = None;
let is_full_width = rules.open_maximized.unwrap_or(false);
// Tell the surface the preferred size and bounds for its likely output. // Tell the surface the preferred size and bounds for its likely output.
let ws = mon let ws = mon
@@ -518,7 +523,13 @@ impl State {
} }
width = ws.resolve_default_width(rules.default_width); width = ws.resolve_default_width(rules.default_width);
ws.configure_new_window(window, width);
let configure_width = if is_full_width {
Some(ColumnWidth::Proportion(1.))
} else {
width
};
ws.configure_new_window(window, configure_width);
} }
// If the user prefers no CSD, it's a reasonable assumption that they would prefer to get // If the user prefers no CSD, it's a reasonable assumption that they would prefer to get
@@ -536,6 +547,7 @@ impl State {
*state = InitialConfigureState::Configured { *state = InitialConfigureState::Configured {
rules, rules,
width, width,
is_full_width,
output, output,
}; };
+6
View File
@@ -29,6 +29,9 @@ pub enum InitialConfigureState {
/// `None` means that the window will pick its own width. /// `None` means that the window will pick its own width.
width: Option<ColumnWidth>, width: Option<ColumnWidth>,
/// Whether the window should open full-width.
is_full_width: bool,
/// Output to open this window on. /// Output to open this window on.
/// ///
/// This can be `None` in cases like: /// This can be `None` in cases like:
@@ -52,6 +55,9 @@ pub struct ResolvedWindowRules {
/// Output to open this window on. /// Output to open this window on.
pub open_on_output: Option<String>, pub open_on_output: Option<String>,
/// Whether the window should open full-width.
pub open_maximized: Option<bool>,
} }
impl Unmapped { impl Unmapped {