feat(wayland): corner-radius protocol support

This commit is contained in:
Ashley Wulber 2025-09-24 15:55:34 -04:00 committed by Ashley Wulber
parent 43314e3e6a
commit 9815d4d981
7 changed files with 355 additions and 28 deletions

View file

@ -5,6 +5,7 @@ use super::Action;
#[cfg(feature = "winit")]
use crate::Application;
use iced::window;
use std::{any::Any, sync::Arc};
/// Used to produce a destroy popup message from within a widget.
@ -20,6 +21,90 @@ pub fn destroy_subsurface(id: iced_core::window::Id) -> Action {
Action::DestroySubsurface(id)
}
#[cfg(feature = "wayland")]
#[must_use]
pub fn destroy_window(id: iced_core::window::Id) -> Action {
Action::DestroyWindow(id)
}
#[cfg(all(feature = "wayland", feature = "winit"))]
#[must_use]
pub fn app_window<App: Application>(
settings: impl Fn(&mut App) -> window::Settings
+ Send
+ Sync
+ 'static,
view: Option<
Box<
dyn for<'a> Fn(&'a App) -> crate::Element<'a, crate::Action<App::Message>>
+ Send
+ Sync
+ 'static,
>,
>,
) -> (window::Id, Action) {
let id = window::Id::unique();
let boxed: Box<
dyn Fn(&mut App) -> window::Settings
+ Send
+ Sync
+ 'static,
> = Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
(
id,
Action::AppWindow(
id,
Arc::new(boxed),
view.map(|view| {
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(view);
Arc::new(boxed)
}),
)
)
}
/// Used to create a window message from within a widget.
#[cfg(all(feature = "wayland", feature = "winit"))]
#[must_use]
pub fn simple_window<Message: 'static>(
settings: impl Fn() -> window::Settings
+ Send
+ Sync
+ 'static,
view: Option<
impl Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static,
>,
) -> (window::Id, Action) {
let id = window::Id::unique();
let boxed: Box<
dyn Fn() -> window::Settings
+ Send
+ Sync
+ 'static,
> = Box::new(settings);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
(
id,
Action::Window(
id,
Arc::new(boxed),
view.map(|view| {
let boxed: Box<
dyn Fn() -> crate::Element<'static, crate::Action<Message>> + Send + Sync + 'static,
> = Box::new(view);
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
Arc::new(boxed)
}),
)
)
}
#[cfg(all(feature = "wayland", feature = "winit"))]
#[must_use]
pub fn app_popup<App: Application>(

View file

@ -36,6 +36,22 @@ pub enum Action {
),
/// Destroy a subsurface with a view function
DestroyPopup(iced::window::Id),
/// Create a window with a view function accepting the App as a parameter
AppWindow(
iced::window::Id,
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
/// Create a window with a view function
Window(
iced::window::Id,
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
),
/// Destroy a window
DestroyWindow(iced::window::Id),
/// Responsive menu bar update
ResponsiveMenuBar {
/// Id of the menu bar
@ -80,6 +96,15 @@ impl std::fmt::Debug for Action {
.field("size", size)
.finish(),
Self::Ignore => write!(f, "Ignore"),
Self::AppWindow(id, arg0, arg1) => {
f.debug_tuple("AppWindow").field(id).field(arg0).field(arg1).finish()
}
Self::Window(id, arg0, arg1) => {
f.debug_tuple("Window").field(id).field(arg0).field(arg1).finish()
}
Self::DestroyWindow(arg0) => {
f.debug_tuple("DestroyWindow").field(arg0).finish()
}
Self::Task(_) => f.debug_tuple("Future").finish(),
}
}