mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Add open-maximized window rule
This commit is contained in:
@@ -583,6 +583,8 @@ pub struct WindowRule {
|
||||
pub default_column_width: Option<DefaultColumnWidth>,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub open_on_output: Option<String>,
|
||||
#[knuffel(child, unwrap(argument))]
|
||||
pub open_maximized: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, Clone)]
|
||||
@@ -1062,6 +1064,7 @@ mod tests {
|
||||
exclude title="~"
|
||||
|
||||
open-on-output "eDP-1"
|
||||
open-maximized true
|
||||
}
|
||||
|
||||
binds {
|
||||
@@ -1221,6 +1224,7 @@ mod tests {
|
||||
title: Some(Regex::new("~").unwrap()),
|
||||
}],
|
||||
open_on_output: Some("eDP-1".to_owned()),
|
||||
open_maximized: Some(true),
|
||||
..Default::default()
|
||||
}],
|
||||
binds: Binds(vec![
|
||||
|
||||
@@ -305,6 +305,9 @@ animations {
|
||||
// If such an output does not exist, it will open on the currently
|
||||
// focused output as usual.
|
||||
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
|
||||
|
||||
@@ -109,16 +109,22 @@ impl CompositorHandler for State {
|
||||
|
||||
window.on_commit();
|
||||
|
||||
let (width, output) =
|
||||
if let InitialConfigureState::Configured { width, output, .. } = state {
|
||||
let (width, is_full_width, output) =
|
||||
if let InitialConfigureState::Configured {
|
||||
width,
|
||||
is_full_width,
|
||||
output,
|
||||
..
|
||||
} = state
|
||||
{
|
||||
// Check that the output is still connected.
|
||||
let output =
|
||||
output.filter(|o| self.niri.layout.monitor_for_output(o).is_some());
|
||||
|
||||
(width, output)
|
||||
(width, is_full_width, output)
|
||||
} else {
|
||||
error!("window map must happen after initial configure");
|
||||
(None, None)
|
||||
(None, false, None)
|
||||
};
|
||||
|
||||
let parent = window
|
||||
@@ -140,14 +146,16 @@ impl CompositorHandler for State {
|
||||
|
||||
let output = if let Some(p) = parent {
|
||||
// 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 {
|
||||
self.niri
|
||||
.layout
|
||||
.add_window_on_output(output, win, width, false);
|
||||
.add_window_on_output(output, win, width, is_full_width);
|
||||
Some(output)
|
||||
} 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() {
|
||||
|
||||
@@ -89,6 +89,10 @@ pub fn resolve_window_rules(
|
||||
if let Some(x) = rule.open_on_output.as_deref() {
|
||||
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());
|
||||
@@ -503,6 +507,7 @@ impl State {
|
||||
let mon = mon.map(|(mon, _)| mon);
|
||||
|
||||
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.
|
||||
let ws = mon
|
||||
@@ -518,7 +523,13 @@ impl State {
|
||||
}
|
||||
|
||||
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
|
||||
@@ -536,6 +547,7 @@ impl State {
|
||||
*state = InitialConfigureState::Configured {
|
||||
rules,
|
||||
width,
|
||||
is_full_width,
|
||||
output,
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,9 @@ pub enum InitialConfigureState {
|
||||
/// `None` means that the window will pick its own width.
|
||||
width: Option<ColumnWidth>,
|
||||
|
||||
/// Whether the window should open full-width.
|
||||
is_full_width: bool,
|
||||
|
||||
/// Output to open this window on.
|
||||
///
|
||||
/// This can be `None` in cases like:
|
||||
@@ -52,6 +55,9 @@ pub struct ResolvedWindowRules {
|
||||
|
||||
/// Output to open this window on.
|
||||
pub open_on_output: Option<String>,
|
||||
|
||||
/// Whether the window should open full-width.
|
||||
pub open_maximized: Option<bool>,
|
||||
}
|
||||
|
||||
impl Unmapped {
|
||||
|
||||
Reference in New Issue
Block a user