Implement ext-background-effect protocol
Browse files at this commit931123f38c700c2e8d2f87c935e24741a889a7f7Parent: 73c0ce712 changed files +612 -12
- niri-config/src/appearance.rs +2 -1
- src/handlers/background_effect.rs +123 -0
- src/handlers/mod.rs +1 -0
- src/layer/mapped.rs +5 -0
- src/layout/mod.rs +1 -0
- src/layout/tile.rs +2 -0
- src/niri.rs +4 -0
- src/render_helpers/background_effect.rs +103 -8
- src/render_helpers/xray.rs +29 -1
- src/utils/mod.rs +16 -1
- src/utils/region.rs +320 -0
- src/window/mapped.rs +6 -1
niri-config/src/appearance.rsmodified+2 -1
| @@ -1079,7 +1079,8 @@ pub struct BackgroundEffect { | |||
| 1079 | 1079 | ||
| 1080 | /// Whether to blur the background. | 1080 | /// Whether to blur the background. |
| 1081 | /// | 1081 | /// |
| 1082 | - /// - `None`: no blur | 1082 | + /// - `None`: blur when the window/layer requests it (e.g. through ext-background-effect |
| 1083 | + /// protocol) | ||
| 1083 | /// - `Some(false)`: never blur | 1084 | /// - `Some(false)`: never blur |
| 1084 | /// - `Some(true)`: always blur | 1085 | /// - `Some(true)`: always blur |
| 1085 | pub blur: Option<bool>, | 1086 | pub blur: Option<bool>, |
src/handlers/background_effect.rsadded+123 -0
| @@ -0,0 +1,123 @@ | |||
| 1 | +use std::sync::{Arc, Mutex}; | ||
| 2 | + | ||
| 3 | +use smithay::delegate_background_effect; | ||
| 4 | +use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | ||
| 5 | +use smithay::utils::{Logical, Rectangle}; | ||
| 6 | +use smithay::wayland::background_effect::{ | ||
| 7 | + self, BackgroundEffectSurfaceCachedState, ExtBackgroundEffectHandler, | ||
| 8 | +}; | ||
| 9 | +use smithay::wayland::compositor::{ | ||
| 10 | + add_post_commit_hook, with_states, RegionAttributes, SurfaceData, | ||
| 11 | +}; | ||
| 12 | + | ||
| 13 | +use crate::niri::State; | ||
| 14 | +use crate::utils::region::region_to_non_overlapping_rects; | ||
| 15 | + | ||
| 16 | +/// Per-surface cache for processed blur region (non-overlapping rects). | ||
| 17 | +#[derive(Default)] | ||
| 18 | +struct CachedBlurRegionUserData(Mutex<CachedBlurRegionInner>); | ||
| 19 | + | ||
| 20 | +#[derive(Default)] | ||
| 21 | +struct CachedBlurRegionInner { | ||
| 22 | + /// Whether a region change is pending to be committed. | ||
| 23 | + pending_dirty: bool, | ||
| 24 | + /// Whether the region must be recomputed. | ||
| 25 | + dirty: bool, | ||
| 26 | + /// Whether the post-commit hook has been registered for this surface. | ||
| 27 | + hook_registered: bool, | ||
| 28 | + /// Cached non-overlapping rects in surface-local coordinates. | ||
| 29 | + /// | ||
| 30 | + /// `None` means there's no blur region. | ||
| 31 | + rects: Option<Arc<Vec<Rectangle<i32, Logical>>>>, | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +/// Gets the cached blur region for a surface, lazily recomputing if dirty. | ||
| 35 | +pub fn get_cached_blur_region(states: &SurfaceData) -> Option<Arc<Vec<Rectangle<i32, Logical>>>> { | ||
| 36 | + let cache = states | ||
| 37 | + .data_map | ||
| 38 | + .get_or_insert_threadsafe(CachedBlurRegionUserData::default); | ||
| 39 | + let mut guard = cache.0.lock().unwrap(); | ||
| 40 | + | ||
| 41 | + if guard.dirty { | ||
| 42 | + guard.dirty = false; | ||
| 43 | + recompute_blur_region(states, &mut guard); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + guard.rects.clone() | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +fn recompute_blur_region(states: &SurfaceData, inner: &mut CachedBlurRegionInner) { | ||
| 50 | + let cached = &states.cached_state; | ||
| 51 | + | ||
| 52 | + let rects = if let Some(arc) = &mut inner.rects { | ||
| 53 | + if Arc::strong_count(arc) > 1 { | ||
| 54 | + debug!("cloning rects due to non-unique reference"); | ||
| 55 | + } | ||
| 56 | + arc | ||
| 57 | + } else { | ||
| 58 | + inner.rects.insert(Arc::new(Vec::new())) | ||
| 59 | + }; | ||
| 60 | + let rects = Arc::make_mut(rects); | ||
| 61 | + | ||
| 62 | + if cached.has::<BackgroundEffectSurfaceCachedState>() { | ||
| 63 | + let mut guard = cached.get::<BackgroundEffectSurfaceCachedState>(); | ||
| 64 | + if let Some(region) = &guard.current().blur_region { | ||
| 65 | + region_to_non_overlapping_rects(region, rects); | ||
| 66 | + } else { | ||
| 67 | + inner.rects = None; | ||
| 68 | + } | ||
| 69 | + return; | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + inner.rects = None; | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +fn mark_blur_region_pending_dirty(wl_surface: &WlSurface) { | ||
| 76 | + let register_hook = with_states(wl_surface, |states| { | ||
| 77 | + let cache = states | ||
| 78 | + .data_map | ||
| 79 | + .get_or_insert_threadsafe(CachedBlurRegionUserData::default); | ||
| 80 | + let mut guard = cache.0.lock().unwrap(); | ||
| 81 | + guard.pending_dirty = true; | ||
| 82 | + | ||
| 83 | + if guard.hook_registered { | ||
| 84 | + false | ||
| 85 | + } else { | ||
| 86 | + guard.hook_registered = true; | ||
| 87 | + true | ||
| 88 | + } | ||
| 89 | + }); | ||
| 90 | + | ||
| 91 | + if register_hook { | ||
| 92 | + add_post_commit_hook::<State, _>(wl_surface, |_state, _dh, surface| { | ||
| 93 | + with_states(surface, |states| { | ||
| 94 | + if let Some(cache) = states.data_map.get::<CachedBlurRegionUserData>() { | ||
| 95 | + let mut guard = cache.0.lock().unwrap(); | ||
| 96 | + if guard.pending_dirty { | ||
| 97 | + guard.pending_dirty = false; | ||
| 98 | + guard.dirty = true; | ||
| 99 | + | ||
| 100 | + crate::render_helpers::background_effect::damage_surface(states); | ||
| 101 | + } | ||
| 102 | + } else { | ||
| 103 | + error!("unexpected missing CachedBlurRegionUserData"); | ||
| 104 | + } | ||
| 105 | + }); | ||
| 106 | + }); | ||
| 107 | + } | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +impl ExtBackgroundEffectHandler for State { | ||
| 111 | + fn capabilities(&self) -> background_effect::Capability { | ||
| 112 | + background_effect::Capability::Blur | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + fn set_blur_region(&mut self, wl_surface: WlSurface, _region: RegionAttributes) { | ||
| 116 | + mark_blur_region_pending_dirty(&wl_surface); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + fn unset_blur_region(&mut self, wl_surface: WlSurface) { | ||
| 120 | + mark_blur_region_pending_dirty(&wl_surface); | ||
| 121 | + } | ||
| 122 | +} | ||
| 123 | +delegate_background_effect!(State); | ||
src/handlers/mod.rsmodified+1 -0
| @@ -1,3 +1,4 @@ | |||
| 1 | +pub mod background_effect; | ||
| 1 | mod compositor; | 2 | mod compositor; |
| 2 | mod layer_shell; | 3 | mod layer_shell; |
| 3 | mod xdg_shell; | 4 | mod xdg_shell; |
src/layer/mapped.rsmodified+5 -0
| @@ -233,6 +233,8 @@ impl MappedLayer { | |||
| 233 | .render(ctx.renderer, location, &mut |elem| push(elem.into())); | 233 | .render(ctx.renderer, location, &mut |elem| push(elem.into())); |
| 234 | 234 | ||
| 235 | let geometry = Rectangle::new(location, self.block_out_buffer.size()); | 235 | let geometry = Rectangle::new(location, self.block_out_buffer.size()); |
| 236 | + let surface_off = Point::new(0., 0.); // No geometry on layer surfaces. | ||
| 237 | + let surface_anim_scale = Scale::from(1.); | ||
| 236 | let radius = self.rules.geometry_corner_radius.unwrap_or_default(); | 238 | let radius = self.rules.geometry_corner_radius.unwrap_or_default(); |
| 237 | background_effect::render_for_tile( | 239 | background_effect::render_for_tile( |
| 238 | ctx.as_gles(), | 240 | ctx.as_gles(), |
| @@ -240,9 +242,12 @@ impl MappedLayer { | |||
| 240 | self.scale, | 242 | self.scale, |
| 241 | false, | 243 | false, |
| 242 | surface, | 244 | surface, |
| 245 | + surface_off, | ||
| 246 | + surface_anim_scale, | ||
| 243 | self.blur_config, | 247 | self.blur_config, |
| 244 | radius, | 248 | radius, |
| 245 | self.rules.background_effect, | 249 | self.rules.background_effect, |
| 250 | + should_block_out, | ||
| 246 | xray_pos, | 251 | xray_pos, |
| 247 | &mut |elem| push(elem.into()), | 252 | &mut |elem| push(elem.into()), |
| 248 | ); | 253 | ); |
src/layout/mod.rsmodified+1 -0
| @@ -203,6 +203,7 @@ pub trait LayoutElement { | |||
| 203 | _geometry: Rectangle<f64, Logical>, | 203 | _geometry: Rectangle<f64, Logical>, |
| 204 | _scale: f64, | 204 | _scale: f64, |
| 205 | _clip_to_geometry: bool, | 205 | _clip_to_geometry: bool, |
| 206 | + _surface_anim_scale: Scale<f64>, | ||
| 206 | _radius: CornerRadius, | 207 | _radius: CornerRadius, |
| 207 | _xray_pos: XrayPos, | 208 | _xray_pos: XrayPos, |
| 208 | _push: &mut dyn FnMut(BackgroundEffectElement), | 209 | _push: &mut dyn FnMut(BackgroundEffectElement), |
src/layout/tile.rsmodified+2 -0
| @@ -1282,11 +1282,13 @@ impl<W: LayoutElement> Tile<W> { | |||
| 1282 | .render(ctx.renderer, location, &mut |elem| push(elem.into())); | 1282 | .render(ctx.renderer, location, &mut |elem| push(elem.into())); |
| 1283 | } | 1283 | } |
| 1284 | 1284 | ||
| 1285 | + let surface_anim_scale = animated_window_size / window_size; | ||
| 1285 | self.window.render_background_effect( | 1286 | self.window.render_background_effect( |
| 1286 | ctx.as_gles(), | 1287 | ctx.as_gles(), |
| 1287 | area, | 1288 | area, |
| 1288 | self.scale, | 1289 | self.scale, |
| 1289 | clip_to_geometry, | 1290 | clip_to_geometry, |
| 1291 | + surface_anim_scale, | ||
| 1290 | radius, | 1292 | radius, |
| 1291 | xray_pos, | 1293 | xray_pos, |
| 1292 | &mut |elem| push(elem.into()), | 1294 | &mut |elem| push(elem.into()), |
src/niri.rsmodified+4 -0
| @@ -71,6 +71,7 @@ use smithay::utils::{ | |||
| 71 | ClockSource, IsAlive as _, Logical, Monotonic, Physical, Point, Rectangle, Scale, Size, | 71 | ClockSource, IsAlive as _, Logical, Monotonic, Physical, Point, Rectangle, Scale, Size, |
| 72 | Transform, SERIAL_COUNTER, | 72 | Transform, SERIAL_COUNTER, |
| 73 | }; | 73 | }; |
| 74 | +use smithay::wayland::background_effect::BackgroundEffectState; | ||
| 74 | use smithay::wayland::compositor::{ | 75 | use smithay::wayland::compositor::{ |
| 75 | with_states, with_surface_tree_downward, CompositorClientState, CompositorHandler, | 76 | with_states, with_surface_tree_downward, CompositorClientState, CompositorHandler, |
| 76 | CompositorState, HookId, SurfaceData, TraversalAction, | 77 | CompositorState, HookId, SurfaceData, TraversalAction, |
| @@ -280,6 +281,7 @@ pub struct Niri { | |||
| 280 | pub screencopy_state: ScreencopyManagerState, | 281 | pub screencopy_state: ScreencopyManagerState, |
| 281 | pub output_management_state: OutputManagementManagerState, | 282 | pub output_management_state: OutputManagementManagerState, |
| 282 | pub viewporter_state: ViewporterState, | 283 | pub viewporter_state: ViewporterState, |
| 284 | + pub background_effect_state: BackgroundEffectState, | ||
| 283 | pub xdg_foreign_state: XdgForeignState, | 285 | pub xdg_foreign_state: XdgForeignState, |
| 284 | pub shm_state: ShmState, | 286 | pub shm_state: ShmState, |
| 285 | pub output_manager_state: OutputManagerState, | 287 | pub output_manager_state: OutputManagerState, |
| @@ -2329,6 +2331,7 @@ impl Niri { | |||
| 2329 | let screencopy_state = | 2331 | let screencopy_state = |
| 2330 | ScreencopyManagerState::new::<State, _>(&display_handle, client_is_unrestricted); | 2332 | ScreencopyManagerState::new::<State, _>(&display_handle, client_is_unrestricted); |
| 2331 | let viewporter_state = ViewporterState::new::<State>(&display_handle); | 2333 | let viewporter_state = ViewporterState::new::<State>(&display_handle); |
| 2334 | + let background_effect_state = BackgroundEffectState::new::<State>(&display_handle); | ||
| 2332 | let xdg_foreign_state = XdgForeignState::new::<State>(&display_handle); | 2335 | let xdg_foreign_state = XdgForeignState::new::<State>(&display_handle); |
| 2333 | 2336 | ||
| 2334 | let is_tty = matches!(backend, Backend::Tty(_)); | 2337 | let is_tty = matches!(backend, Backend::Tty(_)); |
| @@ -2512,6 +2515,7 @@ impl Niri { | |||
| 2512 | output_management_state, | 2515 | output_management_state, |
| 2513 | screencopy_state, | 2516 | screencopy_state, |
| 2514 | viewporter_state, | 2517 | viewporter_state, |
| 2518 | + background_effect_state, | ||
| 2515 | xdg_foreign_state, | 2519 | xdg_foreign_state, |
| 2516 | text_input_state, | 2520 | text_input_state, |
| 2517 | input_method_state, | 2521 | input_method_state, |
src/render_helpers/background_effect.rsmodified+103 -8
| @@ -1,15 +1,18 @@ | |||
| 1 | -use std::sync::Mutex; | 1 | +use std::sync::{Arc, Mutex}; |
| 2 | 2 | ||
| 3 | use niri_config::CornerRadius; | 3 | use niri_config::CornerRadius; |
| 4 | use smithay::backend::renderer::gles::GlesRenderer; | 4 | use smithay::backend::renderer::gles::GlesRenderer; |
| 5 | -use smithay::utils::{Logical, Rectangle}; | 5 | +use smithay::utils::{Logical, Point, Rectangle, Scale}; |
| 6 | use smithay::wayland::compositor::{with_states, SurfaceData}; | 6 | use smithay::wayland::compositor::{with_states, SurfaceData}; |
| 7 | use wayland_server::protocol::wl_surface::WlSurface; | 7 | use wayland_server::protocol::wl_surface::WlSurface; |
| 8 | 8 | ||
| 9 | +use crate::handlers::background_effect::get_cached_blur_region; | ||
| 9 | use crate::niri_render_elements; | 10 | use crate::niri_render_elements; |
| 10 | use crate::render_helpers::damage::ExtraDamage; | 11 | use crate::render_helpers::damage::ExtraDamage; |
| 11 | use crate::render_helpers::xray::{XrayElement, XrayPos}; | 12 | use crate::render_helpers::xray::{XrayElement, XrayPos}; |
| 12 | use crate::render_helpers::RenderCtx; | 13 | use crate::render_helpers::RenderCtx; |
| 14 | +use crate::utils::region::TransformedRegion; | ||
| 15 | +use crate::utils::surface_geo; | ||
| 13 | 16 | ||
| 14 | #[derive(Debug)] | 17 | #[derive(Debug)] |
| 15 | pub struct BackgroundEffect { | 18 | pub struct BackgroundEffect { |
| @@ -46,6 +49,10 @@ impl Options { | |||
| 46 | pub struct RenderParams { | 49 | pub struct RenderParams { |
| 47 | /// Geometry of the background effect. | 50 | /// Geometry of the background effect. |
| 48 | pub geometry: Rectangle<f64, Logical>, | 51 | pub geometry: Rectangle<f64, Logical>, |
| 52 | + /// Effect subregion, will be clipped to `geometry`. | ||
| 53 | + /// | ||
| 54 | + /// `subregion.iter()` should return `geometry`-relative rectangles. | ||
| 55 | + pub subregion: Option<TransformedRegion>, | ||
| 49 | /// Geometry and radius for clipping in the same coordinate space as `geometry`. | 56 | /// Geometry and radius for clipping in the same coordinate space as `geometry`. |
| 50 | pub clip: Option<(Rectangle<f64, Logical>, CornerRadius)>, | 57 | pub clip: Option<(Rectangle<f64, Logical>, CornerRadius)>, |
| 51 | /// Scale to use for rounding to physical pixels. | 58 | /// Scale to use for rounding to physical pixels. |
| @@ -80,6 +87,11 @@ impl BackgroundEffect { | |||
| 80 | } | 87 | } |
| 81 | } | 88 | } |
| 82 | 89 | ||
| 90 | + /// Damage the background effect, for example when a blur subregion changes. | ||
| 91 | + pub fn damage(&mut self) { | ||
| 92 | + self.damage.damage_all(); | ||
| 93 | + } | ||
| 94 | + | ||
| 83 | pub fn update_config(&mut self, config: niri_config::Blur) { | 95 | pub fn update_config(&mut self, config: niri_config::Blur) { |
| 84 | if self.blur_config == config { | 96 | if self.blur_config == config { |
| 85 | return; | 97 | return; |
| @@ -93,9 +105,17 @@ impl BackgroundEffect { | |||
| 93 | &mut self, | 105 | &mut self, |
| 94 | corner_radius: CornerRadius, | 106 | corner_radius: CornerRadius, |
| 95 | effect: niri_config::BackgroundEffect, | 107 | effect: niri_config::BackgroundEffect, |
| 108 | + has_blur_region: bool, | ||
| 96 | ) { | 109 | ) { |
| 110 | + // If the surface explicitly requests a blur region, default blur to true. | ||
| 111 | + let blur = if has_blur_region { | ||
| 112 | + effect.blur != Some(false) | ||
| 113 | + } else { | ||
| 114 | + effect.blur == Some(true) | ||
| 115 | + }; | ||
| 116 | + | ||
| 97 | let mut options = Options { | 117 | let mut options = Options { |
| 98 | - blur: effect.blur == Some(true), | 118 | + blur, |
| 99 | xray: effect.xray == Some(true), | 119 | xray: effect.xray == Some(true), |
| 100 | noise: effect.noise, | 120 | noise: effect.noise, |
| 101 | saturation: effect.saturation, | 121 | saturation: effect.saturation, |
| @@ -171,6 +191,62 @@ impl BackgroundEffect { | |||
| 171 | } | 191 | } |
| 172 | } | 192 | } |
| 173 | 193 | ||
| 194 | +fn render_params_for_tile( | ||
| 195 | + geometry: Rectangle<f64, Logical>, | ||
| 196 | + scale: f64, | ||
| 197 | + clip_to_geometry: bool, | ||
| 198 | + block_out: bool, | ||
| 199 | + blur_region: Option<Arc<Vec<Rectangle<i32, Logical>>>>, | ||
| 200 | + surface_geo: Rectangle<f64, Logical>, | ||
| 201 | + surface_anim_scale: Scale<f64>, | ||
| 202 | +) -> Option<RenderParams> { | ||
| 203 | + // Effects not requested by the surface itself are drawn to match the geometry. | ||
| 204 | + let mut clip = true; | ||
| 205 | + | ||
| 206 | + let mut effect_geometry = geometry; | ||
| 207 | + let mut subregion = None; | ||
| 208 | + if let Some(rects) = blur_region { | ||
| 209 | + if rects.is_empty() { | ||
| 210 | + // Surface has a set, but empty blur region. | ||
| 211 | + return None; | ||
| 212 | + } else { | ||
| 213 | + // If the surface itself requests the effects, apply different defaults. | ||
| 214 | + clip = clip_to_geometry; | ||
| 215 | + | ||
| 216 | + // Use geometry-shaped blur for blocked-out windows to avoid unintentionally | ||
| 217 | + // leaking any surface shapes. We render those windows as geometry-shaped solid | ||
| 218 | + // rectangles anyway. | ||
| 219 | + if block_out { | ||
| 220 | + clip = true; | ||
| 221 | + } else { | ||
| 222 | + let mut surface_geo = surface_geo.upscale(surface_anim_scale); | ||
| 223 | + surface_geo.loc += geometry.loc; | ||
| 224 | + | ||
| 225 | + subregion = Some(TransformedRegion { | ||
| 226 | + rects, | ||
| 227 | + scale: surface_anim_scale, | ||
| 228 | + offset: surface_geo.loc, | ||
| 229 | + }); | ||
| 230 | + | ||
| 231 | + surface_geo = surface_geo | ||
| 232 | + .to_physical_precise_round(scale) | ||
| 233 | + .to_logical(scale); | ||
| 234 | + effect_geometry = surface_geo; | ||
| 235 | + } | ||
| 236 | + } | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + // This corner radius is reset to self.corner_radius in render(). | ||
| 240 | + let clip = clip.then_some((geometry, CornerRadius::default())); | ||
| 241 | + | ||
| 242 | + Some(RenderParams { | ||
| 243 | + geometry: effect_geometry, | ||
| 244 | + subregion, | ||
| 245 | + clip, | ||
| 246 | + scale, | ||
| 247 | + }) | ||
| 248 | +} | ||
| 249 | + | ||
| 174 | /// Per-surface background effect stored in its data map. | 250 | /// Per-surface background effect stored in its data map. |
| 175 | struct SurfaceBackgroundEffect(Mutex<BackgroundEffect>); | 251 | struct SurfaceBackgroundEffect(Mutex<BackgroundEffect>); |
| 176 | 252 | ||
| @@ -182,6 +258,12 @@ impl SurfaceBackgroundEffect { | |||
| 182 | } | 258 | } |
| 183 | } | 259 | } |
| 184 | 260 | ||
| 261 | +pub fn damage_surface(states: &SurfaceData) { | ||
| 262 | + if let Some(effect) = states.data_map.get::<SurfaceBackgroundEffect>() { | ||
| 263 | + effect.0.lock().unwrap().damage(); | ||
| 264 | + } | ||
| 265 | +} | ||
| 266 | + | ||
| 185 | // Silence, Clippy | 267 | // Silence, Clippy |
| 186 | // A Smithay user is talking | 268 | // A Smithay user is talking |
| 187 | #[allow(clippy::too_many_arguments)] | 269 | #[allow(clippy::too_many_arguments)] |
| @@ -191,9 +273,12 @@ pub fn render_for_tile( | |||
| 191 | scale: f64, | 273 | scale: f64, |
| 192 | clip_to_geometry: bool, | 274 | clip_to_geometry: bool, |
| 193 | surface: &WlSurface, | 275 | surface: &WlSurface, |
| 276 | + surface_off: Point<f64, Logical>, | ||
| 277 | + surface_anim_scale: Scale<f64>, | ||
| 194 | blur_config: niri_config::Blur, | 278 | blur_config: niri_config::Blur, |
| 195 | radius: CornerRadius, | 279 | radius: CornerRadius, |
| 196 | effect: niri_config::BackgroundEffect, | 280 | effect: niri_config::BackgroundEffect, |
| 281 | + should_block_out: bool, | ||
| 197 | xray_pos: XrayPos, | 282 | xray_pos: XrayPos, |
| 198 | push: &mut dyn FnMut(BackgroundEffectElement), | 283 | push: &mut dyn FnMut(BackgroundEffectElement), |
| 199 | ) { | 284 | ) { |
| @@ -201,19 +286,29 @@ pub fn render_for_tile( | |||
| 201 | let background_effect = SurfaceBackgroundEffect::get(states); | 286 | let background_effect = SurfaceBackgroundEffect::get(states); |
| 202 | let mut background_effect = background_effect.0.lock().unwrap(); | 287 | let mut background_effect = background_effect.0.lock().unwrap(); |
| 203 | 288 | ||
| 289 | + let blur_region = get_cached_blur_region(states); | ||
| 290 | + let has_blur_region = blur_region.as_ref().is_some_and(|r| !r.is_empty()); | ||
| 291 | + | ||
| 204 | background_effect.update_config(blur_config); | 292 | background_effect.update_config(blur_config); |
| 205 | - background_effect.update_render_elements(radius, effect); | 293 | + background_effect.update_render_elements(radius, effect, has_blur_region); |
| 206 | 294 | ||
| 207 | if !background_effect.is_visible() { | 295 | if !background_effect.is_visible() { |
| 208 | return; | 296 | return; |
| 209 | } | 297 | } |
| 210 | 298 | ||
| 211 | - // Effects not requested by the surface itself are drawn to match the geometry. | 299 | + let mut surface_geo = surface_geo(states).unwrap_or_default().to_f64(); |
| 212 | - let _ = clip_to_geometry; | 300 | + surface_geo.loc += surface_off; |
| 213 | - let params = RenderParams { | 301 | + |
| 302 | + let Some(params) = render_params_for_tile( | ||
| 214 | geometry, | 303 | geometry, |
| 215 | - clip: Some((geometry, CornerRadius::default())), | ||
| 216 | scale, | 304 | scale, |
| 305 | + clip_to_geometry, | ||
| 306 | + should_block_out, | ||
| 307 | + blur_region, | ||
| 308 | + surface_geo, | ||
| 309 | + surface_anim_scale, | ||
| 310 | + ) else { | ||
| 311 | + return; | ||
| 217 | }; | 312 | }; |
| 218 | 313 | ||
| 219 | let xray_pos = xray_pos.offset(params.geometry.loc - geometry.loc); | 314 | let xray_pos = xray_pos.offset(params.geometry.loc - geometry.loc); |
src/render_helpers/xray.rsmodified+29 -1
| @@ -10,7 +10,7 @@ use smithay::backend::renderer::gles::{ | |||
| 10 | }; | 10 | }; |
| 11 | use smithay::backend::renderer::utils::{CommitCounter, OpaqueRegions}; | 11 | use smithay::backend::renderer::utils::{CommitCounter, OpaqueRegions}; |
| 12 | use smithay::backend::renderer::Color32F; | 12 | use smithay::backend::renderer::Color32F; |
| 13 | -use smithay::utils::{Buffer, Logical, Physical, Point, Rectangle, Scale, Transform}; | 13 | +use smithay::utils::{Buffer, Logical, Physical, Point, Rectangle, Scale, Size, Transform}; |
| 14 | 14 | ||
| 15 | use crate::backend::tty::{TtyFrame, TtyRenderer, TtyRendererError}; | 15 | use crate::backend::tty::{TtyFrame, TtyRenderer, TtyRendererError}; |
| 16 | use crate::render_helpers::background_effect::RenderParams; | 16 | use crate::render_helpers::background_effect::RenderParams; |
| @@ -18,6 +18,7 @@ use crate::render_helpers::effect_buffer::EffectBuffer; | |||
| 18 | use crate::render_helpers::renderer::AsGlesFrame as _; | 18 | use crate::render_helpers::renderer::AsGlesFrame as _; |
| 19 | use crate::render_helpers::shaders::{mat3_uniform, Shaders}; | 19 | use crate::render_helpers::shaders::{mat3_uniform, Shaders}; |
| 20 | use crate::render_helpers::{RenderCtx, RenderTarget}; | 20 | use crate::render_helpers::{RenderCtx, RenderTarget}; |
| 21 | +use crate::utils::region::TransformedRegion; | ||
| 21 | 22 | ||
| 22 | #[derive(Debug)] | 23 | #[derive(Debug)] |
| 23 | pub struct Xray { | 24 | pub struct Xray { |
| @@ -69,6 +70,7 @@ pub struct XrayElement { | |||
| 69 | id: Id, | 70 | id: Id, |
| 70 | geometry: Rectangle<f64, Logical>, | 71 | geometry: Rectangle<f64, Logical>, |
| 71 | src: Rectangle<f64, Buffer>, | 72 | src: Rectangle<f64, Buffer>, |
| 73 | + subregion: Option<TransformedRegion>, | ||
| 72 | input_to_clip_geo: Mat3, | 74 | input_to_clip_geo: Mat3, |
| 73 | clip_geo_size: Vec2, | 75 | clip_geo_size: Vec2, |
| 74 | corner_radius: CornerRadius, | 76 | corner_radius: CornerRadius, |
| @@ -189,6 +191,7 @@ impl Xray { | |||
| 189 | id: background.id().clone(), | 191 | id: background.id().clone(), |
| 190 | geometry, | 192 | geometry, |
| 191 | src, | 193 | src, |
| 194 | + subregion: params.subregion.clone(), | ||
| 192 | input_to_clip_geo, | 195 | input_to_clip_geo, |
| 193 | clip_geo_size, | 196 | clip_geo_size, |
| 194 | corner_radius, | 197 | corner_radius, |
| @@ -238,6 +241,7 @@ impl Xray { | |||
| 238 | id: backdrop.id().clone(), | 241 | id: backdrop.id().clone(), |
| 239 | geometry: params.geometry, | 242 | geometry: params.geometry, |
| 240 | src, | 243 | src, |
| 244 | + subregion: params.subregion.clone(), | ||
| 241 | input_to_clip_geo, | 245 | input_to_clip_geo, |
| 242 | clip_geo_size, | 246 | clip_geo_size, |
| 243 | corner_radius: corner_radius.scaled_by(zoom as f32), | 247 | corner_radius: corner_radius.scaled_by(zoom as f32), |
| @@ -309,6 +313,30 @@ impl RenderElement<GlesRenderer> for XrayElement { | |||
| 309 | } | 313 | } |
| 310 | }; | 314 | }; |
| 311 | 315 | ||
| 316 | + // FIXME: avoid reallocating a fresh Vec here somehow. | ||
| 317 | + let mut filtered_damage = Vec::new(); | ||
| 318 | + let damage = if let Some(subregion) = &self.subregion { | ||
| 319 | + let src_to_geo = self.geometry.size / self.src.size; | ||
| 320 | + | ||
| 321 | + // Compute crop in geometry coordinates. | ||
| 322 | + let mut crop = src; | ||
| 323 | + crop.loc -= self.src.loc; | ||
| 324 | + crop = crop.upscale(src_to_geo); | ||
| 325 | + let mut crop = crop.to_logical(1., Transform::Normal, &Size::default()); | ||
| 326 | + | ||
| 327 | + // Then convert to subregion coordinates. | ||
| 328 | + crop.loc += self.geometry.loc; | ||
| 329 | + | ||
| 330 | + subregion.filter_damage(crop, dst, damage, &mut filtered_damage); | ||
| 331 | + | ||
| 332 | + if filtered_damage.is_empty() { | ||
| 333 | + return Ok(()); | ||
| 334 | + } | ||
| 335 | + &filtered_damage[..] | ||
| 336 | + } else { | ||
| 337 | + damage | ||
| 338 | + }; | ||
| 339 | + | ||
| 312 | let uniforms = self.program.is_some().then(|| self.compute_uniforms()); | 340 | let uniforms = self.program.is_some().then(|| self.compute_uniforms()); |
| 313 | let uniforms = uniforms.as_ref().map_or(&[][..], |x| &x[..]); | 341 | let uniforms = uniforms.as_ref().map_or(&[][..], |x| &x[..]); |
| 314 | 342 | ||
src/utils/mod.rsmodified+16 -1
| @@ -14,7 +14,9 @@ use bitflags::bitflags; | |||
| 14 | use directories::UserDirs; | 14 | use directories::UserDirs; |
| 15 | use git_version::git_version; | 15 | use git_version::git_version; |
| 16 | use niri_config::{Config, OutputName}; | 16 | use niri_config::{Config, OutputName}; |
| 17 | -use smithay::backend::renderer::utils::with_renderer_surface_state; | 17 | +use smithay::backend::renderer::utils::{ |
| 18 | + with_renderer_surface_state, RendererSurfaceStateUserData, | ||
| 19 | +}; | ||
| 18 | use smithay::input::pointer::CursorIcon; | 20 | use smithay::input::pointer::CursorIcon; |
| 19 | use smithay::output::{self, Output}; | 21 | use smithay::output::{self, Output}; |
| 20 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; | 22 | use smithay::reexports::rustix::time::{clock_gettime, ClockId}; |
| @@ -35,6 +37,7 @@ use crate::handlers::KdeDecorationsModeState; | |||
| 35 | use crate::niri::ClientState; | 37 | use crate::niri::ClientState; |
| 36 | 38 | ||
| 37 | pub mod id; | 39 | pub mod id; |
| 40 | +pub mod region; | ||
| 38 | pub mod scale; | 41 | pub mod scale; |
| 39 | pub mod signals; | 42 | pub mod signals; |
| 40 | pub mod spawning; | 43 | pub mod spawning; |
| @@ -325,6 +328,18 @@ pub fn is_laptop_panel(connector: &str) -> bool { | |||
| 325 | matches!(connector.get(..4), Some("eDP-" | "LVDS" | "DSI-")) | 328 | matches!(connector.get(..4), Some("eDP-" | "LVDS" | "DSI-")) |
| 326 | } | 329 | } |
| 327 | 330 | ||
| 331 | +/// Returns the geometry of the surface. | ||
| 332 | +/// | ||
| 333 | +/// Returns `None` if the surface isn't mapped. | ||
| 334 | +pub fn surface_geo(states: &SurfaceData) -> Option<Rectangle<i32, Logical>> { | ||
| 335 | + let data = states.data_map.get::<RendererSurfaceStateUserData>(); | ||
| 336 | + data.and_then(|d| d.lock().unwrap().view()) | ||
| 337 | + .map(|view| Rectangle { | ||
| 338 | + loc: view.offset, | ||
| 339 | + size: view.dst, | ||
| 340 | + }) | ||
| 341 | +} | ||
| 342 | + | ||
| 328 | pub fn with_toplevel_role<T>( | 343 | pub fn with_toplevel_role<T>( |
| 329 | toplevel: &ToplevelSurface, | 344 | toplevel: &ToplevelSurface, |
| 330 | f: impl FnOnce(&mut XdgToplevelSurfaceRoleAttributes) -> T, | 345 | f: impl FnOnce(&mut XdgToplevelSurfaceRoleAttributes) -> T, |
src/utils/region.rsadded+320 -0
| @@ -0,0 +1,320 @@ | |||
| 1 | +use std::cmp::{max, min}; | ||
| 2 | +use std::collections::BTreeSet; | ||
| 3 | +use std::sync::Arc; | ||
| 4 | + | ||
| 5 | +use smithay::utils::{Logical, Physical, Point, Rectangle, Scale}; | ||
| 6 | +use smithay::wayland::compositor::{RectangleKind, RegionAttributes}; | ||
| 7 | + | ||
| 8 | +/// Helper for fractionally transforming an i32 region while preserving adjacent rects. | ||
| 9 | +/// | ||
| 10 | +/// Naively applying floating point transforms may cause adjacent rects to go misaligned due to | ||
| 11 | +/// rounding differences. This struct helps apply the transforms in such a way as to preserve | ||
| 12 | +/// alignment. | ||
| 13 | +#[derive(Debug, Clone)] | ||
| 14 | +pub struct TransformedRegion { | ||
| 15 | + /// Non-overlapping rects (usually in surface-local coordinates). | ||
| 16 | + pub rects: Arc<Vec<Rectangle<i32, Logical>>>, | ||
| 17 | + /// Scale to apply to each rect. | ||
| 18 | + pub scale: Scale<f64>, | ||
| 19 | + /// Translation to apply to each rect after scaling. | ||
| 20 | + pub offset: Point<f64, Logical>, | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +impl TransformedRegion { | ||
| 24 | + /// Returns an iterator over the top-left and bottom-right corners of transformed rects. | ||
| 25 | + pub fn iter(&self) -> impl Iterator<Item = (Point<f64, Logical>, Point<f64, Logical>)> + '_ { | ||
| 26 | + self.rects.iter().map(|r| { | ||
| 27 | + // Here we start in a happy i32 world where everything lines up, and rectangle loc + | ||
| 28 | + // size is exactly equal to the adjacent rectangle's loc. | ||
| 29 | + // | ||
| 30 | + // Unfortunately, we're about to descend to the floating point hell. And we *really* | ||
| 31 | + // want adjacent rects to remain adjacent no matter what. So we'll convert our rects to | ||
| 32 | + // their extremities (rather than loc and size), and operate on those. Coordinates from | ||
| 33 | + // adjacent rects will undergo exactly the same floating point operations, so when | ||
| 34 | + // they're ultimately rounded to physical pixels, they will remain adjacent. | ||
| 35 | + let r = r.to_f64(); | ||
| 36 | + | ||
| 37 | + let mut a = r.loc; | ||
| 38 | + // f64 is enough to represent this i32 addition exactly. | ||
| 39 | + let mut b = r.loc + r.size.to_point(); | ||
| 40 | + | ||
| 41 | + a = a.upscale(self.scale); | ||
| 42 | + b = b.upscale(self.scale); | ||
| 43 | + | ||
| 44 | + a += self.offset; | ||
| 45 | + b += self.offset; | ||
| 46 | + | ||
| 47 | + (a, b) | ||
| 48 | + }) | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + /// Intersects damage with this subregion. | ||
| 52 | + pub fn filter_damage( | ||
| 53 | + &self, | ||
| 54 | + // Same coordinate space as self.iter(). | ||
| 55 | + crop: Rectangle<f64, Logical>, | ||
| 56 | + dst: Rectangle<i32, Physical>, | ||
| 57 | + damage: &[Rectangle<i32, Physical>], | ||
| 58 | + filtered: &mut Vec<Rectangle<i32, Physical>>, | ||
| 59 | + ) { | ||
| 60 | + let scale = dst.size.to_f64() / crop.size; | ||
| 61 | + | ||
| 62 | + let cs = crop.size.to_point(); | ||
| 63 | + | ||
| 64 | + for (mut a, mut b) in self.iter() { | ||
| 65 | + // Convert to dst-relative. | ||
| 66 | + a -= crop.loc; | ||
| 67 | + b -= crop.loc; | ||
| 68 | + | ||
| 69 | + // Intersect with crop. | ||
| 70 | + let ia = Point::new(f64::max(a.x, 0.), f64::max(a.y, 0.)); | ||
| 71 | + let ib = Point::new(f64::min(b.x, cs.x), f64::min(b.y, cs.y)); | ||
| 72 | + if ib.x <= ia.x || ib.y <= ia.y { | ||
| 73 | + // No intersection. | ||
| 74 | + continue; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + // Round extremities to physical pixels, ensuring that adjacent rectangles stay adjacent | ||
| 78 | + // at fractional scales. | ||
| 79 | + let ia = ia.to_physical_precise_round(scale); | ||
| 80 | + let ib = ib.to_physical_precise_round(scale); | ||
| 81 | + | ||
| 82 | + let r = Rectangle::from_extremities(ia, ib); | ||
| 83 | + | ||
| 84 | + // Intersect with each damage rect. | ||
| 85 | + for d in damage { | ||
| 86 | + if let Some(intersection) = r.intersection(*d) { | ||
| 87 | + filtered.push(intersection); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +pub fn region_to_non_overlapping_rects( | ||
| 95 | + region: &RegionAttributes, | ||
| 96 | + output: &mut Vec<Rectangle<i32, Logical>>, | ||
| 97 | +) { | ||
| 98 | + let _span = tracy_client::span!("region_to_non_overlapping_rects"); | ||
| 99 | + | ||
| 100 | + output.clear(); | ||
| 101 | + | ||
| 102 | + // Collect all unique Y coordinates. | ||
| 103 | + let ys = BTreeSet::from_iter( | ||
| 104 | + region | ||
| 105 | + .rects | ||
| 106 | + .iter() | ||
| 107 | + .flat_map(|(_, r)| [r.loc.y, r.loc.y + r.size.h]), | ||
| 108 | + ); | ||
| 109 | + | ||
| 110 | + let mut ys = ys.into_iter(); | ||
| 111 | + let Some(mut lo) = ys.next() else { | ||
| 112 | + // The region was empty. | ||
| 113 | + return; | ||
| 114 | + }; | ||
| 115 | + | ||
| 116 | + // Sorted list of non-overlapping [start, end) tuples. | ||
| 117 | + let mut spans = Vec::<(i32, i32)>::new(); | ||
| 118 | + | ||
| 119 | + // Iterate over Y bands. | ||
| 120 | + for hi in ys { | ||
| 121 | + spans.clear(); | ||
| 122 | + | ||
| 123 | + 'region: for (kind, r) in ®ion.rects { | ||
| 124 | + // Skip rects that don't overlap with the Y band. | ||
| 125 | + if hi <= r.loc.y || r.loc.y + r.size.h <= lo { | ||
| 126 | + continue; | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + let mut x1 = r.loc.x; | ||
| 130 | + let mut x2 = r.loc.x + r.size.w; | ||
| 131 | + if x1 == x2 { | ||
| 132 | + // Empty rect. | ||
| 133 | + continue; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + match *kind { | ||
| 137 | + RectangleKind::Add => { | ||
| 138 | + // Iterate over existing spans backwards. | ||
| 139 | + for i in (0..spans.len()).rev() { | ||
| 140 | + let (start, end) = spans[i]; | ||
| 141 | + | ||
| 142 | + // New span is to the right. | ||
| 143 | + if end < x1 { | ||
| 144 | + spans.insert(i + 1, (x1, x2)); | ||
| 145 | + continue 'region; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + // New span is to the left. | ||
| 149 | + if x2 < start { | ||
| 150 | + continue; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + // New span overlaps this span; merge them. | ||
| 154 | + spans.remove(i); | ||
| 155 | + x1 = min(x1, start); | ||
| 156 | + x2 = max(x2, end); | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + spans.insert(0, (x1, x2)); | ||
| 160 | + } | ||
| 161 | + RectangleKind::Subtract => { | ||
| 162 | + // Iterate over existing spans backwards. | ||
| 163 | + for i in (0..spans.len()).rev() { | ||
| 164 | + let (start, end) = spans[i]; | ||
| 165 | + | ||
| 166 | + // Subtract span is to the right. | ||
| 167 | + if end <= x1 { | ||
| 168 | + continue 'region; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + // Subtract span is to the left. | ||
| 172 | + if x2 <= start { | ||
| 173 | + continue; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + // Subtract span overlaps this span. | ||
| 177 | + spans.remove(i); | ||
| 178 | + if x2 < end { | ||
| 179 | + spans.insert(i, (x2, end)); | ||
| 180 | + } | ||
| 181 | + if start < x1 { | ||
| 182 | + spans.insert(i, (start, x1)); | ||
| 183 | + } | ||
| 184 | + } | ||
| 185 | + } | ||
| 186 | + } | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + for (x1, x2) in spans.drain(..) { | ||
| 190 | + output.push(Rectangle::from_extremities((x1, lo), (x2, hi))); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + lo = hi; | ||
| 194 | + } | ||
| 195 | +} | ||
| 196 | + | ||
| 197 | +#[cfg(test)] | ||
| 198 | +mod tests { | ||
| 199 | + use std::fmt::Write as _; | ||
| 200 | + | ||
| 201 | + use insta::assert_snapshot; | ||
| 202 | + use proptest::prelude::*; | ||
| 203 | + use smithay::utils::{Logical, Point, Rectangle, Size}; | ||
| 204 | + use smithay::wayland::compositor::{RectangleKind, RegionAttributes}; | ||
| 205 | + | ||
| 206 | + use super::region_to_non_overlapping_rects; | ||
| 207 | + | ||
| 208 | + #[allow(clippy::type_complexity)] | ||
| 209 | + fn check(rects: &[(RectangleKind, (i32, i32, i32, i32))]) -> String { | ||
| 210 | + let region = RegionAttributes { | ||
| 211 | + rects: rects | ||
| 212 | + .iter() | ||
| 213 | + .map(|(kind, (x1, y1, x2, y2))| { | ||
| 214 | + (*kind, Rectangle::from_extremities((*x1, *y1), (*x2, *y2))) | ||
| 215 | + }) | ||
| 216 | + .collect(), | ||
| 217 | + }; | ||
| 218 | + let mut output = Vec::new(); | ||
| 219 | + region_to_non_overlapping_rects(®ion, &mut output); | ||
| 220 | + let mut s = String::new(); | ||
| 221 | + for r in &output { | ||
| 222 | + let x1 = r.loc.x; | ||
| 223 | + let y1 = r.loc.y; | ||
| 224 | + let x2 = x1 + r.size.w; | ||
| 225 | + let y2 = y1 + r.size.h; | ||
| 226 | + writeln!(s, "{x1:2} {y1:2} - {x2:2} {y2:2}").unwrap(); | ||
| 227 | + } | ||
| 228 | + s | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + #[test] | ||
| 232 | + fn test_region_to_non_overlapping_rects() { | ||
| 233 | + use RectangleKind::*; | ||
| 234 | + | ||
| 235 | + // empty_region | ||
| 236 | + assert_snapshot!(check(&[]), @""); | ||
| 237 | + | ||
| 238 | + // single_rectangle | ||
| 239 | + assert_snapshot!(check(&[(Add, (0, 0, 10, 10))]), @" 0 0 - 10 10"); | ||
| 240 | + | ||
| 241 | + // empty_rectangle | ||
| 242 | + assert_snapshot!(check(&[(Add, (0, 0, 0, 1))]), @""); | ||
| 243 | + assert_snapshot!(check(&[(Add, (0, 0, 1, 0))]), @""); | ||
| 244 | + | ||
| 245 | + // two_non_overlapping | ||
| 246 | + assert_snapshot!( | ||
| 247 | + check(&[(Add, (0, 0, 5, 10)), (Add, (7, 0, 12, 10))]), | ||
| 248 | + @" | ||
| 249 | + 0 0 - 5 10 | ||
| 250 | + 7 0 - 12 10 | ||
| 251 | + " | ||
| 252 | + ); | ||
| 253 | + | ||
| 254 | + // two_overlapping | ||
| 255 | + assert_snapshot!( | ||
| 256 | + check(&[(Add, (0, 0, 10, 10)), (Add, (5, 5, 15, 15))]), | ||
| 257 | + @" | ||
| 258 | + 0 0 - 10 5 | ||
| 259 | + 0 5 - 15 10 | ||
| 260 | + 5 10 - 15 15 | ||
| 261 | + " | ||
| 262 | + ); | ||
| 263 | + | ||
| 264 | + // subtraction | ||
| 265 | + assert_snapshot!( | ||
| 266 | + check(&[(Add, (0, 0, 20, 20)), (Subtract, (5, 5, 15, 15))]), | ||
| 267 | + @" | ||
| 268 | + 0 0 - 20 5 | ||
| 269 | + 0 5 - 5 15 | ||
| 270 | + 15 5 - 20 15 | ||
| 271 | + 0 15 - 20 20 | ||
| 272 | + " | ||
| 273 | + ); | ||
| 274 | + | ||
| 275 | + // adjacent_rectangles | ||
| 276 | + assert_snapshot!( | ||
| 277 | + check(&[(Add, (0, 0, 10, 10)), (Add, (10, 0, 20, 10))]), | ||
| 278 | + @" 0 0 - 20 10" | ||
| 279 | + ); | ||
| 280 | + } | ||
| 281 | + | ||
| 282 | + proptest! { | ||
| 283 | + #[test] | ||
| 284 | + fn non_overlapping_output( | ||
| 285 | + rects in proptest::collection::vec( | ||
| 286 | + ( | ||
| 287 | + prop_oneof![Just(RectangleKind::Add), Just(RectangleKind::Subtract)], | ||
| 288 | + (0..20i32, 0..20i32, 0..20i32, 0..20i32), | ||
| 289 | + ), | ||
| 290 | + 1..10, | ||
| 291 | + ) | ||
| 292 | + ) { | ||
| 293 | + let region = RegionAttributes { | ||
| 294 | + rects: rects | ||
| 295 | + .into_iter() | ||
| 296 | + .map(|(kind, (x, y, w, h))| { | ||
| 297 | + (kind, Rectangle::new(Point::new(x, y), Size::new(w, h))) | ||
| 298 | + }) | ||
| 299 | + .collect(), | ||
| 300 | + }; | ||
| 301 | + | ||
| 302 | + let mut output: Vec<Rectangle<i32, Logical>> = Vec::new(); | ||
| 303 | + region_to_non_overlapping_rects(®ion, &mut output); | ||
| 304 | + | ||
| 305 | + for i in 0..output.len() { | ||
| 306 | + prop_assert!(!output[i].is_empty()); | ||
| 307 | + | ||
| 308 | + // Verify no pair of output rectangles overlaps. | ||
| 309 | + for j in (i + 1)..output.len() { | ||
| 310 | + prop_assert!( | ||
| 311 | + !output[i].overlaps(output[j]), | ||
| 312 | + "rectangles overlap: {:?} and {:?}", | ||
| 313 | + output[i], | ||
| 314 | + output[j], | ||
| 315 | + ); | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | + } | ||
| 319 | + } | ||
| 320 | +} | ||
src/window/mapped.rsmodified+6 -1
| @@ -1,7 +1,7 @@ | |||
| 1 | use std::cell::{Cell, Ref, RefCell}; | 1 | use std::cell::{Cell, Ref, RefCell}; |
| 2 | use std::time::Duration; | 2 | use std::time::Duration; |
| 3 | 3 | ||
| 4 | -use niri_config::{Color, CornerRadius, GradientInterpolation, WindowRule}; | 4 | +use niri_config::{Color, Config, CornerRadius, GradientInterpolation, WindowRule}; |
| 5 | use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement; | 5 | 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; |
| @@ -689,19 +689,24 @@ impl LayoutElement for Mapped { | |||
| 689 | geometry: Rectangle<f64, Logical>, | 689 | geometry: Rectangle<f64, Logical>, |
| 690 | scale: f64, | 690 | scale: f64, |
| 691 | clip_to_geometry: bool, | 691 | clip_to_geometry: bool, |
| 692 | + surface_anim_scale: Scale<f64>, | ||
| 692 | radius: CornerRadius, | 693 | radius: CornerRadius, |
| 693 | xray_pos: XrayPos, | 694 | xray_pos: XrayPos, |
| 694 | push: &mut dyn FnMut(BackgroundEffectElement), | 695 | push: &mut dyn FnMut(BackgroundEffectElement), |
| 695 | ) { | 696 | ) { |
| 697 | + let should_block_out = ctx.target.should_block_out(self.rules.block_out_from); | ||
| 696 | background_effect::render_for_tile( | 698 | background_effect::render_for_tile( |
| 697 | ctx, | 699 | ctx, |
| 698 | geometry, | 700 | geometry, |
| 699 | scale, | 701 | scale, |
| 700 | clip_to_geometry, | 702 | clip_to_geometry, |
| 701 | self.toplevel().wl_surface(), | 703 | self.toplevel().wl_surface(), |
| 704 | + self.buf_loc().to_f64(), | ||
| 705 | + surface_anim_scale, | ||
| 702 | self.blur_config, | 706 | self.blur_config, |
| 703 | radius, | 707 | radius, |
| 704 | self.rules.background_effect, | 708 | self.rules.background_effect, |
| 709 | + should_block_out, | ||
| 705 | xray_pos, | 710 | xray_pos, |
| 706 | push, | 711 | push, |
| 707 | ); | 712 | ); |