forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBbbbd35eIvan Molodetskikh1 year ago1693 commits

mod.rs69 lines, 1.8 KiBHistoryRawDownload
1use niri_config::layer_rule::{LayerRule, Match};
2use niri_config::BlockOutFrom;
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 window with.
12 pub opacity: Option<f32>,
13 /// Whether to block out this window from certain render targets.
14 pub block_out_from: Option<BlockOutFrom>,
15}
16
17impl ResolvedLayerRules {
18 pub const fn empty() -> Self {
19 Self {
20 opacity: None,
21 block_out_from: None,
22 }
23 }
24
25 pub fn compute(rules: &[LayerRule], surface: &LayerSurface, is_at_startup: bool) -> Self {
26 let _span = tracy_client::span!("ResolvedLayerRules::compute");
27
28 let mut resolved = ResolvedLayerRules::empty();
29
30 for rule in rules {
31 let matches = |m: &Match| {
32 if let Some(at_startup) = m.at_startup {
33 if at_startup != is_at_startup {
34 return false;
35 }
36 }
37
38 surface_matches(surface, m)
39 };
40
41 if !(rule.matches.is_empty() || rule.matches.iter().any(matches)) {
42 continue;
43 }
44
45 if rule.excludes.iter().any(matches) {
46 continue;
47 }
48
49 if let Some(x) = rule.opacity {
50 resolved.opacity = Some(x);
51 }
52 if let Some(x) = rule.block_out_from {
53 resolved.block_out_from = Some(x);
54 }
55 }
56
57 resolved
58 }
59}
60
61fn surface_matches(surface: &LayerSurface, m: &Match) -> bool {
62 if let Some(namespace_re) = &m.namespace {
63 if !namespace_re.0.is_match(surface.namespace()) {
64 return false;
65 }
66 }
67
68 true
69}