Add popups { opacity } window and layer rule
Browse files at this commit5a24aae560e7fe25b74f76624379465a6dc827a6Parent: 91701617 changed files +65 -6
- niri-config/src/layer_rule.rs +3 -0
- niri-config/src/lib.rs +9 -1
- niri-config/src/window_rule.rs +25 -1
- src/layer/mapped.rs +8 -1
- src/layer/mod.rs +6 -1
- src/window/mapped.rs +8 -1
- src/window/mod.rs +6 -1
niri-config/src/layer_rule.rsmodified+3 -0
| @@ -1,5 +1,6 @@ | |||
| 1 | use crate::appearance::{BackgroundEffectRule, BlockOutFrom, CornerRadius, ShadowRule}; | 1 | use crate::appearance::{BackgroundEffectRule, BlockOutFrom, CornerRadius, ShadowRule}; |
| 2 | use crate::utils::RegexEq; | 2 | use crate::utils::RegexEq; |
| 3 | +use crate::window_rule::PopupsRule; | ||
| 3 | 4 | ||
| 4 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | 5 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] |
| 5 | pub struct LayerRule { | 6 | pub struct LayerRule { |
| @@ -22,6 +23,8 @@ pub struct LayerRule { | |||
| 22 | pub baba_is_float: Option<bool>, | 23 | pub baba_is_float: Option<bool>, |
| 23 | #[knuffel(child, default)] | 24 | #[knuffel(child, default)] |
| 24 | pub background_effect: BackgroundEffectRule, | 25 | pub background_effect: BackgroundEffectRule, |
| 26 | + #[knuffel(child, default)] | ||
| 27 | + pub popups: PopupsRule, | ||
| 25 | } | 28 | } |
| 26 | 29 | ||
| 27 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | 30 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] |
niri-config/src/lib.rsmodified+9 -1
| @@ -59,7 +59,9 @@ use crate::recent_windows::RecentWindowsPart; | |||
| 59 | pub use crate::recent_windows::{MruDirection, MruFilter, MruPreviews, MruScope, RecentWindows}; | 59 | pub use crate::recent_windows::{MruDirection, MruFilter, MruPreviews, MruScope, RecentWindows}; |
| 60 | pub use crate::utils::FloatOrInt; | 60 | pub use crate::utils::FloatOrInt; |
| 61 | use crate::utils::{Flag, MergeWith as _}; | 61 | use crate::utils::{Flag, MergeWith as _}; |
| 62 | -pub use crate::window_rule::{FloatingPosition, RelativeTo, WindowRule}; | 62 | +pub use crate::window_rule::{ |
| 63 | + FloatingPosition, PopupsRule, RelativeTo, ResolvedPopupsRules, WindowRule, | ||
| 64 | +}; | ||
| 63 | pub use crate::workspace::{Workspace, WorkspaceLayoutPart}; | 65 | pub use crate::workspace::{Workspace, WorkspaceLayoutPart}; |
| 64 | 66 | ||
| 65 | const RECURSION_LIMIT: u8 = 10; | 67 | const RECURSION_LIMIT: u8 = 10; |
| @@ -1860,6 +1862,9 @@ mod tests { | |||
| 1860 | noise: None, | 1862 | noise: None, |
| 1861 | saturation: None, | 1863 | saturation: None, |
| 1862 | }, | 1864 | }, |
| 1865 | + popups: PopupsRule { | ||
| 1866 | + opacity: None, | ||
| 1867 | + }, | ||
| 1863 | }, | 1868 | }, |
| 1864 | ], | 1869 | ], |
| 1865 | layer_rules: [ | 1870 | layer_rules: [ |
| @@ -1901,6 +1906,9 @@ mod tests { | |||
| 1901 | noise: None, | 1906 | noise: None, |
| 1902 | saturation: None, | 1907 | saturation: None, |
| 1903 | }, | 1908 | }, |
| 1909 | + popups: PopupsRule { | ||
| 1910 | + opacity: None, | ||
| 1911 | + }, | ||
| 1904 | }, | 1912 | }, |
| 1905 | ], | 1913 | ], |
| 1906 | binds: Binds( | 1914 | binds: Binds( |
niri-config/src/window_rule.rsmodified+25 -1
| @@ -4,7 +4,7 @@ use crate::appearance::{ | |||
| 4 | BackgroundEffectRule, BlockOutFrom, BorderRule, CornerRadius, ShadowRule, TabIndicatorRule, | 4 | BackgroundEffectRule, BlockOutFrom, BorderRule, CornerRadius, ShadowRule, TabIndicatorRule, |
| 5 | }; | 5 | }; |
| 6 | use crate::layout::DefaultPresetSize; | 6 | use crate::layout::DefaultPresetSize; |
| 7 | -use crate::utils::RegexEq; | 7 | +use crate::utils::{MergeWith, RegexEq}; |
| 8 | use crate::FloatOrInt; | 8 | use crate::FloatOrInt; |
| 9 | 9 | ||
| 10 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | 10 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] |
| @@ -76,6 +76,30 @@ pub struct WindowRule { | |||
| 76 | pub tiled_state: Option<bool>, | 76 | pub tiled_state: Option<bool>, |
| 77 | #[knuffel(child, default)] | 77 | #[knuffel(child, default)] |
| 78 | pub background_effect: BackgroundEffectRule, | 78 | pub background_effect: BackgroundEffectRule, |
| 79 | + #[knuffel(child, default)] | ||
| 80 | + pub popups: PopupsRule, | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +/// Rules for popup surfaces. | ||
| 84 | +#[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | ||
| 85 | +pub struct PopupsRule { | ||
| 86 | + #[knuffel(child, unwrap(argument))] | ||
| 87 | + pub opacity: Option<f32>, | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | +/// Resolved popup-specific rules. | ||
| 91 | +#[derive(Debug, Default, Clone, Copy, PartialEq)] | ||
| 92 | +pub struct ResolvedPopupsRules { | ||
| 93 | + /// Extra opacity to draw popups with. | ||
| 94 | + pub opacity: Option<f32>, | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +impl MergeWith<PopupsRule> for ResolvedPopupsRules { | ||
| 98 | + fn merge_with(&mut self, part: &PopupsRule) { | ||
| 99 | + if let Some(x) = part.opacity { | ||
| 100 | + self.opacity = Some(x); | ||
| 101 | + } | ||
| 102 | + } | ||
| 79 | } | 103 | } |
| 80 | 104 | ||
| 81 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] | 105 | #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)] |
src/layer/mapped.rsmodified+8 -1
| @@ -2,7 +2,7 @@ use niri_config::utils::MergeWith as _; | |||
| 2 | use niri_config::{Config, LayerRule}; | 2 | use niri_config::{Config, LayerRule}; |
| 3 | use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; | 3 | use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; |
| 4 | use smithay::backend::renderer::element::Kind; | 4 | use smithay::backend::renderer::element::Kind; |
| 5 | -use smithay::desktop::{LayerSurface, PopupManager}; | 5 | +use smithay::desktop::{LayerSurface, PopupKind, PopupManager}; |
| 6 | use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; | 6 | use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; |
| 7 | use smithay::wayland::compositor::{remove_pre_commit_hook, HookId}; | 7 | use smithay::wayland::compositor::{remove_pre_commit_hook, HookId}; |
| 8 | use smithay::wayland::shell::wlr_layer::{ExclusiveZone, Layer}; | 8 | use smithay::wayland::shell::wlr_layer::{ExclusiveZone, Layer}; |
| @@ -275,6 +275,13 @@ impl MappedLayer { | |||
| 275 | 275 | ||
| 276 | let surface = self.surface.wl_surface(); | 276 | let surface = self.surface.wl_surface(); |
| 277 | for (popup, offset) in PopupManager::popups_for_surface(surface) { | 277 | for (popup, offset) in PopupManager::popups_for_surface(surface) { |
| 278 | + let popup_rules = match popup { | ||
| 279 | + PopupKind::Xdg(_) => self.rules.popups, | ||
| 280 | + // IME popups aren't affected by rules for regular popups. | ||
| 281 | + PopupKind::InputMethod(_) => niri_config::ResolvedPopupsRules::default(), | ||
| 282 | + }; | ||
| 283 | + let alpha = alpha * popup_rules.opacity.unwrap_or(1.).clamp(0., 1.); | ||
| 284 | + | ||
| 278 | let surface = popup.wl_surface(); | 285 | let surface = popup.wl_surface(); |
| 279 | let popup_geo = popup.geometry(); | 286 | let popup_geo = popup.geometry(); |
| 280 | let surface_loc = location + (offset - popup_geo.loc).to_f64(); | 287 | let surface_loc = location + (offset - popup_geo.loc).to_f64(); |
src/layer/mod.rsmodified+6 -1
| @@ -1,6 +1,6 @@ | |||
| 1 | use niri_config::layer_rule::{LayerRule, Match}; | 1 | use niri_config::layer_rule::{LayerRule, Match}; |
| 2 | use niri_config::utils::MergeWith as _; | 2 | use niri_config::utils::MergeWith as _; |
| 3 | -use niri_config::{BackgroundEffect, BlockOutFrom, CornerRadius, ShadowRule}; | 3 | +use niri_config::{BackgroundEffect, BlockOutFrom, CornerRadius, ResolvedPopupsRules, ShadowRule}; |
| 4 | use smithay::desktop::LayerSurface; | 4 | use smithay::desktop::LayerSurface; |
| 5 | use smithay::wayland::shell::wlr_layer::Layer; | 5 | use smithay::wayland::shell::wlr_layer::Layer; |
| 6 | 6 | ||
| @@ -30,6 +30,9 @@ pub struct ResolvedLayerRules { | |||
| 30 | 30 | ||
| 31 | /// Background effect configuration. | 31 | /// Background effect configuration. |
| 32 | pub background_effect: BackgroundEffect, | 32 | pub background_effect: BackgroundEffect, |
| 33 | + | ||
| 34 | + /// Rules for this layer surface's popups. | ||
| 35 | + pub popups: ResolvedPopupsRules, | ||
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | impl ResolvedLayerRules { | 38 | impl ResolvedLayerRules { |
| @@ -78,6 +81,8 @@ impl ResolvedLayerRules { | |||
| 78 | resolved | 81 | resolved |
| 79 | .background_effect | 82 | .background_effect |
| 80 | .merge_with(&rule.background_effect); | 83 | .merge_with(&rule.background_effect); |
| 84 | + | ||
| 85 | + resolved.popups.merge_with(&rule.popups); | ||
| 81 | } | 86 | } |
| 82 | 87 | ||
| 83 | resolved | 88 | resolved |
src/window/mapped.rsmodified+8 -1
| @@ -6,7 +6,7 @@ use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; | |||
| 6 | use smithay::backend::renderer::element::Kind; | 6 | use smithay::backend::renderer::element::Kind; |
| 7 | use smithay::backend::renderer::gles::GlesRenderer; | 7 | use smithay::backend::renderer::gles::GlesRenderer; |
| 8 | use smithay::desktop::space::SpaceElement as _; | 8 | use smithay::desktop::space::SpaceElement as _; |
| 9 | -use smithay::desktop::{PopupManager, Window}; | 9 | +use smithay::desktop::{PopupKind, PopupManager, Window}; |
| 10 | use smithay::output::{self, Output}; | 10 | use smithay::output::{self, Output}; |
| 11 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; | 11 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; |
| 12 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 12 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| @@ -669,6 +669,13 @@ impl LayoutElement for Mapped { | |||
| 669 | 669 | ||
| 670 | let surface = self.toplevel().wl_surface(); | 670 | let surface = self.toplevel().wl_surface(); |
| 671 | for (popup, offset) in PopupManager::popups_for_surface(surface) { | 671 | for (popup, offset) in PopupManager::popups_for_surface(surface) { |
| 672 | + let popup_rules = match popup { | ||
| 673 | + PopupKind::Xdg(_) => self.rules.popups, | ||
| 674 | + // IME popups aren't affected by rules for regular popups. | ||
| 675 | + PopupKind::InputMethod(_) => niri_config::ResolvedPopupsRules::default(), | ||
| 676 | + }; | ||
| 677 | + let alpha = alpha * popup_rules.opacity.unwrap_or(1.).clamp(0., 1.); | ||
| 678 | + | ||
| 672 | let surface = popup.wl_surface(); | 679 | let surface = popup.wl_surface(); |
| 673 | let popup_geo = popup.geometry(); | 680 | let popup_geo = popup.geometry(); |
| 674 | let surface_loc = location + (offset - popup.geometry().loc).to_f64(); | 681 | let surface_loc = location + (offset - popup.geometry().loc).to_f64(); |
src/window/mod.rsmodified+6 -1
| @@ -4,7 +4,7 @@ use niri_config::utils::MergeWith as _; | |||
| 4 | use niri_config::window_rule::{Match, WindowRule}; | 4 | use niri_config::window_rule::{Match, WindowRule}; |
| 5 | use niri_config::{ | 5 | use niri_config::{ |
| 6 | BackgroundEffect, BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, PresetSize, | 6 | BackgroundEffect, BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, PresetSize, |
| 7 | - ShadowRule, TabIndicatorRule, | 7 | + ResolvedPopupsRules, ShadowRule, TabIndicatorRule, |
| 8 | }; | 8 | }; |
| 9 | use niri_ipc::ColumnDisplay; | 9 | use niri_ipc::ColumnDisplay; |
| 10 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 10 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| @@ -122,6 +122,9 @@ pub struct ResolvedWindowRules { | |||
| 122 | 122 | ||
| 123 | /// Background effect configuration. | 123 | /// Background effect configuration. |
| 124 | pub background_effect: BackgroundEffect, | 124 | pub background_effect: BackgroundEffect, |
| 125 | + | ||
| 126 | + /// Rules for this window's popups. | ||
| 127 | + pub popups: ResolvedPopupsRules, | ||
| 125 | } | 128 | } |
| 126 | 129 | ||
| 127 | impl<'a> WindowRef<'a> { | 130 | impl<'a> WindowRef<'a> { |
| @@ -303,6 +306,8 @@ impl ResolvedWindowRules { | |||
| 303 | resolved | 306 | resolved |
| 304 | .background_effect | 307 | .background_effect |
| 305 | .merge_with(&rule.background_effect); | 308 | .merge_with(&rule.background_effect); |
| 309 | + | ||
| 310 | + resolved.popups.merge_with(&rule.popups); | ||
| 306 | } | 311 | } |
| 307 | 312 | ||
| 308 | resolved.open_on_output = open_on_output.map(|x| x.to_owned()); | 313 | resolved.open_on_output = open_on_output.map(|x| x.to_owned()); |