niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·97dfd2b·Ivan Molodetskikh·1 year ago·2184 commits
| 1 | use niri_config::layer_rule::{LayerRule, Match}; |
| 2 | use niri_config::{BlockOutFrom, CornerRadius, ShadowRule}; |
| 3 | use smithay::desktop::LayerSurface; |
| 4 | |
| 5 | pub mod mapped; |
| 6 | pub use mapped::MappedLayer; |
| 7 | |
| 8 | /// Rules fully resolved for a layer-shell surface. |
| 9 | #[derive(Debug, PartialEq)] |
| 10 | pub 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 | /// Whether to bob this window up and down. |
| 27 | pub baba_is_float: bool, |
| 28 | } |
| 29 | |
| 30 | impl ResolvedLayerRules { |
| 31 | pub const fn empty() -> Self { |
| 32 | Self { |
| 33 | opacity: None, |
| 34 | block_out_from: None, |
| 35 | shadow: ShadowRule { |
| 36 | off: false, |
| 37 | on: false, |
| 38 | offset: None, |
| 39 | softness: None, |
| 40 | spread: None, |
| 41 | draw_behind_window: None, |
| 42 | color: None, |
| 43 | inactive_color: None, |
| 44 | }, |
| 45 | geometry_corner_radius: None, |
| 46 | place_within_backdrop: false, |
| 47 | baba_is_float: false, |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | pub fn compute(rules: &[LayerRule], surface: &LayerSurface, is_at_startup: bool) -> Self { |
| 52 | let _span = tracy_client::span!("ResolvedLayerRules::compute"); |
| 53 | |
| 54 | let mut resolved = ResolvedLayerRules::empty(); |
| 55 | |
| 56 | for rule in rules { |
| 57 | let matches = |m: &Match| { |
| 58 | if let Some(at_startup) = m.at_startup { |
| 59 | if at_startup != is_at_startup { |
| 60 | return false; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | surface_matches(surface, m) |
| 65 | }; |
| 66 | |
| 67 | if !(rule.matches.is_empty() || rule.matches.iter().any(matches)) { |
| 68 | continue; |
| 69 | } |
| 70 | |
| 71 | if rule.excludes.iter().any(matches) { |
| 72 | continue; |
| 73 | } |
| 74 | |
| 75 | if let Some(x) = rule.opacity { |
| 76 | resolved.opacity = Some(x); |
| 77 | } |
| 78 | if let Some(x) = rule.block_out_from { |
| 79 | resolved.block_out_from = Some(x); |
| 80 | } |
| 81 | if let Some(x) = rule.geometry_corner_radius { |
| 82 | resolved.geometry_corner_radius = Some(x); |
| 83 | } |
| 84 | if let Some(x) = rule.place_within_backdrop { |
| 85 | resolved.place_within_backdrop = x; |
| 86 | } |
| 87 | if let Some(x) = rule.baba_is_float { |
| 88 | resolved.baba_is_float = x; |
| 89 | } |
| 90 | |
| 91 | resolved.shadow.merge_with(&rule.shadow); |
| 92 | } |
| 93 | |
| 94 | resolved |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | fn surface_matches(surface: &LayerSurface, m: &Match) -> bool { |
| 99 | if let Some(namespace_re) = &m.namespace { |
| 100 | if !namespace_re.0.is_match(surface.namespace()) { |
| 101 | return false; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | true |
| 106 | } |