From 17ad618fae133a9229eefad65758bf372cf5aac8 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 24 Feb 2025 14:35:17 -0500 Subject: [PATCH] refactor: make SurfaceMessage handling opt in --- Cargo.toml | 2 ++ examples/open-dialog/src/main.rs | 12 ++++++------ src/app/core.rs | 2 +- src/surface_message.rs | 7 +++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ee0d6bd0..bc501e3a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/examples/open-dialog/src/main.rs b/examples/open-dialog/src/main.rs index 7aff13ce..a4b5f00d 100644 --- a/examples/open-dialog/src/main.rs +++ b/examples/open-dialog/src/main.rs @@ -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 { - match self { - Message::Surface(m) => cosmic::surface_message::MessageWrapper::Surface(m), - m => cosmic::surface_message::MessageWrapper::Message(m), +impl From for MessageWrapper { + fn from(value: Message) -> Self { + match value { + Message::Surface(s) => MessageWrapper::Surface(s), + m => MessageWrapper::Message(m), } } } diff --git a/src/app/core.rs b/src/app/core.rs index f684cd5c..7ef7c684 100644 --- a/src/app/core.rs +++ b/src/app/core.rs @@ -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 diff --git a/src/surface_message.rs b/src/surface_message.rs index da34bf20..429fa463 100644 --- a/src/surface_message.rs +++ b/src/surface_message.rs @@ -7,6 +7,13 @@ pub enum MessageWrapper { Message(M), } +#[cfg(not(feature = "surface-message"))] +impl From for MessageWrapper { + fn from(value: M) -> Self { + MessageWrapper::Message(value) + } +} + /// Ignore this message in your application. It will be intercepted. #[derive(Clone)] pub enum SurfaceMessage {