From 1bf1e33317b8da299ffd9a620e7e0e099c0c3478 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Tue, 14 Apr 2026 14:47:25 -0400 Subject: [PATCH] improv(wayland): handle capabilities for ext_background_effect --- .../wayland/event_loop/state.rs | 7 +++ .../wayland/handlers/ext_background_effect.rs | 50 +++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index 68de367f..f99e48ba 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -1647,6 +1647,13 @@ impl SctkState { } } Action::BlurSurface(id, rectangles) => { + use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_manager_v1; + + if let Some(bg_effect_mgr) = self.ext_background_effect_manager.as_mut() && !bg_effect_mgr.capabilities().contains(ext_background_effect_manager_v1::Capability::Blur) { + bg_effect_mgr.enqueue(id, rectangles.clone()); + return Ok(()); + } + let s = if let Some(s) = self.popups.iter().find(|s| s.data.id == id) { s.popup.wl_surface() } else if let Some(s) = self.layer_surfaces.iter().find(|s| s.id == id) { diff --git a/winit/src/platform_specific/wayland/handlers/ext_background_effect.rs b/winit/src/platform_specific/wayland/handlers/ext_background_effect.rs index 3e33d9a1..03a80da9 100644 --- a/winit/src/platform_specific/wayland/handlers/ext_background_effect.rs +++ b/winit/src/platform_specific/wayland/handlers/ext_background_effect.rs @@ -1,16 +1,23 @@ +use std::collections::HashMap; + use cctk::sctk; +use iced_runtime::core::Rectangle; +use iced_runtime::platform_specific::wayland::Action; use sctk::globals::GlobalData; use sctk::reexports::client::globals::{BindError, GlobalList}; use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; -use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_manager_v1::ExtBackgroundEffectManagerV1; +use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_manager_v1::{Capability, Event, ExtBackgroundEffectManagerV1}; use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1; use crate::event_loop::state::SctkState; +use crate::window; #[derive(Debug, Clone)] pub struct ExtBackgroundEffectManager { manager: ExtBackgroundEffectManagerV1, + capabilities: Capability, + queued_blur_actions: HashMap>>, } impl ExtBackgroundEffectManager { @@ -19,7 +26,11 @@ impl ExtBackgroundEffectManager { queue_handle: &QueueHandle, ) -> Result { let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; - Ok(Self { manager }) + Ok(Self { + manager, + capabilities: Capability::empty(), + queued_blur_actions: HashMap::new(), + }) } pub fn blur( @@ -30,19 +41,50 @@ impl ExtBackgroundEffectManager { self.manager .get_background_effect(surface, queue_handle, ()) } + + pub fn enqueue(&mut self, id: window::Id, rects: Option>) { + _ = self.queued_blur_actions.insert(id, rects); + } + + pub fn capabilities(&self) -> Capability { + self.capabilities + } } impl Dispatch for ExtBackgroundEffectManager { fn event( - _: &mut SctkState, + state: &mut SctkState, _: &ExtBackgroundEffectManagerV1, - _: ::Event, + event: ::Event, _: &GlobalData, _: &Connection, _: &QueueHandle, ) { + match event { + Event::Capabilities { flags } => match flags { + wayland_client::WEnum::Value(capability) => { + let mut queued_actions = Vec::new(); + if let Some(bg_effect_mgr) = + state.ext_background_effect_manager.as_mut() + { + bg_effect_mgr.capabilities = capability; + queued_actions = + bg_effect_mgr.queued_blur_actions.drain().collect(); + } + for (id, rects) in queued_actions { + _ = state.handle_action(Action::BlurSurface(id, rects)); + } + } + wayland_client::WEnum::Unknown(u) => { + log::warn!("Unknown value: {u:?}"); + } + }, + e => { + log::warn!("Ignored event {e:?}"); + } + } } }