forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBb0eb8adIvan Molodetskikh3 months ago2857 commits

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