chore: session lock action

This commit is contained in:
Ashley Wulber 2026-09-15 18:53:27 -04:00 • committed by Ashley Wulber
parent 8cb86195ec
commit 3664828bf8
3 changed files with 100 additions and 1 deletions

View file

@ -452,6 +452,33 @@ where
crate::surface::Action::DestroyLayerShell(id) => {
iced_winit::commands::layer_surface::destroy_layer_surface(id)
}
#[cfg(wayland_platform)]
crate::surface::Action::Lock(id, output, live_settings, view) => {
let Some(live_settings) =
std::sync::Arc::try_unwrap(live_settings)
.ok()
.and_then(|s| {
s.downcast::<Box<dyn Fn() -> LiveSettings + Send + Sync>>()
.ok()
})
else {
tracing::error!("Invalid live settings for popup");
return Task::none();
};
let live_settings = live_settings();
let live_settings = Box::new(move |_app: &T| live_settings);
if let Some(view) = view {
self.get_lock(id, output, live_settings, Some(Box::new(move |_| view())))
} else {
self.get_lock(id, output, live_settings, None)
}
}
#[cfg(wayland_platform)]
crate::surface::Action::DestroyLock(id) => {
iced_winit::commands::session_lock::destroy_lock_surface(id)
}
crate::surface::Action::SyncLiveSettings(id) => {
if let Some((_, id, live_settings, _)) = self.surface_views.get(&id) {
let live_settings = live_settings(&self.app);
@ -1741,6 +1768,34 @@ impl<App: Application> Cosmic<App> {
);
Task::batch([live_settings_task, get_layer_surface(settings)])
}
#[cfg(wayland_platform)]
pub fn get_lock(
&mut self,
id: window::Id,
output: cctk::wayland_client::protocol::wl_output::WlOutput,
live_settings: Box<dyn for<'a> Fn(&'a App) -> LiveSettings + Send + Sync>,
view: Option<
Box<dyn for<'a> Fn(&'a App) -> Element<'a, crate::Action<App::Message>> + Send + Sync>,
>,
) -> Task<crate::Action<App::Message>> {
use iced_winit::SurfaceIdWrapper;
use iced_winit::platform_specific::commands::session_lock::get_lock_surface;
*self.opened_surfaces.entry(id).or_insert(0) += 1;
let live_settings_task =
self.apply_live_settings(SurfaceIdWrapper::SessionLock(id), &live_settings(&self.app));
self.surface_views.insert(
id,
(
None, // TODO parent for layer shell, platform specific option maybe?
SurfaceIdWrapper::SessionLock(id),
live_settings,
view,
),
);
live_settings_task.chain(get_lock_surface(id, output))
}
}
#[cfg(wayland_platform)]