refactor: make SurfaceMessage handling opt in

This commit is contained in:
Ashley Wulber 2025-02-24 14:35:17 -05:00
parent 63f249a395
commit 31d676a4f2
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
4 changed files with 16 additions and 7 deletions

View file

@ -71,7 +71,9 @@ wayland = [
"iced/wayland",
"iced_winit/wayland",
"cctk",
"surface-message",
]
surface-message = []
# multi-window support
multi-window = ["iced/multi-window"]
# Render with wgpu

View file

@ -7,7 +7,7 @@ use apply::Apply;
use cosmic::app::{Core, Settings, Task};
use cosmic::dialog::file_chooser::{self, FileFilter};
use cosmic::iced_core::Length;
use cosmic::surface_message::{SurfaceMessage, SurfaceMessageHandler};
use cosmic::surface_message::{MessageWrapper, SurfaceMessage};
use cosmic::widget::button;
use cosmic::{executor, iced, ApplicationExt, Element};
use std::sync::Arc;
@ -38,11 +38,11 @@ pub enum Message {
Surface(SurfaceMessage),
}
impl SurfaceMessageHandler for Message {
fn to_surface_message(self) -> cosmic::surface_message::MessageWrapper<Self> {
match self {
Message::Surface(m) => cosmic::surface_message::MessageWrapper::Surface(m),
m => cosmic::surface_message::MessageWrapper::Message(m),
impl From<Message> for MessageWrapper<Message> {
fn from(value: Message) -> Self {
match value {
Message::Surface(s) => MessageWrapper::Surface(s),
m => MessageWrapper::Message(m),
}
}
}

View file

@ -388,7 +388,7 @@ impl Core {
id
}
#[cfg(feature = "wayland")]
#[cfg(feature = "surface-message")]
/// # Panics
///
/// Will panic if the menu bar collapses without tracking the size

View file

@ -7,6 +7,13 @@ pub enum MessageWrapper<M> {
Message(M),
}
#[cfg(not(feature = "surface-message"))]
impl<M> From<M> for MessageWrapper<M> {
fn from(value: M) -> Self {
MessageWrapper::Message(value)
}
}
/// Ignore this message in your application. It will be intercepted.
#[derive(Clone)]
pub enum SurfaceMessage {