element/wayland: Add blur background-effect
This commit is contained in:
parent
e4c0716951
commit
a9bf89d8b2
10 changed files with 747 additions and 5 deletions
59
src/wayland/handlers/background_effect.rs
Normal file
59
src/wayland/handlers/background_effect.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
use smithay::{
|
||||
reexports::wayland_server::{DisplayHandle, protocol::wl_surface::WlSurface},
|
||||
utils::{Logical, Rectangle},
|
||||
wayland::{
|
||||
background_effect::{Capability, ExtBackgroundEffectHandler},
|
||||
compositor::{Cacheable, RectangleKind, RegionAttributes, with_states},
|
||||
},
|
||||
};
|
||||
|
||||
use crate::state::State;
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ComputedBlurRegionCachedState {
|
||||
/// Region of the surface that will have its background blurred.
|
||||
pub blur_region: Option<Vec<Rectangle<i32, Logical>>>,
|
||||
}
|
||||
|
||||
impl Cacheable for ComputedBlurRegionCachedState {
|
||||
fn commit(&mut self, _dh: &DisplayHandle) -> Self {
|
||||
self.clone()
|
||||
}
|
||||
|
||||
fn merge_into(self, into: &mut Self, _dh: &DisplayHandle) {
|
||||
*into = self;
|
||||
}
|
||||
}
|
||||
|
||||
impl ExtBackgroundEffectHandler for State {
|
||||
fn capabilities(&self) -> Capability {
|
||||
Capability::Blur
|
||||
}
|
||||
|
||||
fn set_blur_region(&mut self, surface: WlSurface, region: RegionAttributes) {
|
||||
with_states(&surface, |states| {
|
||||
let mut blur_state = states.cached_state.get::<ComputedBlurRegionCachedState>();
|
||||
|
||||
blur_state.pending().blur_region = Some({
|
||||
let (added, subtracted) = region
|
||||
.rects
|
||||
.iter()
|
||||
.cloned()
|
||||
.partition::<Vec<_>, _>(|(op, _)| matches!(op, RectangleKind::Add));
|
||||
let added = added.into_iter().map(|(_, rect)| rect).collect::<Vec<_>>();
|
||||
Rectangle::subtract_rects_many_in_place(
|
||||
added,
|
||||
subtracted.into_iter().map(|(_, rect)| rect),
|
||||
)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn unset_blur_region(&mut self, surface: WlSurface) {
|
||||
with_states(&surface, |states| {
|
||||
let mut blur_state = states.cached_state.get::<ComputedBlurRegionCachedState>();
|
||||
|
||||
blur_state.pending().blur_region.take();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
pub mod a11y;
|
||||
pub mod background_effect;
|
||||
pub mod buffer;
|
||||
pub mod compositor;
|
||||
pub mod corner_radius;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue