better surface messages
This commit is contained in:
parent
681aed735b
commit
b316d8901b
4 changed files with 256 additions and 196 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use cosmic::app::message::{SurfaceMessage, SurfaceMessageHandler};
|
||||||
use cosmic::app::Core;
|
use cosmic::app::Core;
|
||||||
use cosmic::iced::application;
|
use cosmic::iced::application;
|
||||||
use cosmic::iced::platform_specific::shell::commands::popup::{destroy_popup, get_popup};
|
use cosmic::iced::platform_specific::shell::commands::popup::{destroy_popup, get_popup};
|
||||||
|
|
@ -23,11 +24,24 @@ pub struct Window {
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Message {
|
pub enum Message {
|
||||||
TogglePopup,
|
|
||||||
PopupClosed(Id),
|
PopupClosed(Id),
|
||||||
ToggleExampleRow(bool),
|
ToggleExampleRow(bool),
|
||||||
Hover,
|
Surface(SurfaceMessage),
|
||||||
Leave,
|
}
|
||||||
|
|
||||||
|
impl SurfaceMessageHandler for Message {
|
||||||
|
fn to_surface_message(self) -> cosmic::app::message::MessageWrapper<Self> {
|
||||||
|
match self {
|
||||||
|
Message::Surface(msg) => cosmic::app::message::MessageWrapper::Surface(msg),
|
||||||
|
msg => cosmic::app::message::MessageWrapper::Message(msg),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SurfaceMessage> for Message {
|
||||||
|
fn from(value: SurfaceMessage) -> Self {
|
||||||
|
Message::Surface(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl cosmic::Application for Window {
|
impl cosmic::Application for Window {
|
||||||
|
|
@ -58,12 +72,27 @@ impl cosmic::Application for Window {
|
||||||
|
|
||||||
fn update(&mut self, message: Self::Message) -> Task<cosmic::app::Message<Self::Message>> {
|
fn update(&mut self, message: Self::Message) -> Task<cosmic::app::Message<Self::Message>> {
|
||||||
match message {
|
match message {
|
||||||
Message::TogglePopup => {
|
Message::PopupClosed(id) => {
|
||||||
return if let Some(p) = self.popup.take() {
|
if self.popup.as_ref() == Some(&id) {
|
||||||
cosmic::task::message(cosmic::app::message::destroy_popup(p))
|
self.popup = None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Message::ToggleExampleRow(toggled) => {
|
||||||
|
self.example_row = toggled;
|
||||||
|
}
|
||||||
|
|
||||||
|
Message::Surface(surface_message) => {}
|
||||||
|
}
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn view(&self) -> Element<Self::Message> {
|
||||||
|
cosmic::widget::wayland::tooltip::widget::Tooltip::new(
|
||||||
|
self.core.applet.icon_button("display-symbolic").on_press(
|
||||||
|
if let Some(id) = self.popup {
|
||||||
|
cosmic::app::message::destroy_popup::<Window>(id)
|
||||||
} else {
|
} else {
|
||||||
cosmic::task::message(
|
cosmic::app::message::get_popup::<Window>(
|
||||||
cosmic::app::message::get_popup(
|
|
||||||
|state: &mut Window| {
|
|state: &mut Window| {
|
||||||
let new_id = Id::unique();
|
let new_id = Id::unique();
|
||||||
state.popup = Some(new_id);
|
state.popup = Some(new_id);
|
||||||
|
|
@ -109,20 +138,11 @@ impl cosmic::Application for Window {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
)
|
)
|
||||||
};
|
},
|
||||||
}
|
),
|
||||||
Message::PopupClosed(id) => {
|
|layout| {
|
||||||
if self.popup.as_ref() == Some(&id) {
|
cosmic::app::message::get_subsurface::<Window>(
|
||||||
self.popup = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Message::ToggleExampleRow(toggled) => {
|
|
||||||
self.example_row = toggled;
|
|
||||||
}
|
|
||||||
Message::Hover => {
|
|
||||||
return cosmic::task::message(cosmic::app::message::get_subsurface(
|
|
||||||
|app: &mut Window| {
|
|app: &mut Window| {
|
||||||
let id = window::Id::unique();
|
let id = window::Id::unique();
|
||||||
app.subsurface_id = Some(id);
|
app.subsurface_id = Some(id);
|
||||||
|
|
@ -136,25 +156,11 @@ impl cosmic::Application for Window {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(|app: &Window| layer_container(cosmic::widget::text("hello")).into()),
|
Some(|app: &Window| layer_container(cosmic::widget::text("hello")).into()),
|
||||||
));
|
)
|
||||||
}
|
},
|
||||||
Message::Leave => {
|
cosmic::app::message::destroy_subsurface::<Window>(
|
||||||
return cosmic::task::message(cosmic::app::message::destroy_subsurface(
|
|
||||||
self.subsurface_id.unwrap_or(window::Id::NONE),
|
self.subsurface_id.unwrap_or(window::Id::NONE),
|
||||||
));
|
),
|
||||||
}
|
|
||||||
}
|
|
||||||
Task::none()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self) -> Element<Self::Message> {
|
|
||||||
cosmic::widget::wayland::tooltip::widget::Tooltip::new(
|
|
||||||
self.core
|
|
||||||
.applet
|
|
||||||
.icon_button("display-symbolic")
|
|
||||||
.on_press(Message::TogglePopup),
|
|
||||||
|layout| Message::Hover,
|
|
||||||
Message::Leave,
|
|
||||||
)
|
)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ pub struct Cosmic<App: Application> {
|
||||||
|
|
||||||
impl<T: Application> Cosmic<T>
|
impl<T: Application> Cosmic<T>
|
||||||
where
|
where
|
||||||
T::Message: Send + 'static,
|
T::Message: Send + 'static + super::message::SurfaceMessageHandler,
|
||||||
{
|
{
|
||||||
pub fn init(
|
pub fn init(
|
||||||
(mut core, flags): (Core, T::Flags),
|
(mut core, flags): (Core, T::Flags),
|
||||||
|
|
@ -122,13 +122,13 @@ where
|
||||||
message: super::Message<T::Message>,
|
message: super::Message<T::Message>,
|
||||||
) -> iced::Task<super::Message<T::Message>> {
|
) -> iced::Task<super::Message<T::Message>> {
|
||||||
let message = match message {
|
let message = match message {
|
||||||
super::Message::App(message) => self.app.update(message),
|
super::Message::App(message) => {
|
||||||
super::Message::Cosmic(message) => self.cosmic_update(message),
|
match super::message::SurfaceMessageHandler::to_surface_message(message) {
|
||||||
super::Message::None => iced::Task::none(),
|
super::message::MessageWrapper::Surface(surface_message) =>
|
||||||
#[cfg(feature = "single-instance")]
|
{
|
||||||
super::Message::DbusActivation(message) => self.app.dbus_activation(message),
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
super::Message::Subsurface(settings, view) => {
|
match surface_message {
|
||||||
|
super::message::SurfaceMessage::Subsurface(settings, view) => {
|
||||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|s| s.downcast::<Box<dyn Fn(&mut T) -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync>>().ok()) else {
|
.and_then(|s| s.downcast::<Box<dyn Fn(&mut T) -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync>>().ok()) else {
|
||||||
|
|
@ -138,11 +138,16 @@ where
|
||||||
|
|
||||||
if let Some(view) = view.and_then(|view| {
|
if let Some(view) = view.and_then(|view| {
|
||||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||||
dyn Fn(&T) -> Element<'static, super::Message<T::Message>> + Send + Sync,
|
dyn Fn(&T) -> Element<'static, super::Message<T::Message>>
|
||||||
>>() {
|
+ Send
|
||||||
|
+ Sync,
|
||||||
|
>>(
|
||||||
|
) {
|
||||||
Ok(v) => Some(v),
|
Ok(v) => Some(v),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::error!("Invalid view for subsurface view: {err:?}");
|
tracing::error!(
|
||||||
|
"Invalid view for subsurface view: {err:?}"
|
||||||
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -150,11 +155,13 @@ where
|
||||||
let settings = settings(&mut self.app);
|
let settings = settings(&mut self.app);
|
||||||
self.get_subsurface(settings, *view)
|
self.get_subsurface(settings, *view)
|
||||||
} else {
|
} else {
|
||||||
iced_winit::commands::subsurface::get_subsurface(settings(&mut self.app))
|
iced_winit::commands::subsurface::get_subsurface(settings(
|
||||||
|
&mut self.app,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
super::Message::Popup(settings, view) => {
|
super::message::SurfaceMessage::Popup(settings, view) => {
|
||||||
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
let Some(settings) = std::sync::Arc::try_unwrap(settings)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|s| s.downcast::<Box<dyn Fn(&mut T) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else {
|
.and_then(|s| s.downcast::<Box<dyn Fn(&mut T) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings + Send + Sync>>().ok()) else {
|
||||||
|
|
@ -164,11 +171,16 @@ where
|
||||||
|
|
||||||
if let Some(view) = view.and_then(|view| {
|
if let Some(view) = view.and_then(|view| {
|
||||||
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
match std::sync::Arc::try_unwrap(view).ok()?.downcast::<Box<
|
||||||
dyn Fn(&T) -> Element<'static, super::Message<T::Message>> + Send + Sync,
|
dyn Fn(&T) -> Element<'static, super::Message<T::Message>>
|
||||||
>>() {
|
+ Send
|
||||||
|
+ Sync,
|
||||||
|
>>(
|
||||||
|
) {
|
||||||
Ok(v) => Some(v),
|
Ok(v) => Some(v),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
tracing::error!("Invalid view for subsurface view: {err:?}");
|
tracing::error!(
|
||||||
|
"Invalid view for subsurface view: {err:?}"
|
||||||
|
);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -181,11 +193,22 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
super::Message::DestroyPopup(id) => iced_winit::commands::popup::destroy_popup(id),
|
super::message::SurfaceMessage::DestroyPopup(id) => {
|
||||||
|
iced_winit::commands::popup::destroy_popup(id)
|
||||||
|
}
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
super::Message::DestroySubsurface(id) => {
|
super::message::SurfaceMessage::DestroySubsurface(id) => {
|
||||||
iced_winit::commands::subsurface::destroy_subsurface(id)
|
iced_winit::commands::subsurface::destroy_subsurface(id)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super::message::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")]
|
||||||
|
super::Message::DbusActivation(message) => self.app.dbus_activation(message),
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(target_env = "gnu")]
|
#[cfg(target_env = "gnu")]
|
||||||
|
|
|
||||||
136
src/app/mod.rs
136
src/app/mod.rs
|
|
@ -15,7 +15,57 @@ pub(crate) mod multi_window;
|
||||||
pub mod settings;
|
pub mod settings;
|
||||||
|
|
||||||
pub mod message {
|
pub mod message {
|
||||||
|
pub enum MessageWrapper<M> {
|
||||||
|
Surface(SurfaceMessage),
|
||||||
|
Message(M),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait SurfaceMessageHandler: Sized {
|
||||||
|
fn to_surface_message(self) -> MessageWrapper<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "wayland"))]
|
||||||
|
impl<M> SurfaceMessageHandler for M {
|
||||||
|
fn to_surface_message(self) -> MessageWrapper<Self> {
|
||||||
|
MessageWrapper::Message(self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
pub enum SurfaceMessage {
|
||||||
|
/// Create a subsurface with a view function
|
||||||
|
Subsurface(
|
||||||
|
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
|
||||||
|
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
|
||||||
|
),
|
||||||
|
/// Destroy a subsurface with a view function
|
||||||
|
DestroySubsurface(iced::window::Id),
|
||||||
|
/// Create a popup with a view function
|
||||||
|
Popup(
|
||||||
|
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
|
||||||
|
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
|
||||||
|
),
|
||||||
|
/// Destroy a subsurface with a view function
|
||||||
|
DestroyPopup(iced::window::Id),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "wayland")]
|
||||||
|
impl std::fmt::Debug for SurfaceMessage {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
match self {
|
||||||
|
SurfaceMessage::Subsurface(any, any1) => f.debug_tuple("Subsurface").finish(),
|
||||||
|
SurfaceMessage::DestroySubsurface(id) => {
|
||||||
|
f.debug_tuple("DestroySubsurface").field(id).finish()
|
||||||
|
}
|
||||||
|
SurfaceMessage::Popup(any, any1) => f.debug_tuple("Popup").finish(),
|
||||||
|
SurfaceMessage::DestroyPopup(id) => {
|
||||||
|
f.debug_tuple("DestroyPopup").field(id).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub enum Message<M> {
|
pub enum Message<M> {
|
||||||
/// Messages from the application, for the application.
|
/// Messages from the application, for the application.
|
||||||
|
|
@ -27,24 +77,6 @@ pub mod message {
|
||||||
DbusActivation(super::DbusActivationMessage),
|
DbusActivation(super::DbusActivationMessage),
|
||||||
/// Do nothing
|
/// Do nothing
|
||||||
None,
|
None,
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
/// Create a subsurface with a view function
|
|
||||||
Subsurface(
|
|
||||||
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
|
|
||||||
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
|
|
||||||
),
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
/// Destroy a subsurface with a view function
|
|
||||||
DestroySubsurface(iced::window::Id),
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
/// Create a popup with a view function
|
|
||||||
Popup(
|
|
||||||
std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>,
|
|
||||||
Option<std::sync::Arc<Box<dyn std::any::Any + Send + Sync>>>,
|
|
||||||
),
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
/// Destroy a subsurface with a view function
|
|
||||||
DestroyPopup(iced::window::Id),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn app<M>(message: M) -> Message<M> {
|
pub const fn app<M>(message: M) -> Message<M> {
|
||||||
|
|
@ -60,17 +92,25 @@ pub mod message {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
pub const fn destroy_popup<M>(id: iced_core::window::Id) -> Message<M> {
|
pub fn destroy_popup<App: super::Application>(id: iced_core::window::Id) -> App::Message
|
||||||
Message::DestroyPopup(id)
|
where
|
||||||
|
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||||
|
{
|
||||||
|
let surface_msg = SurfaceMessage::DestroyPopup(id);
|
||||||
|
App::Message::from(surface_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
pub const fn destroy_subsurface<M>(id: iced_core::window::Id) -> Message<M> {
|
pub fn destroy_subsurface<App: super::Application>(id: iced_core::window::Id) -> App::Message
|
||||||
Message::DestroySubsurface(id)
|
where
|
||||||
|
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||||
|
{
|
||||||
|
let surface_msg = SurfaceMessage::DestroySubsurface(id);
|
||||||
|
App::Message::from(surface_msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
pub fn get_popup<App: crate::Application>(
|
pub fn get_popup<App: super::Application>(
|
||||||
settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
|
settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
|
|
@ -81,7 +121,10 @@ pub mod message {
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
>,
|
>,
|
||||||
) -> Message<App::Message> {
|
) -> App::Message
|
||||||
|
where
|
||||||
|
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||||
|
{
|
||||||
use std::{any::Any, sync::Arc};
|
use std::{any::Any, sync::Arc};
|
||||||
let boxed: Box<
|
let boxed: Box<
|
||||||
dyn Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
|
dyn Fn(&mut App) -> iced_runtime::platform_specific::wayland::popup::SctkPopupSettings
|
||||||
|
|
@ -91,7 +134,7 @@ pub mod message {
|
||||||
> = Box::new(settings);
|
> = Box::new(settings);
|
||||||
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
||||||
|
|
||||||
Message::Popup(
|
App::Message::from(SurfaceMessage::Popup(
|
||||||
Arc::new(boxed),
|
Arc::new(boxed),
|
||||||
view.map(|view| {
|
view.map(|view| {
|
||||||
let boxed: Box<
|
let boxed: Box<
|
||||||
|
|
@ -103,11 +146,11 @@ pub mod message {
|
||||||
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
||||||
Arc::new(boxed)
|
Arc::new(boxed)
|
||||||
}),
|
}),
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "wayland")]
|
#[cfg(feature = "wayland")]
|
||||||
pub fn get_subsurface<App: crate::Application>(
|
pub fn get_subsurface<App: super::Application>(
|
||||||
settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync + 'static,
|
settings: impl Fn(&mut App) -> iced_runtime::platform_specific::wayland::subsurface::SctkSubsurfaceSettings + Send + Sync + 'static,
|
||||||
view: Option<
|
view: Option<
|
||||||
impl Fn(&App) -> crate::Element<'static, super::Message<App::Message>>
|
impl Fn(&App) -> crate::Element<'static, super::Message<App::Message>>
|
||||||
|
|
@ -115,7 +158,10 @@ pub mod message {
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
>,
|
>,
|
||||||
) -> Message<App::Message> {
|
) -> App::Message
|
||||||
|
where
|
||||||
|
App::Message: SurfaceMessageHandler + From<SurfaceMessage>,
|
||||||
|
{
|
||||||
use std::{any::Any, sync::Arc};
|
use std::{any::Any, sync::Arc};
|
||||||
let boxed: Box<
|
let boxed: Box<
|
||||||
dyn Fn(
|
dyn Fn(
|
||||||
|
|
@ -128,7 +174,7 @@ pub mod message {
|
||||||
> = Box::new(settings);
|
> = Box::new(settings);
|
||||||
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
||||||
|
|
||||||
Message::Subsurface(
|
App::Message::from(SurfaceMessage::Subsurface(
|
||||||
Arc::new(boxed),
|
Arc::new(boxed),
|
||||||
view.map(|view| {
|
view.map(|view| {
|
||||||
let boxed: Box<
|
let boxed: Box<
|
||||||
|
|
@ -140,7 +186,7 @@ pub mod message {
|
||||||
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
let boxed: Box<dyn Any + Send + Sync + 'static> = Box::new(boxed);
|
||||||
Arc::new(boxed)
|
Arc::new(boxed)
|
||||||
}),
|
}),
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M> From<M> for Message<M> {
|
impl<M> From<M> for Message<M> {
|
||||||
|
|
@ -148,29 +194,6 @@ pub mod message {
|
||||||
Self::App(value)
|
Self::App(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<M: std::fmt::Debug> std::fmt::Debug for Message<M> {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
match self {
|
|
||||||
Self::App(arg0) => f.debug_tuple("App").field(arg0).finish(),
|
|
||||||
Self::Cosmic(arg0) => f.debug_tuple("Cosmic").field(arg0).finish(),
|
|
||||||
|
|
||||||
#[cfg(feature = "single-instance")]
|
|
||||||
Self::DbusActivation(arg0) => f.debug_tuple("DbusActivation").field(arg0).finish(),
|
|
||||||
Self::None => write!(f, "None"),
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
Self::Subsurface(arg0, arg1) => f.debug_tuple("Subsurface").field(arg1).finish(),
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
Self::DestroySubsurface(arg0) => {
|
|
||||||
f.debug_tuple("DestroySubsurface").field(arg0).finish()
|
|
||||||
}
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
Self::Popup(arg0, arg1) => f.debug_tuple("Popup").field(arg1).finish(),
|
|
||||||
#[cfg(feature = "wayland")]
|
|
||||||
Self::DestroyPopup(arg0) => f.debug_tuple("DestroyPopup").field(arg0).finish(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
@ -186,6 +209,7 @@ use context_drawer::ContextDrawer;
|
||||||
use iced::window;
|
use iced::window;
|
||||||
use iced::{Length, Subscription};
|
use iced::{Length, Subscription};
|
||||||
pub use message::Message;
|
pub use message::Message;
|
||||||
|
use message::SurfaceMessageHandler;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
#[cfg(feature = "single-instance")]
|
#[cfg(feature = "single-instance")]
|
||||||
use {
|
use {
|
||||||
|
|
@ -262,12 +286,16 @@ pub(crate) fn iced_settings<App: Application>(
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns error on application failure.
|
/// Returns error on application failure.
|
||||||
pub fn run<App: Application>(settings: Settings, flags: App::Flags) -> iced::Result {
|
pub fn run<App: Application>(settings: Settings, flags: App::Flags) -> iced::Result
|
||||||
|
where
|
||||||
|
App::Message: SurfaceMessageHandler,
|
||||||
|
{
|
||||||
#[cfg(target_env = "gnu")]
|
#[cfg(target_env = "gnu")]
|
||||||
if let Some(threshold) = settings.default_mmap_threshold {
|
if let Some(threshold) = settings.default_mmap_threshold {
|
||||||
crate::malloc::limit_mmap_threshold(threshold);
|
crate::malloc::limit_mmap_threshold(threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let default_font = settings.default_font;
|
||||||
let (settings, mut flags, window_settings) = iced_settings::<App>(settings, flags);
|
let (settings, mut flags, window_settings) = iced_settings::<App>(settings, flags);
|
||||||
#[cfg(not(feature = "multi-window"))]
|
#[cfg(not(feature = "multi-window"))]
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
pub mod token;
|
pub mod token;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{self, iced_settings, Core},
|
app::{self, iced_settings, message::SurfaceMessageHandler, Core},
|
||||||
cctk::sctk,
|
cctk::sctk,
|
||||||
iced::{
|
iced::{
|
||||||
self,
|
self,
|
||||||
|
|
@ -376,7 +376,10 @@ impl Context {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Returns error on application failure.
|
/// Returns error on application failure.
|
||||||
pub fn run<App: Application>(flags: App::Flags) -> iced::Result {
|
pub fn run<App: Application>(flags: App::Flags) -> iced::Result
|
||||||
|
where
|
||||||
|
App::Message: SurfaceMessageHandler,
|
||||||
|
{
|
||||||
let helper = Context::default();
|
let helper = Context::default();
|
||||||
|
|
||||||
let mut settings = helper.window_settings();
|
let mut settings = helper.window_settings();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue