forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB6c9705dIvan Molodetskikh1 year ago2085 commits

mod.rs92 lines, 2.5 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
24impl ResolvedLayerRules {
25 pub const fn empty() -> Self {
26 Self {
27 opacity: None,
28 block_out_from: None,
29 shadow: ShadowRule {
30 off: false,
31 on: false,
32 offset: None,
33 softness: None,
34 spread: None,
35 draw_behind_window: None,
36 color: None,
37 inactive_color: None,
38 },
39 geometry_corner_radius: None,
40 }
41 }
42
43 pub fn compute(rules: &[LayerRule], surface: &LayerSurface, is_at_startup: bool) -> Self {
44 let _span = tracy_client::span!("ResolvedLayerRules::compute");
45
46 let mut resolved = ResolvedLayerRules::empty();
47
48 for rule in rules {
49 let matches = |m: &Match| {
50 if let Some(at_startup) = m.at_startup {
51 if at_startup != is_at_startup {
52 return false;
53 }
54 }
55
56 surface_matches(surface, m)
57 };
58
59 if !(rule.matches.is_empty() || rule.matches.iter().any(matches)) {
60 continue;
61 }
62
63 if rule.excludes.iter().any(matches) {
64 continue;
65 }
66
67 if let Some(x) = rule.opacity {
68 resolved.opacity = Some(x);
69 }
70 if let Some(x) = rule.block_out_from {
71 resolved.block_out_from = Some(x);
72 }
73 if let Some(x) = rule.geometry_corner_radius {
74 resolved.geometry_corner_radius = Some(x);
75 }
76
77 resolved.shadow.merge_with(&rule.shadow);
78 }
79
80 resolved
81 }
82}
83
84fn surface_matches(surface: &LayerSurface, m: &Match) -> bool {
85 if let Some(namespace_re) = &m.namespace {
86 if !namespace_re.0.is_match(surface.namespace()) {
87 return false;
88 }
89 }
90
91 true
92}