improv(wayland): handle capabilities for ext_background_effect
This commit is contained in:
parent
d2b2715835
commit
1bf1e33317
2 changed files with 53 additions and 4 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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<window::Id, Option<Vec<Rectangle>>>,
|
||||
}
|
||||
|
||||
impl ExtBackgroundEffectManager {
|
||||
|
|
@ -19,7 +26,11 @@ impl ExtBackgroundEffectManager {
|
|||
queue_handle: &QueueHandle<SctkState>,
|
||||
) -> Result<Self, BindError> {
|
||||
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<Vec<Rectangle>>) {
|
||||
_ = self.queued_blur_actions.insert(id, rects);
|
||||
}
|
||||
|
||||
pub fn capabilities(&self) -> Capability {
|
||||
self.capabilities
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<ExtBackgroundEffectManagerV1, GlobalData, SctkState>
|
||||
for ExtBackgroundEffectManager
|
||||
{
|
||||
fn event(
|
||||
_: &mut SctkState,
|
||||
state: &mut SctkState,
|
||||
_: &ExtBackgroundEffectManagerV1,
|
||||
_: <ExtBackgroundEffectManagerV1 as Proxy>::Event,
|
||||
event: <ExtBackgroundEffectManagerV1 as Proxy>::Event,
|
||||
_: &GlobalData,
|
||||
_: &Connection,
|
||||
_: &QueueHandle<SctkState>,
|
||||
) {
|
||||
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:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue