refactor: remove SurfaceMessageHandler
This commit is contained in:
parent
306995febf
commit
63f249a395
7 changed files with 131 additions and 156 deletions
|
|
@ -19,7 +19,7 @@ use iced_core::{window::Id, Element};
|
|||
use palette::Srgba;
|
||||
use slotmap::Key;
|
||||
|
||||
use crate::{surface_message::SurfaceMessageHandler, Theme};
|
||||
use crate::Theme;
|
||||
|
||||
use super::{Renderer, Task};
|
||||
|
||||
|
|
@ -396,7 +396,7 @@ impl Core {
|
|||
'a,
|
||||
Message: Clone
|
||||
+ From<crate::surface_message::SurfaceMessage>
|
||||
+ crate::surface_message::SurfaceMessageHandler
|
||||
+ Into<crate::surface_message::MessageWrapper<Message>>
|
||||
+ 'static,
|
||||
A: menu::Action<Message = Message>,
|
||||
>(
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::sync::Arc;
|
|||
|
||||
use super::{Application, ApplicationExt, Core, Subscription};
|
||||
use crate::config::CosmicTk;
|
||||
use crate::surface_message::{MessageWrapper, SurfaceMessage, SurfaceMessageHandler};
|
||||
use crate::surface_message::{MessageWrapper, SurfaceMessage};
|
||||
use crate::theme::{Theme, ThemeType, THEME};
|
||||
use crate::widget::nav_bar;
|
||||
use crate::{keyboard_nav, Element};
|
||||
|
|
@ -94,7 +94,7 @@ pub struct Cosmic<App: Application> {
|
|||
|
||||
impl<T: Application> Cosmic<T>
|
||||
where
|
||||
T::Message: Send + 'static + crate::surface_message::SurfaceMessageHandler,
|
||||
T::Message: Send + 'static + Into<crate::surface_message::MessageWrapper<T::Message>>,
|
||||
{
|
||||
pub fn init(
|
||||
(mut core, flags): (Core, T::Flags),
|
||||
|
|
@ -125,135 +125,128 @@ where
|
|||
message: super::Message<T::Message>,
|
||||
) -> iced::Task<super::Message<T::Message>> {
|
||||
let message = match message {
|
||||
super::Message::App(message) => {
|
||||
match SurfaceMessageHandler::to_surface_message(message) {
|
||||
MessageWrapper::Surface(surface_message) => {
|
||||
#[cfg(feature = "wayland")]
|
||||
match surface_message {
|
||||
SurfaceMessage::Subsurface(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
super::Message::App(message) => match Into::<MessageWrapper<T::Message>>::into(message)
|
||||
{
|
||||
MessageWrapper::Surface(surface_message) => {
|
||||
#[cfg(feature = "wayland")]
|
||||
match surface_message {
|
||||
SurfaceMessage::Subsurface(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
.ok()
|
||||
.and_then(|s| s.downcast::<Box<dyn Fn(&mut T) -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync>>().ok()) else {
|
||||
tracing::error!("Invalid settings for subsurface");
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
if let Some(view) = view.and_then(|view| {
|
||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||
dyn for<'a> Fn(
|
||||
&'a T,
|
||||
)
|
||||
-> Element<'a, super::Message<T::Message>>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>>(
|
||||
) {
|
||||
Ok(v) => Some(v),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
"Invalid view for subsurface view: {err:?}"
|
||||
);
|
||||
None
|
||||
}
|
||||
if let Some(view) = view.and_then(|view| {
|
||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||
dyn for<'a> Fn(&'a T) -> Element<'a, super::Message<T::Message>>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>>(
|
||||
) {
|
||||
Ok(v) => Some(v),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
"Invalid view for subsurface view: {err:?}"
|
||||
);
|
||||
None
|
||||
}
|
||||
}) {
|
||||
let settings = settings(&mut self.app);
|
||||
self.get_subsurface(settings, *view)
|
||||
} else {
|
||||
iced_winit::commands::subsurface::get_subsurface(settings(
|
||||
&mut self.app,
|
||||
))
|
||||
}
|
||||
}) {
|
||||
let settings = settings(&mut self.app);
|
||||
self.get_subsurface(settings, *view)
|
||||
} else {
|
||||
iced_winit::commands::subsurface::get_subsurface(settings(
|
||||
&mut self.app,
|
||||
))
|
||||
}
|
||||
SurfaceMessage::AppPopup(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
}
|
||||
SurfaceMessage::AppPopup(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
.ok()
|
||||
.and_then(|s| s.downcast::<Box<dyn Fn(&mut T) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else {
|
||||
tracing::error!("Invalid settings for popup");
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
if let Some(view) = view.and_then(|view| {
|
||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||
dyn for<'a> Fn(
|
||||
&'a T,
|
||||
)
|
||||
-> Element<'a, super::Message<T::Message>>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>>(
|
||||
) {
|
||||
Ok(v) => Some(v),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
"Invalid view for subsurface view: {err:?}"
|
||||
);
|
||||
None
|
||||
}
|
||||
if let Some(view) = view.and_then(|view| {
|
||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||
dyn for<'a> Fn(&'a T) -> Element<'a, super::Message<T::Message>>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>>(
|
||||
) {
|
||||
Ok(v) => Some(v),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
"Invalid view for subsurface view: {err:?}"
|
||||
);
|
||||
None
|
||||
}
|
||||
}) {
|
||||
let settings = settings(&mut self.app);
|
||||
|
||||
self.get_popup(settings, *view)
|
||||
} else {
|
||||
iced_winit::commands::popup::get_popup(settings(&mut self.app))
|
||||
}
|
||||
}) {
|
||||
let settings = settings(&mut self.app);
|
||||
|
||||
self.get_popup(settings, *view)
|
||||
} else {
|
||||
iced_winit::commands::popup::get_popup(settings(&mut self.app))
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
SurfaceMessage::DestroyPopup(id) => {
|
||||
iced_winit::commands::popup::destroy_popup(id)
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
SurfaceMessage::DestroySubsurface(id) => {
|
||||
iced_winit::commands::subsurface::destroy_subsurface(id)
|
||||
}
|
||||
SurfaceMessage::ResponsiveMenuBar {
|
||||
menu_bar,
|
||||
limits,
|
||||
size,
|
||||
} => {
|
||||
let core = self.app.core_mut();
|
||||
core.menu_bars.insert(menu_bar, (limits, size));
|
||||
iced::Task::none()
|
||||
}
|
||||
SurfaceMessage::Popup(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
SurfaceMessage::DestroyPopup(id) => {
|
||||
iced_winit::commands::popup::destroy_popup(id)
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
SurfaceMessage::DestroySubsurface(id) => {
|
||||
iced_winit::commands::subsurface::destroy_subsurface(id)
|
||||
}
|
||||
SurfaceMessage::ResponsiveMenuBar {
|
||||
menu_bar,
|
||||
limits,
|
||||
size,
|
||||
} => {
|
||||
let core = self.app.core_mut();
|
||||
core.menu_bars.insert(menu_bar, (limits, size));
|
||||
iced::Task::none()
|
||||
}
|
||||
SurfaceMessage::Popup(settings, view) => {
|
||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||
.ok()
|
||||
.and_then(|s| s.downcast::<Box<dyn Fn() -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else {
|
||||
tracing::error!("Invalid settings for popup");
|
||||
return Task::none();
|
||||
};
|
||||
|
||||
if let Some(view) = view.and_then(|view| {
|
||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||
dyn Fn() -> Element<'static, super::Message<T::Message>>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>>(
|
||||
) {
|
||||
Ok(v) => Some(v),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
"Invalid view for subsurface view: {err:?}"
|
||||
);
|
||||
None
|
||||
}
|
||||
if let Some(view) = view.and_then(|view| {
|
||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||
dyn Fn() -> Element<'static, super::Message<T::Message>>
|
||||
+ Send
|
||||
+ Sync,
|
||||
>>(
|
||||
) {
|
||||
Ok(v) => Some(v),
|
||||
Err(err) => {
|
||||
tracing::error!(
|
||||
"Invalid view for subsurface view: {err:?}"
|
||||
);
|
||||
None
|
||||
}
|
||||
}) {
|
||||
let settings = settings();
|
||||
|
||||
self.get_popup(settings, Box::new(move |_| view()))
|
||||
} else {
|
||||
iced_winit::commands::popup::get_popup(settings())
|
||||
}
|
||||
}) {
|
||||
let settings = settings();
|
||||
|
||||
self.get_popup(settings, Box::new(move |_| view()))
|
||||
} else {
|
||||
iced_winit::commands::popup::get_popup(settings())
|
||||
}
|
||||
}
|
||||
#[cfg(not(feature = "wayland"))]
|
||||
iced::Task::none()
|
||||
}
|
||||
MessageWrapper::Message(message) => self.app.update(message),
|
||||
#[cfg(not(feature = "wayland"))]
|
||||
iced::Task::none()
|
||||
}
|
||||
}
|
||||
MessageWrapper::Message(message) => self.app.update(message),
|
||||
},
|
||||
super::Message::Cosmic(message) => self.cosmic_update(message),
|
||||
super::Message::None => iced::Task::none(),
|
||||
#[cfg(feature = "single-instance")]
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
//! Check out our [application](https://github.com/pop-os/libcosmic/tree/master/examples/application)
|
||||
//! example in our repository.
|
||||
|
||||
use crate::surface_message::{MessageWrapper, SurfaceMessage, SurfaceMessageHandler};
|
||||
use crate::surface_message::{MessageWrapper, SurfaceMessage};
|
||||
|
||||
pub mod command;
|
||||
pub mod context_drawer;
|
||||
|
|
@ -17,7 +17,7 @@ pub(crate) mod multi_window;
|
|||
pub mod settings;
|
||||
|
||||
pub mod message {
|
||||
use crate::surface_message::{MessageWrapper, SurfaceMessage, SurfaceMessageHandler};
|
||||
use crate::surface_message::{MessageWrapper, SurfaceMessage};
|
||||
|
||||
use iced::{Limits, Size};
|
||||
|
||||
|
|
@ -50,7 +50,8 @@ pub mod message {
|
|||
#[cfg(feature = "wayland")]
|
||||
pub fn destroy_popup<App: super::Application>(id: iced_core::window::Id) -> App::Message
|
||||
where
|
||||
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||
App::Message:
|
||||
Into<crate::surface_message::MessageWrapper<App::Message>> + From<SurfaceMessage>,
|
||||
{
|
||||
let surface_msg = SurfaceMessage::DestroyPopup(id);
|
||||
App::Message::from(surface_msg)
|
||||
|
|
@ -60,7 +61,8 @@ pub mod message {
|
|||
#[cfg(feature = "wayland")]
|
||||
pub fn destroy_popup_simple<Message>(id: iced_core::window::Id) -> Message
|
||||
where
|
||||
Message: SurfaceMessageHandler + From<SurfaceMessage> + 'static,
|
||||
Message:
|
||||
Into<crate::surface_message::MessageWrapper<Message>> + From<SurfaceMessage> + 'static,
|
||||
{
|
||||
Message::from(SurfaceMessage::DestroyPopup(id))
|
||||
}
|
||||
|
|
@ -68,7 +70,8 @@ pub mod message {
|
|||
#[cfg(feature = "wayland")]
|
||||
pub fn destroy_subsurface<App: super::Application>(id: iced_core::window::Id) -> App::Message
|
||||
where
|
||||
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||
App::Message:
|
||||
Into<crate::surface_message::MessageWrapper<App::Message>> + From<SurfaceMessage>,
|
||||
{
|
||||
let surface_msg = SurfaceMessage::DestroySubsurface(id);
|
||||
App::Message::from(surface_msg)
|
||||
|
|
@ -90,11 +93,12 @@ pub mod message {
|
|||
>,
|
||||
) -> App::Message
|
||||
where
|
||||
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||
App::Message:
|
||||
Into<crate::surface_message::MessageWrapper<App::Message>> + From<SurfaceMessage>,
|
||||
{
|
||||
use std::{any::Any, sync::Arc};
|
||||
|
||||
use crate::surface_message::{SurfaceMessage, SurfaceMessageHandler};
|
||||
use crate::surface_message::SurfaceMessage;
|
||||
let boxed: Box<
|
||||
dyn Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
|
||||
+ Send
|
||||
|
|
@ -124,12 +128,13 @@ pub mod message {
|
|||
>,
|
||||
) -> Message
|
||||
where
|
||||
Message: SurfaceMessageHandler + From<SurfaceMessage> + 'static,
|
||||
Message:
|
||||
Into<crate::surface_message::MessageWrapper<Message>> + From<SurfaceMessage> + 'static,
|
||||
V:,
|
||||
{
|
||||
use std::{any::Any, sync::Arc};
|
||||
|
||||
use crate::surface_message::{SurfaceMessage, SurfaceMessageHandler};
|
||||
use crate::surface_message::SurfaceMessage;
|
||||
let boxed: Box<
|
||||
dyn Fn() -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
|
||||
+ Send
|
||||
|
|
@ -153,20 +158,6 @@ pub mod message {
|
|||
))
|
||||
}
|
||||
|
||||
// TODO could this somehow be used by widgets? It is the wrong message type though.
|
||||
// #[cfg(feature = "wayland")]
|
||||
// pub fn get_simple_popup<App: super::Application>(
|
||||
// settings: iced_runtime::platform_specific::wayland::popup::SctkPopupSettings,
|
||||
// view: Option<
|
||||
// impl Fn() -> crate::Element<'static, super::Message<App::Message>> + Send + Sync + 'static,
|
||||
// >,
|
||||
// ) -> App::Message
|
||||
// where
|
||||
// App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||
// {
|
||||
// todo!()
|
||||
// }
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
pub fn subsurface<App: super::Application>(
|
||||
settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync + 'static,
|
||||
|
|
@ -181,7 +172,8 @@ pub mod message {
|
|||
>,
|
||||
) -> App::Message
|
||||
where
|
||||
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||
App::Message:
|
||||
Into<crate::surface_message::MessageWrapper<App::Message>> + From<SurfaceMessage>,
|
||||
{
|
||||
use crate::surface_message::SurfaceMessage;
|
||||
use std::{any::Any, sync::Arc};
|
||||
|
|
@ -303,7 +295,7 @@ pub(crate) fn iced_settings<App: Application>(
|
|||
/// Returns error on application failure.
|
||||
pub fn run<App: Application>(settings: Settings, flags: App::Flags) -> iced::Result
|
||||
where
|
||||
App::Message: SurfaceMessageHandler,
|
||||
App::Message: Into<crate::surface_message::MessageWrapper<App::Message>>,
|
||||
{
|
||||
#[cfg(target_env = "gnu")]
|
||||
if let Some(threshold) = settings.default_mmap_threshold {
|
||||
|
|
@ -492,7 +484,11 @@ impl DbusActivation {
|
|||
pub fn run_single_instance<App: Application>(settings: Settings, flags: App::Flags) -> iced::Result
|
||||
where
|
||||
App::Flags: CosmicFlags,
|
||||
App::Message: Clone + std::fmt::Debug + Send + SurfaceMessageHandler + 'static,
|
||||
App::Message: Clone
|
||||
+ std::fmt::Debug
|
||||
+ Send
|
||||
+ Into<crate::surface_message::MessageWrapper<App::Message>>
|
||||
+ 'static,
|
||||
{
|
||||
let activation_token = std::env::var("XDG_ACTIVATION_TOKEN").ok();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue