forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9ff2f83Ivan Molodetskikh1 year ago2099 commits

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