Implement layer rules: opacity and block-out-from

This commit is contained in:
Ivan Molodetskikh
2024-11-14 11:33:08 +03:00
parent fbbd3ba349
commit 1a0612cbfd
11 changed files with 401 additions and 17 deletions
+22
View File
@@ -0,0 +1,22 @@
use crate::{BlockOutFrom, RegexEq};
#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
pub struct LayerRule {
#[knuffel(children(name = "match"))]
pub matches: Vec<Match>,
#[knuffel(children(name = "exclude"))]
pub excludes: Vec<Match>,
#[knuffel(child, unwrap(argument))]
pub opacity: Option<f32>,
#[knuffel(child, unwrap(argument))]
pub block_out_from: Option<BlockOutFrom>,
}
#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
pub struct Match {
#[knuffel(property, str)]
pub namespace: Option<RegexEq>,
#[knuffel(property)]
pub at_startup: Option<bool>,
}
+21
View File
@@ -10,6 +10,7 @@ use std::time::Duration;
use bitflags::bitflags;
use knuffel::errors::DecodeError;
use knuffel::Decode as _;
use layer_rule::LayerRule;
use miette::{miette, Context, IntoDiagnostic, NarratableReportHandler};
use niri_ipc::{ConfiguredMode, LayoutSwitchTarget, SizeChange, Transform, WorkspaceReferenceArg};
use smithay::backend::renderer::Color32F;
@@ -20,6 +21,8 @@ use smithay::reexports::input;
pub const DEFAULT_BACKGROUND_COLOR: Color = Color::from_array_unpremul([0.2, 0.2, 0.2, 1.]);
pub mod layer_rule;
mod utils;
pub use utils::RegexEq;
@@ -53,6 +56,8 @@ pub struct Config {
pub environment: Environment,
#[knuffel(children(name = "window-rule"))]
pub window_rules: Vec<WindowRule>,
#[knuffel(children(name = "layer-rule"))]
pub layer_rules: Vec<LayerRule>,
#[knuffel(child, default)]
pub binds: Binds,
#[knuffel(child, default)]
@@ -3119,6 +3124,11 @@ mod tests {
}
}
layer-rule {
match namespace="^notifications$"
block-out-from "screencast"
}
binds {
Mod+T allow-when-locked=true { spawn "alacritty"; }
Mod+Q { close-window; }
@@ -3391,6 +3401,17 @@ mod tests {
},
..Default::default()
}],
layer_rules: vec![
LayerRule {
matches: vec![layer_rule::Match {
namespace: Some(RegexEq::from_str("^notifications$").unwrap()),
at_startup: None,
}],
excludes: vec![],
opacity: None,
block_out_from: Some(BlockOutFrom::Screencast),
}
],
workspaces: vec![
Workspace {
name: WorkspaceName("workspace-1".to_string()),