forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBad3847fIvan Molodetskikh1 year ago2457 commits

mod.rs107 lines, 3.1 KiBHistoryRawDownload
1use niri_config::layer_rule::{LayerRule, Match};
2use niri_config::utils::MergeWith as _;
3use niri_config::{BlockOutFrom, CornerRadius, ShadowRule};
4use smithay::desktop::LayerSurface;
5
6pub mod mapped;
7pub use mapped::MappedLayer;
8
9/// Rules fully resolved for a layer-shell surface.
10#[derive(Debug, PartialEq)]
11pub struct ResolvedLayerRules {
12 /// Extra opacity to draw this layer surface with.
13 pub opacity: Option<f32>,
14
15 /// Whether to block out this layer surface from certain render targets.
16 pub block_out_from: Option<BlockOutFrom>,
17
18 /// Shadow overrides.
19 pub shadow: ShadowRule,
20
21 /// Corner radius to assume this layer surface has.
22 pub geometry_corner_radius: Option<CornerRadius>,
23
24 /// Whether to place this layer surface within the overview backdrop.
25 pub place_within_backdrop: bool,
26
27 /// Whether to bob this window up and down.
28 pub baba_is_float: bool,
29}
30
31impl ResolvedLayerRules {
32 pub const fn empty() -> Self {
33 Self {
34 opacity: None,
35 block_out_from: None,
36 shadow: ShadowRule {
37 off: false,
38 on: false,
39 offset: None,
40 softness: None,
41 spread: None,
42 draw_behind_window: None,
43 color: None,
44 inactive_color: None,
45 },
46 geometry_corner_radius: None,
47 place_within_backdrop: false,
48 baba_is_float: false,
49 }
50 }
51
52 pub fn compute(rules: &[LayerRule], surface: &LayerSurface, is_at_startup: bool) -> Self {
53 let _span = tracy_client::span!("ResolvedLayerRules::compute");
54
55 let mut resolved = ResolvedLayerRules::empty();
56
57 for rule in rules {
58 let matches = |m: &Match| {
59 if let Some(at_startup) = m.at_startup {
60 if at_startup != is_at_startup {
61 return false;
62 }
63 }
64
65 surface_matches(surface, m)
66 };
67
68 if !(rule.matches.is_empty() || rule.matches.iter().any(matches)) {
69 continue;
70 }
71
72 if rule.excludes.iter().any(matches) {
73 continue;
74 }
75
76 if let Some(x) = rule.opacity {
77 resolved.opacity = Some(x);
78 }
79 if let Some(x) = rule.block_out_from {
80 resolved.block_out_from = Some(x);
81 }
82 if let Some(x) = rule.geometry_corner_radius {
83 resolved.geometry_corner_radius = Some(x);
84 }
85 if let Some(x) = rule.place_within_backdrop {
86 resolved.place_within_backdrop = x;
87 }
88 if let Some(x) = rule.baba_is_float {
89 resolved.baba_is_float = x;
90 }
91
92 resolved.shadow.merge_with(&rule.shadow);
93 }
94
95 resolved
96 }
97}
98
99fn surface_matches(surface: &LayerSurface, m: &Match) -> bool {
100 if let Some(namespace_re) = &m.namespace {
101 if !namespace_re.0.is_match(surface.namespace()) {
102 return false;
103 }
104 }
105
106 true
107}