diff --git a/Cargo.lock b/Cargo.lock index 4eace4b..bd6d03e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -536,9 +536,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.2" +version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f34d93e62b03caf570cccc334cbc6c2fceca82f39211051345108adcba3eebdc" +checksum = "27f657647bcff5394bf56c7317665bbf790a137a50eaaa5c6bfbb9e27a518f2d" dependencies = [ "jobserver", "libc", @@ -1214,9 +1214,9 @@ checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "fdeflate" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c6f4c64c1d33a3111c4466f7365ebdcc37c5bd1ea0d62aae2e3d722aacbedb" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" dependencies = [ "simd-adler32", ] @@ -2091,9 +2091,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a865e038f7f6ed956f788f0d7d60c541fff74c7bd74272c5d4cf15c63743e705" +checksum = "6717b6b5b077764fb5966237269cb3c64edddde4b14ce42647430a78ced9e7b7" dependencies = [ "once_cell", "wasm-bindgen", @@ -3057,9 +3057,9 @@ checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" [[package]] name = "png" -version = "0.17.14" +version = "0.17.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52f9d46a34a05a6a57566bc2bfae066ef07585a6e3fa30fbbdff5936380623f0" +checksum = "b67582bd5b65bdff614270e2ea89a1cf15bef71245cc1e5f7ea126977144211d" dependencies = [ "bitflags 1.3.2", "crc32fast", @@ -3457,9 +3457,9 @@ dependencies = [ [[package]] name = "self_cell" -version = "1.0.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d369a96f978623eb3dc28807c4852d6cc617fed53da5d3c400feff1ef34a714a" +checksum = "c2fdfc24bc566f839a2da4c4295b82db7d25a24253867d5c64355abb5799bdbe" [[package]] name = "serde" @@ -4233,9 +4233,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d15e63b4482863c109d70a7b8706c1e364eb6ea449b201a76c5b89cedcec2d5c" +checksum = "a474f6281d1d70c17ae7aa6a613c87fce69a127e2624002df63dcb39d6cf6396" dependencies = [ "cfg-if", "once_cell", @@ -4244,13 +4244,12 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d36ef12e3aaca16ddd3f67922bc63e48e953f126de60bd33ccc0101ef9998cd" +checksum = "5f89bb38646b4f81674e8f5c3fb81b562be1fd936d84320f3264486418519c79" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", "syn 2.0.90", @@ -4259,9 +4258,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.47" +version = "0.4.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dfaf8f50e5f293737ee323940c7d8b08a66a95a419223d9f41610ca08b0833d" +checksum = "38176d9b44ea84e9184eff0bc34cc167ed044f816accfe5922e54d84cf48eca2" dependencies = [ "cfg-if", "js-sys", @@ -4272,9 +4271,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "705440e08b42d3e4b36de7d66c944be628d579796b8090bfa3471478a2260051" +checksum = "2cc6181fd9a7492eef6fef1f33961e3695e4579b9872a6f7c83aee556666d4fe" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4282,9 +4281,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c9ae5a76e46f4deecd0f0255cc223cfa18dc9b261213b8aa0c7b36f61b3f1d" +checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", @@ -4295,9 +4294,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.97" +version = "0.2.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee99da9c5ba11bd675621338ef6fa52296b76b83305e9b6e5c77d4c286d6d49" +checksum = "943aab3fdaaa029a6e0271b35ea10b72b943135afe9bffca82384098ad0e06a6" [[package]] name = "wasm-timer" @@ -4452,9 +4451,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.74" +version = "0.3.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a98bc3c33f0fe7e59ad7cd041b89034fa82a7c2d4365ca538dda6cdaf513863c" +checksum = "04dd7223427d52553d3702c004d3b2fe07c148165faa56313cb00211e31c12bc" dependencies = [ "js-sys", "wasm-bindgen", @@ -5014,9 +5013,9 @@ checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" [[package]] name = "xml-rs" -version = "0.8.23" +version = "0.8.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f" +checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" [[package]] name = "xmlwriter" diff --git a/iced_examples/application_launcher/src/main.rs b/iced_examples/application_launcher/src/main.rs index 43d966a..ea551f0 100644 --- a/iced_examples/application_launcher/src/main.rs +++ b/iced_examples/application_launcher/src/main.rs @@ -2,7 +2,7 @@ use applications::{all_apps, App}; use iced::widget::{column, scrollable, text_input}; use iced::{event, Element, Event, Length, Task as Command, Theme}; mod applications; -use iced_layershell::actions::LayershellCustomActionsWithInfo; +use iced_layershell::actions::LayershellCustomActions; use iced_layershell::reexport::{Anchor, KeyboardInteractivity}; use iced_layershell::settings::{LayerShellSettings, Settings}; use iced_layershell::Application; @@ -27,9 +27,9 @@ fn main() -> Result<(), iced_layershell::Error> { Ok(()) } -impl TryInto> for Message { +impl TryInto for Message { type Error = Self; - fn try_into(self) -> Result, Self::Error> { + fn try_into(self) -> Result { Err(self) } } diff --git a/iced_examples/counter_mulit_pattern/src/main.rs b/iced_examples/counter_mulit_pattern/src/main.rs index 4b8249e..1c46f80 100644 --- a/iced_examples/counter_mulit_pattern/src/main.rs +++ b/iced_examples/counter_mulit_pattern/src/main.rs @@ -10,7 +10,7 @@ use iced_runtime::{task, Action}; use iced_layershell::build_pattern::{daemon, MainSettings}; use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; use iced_layershell::settings::{LayerShellSettings, StartMode}; -use iced_layershell::{to_layer_message, WindowInfoMarker}; +use iced_layershell::to_layer_message; pub fn main() -> Result<(), iced_layershell::Error> { tracing_subscriber::fmt().init(); @@ -18,8 +18,6 @@ pub fn main() -> Result<(), iced_layershell::Error> { Counter::namespace, Counter::update, Counter::view, - Counter::id_info, - Counter::set_id_info, Counter::remove_id, ) .subscription(Counter::subscription) @@ -43,15 +41,11 @@ struct Counter { ids: HashMap, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, WindowInfoMarker)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] enum WindowInfo { - #[singleton] Left, - #[singleton] Right, PopUp, - #[main] - Main, } #[derive(Debug, Clone, Copy)] @@ -62,7 +56,7 @@ enum WindowDirection { Bottom(Id), } -#[to_layer_message(multi, info_name = "WindowInfo")] +#[to_layer_message(multi)] #[derive(Debug, Clone)] enum Message { IncrementPressed, @@ -102,14 +96,6 @@ impl Counter { self.ids.get(&id).cloned() } - fn set_id_info(&mut self, id: iced::window::Id, info: WindowInfo) { - if let WindowInfo::Main = info { - println!("it is main window: {id}"); - return; - } - self.ids.insert(id, info); - } - fn remove_id(&mut self, id: iced::window::Id) { self.ids.remove(&id); } @@ -140,12 +126,14 @@ impl Counter { } } Event::Mouse(iced::mouse::Event::ButtonPressed(iced::mouse::Button::Right)) => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::PopUp); return Command::done(Message::NewMenu { settings: IcedNewMenuSettings { size: (100, 100), direction: MenuDirection::Up, }, - info: WindowInfo::PopUp, + id, }); } _ => {} @@ -186,32 +174,40 @@ impl Counter { size: (0, 400), }), }, - Message::NewWindowLeft => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Left | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Left, - }), - Message::NewWindowRight => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Right | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Right, - }), + Message::NewWindowLeft => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Left); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Left | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } + Message::NewWindowRight => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Right); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Right | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } Message::Close(id) => task::effect(Action::Window(WindowAction::Close(id))), _ => unreachable!(), } diff --git a/iced_examples/counter_muti/src/main.rs b/iced_examples/counter_muti/src/main.rs index fa4a415..aa16133 100644 --- a/iced_examples/counter_muti/src/main.rs +++ b/iced_examples/counter_muti/src/main.rs @@ -9,8 +9,8 @@ use iced_runtime::{task, Action}; use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; +use iced_layershell::to_layer_message; use iced_layershell::MultiApplication; -use iced_layershell::{to_layer_message, WindowInfoMarker}; pub fn main() -> Result<(), iced_layershell::Error> { tracing_subscriber::fmt().init(); @@ -32,11 +32,9 @@ struct Counter { ids: HashMap, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, WindowInfoMarker)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] enum WindowInfo { - #[singleton] Left, - #[singleton] Right, PopUp, } @@ -49,7 +47,7 @@ enum WindowDirection { Bottom(Id), } -#[to_layer_message(multi, info_name = "WindowInfo")] +#[to_layer_message(multi)] #[derive(Debug, Clone)] enum Message { IncrementPressed, @@ -73,12 +71,17 @@ impl Counter { } } +impl Counter { + fn id_info(&self, id: iced::window::Id) -> Option { + self.ids.get(&id).cloned() + } +} + impl MultiApplication for Counter { type Message = Message; type Flags = (); type Theme = Theme; type Executor = iced::executor::Default; - type WindowInfo = WindowInfo; fn new(_flags: ()) -> (Self, Command) { ( @@ -90,19 +93,6 @@ impl MultiApplication for Counter { Command::none(), ) } - - fn id_info(&self, id: iced::window::Id) -> Option { - self.ids.get(&id).cloned() - } - - fn set_id_info(&mut self, id: iced::window::Id, info: Self::WindowInfo) { - self.ids.insert(id, info); - } - - fn remove_id(&mut self, id: iced::window::Id) { - self.ids.remove(&id); - } - fn namespace(&self) -> String { String::from("Counter - Iced") } @@ -110,7 +100,9 @@ impl MultiApplication for Counter { fn subscription(&self) -> iced::Subscription { event::listen().map(Message::IcedEvent) } - + fn remove_id(&mut self, id: iced::window::Id) { + self.ids.remove(&id); + } fn update(&mut self, message: Message) -> Command { use iced::keyboard; use iced::keyboard::key::Named; @@ -129,12 +121,14 @@ impl MultiApplication for Counter { } } Event::Mouse(iced::mouse::Event::ButtonPressed(iced::mouse::Button::Right)) => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::PopUp); return Command::done(Message::NewMenu { settings: IcedNewMenuSettings { size: (100, 100), direction: MenuDirection::Up, }, - info: WindowInfo::PopUp, + id, }); } _ => {} @@ -175,32 +169,40 @@ impl MultiApplication for Counter { size: (0, 400), }), }, - Message::NewWindowLeft => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Left | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Left, - }), - Message::NewWindowRight => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Right | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Right, - }), + Message::NewWindowLeft => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Left); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Left | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } + Message::NewWindowRight => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Right); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Right | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } Message::Close(id) => task::effect(Action::Window(WindowAction::Close(id))), _ => unreachable!(), } @@ -221,7 +223,6 @@ impl MultiApplication for Counter { background: Some(iced::Color::new(0., 0.5, 0.7, 0.6).into()), ..Default::default() }) - //.style(Container::Custom(Box::new(BlackMenu))) .width(Length::Fill) .height(Length::Fill) .into(); diff --git a/iced_examples/iced_virtualkeyboard/src/main.rs b/iced_examples/iced_virtualkeyboard/src/main.rs index b762846..7ab8d08 100644 --- a/iced_examples/iced_virtualkeyboard/src/main.rs +++ b/iced_examples/iced_virtualkeyboard/src/main.rs @@ -4,7 +4,7 @@ use iced::widget::canvas; use iced::widget::canvas::{Cache, Event, Geometry, Path, Text}; use iced::{Color, Task as Command}; use iced::{Element, Length, Point, Rectangle, Renderer, Size, Theme}; -use iced_layershell::actions::{LayershellCustomActions, LayershellCustomActionsWithInfo}; +use iced_layershell::actions::LayershellCustomActions; use iced_layershell::reexport::wl_keyboard::KeymapFormat; use iced_layershell::reexport::{Anchor, KeyboardInteractivity}; use iced_layershell::settings::{LayerShellSettings, Settings, VirtualKeyboardSettings}; @@ -89,9 +89,9 @@ enum Message { InputKeyPressed(u32), } -impl TryInto> for Message { +impl TryInto for Message { type Error = Self; - fn try_into(self) -> Result, Self::Error> { + fn try_into(self) -> Result { let Message::InputKeyPressed(key) = self; Ok(LayershellCustomActions::VirtualKeyboardPressed { time: 100, key }) } diff --git a/iced_examples/zbus_invoked_widget/Cargo.toml b/iced_examples/zbus_invoked_widget/Cargo.toml index ef3dcf1..b93bced 100644 --- a/iced_examples/zbus_invoked_widget/Cargo.toml +++ b/iced_examples/zbus_invoked_widget/Cargo.toml @@ -10,7 +10,7 @@ keywords.workspace = true readme.workspace = true [dependencies] -iced.workspace = true +iced = { workspace = true, features = ["tokio"] } iced_runtime.workspace = true iced_layershell.workspace = true diff --git a/iced_examples/zbus_invoked_widget/src/main.rs b/iced_examples/zbus_invoked_widget/src/main.rs index 7485830..c649a02 100644 --- a/iced_examples/zbus_invoked_widget/src/main.rs +++ b/iced_examples/zbus_invoked_widget/src/main.rs @@ -2,9 +2,7 @@ use futures::future::pending; use iced::widget::{button, column, container, text, text_input}; use iced::window::Id; use iced::{Element, Length, Task as Command, Theme}; -use iced_layershell::actions::{ - LayershellCustomActionsWithIdAndInfo, LayershellCustomActionsWithInfo, -}; +use iced_layershell::to_layer_message; use iced_runtime::window::Action as WindowAction; use iced_runtime::Action; @@ -15,9 +13,6 @@ use zbus::{connection, interface}; use futures::channel::mpsc::Sender; -type LaLaShellIdAction = LayershellCustomActionsWithIdAndInfo<()>; -type LalaShellAction = LayershellCustomActionsWithInfo<()>; - struct Counter { window_shown: bool, text: String, @@ -32,6 +27,7 @@ pub fn main() -> Result<(), iced_layershell::Error> { }) } +#[to_layer_message(multi)] #[derive(Debug, Clone)] enum Message { NewWindow, @@ -39,41 +35,11 @@ enum Message { CloseWindow(Id), } -impl TryInto for Message { - type Error = Self; - fn try_into(self) -> Result, Self::Error> { - match self { - Self::NewWindow => Ok(LaLaShellIdAction::new( - None, - LalaShellAction::NewLayerShell { - settings: NewLayerShellSettings { - size: None, - exclusive_zone: None, - anchor: Anchor::Right | Anchor::Top | Anchor::Left | Anchor::Bottom, - layer: Layer::Top, - margin: Some((100, 100, 100, 100)), - keyboard_interactivity: KeyboardInteractivity::OnDemand, - use_last_output: false, - ..Default::default() - }, - info: (), - }, - )), - _ => Err(self), - } - } -} - impl MultiApplication for Counter { type Message = Message; type Flags = (); type Theme = Theme; type Executor = iced::executor::Default; - type WindowInfo = (); - - fn set_id_info(&mut self, _id: iced_runtime::core::window::Id, _info: Self::WindowInfo) { - self.window_shown = true; - } fn remove_id(&mut self, _id: iced_runtime::core::window::Id) { self.window_shown = false; @@ -140,12 +106,27 @@ impl MultiApplication for Counter { if self.window_shown { return Command::none(); } - Command::done(message) + + self.window_shown = true; + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: None, + exclusive_zone: None, + anchor: Anchor::Right | Anchor::Top | Anchor::Left | Anchor::Bottom, + layer: Layer::Top, + margin: Some((100, 100, 100, 100)), + keyboard_interactivity: KeyboardInteractivity::OnDemand, + use_last_output: false, + ..Default::default() + }, + id: iced::window::Id::unique(), + }) } Message::TextInput(text) => { self.text = text; Command::none() } + _ => unreachable!(), } } } diff --git a/iced_layershell/README.md b/iced_layershell/README.md index f5ebba7..8d90515 100644 --- a/iced_layershell/README.md +++ b/iced_layershell/README.md @@ -203,15 +203,13 @@ use iced_runtime::{task, Action}; use iced_layershell::build_pattern::{daemon, MainSettings}; use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; use iced_layershell::settings::{LayerShellSettings, StartMode}; -use iced_layershell::{to_layer_message, WindowInfoMarker}; +use iced_layershell::to_layer_message; pub fn main() -> Result<(), iced_layershell::Error> { daemon( Counter::namespace, Counter::update, Counter::view, - Counter::id_info, - Counter::set_id_info, Counter::remove_id, ) .subscription(Counter::subscription) @@ -235,15 +233,11 @@ struct Counter { ids: HashMap, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, WindowInfoMarker)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] enum WindowInfo { - #[singleton] Left, - #[singleton] Right, PopUp, - #[main] - Main, } #[derive(Debug, Clone, Copy)] @@ -254,7 +248,7 @@ enum WindowDirection { Bottom(Id), } -#[to_layer_message(multi, info_name = "WindowInfo")] +#[to_layer_message(multi)] #[derive(Debug, Clone)] enum Message { IncrementPressed, @@ -294,14 +288,6 @@ impl Counter { self.ids.get(&id).cloned() } - fn set_id_info(&mut self, id: iced::window::Id, info: WindowInfo) { - if let WindowInfo::Main = info { - println!("it is main window: {id}"); - return; - } - self.ids.insert(id, info); - } - fn remove_id(&mut self, id: iced::window::Id) { self.ids.remove(&id); } @@ -332,12 +318,14 @@ impl Counter { } } Event::Mouse(iced::mouse::Event::ButtonPressed(iced::mouse::Button::Right)) => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::PopUp); return Command::done(Message::NewMenu { settings: IcedNewMenuSettings { size: (100, 100), direction: MenuDirection::Up, }, - info: WindowInfo::PopUp, + id, }); } _ => {} @@ -378,32 +366,40 @@ impl Counter { size: (0, 400), }), }, - Message::NewWindowLeft => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Left | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Left, - }), - Message::NewWindowRight => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Right | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Right, - }), + Message::NewWindowLeft => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Left); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Left | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } + Message::NewWindowRight => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Right); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Right | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } Message::Close(id) => task::effect(Action::Window(WindowAction::Close(id))), _ => unreachable!(), } @@ -469,6 +465,7 @@ impl Counter { .into() } } + ``` For more example, please take a look at [exwlshelleventloop](https://github.com/waycrate/exwlshelleventloop) diff --git a/iced_layershell/src/actions.rs b/iced_layershell/src/actions.rs index af94a33..464c112 100644 --- a/iced_layershell/src/actions.rs +++ b/iced_layershell/src/actions.rs @@ -4,16 +4,16 @@ use iced_core::mouse::Interaction; use layershellev::id::Id as LayerId; use layershellev::NewLayerShellSettings; -pub(crate) type LayerShellActionVec = Vec>; +pub(crate) type LayerShellActionVec = Vec; #[derive(Debug, Clone)] -pub(crate) enum LayerShellAction { +pub(crate) enum LayerShellAction { Mouse(Interaction), - CustomActions(LayershellCustomActionsWithInfo), - CustomActionsWithId(LayershellCustomActionsWithIdInner), + CustomActions(LayershellCustomActions), + CustomActionsWithId(LayershellCustomActionsWithIdInner), RedrawAll, RedrawWindow(LayerId), // maybe one day it is useful, but now useless - NewMenu((IcedNewPopupSettings, INFO)), + NewMenu((IcedNewPopupSettings, iced_core::window::Id)), } pub trait IsSingleton { @@ -54,7 +54,7 @@ pub struct IcedNewMenuSettings { /// NOTE: DO NOT USE THIS ENUM DIERCTLY /// use macro to_layer_message #[derive(Debug, Clone, Copy)] -pub enum LayershellCustomActionsWithInfo { +pub enum LayershellCustomActions { AnchorChange(Anchor), LayerChange(Layer), AnchorSizeChange(Anchor, (u32, u32)), @@ -67,43 +67,36 @@ pub enum LayershellCustomActionsWithInfo { // settings, info, single_tone NewLayerShell { settings: NewLayerShellSettings, - info: INFO, + id: IcedId, }, NewPopUp { settings: IcedNewPopupSettings, - info: INFO, + id: IcedId, }, NewMenu { settings: IcedNewMenuSettings, - info: INFO, + id: IcedId, }, /// is same with WindowAction::Close(id) RemoveWindow(IcedId), ForgetLastOutput, } -pub type LayershellCustomActions = LayershellCustomActionsWithInfo<()>; - /// Please do not use this struct directly /// Use macro to_layer_message instead #[derive(Debug, Clone, Copy)] -pub struct LayershellCustomActionsWithIdAndInfo( - pub Option, - pub LayershellCustomActionsWithInfo, -); +pub struct LayershellCustomActionsWithId(pub Option, pub LayershellCustomActions); -impl LayershellCustomActionsWithIdAndInfo { - pub fn new(id: Option, actions: LayershellCustomActionsWithInfo) -> Self { +impl LayershellCustomActionsWithId { + pub fn new(id: Option, actions: LayershellCustomActions) -> Self { Self(id, actions) } } -pub type LayershellCustomActionsWithId = LayershellCustomActionsWithIdAndInfo<()>; - // first one means #[derive(Debug, Clone, Copy)] -pub(crate) struct LayershellCustomActionsWithIdInner( - pub Option, // come from - pub Option, // target if has one - pub LayershellCustomActionsWithInfo, // actions +pub(crate) struct LayershellCustomActionsWithIdInner( + pub Option, // come from + pub Option, // target if has one + pub LayershellCustomActions, // actions ); diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index ef6d06b..6cef920 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -3,10 +3,7 @@ mod state; use std::{borrow::Cow, mem::ManuallyDrop, os::fd::AsFd, sync::Arc, time::Duration}; use crate::{ - actions::{ - LayerShellAction, LayerShellActionVec, LayershellCustomActions, - LayershellCustomActionsWithInfo, - }, + actions::{LayerShellAction, LayerShellActionVec, LayershellCustomActions}, clipboard::LayerShellClipboard, conversion, error::Error, @@ -183,8 +180,8 @@ where let state = State::new(&application, &ev); let (mut event_sender, event_receiver) = - mpsc::unbounded::, ()>>(); - let (control_sender, mut control_receiver) = mpsc::unbounded::>(); + mpsc::unbounded::>>(); + let (control_sender, mut control_receiver) = mpsc::unbounded::(); let mut instance = Box::pin(run_instance::( application, @@ -263,22 +260,22 @@ where for flow in flows { match flow { LayerShellAction::CustomActions(action) => match action { - LayershellCustomActionsWithInfo::AnchorChange(anchor) => { + LayershellCustomActions::AnchorChange(anchor) => { ev.main_window().set_anchor(anchor); } - LayershellCustomActionsWithInfo::AnchorSizeChange(anchor, size) => { + LayershellCustomActions::AnchorSizeChange(anchor, size) => { ev.main_window().set_anchor_with_size(anchor, size); } - LayershellCustomActionsWithInfo::LayerChange(layer) => { + LayershellCustomActions::LayerChange(layer) => { ev.main_window().set_layer(layer); } - LayershellCustomActionsWithInfo::MarginChange(margin) => { + LayershellCustomActions::MarginChange(margin) => { ev.main_window().set_margin(margin); } - LayershellCustomActionsWithInfo::SizeChange((width, height)) => { + LayershellCustomActions::SizeChange((width, height)) => { ev.main_window().set_size((width, height)); } - LayershellCustomActionsWithInfo::VirtualKeyboardPressed { time, key } => { + LayershellCustomActions::VirtualKeyboardPressed { time, key } => { use layershellev::reexport::wayland_client::KeyState; let ky = ev.get_virtual_keyboard().unwrap(); ky.key(time, key, KeyState::Pressed.into()); @@ -328,8 +325,8 @@ async fn run_instance( compositor_settings: iced_graphics::Settings, mut runtime: SingleRuntime, mut debug: Debug, - mut event_receiver: mpsc::UnboundedReceiver, ()>>, - mut control_sender: mpsc::UnboundedSender>, + mut event_receiver: mpsc::UnboundedReceiver>>, + mut control_sender: mpsc::UnboundedSender, mut state: State, window: Arc, fonts: Vec>, @@ -637,7 +634,7 @@ pub(crate) fn run_action( event: Action, messages: &mut Vec, clipboard: &mut LayerShellClipboard, - custom_actions: &mut Vec>, + custom_actions: &mut Vec, should_exit: &mut bool, debug: &mut Debug, ) where diff --git a/iced_layershell/src/build_pattern/daemon.md b/iced_layershell/src/build_pattern/daemon.md index 2d01185..727a811 100644 --- a/iced_layershell/src/build_pattern/daemon.md +++ b/iced_layershell/src/build_pattern/daemon.md @@ -14,15 +14,13 @@ use iced_runtime::{task, Action}; use iced_layershell::build_pattern::{daemon, MainSettings}; use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; use iced_layershell::settings::{LayerShellSettings, StartMode}; -use iced_layershell::{to_layer_message, WindowInfoMarker}; +use iced_layershell::to_layer_message; pub fn main() -> Result<(), iced_layershell::Error> { daemon( Counter::namespace, Counter::update, Counter::view, - Counter::id_info, - Counter::set_id_info, Counter::remove_id, ) .subscription(Counter::subscription) @@ -46,15 +44,11 @@ struct Counter { ids: HashMap, } -#[derive(Debug, Clone, Copy, PartialEq, Eq, WindowInfoMarker)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] enum WindowInfo { - #[singleton] Left, - #[singleton] Right, PopUp, - #[main] - Main, } #[derive(Debug, Clone, Copy)] @@ -65,7 +59,7 @@ enum WindowDirection { Bottom(Id), } -#[to_layer_message(multi, info_name = "WindowInfo")] +#[to_layer_message(multi)] #[derive(Debug, Clone)] enum Message { IncrementPressed, @@ -105,14 +99,6 @@ impl Counter { self.ids.get(&id).cloned() } - fn set_id_info(&mut self, id: iced::window::Id, info: WindowInfo) { - if let WindowInfo::Main = info { - println!("it is main window: {id}"); - return; - } - self.ids.insert(id, info); - } - fn remove_id(&mut self, id: iced::window::Id) { self.ids.remove(&id); } @@ -143,12 +129,14 @@ impl Counter { } } Event::Mouse(iced::mouse::Event::ButtonPressed(iced::mouse::Button::Right)) => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::PopUp); return Command::done(Message::NewMenu { settings: IcedNewMenuSettings { size: (100, 100), direction: MenuDirection::Up, }, - info: WindowInfo::PopUp, + id, }); } _ => {} @@ -189,32 +177,40 @@ impl Counter { size: (0, 400), }), }, - Message::NewWindowLeft => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Left | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Left, - }), - Message::NewWindowRight => Command::done(Message::NewLayerShell { - settings: NewLayerShellSettings { - size: Some((100, 100)), - exclusive_zone: None, - anchor: Anchor::Right | Anchor::Bottom, - layer: Layer::Top, - margin: None, - keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, - ..Default::default() - }, - info: WindowInfo::Right, - }), + Message::NewWindowLeft => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Left); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Left | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } + Message::NewWindowRight => { + let id = iced::window::Id::unique(); + self.ids.insert(id, WindowInfo::Right); + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((100, 100)), + exclusive_zone: None, + anchor: Anchor::Right | Anchor::Bottom, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::Exclusive, + use_last_output: false, + ..Default::default() + }, + id, + }) + } Message::Close(id) => task::effect(Action::Window(WindowAction::Close(id))), _ => unreachable!(), } diff --git a/iced_layershell/src/build_pattern/daemon.rs b/iced_layershell/src/build_pattern/daemon.rs index dd0a10b..1dc86a7 100644 --- a/iced_layershell/src/build_pattern/daemon.rs +++ b/iced_layershell/src/build_pattern/daemon.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use iced::Font; use iced::{Element, Task}; -use crate::actions::{IsSingleton, LayershellCustomActionsWithIdAndInfo, MainWindowInfo}; +use crate::actions::LayershellCustomActionsWithId; use crate::settings::LayerShellSettings; use crate::DefaultStyle; @@ -27,26 +27,15 @@ pub trait Program: Sized { type State; type Renderer: Renderer; - type WindowInfo: Clone + PartialEq + IsSingleton + TryFrom; /// The type of __messages__ your [`Application`] will produce. type Message: std::fmt::Debug + Send + 'static - + TryInto, Error = Self::Message>; + + TryInto; /// The theme of your [`Application`]. type Theme: Default + DefaultStyle; - fn id_info(&self, _state: &Self::State, _id: iced_core::window::Id) - -> Option; - - fn set_id_info( - &self, - _state: &mut Self::State, - _id: iced_core::window::Id, - _info: Self::WindowInfo, - ); fn remove_id(&self, _state: &mut Self::State, _id: iced_core::window::Id); - /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -154,7 +143,6 @@ pub trait Program: Sized { crate::multi_window::Application for Instance { type Flags = (P, I); - type WindowInfo = P::WindowInfo; fn new((program, initialize): Self::Flags) -> (Self, Task) { let (state, task) = initialize(); @@ -169,18 +157,13 @@ pub trait Program: Sized { ) } - fn id_info(&self, id: iced_core::window::Id) -> Option { - self.program.id_info(&self.state, id) - } - fn set_id_info(&mut self, id: iced_core::window::Id, info: Self::WindowInfo) { - self.program.set_id_info(&mut self.state, id, info) + fn namespace(&self) -> String { + self.program.namespace(&self.state) } + fn remove_id(&mut self, id: iced_core::window::Id) { self.program.remove_id(&mut self.state, id) } - fn namespace(&self) -> String { - self.program.namespace(&self.state) - } fn subscription(&self) -> iced::Subscription { self.program.subscription(&self.state) @@ -270,30 +253,6 @@ impl Update for () { fn update(&self, _state: &mut State, _message: Message) -> impl Into> {} } -pub trait IdInfo { - fn id_info(&self, state: &State, id: iced_core::window::Id) -> Option; -} - -impl IdInfo for T -where - T: Fn(&State, iced_core::window::Id) -> Option, -{ - fn id_info(&self, state: &State, id: iced_core::window::Id) -> Option { - self(state, id) - } -} -pub trait SetIdInfo { - fn set_id_info(&self, state: &mut State, id: iced_core::window::Id, window_info: WindowInfo); -} - -impl SetIdInfo for T -where - T: Fn(&mut State, iced_core::window::Id, WindowInfo), -{ - fn set_id_info(&self, state: &mut State, id: iced_core::window::Id, window_info: WindowInfo) { - self(state, id, window_info) - } -} pub trait RemoveId { fn remove_id(&self, state: &mut State, id: iced_core::window::Id); } @@ -351,115 +310,55 @@ pub struct Daemon { settings: MainSettings, } -pub fn daemon( +pub fn daemon( namespace: impl NameSpace, update: impl Update, view: impl for<'a> self::View<'a, State, Message, Theme, Renderer>, - id_info: impl IdInfo, - set_id_info: impl SetIdInfo, remove_id: impl RemoveId, -) -> Daemon> +) -> Daemon> where State: 'static, - WindowInfo: Clone + PartialEq + IsSingleton + TryFrom, - Message: 'static - + TryInto, Error = Message> - + Send - + std::fmt::Debug, + Message: + 'static + TryInto + Send + std::fmt::Debug, Theme: Default + DefaultStyle, Renderer: self::Renderer, { use std::marker::PhantomData; - struct Instance< - State, - Message, - Theme, - Renderer, - Update, - View, - IdInfo, - SetIdInfo, - RemoveId, - WindowInfo, - > { + struct Instance { update: Update, view: View, - id_info: IdInfo, - set_id_info: SetIdInfo, remove_id: RemoveId, _state: PhantomData, _message: PhantomData, _theme: PhantomData, _renderer: PhantomData, - _windowinfo: PhantomData, } - impl< - State, - Message, - Theme, - Renderer, - Update, - View, - WindowInfo, - IdInfo, - SetIdInfo, - RemoveId, - > Program - for Instance< - State, - Message, - Theme, - Renderer, - Update, - View, - IdInfo, - SetIdInfo, - RemoveId, - WindowInfo, - > + impl Program + for Instance where - WindowInfo: Clone + PartialEq + IsSingleton + TryFrom, Message: 'static - + TryInto, Error = Message> + + TryInto + Send + std::fmt::Debug, Theme: Default + DefaultStyle, - IdInfo: self::IdInfo, - SetIdInfo: self::SetIdInfo, - RemoveId: self::RemoveId, Renderer: self::Renderer, Update: self::Update, + RemoveId: self::RemoveId, View: for<'a> self::View<'a, State, Message, Theme, Renderer>, { type State = State; type Renderer = Renderer; type Message = Message; type Theme = Theme; - type WindowInfo = WindowInfo; type Executor = iced_futures::backend::default::Executor; fn update(&self, state: &mut Self::State, message: Self::Message) -> Task { self.update.update(state, message).into() } - fn id_info( - &self, - state: &Self::State, - id: iced_core::window::Id, - ) -> Option { - self.id_info.id_info(state, id) - } + fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { - self.remove_id.remove_id(state, id) + self.remove_id.remove_id(state, id); } - fn set_id_info( - &self, - state: &mut Self::State, - id: iced_core::window::Id, - info: Self::WindowInfo, - ) { - self.set_id_info.set_id_info(state, id, info) - } - fn view<'a>( &self, state: &'a Self::State, @@ -472,15 +371,12 @@ where raw: Instance { update, view, - id_info, - set_id_info, remove_id, _state: PhantomData, _message: PhantomData, _theme: PhantomData, _renderer: PhantomData, - _windowinfo: PhantomData, }, settings: MainSettings::default(), } @@ -490,8 +386,7 @@ where fn with_namespace( program: P, namespace: impl Fn(&P::State) -> String, -) -> impl Program -{ +) -> impl Program { struct WithNamespace { program: P, namespace: NameSpace, @@ -506,37 +401,18 @@ fn with_namespace( type Theme = P::Theme; type Renderer = P::Renderer; type Executor = P::Executor; - type WindowInfo = P::WindowInfo; - fn namespace(&self, state: &Self::State) -> String { (self.namespace)(state) } - fn id_info( - &self, - state: &Self::State, - id: iced_core::window::Id, - ) -> Option { - self.program.id_info(state, id) + fn update(&self, state: &mut Self::State, message: Self::Message) -> Task { + self.program.update(state, message) } fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { self.program.remove_id(state, id) } - fn set_id_info( - &self, - state: &mut Self::State, - id: iced_core::window::Id, - info: Self::WindowInfo, - ) { - self.program.set_id_info(state, id, info) - } - - fn update(&self, state: &mut Self::State, message: Self::Message) -> Task { - self.program.update(state, message) - } - fn view<'a>( &self, state: &'a Self::State, @@ -568,8 +444,7 @@ fn with_namespace( pub fn with_subscription( program: P, f: impl Fn(&P::State) -> iced::Subscription, -) -> impl Program -{ +) -> impl Program { struct WithSubscription { program: P, subscription: F, @@ -584,32 +459,13 @@ pub fn with_subscription( type Theme = P::Theme; type Renderer = P::Renderer; type Executor = P::Executor; - type WindowInfo = P::WindowInfo; - fn id_info( - &self, - state: &Self::State, - id: iced_core::window::Id, - ) -> Option { - self.program.id_info(state, id) - } - - fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { - self.program.remove_id(state, id) - } - - fn set_id_info( - &self, - state: &mut Self::State, - id: iced_core::window::Id, - info: Self::WindowInfo, - ) { - self.program.set_id_info(state, id, info) - } fn subscription(&self, state: &Self::State) -> iced::Subscription { (self.subscription)(state) } - + fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { + self.program.remove_id(state, id) + } fn update(&self, state: &mut Self::State, message: Self::Message) -> Task { self.program.update(state, message) } @@ -648,8 +504,7 @@ pub fn with_subscription( pub fn with_theme( program: P, f: impl Fn(&P::State) -> P::Theme, -) -> impl Program -{ +) -> impl Program { struct WithTheme { program: P, theme: F, @@ -664,32 +519,13 @@ pub fn with_theme( type Theme = P::Theme; type Renderer = P::Renderer; type Executor = P::Executor; - type WindowInfo = P::WindowInfo; - fn id_info( - &self, - state: &Self::State, - id: iced_core::window::Id, - ) -> Option { - self.program.id_info(state, id) - } - - fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { - self.program.remove_id(state, id) - } - - fn set_id_info( - &self, - state: &mut Self::State, - id: iced_core::window::Id, - info: Self::WindowInfo, - ) { - self.program.set_id_info(state, id, info) - } fn theme(&self, state: &Self::State) -> Self::Theme { (self.theme)(state) } - + fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { + self.program.remove_id(state, id) + } fn namespace(&self, state: &Self::State) -> String { self.program.namespace(state) } @@ -725,8 +561,7 @@ pub fn with_theme( pub fn with_style( program: P, f: impl Fn(&P::State, &P::Theme) -> crate::Appearance, -) -> impl Program -{ +) -> impl Program { struct WithStyle { program: P, style: F, @@ -741,27 +576,6 @@ pub fn with_style( type Theme = P::Theme; type Renderer = P::Renderer; type Executor = P::Executor; - type WindowInfo = P::WindowInfo; - fn id_info( - &self, - state: &Self::State, - id: iced_core::window::Id, - ) -> Option { - self.program.id_info(state, id) - } - - fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { - self.program.remove_id(state, id) - } - - fn set_id_info( - &self, - state: &mut Self::State, - id: iced_core::window::Id, - info: Self::WindowInfo, - ) { - self.program.set_id_info(state, id, info) - } fn style(&self, state: &Self::State, theme: &Self::Theme) -> crate::Appearance { (self.style)(state, theme) @@ -774,7 +588,9 @@ pub fn with_style( fn update(&self, state: &mut Self::State, message: Self::Message) -> Task { self.program.update(state, message) } - + fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { + self.program.remove_id(state, id) + } fn view<'a>( &self, state: &'a Self::State, @@ -802,8 +618,7 @@ pub fn with_style( pub fn with_scale_factor( program: P, f: impl Fn(&P::State, iced_core::window::Id) -> f64, -) -> impl Program -{ +) -> impl Program { struct WithScaleFactor { program: P, scale_factor: F, @@ -818,32 +633,13 @@ pub fn with_scale_factor( type Theme = P::Theme; type Renderer = P::Renderer; type Executor = P::Executor; - type WindowInfo = P::WindowInfo; - fn id_info( - &self, - state: &Self::State, - id: iced_core::window::Id, - ) -> Option { - self.program.id_info(state, id) - } - - fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { - self.program.remove_id(state, id) - } - - fn set_id_info( - &self, - state: &mut Self::State, - id: iced_core::window::Id, - info: Self::WindowInfo, - ) { - self.program.set_id_info(state, id, info) - } fn namespace(&self, state: &Self::State) -> String { self.program.namespace(state) } - + fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { + self.program.remove_id(state, id) + } fn update(&self, state: &mut Self::State, message: Self::Message) -> Task { self.program.update(state, message) } @@ -881,8 +677,7 @@ pub fn with_scale_factor( pub fn with_executor( program: P, -) -> impl Program -{ +) -> impl Program { use std::marker::PhantomData; struct WithExecutor { @@ -899,28 +694,6 @@ pub fn with_executor( type Theme = P::Theme; type Renderer = P::Renderer; type Executor = E; - type WindowInfo = P::WindowInfo; - - fn id_info( - &self, - state: &Self::State, - id: iced_core::window::Id, - ) -> Option { - self.program.id_info(state, id) - } - - fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { - self.program.remove_id(state, id) - } - - fn set_id_info( - &self, - state: &mut Self::State, - id: iced_core::window::Id, - info: Self::WindowInfo, - ) { - self.program.set_id_info(state, id, info) - } fn namespace(&self, state: &Self::State) -> String { self.program.namespace(state) @@ -929,7 +702,9 @@ pub fn with_executor( fn update(&self, state: &mut Self::State, message: Self::Message) -> Task { self.program.update(state, message) } - + fn remove_id(&self, state: &mut Self::State, id: iced_core::window::Id) { + self.program.remove_id(state, id) + } fn view<'a>( &self, state: &'a Self::State, @@ -1032,14 +807,7 @@ impl Daemon

{ pub fn namespace( self, namespace: impl NameSpace, - ) -> Daemon< - impl Program< - State = P::State, - Message = P::Message, - Theme = P::Theme, - WindowInfo = P::WindowInfo, - >, - > { + ) -> Daemon> { Daemon { raw: with_namespace(self.raw, move |state| namespace.namespace(state)), settings: self.settings, @@ -1049,14 +817,7 @@ impl Daemon

{ pub fn style( self, f: impl Fn(&P::State, &P::Theme) -> crate::Appearance, - ) -> Daemon< - impl Program< - State = P::State, - Message = P::Message, - Theme = P::Theme, - WindowInfo = P::WindowInfo, - >, - > { + ) -> Daemon> { Daemon { raw: with_style(self.raw, f), settings: self.settings, @@ -1066,14 +827,7 @@ impl Daemon

{ pub fn subscription( self, f: impl Fn(&P::State) -> iced::Subscription, - ) -> Daemon< - impl Program< - State = P::State, - Message = P::Message, - Theme = P::Theme, - WindowInfo = P::WindowInfo, - >, - > { + ) -> Daemon> { Daemon { raw: with_subscription(self.raw, f), settings: self.settings, @@ -1084,14 +838,7 @@ impl Daemon

{ pub fn theme( self, f: impl Fn(&P::State) -> P::Theme, - ) -> Daemon< - impl Program< - State = P::State, - Message = P::Message, - Theme = P::Theme, - WindowInfo = P::WindowInfo, - >, - > { + ) -> Daemon> { Daemon { raw: with_theme(self.raw, f), settings: self.settings, @@ -1102,14 +849,7 @@ impl Daemon

{ pub fn scale_factor( self, f: impl Fn(&P::State, iced_core::window::Id) -> f64, - ) -> Daemon< - impl Program< - State = P::State, - Message = P::Message, - Theme = P::Theme, - WindowInfo = P::WindowInfo, - >, - > { + ) -> Daemon> { Daemon { raw: with_scale_factor(self.raw, f), settings: self.settings, @@ -1118,14 +858,7 @@ impl Daemon

{ /// Sets the executor of the [`Application`]. pub fn executor( self, - ) -> Daemon< - impl Program< - State = P::State, - Message = P::Message, - Theme = P::Theme, - WindowInfo = P::WindowInfo, - >, - > + ) -> Daemon> where E: iced_futures::Executor, { diff --git a/iced_layershell/src/event.rs b/iced_layershell/src/event.rs index 2d12308..9dc4d67 100644 --- a/iced_layershell/src/event.rs +++ b/iced_layershell/src/event.rs @@ -95,14 +95,13 @@ pub enum WindowEvent { } #[derive(Debug)] -pub enum IcedLayerEvent { +pub enum IcedLayerEvent { RequestRefreshWithWrapper { width: u32, height: u32, fractal_scale: f64, wrapper: WindowWrapper, - is_created: bool, - info: Option, + info: Option, }, RequestRefresh { width: u32, @@ -113,25 +112,22 @@ pub enum IcedLayerEvent { NormalUpdate, UserEvent(Message), WindowRemoved(iced_core::window::Id), - NewMenu((IcedNewMenuSettings, INFO)), + NewMenu((IcedNewMenuSettings, iced_core::window::Id)), } #[allow(unused)] #[derive(Debug)] -pub struct MultiWindowIcedLayerEvent( - pub Option, - pub IcedLayerEvent, -); +pub struct MultiWindowIcedLayerEvent(pub Option, pub IcedLayerEvent); -impl From<(Option, IcedLayerEvent)> - for MultiWindowIcedLayerEvent +impl From<(Option, IcedLayerEvent)> + for MultiWindowIcedLayerEvent { - fn from((id, message): (Option, IcedLayerEvent)) -> Self { + fn from((id, message): (Option, IcedLayerEvent)) -> Self { MultiWindowIcedLayerEvent(id, message) } } -impl From<&DispatchMessage> for IcedLayerEvent { +impl From<&DispatchMessage> for IcedLayerEvent { fn from(value: &DispatchMessage) -> Self { match value { DispatchMessage::RequestRefresh { diff --git a/iced_layershell/src/lib.rs b/iced_layershell/src/lib.rs index d1e0704..22e1639 100644 --- a/iced_layershell/src/lib.rs +++ b/iced_layershell/src/lib.rs @@ -20,14 +20,12 @@ pub mod reexport { pub use layershellev::NewLayerShellSettings; } -use actions::MainWindowInfo; -use actions::{IsSingleton, LayershellCustomActions, LayershellCustomActionsWithIdAndInfo}; +use actions::{LayershellCustomActions, LayershellCustomActionsWithId}; use settings::Settings; use iced_runtime::Task; pub use iced_layershell_macros::to_layer_message; -pub use iced_layershell_macros::WindowInfoMarker; pub use error::Error; @@ -261,8 +259,6 @@ pub trait MultiApplication: Sized { /// The data needed to initialize your [`Application`]. type Flags; - type WindowInfo; - type Theme: Default + DefaultStyle; /// Initializes the [`Application`] with the flags provided to @@ -283,11 +279,6 @@ pub trait MultiApplication: Sized { /// title of your window when necessary. fn namespace(&self) -> String; - fn id_info(&self, _id: iced_core::window::Id) -> Option { - None - } - - fn set_id_info(&mut self, _id: iced_core::window::Id, _info: Self::WindowInfo) {} fn remove_id(&mut self, _id: iced_core::window::Id) {} /// Handles a __message__ and updates the state of the [`Application`]. /// @@ -359,10 +350,7 @@ pub trait MultiApplication: Sized { fn run(settings: Settings) -> Result where Self: 'static, - ::WindowInfo: - Clone + PartialEq + IsSingleton + TryFrom, - Self::Message: 'static - + TryInto, Error = Self::Message>, + Self::Message: 'static + TryInto, { #[allow(clippy::needless_update)] let renderer_settings = iced_graphics::Settings { @@ -411,8 +399,6 @@ where { type Flags = A::Flags; - type WindowInfo = A::WindowInfo; - fn new(flags: Self::Flags) -> (Self, Task) { let (app, command) = A::new(flags); @@ -438,14 +424,6 @@ where fn scale_factor(&self, window: iced::window::Id) -> f64 { self.0.scale_factor(window) } - - fn id_info(&self, id: iced_core::window::Id) -> Option { - self.0.id_info(id) - } - - fn set_id_info(&mut self, id: iced_core::window::Id, info: Self::WindowInfo) { - self.0.set_id_info(id, info) - } fn remove_id(&mut self, id: iced_core::window::Id) { self.0.remove_id(id) } diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index 739d062..2b422e6 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -1,9 +1,8 @@ mod state; use crate::{ actions::{ - IcedNewMenuSettings, IcedNewPopupSettings, IsSingleton, LayerShellActionVec, - LayershellCustomActionsWithIdAndInfo, LayershellCustomActionsWithIdInner, MainWindowInfo, - MenuDirection, + IcedNewMenuSettings, IcedNewPopupSettings, LayerShellActionVec, + LayershellCustomActionsWithId, LayershellCustomActionsWithIdInner, MenuDirection, }, multi_window::window_manager::WindowManager, settings::VirtualKeyboardSettings, @@ -15,7 +14,7 @@ use std::{ }; use crate::{ - actions::{LayerShellAction, LayershellCustomActionsWithInfo}, + actions::{LayerShellAction, LayershellCustomActions}, clipboard::LayerShellClipboard, conversion, error::Error, @@ -65,8 +64,6 @@ where /// The data needed to initialize your [`Application`]. type Flags; - type WindowInfo; - /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -87,17 +84,7 @@ where self.namespace() } - /// get the binded [Application::WindowInfo] - fn id_info(&self, _id: iced_core::window::Id) -> Option; - - /// be used by [`run`], set the [Application::WindowInfo] for [iced_core::window::Id]. do not - /// use it in your program, just realize it. - fn set_id_info(&mut self, _id: iced_core::window::Id, info: Self::WindowInfo); - - /// be used by [`run`], the id will be removed after the window is disappeared. do not use it - /// in your program, just realize it. fn remove_id(&mut self, _id: iced_core::window::Id); - /// Returns the current `Theme` of the [`Application`]. fn theme(&self) -> Self::Theme; @@ -157,10 +144,7 @@ where E: Executor + 'static, C: Compositor + 'static, A::Theme: DefaultStyle, - ::WindowInfo: - Clone + PartialEq + IsSingleton + TryFrom, - A::Message: - 'static + TryInto, Error = A::Message>, + A::Message: 'static + TryInto, { use futures::task; use futures::Future; @@ -191,25 +175,25 @@ where )); let is_background_mode = settings.layer_settings.start_mode.is_background(); - let ev: WindowState = layershellev::WindowState::new(&application.namespace()) - .with_start_mode(settings.layer_settings.start_mode) - .with_use_display_handle(true) - .with_events_transparent(settings.layer_settings.events_transparent) - .with_option_size(settings.layer_settings.size) - .with_layer(settings.layer_settings.layer) - .with_anchor(settings.layer_settings.anchor) - .with_exclusize_zone(settings.layer_settings.exclusive_zone) - .with_margin(settings.layer_settings.margin) - .with_keyboard_interacivity(settings.layer_settings.keyboard_interactivity) - .build() - .expect("Cannot create layershell"); + let ev: WindowState = + layershellev::WindowState::new(&application.namespace()) + .with_start_mode(settings.layer_settings.start_mode) + .with_use_display_handle(true) + .with_events_transparent(settings.layer_settings.events_transparent) + .with_option_size(settings.layer_settings.size) + .with_layer(settings.layer_settings.layer) + .with_anchor(settings.layer_settings.anchor) + .with_exclusize_zone(settings.layer_settings.exclusive_zone) + .with_margin(settings.layer_settings.margin) + .with_keyboard_interacivity(settings.layer_settings.keyboard_interactivity) + .build() + .expect("Cannot create layershell"); let window = Arc::new(ev.gen_main_wrapper()); let (mut event_sender, event_receiver) = - mpsc::unbounded::, A::WindowInfo>>(); - let (control_sender, mut control_receiver) = - mpsc::unbounded::>(); + mpsc::unbounded::>>(); + let (control_sender, mut control_receiver) = mpsc::unbounded::(); let mut instance = Box::pin(run_instance::( application, @@ -264,7 +248,6 @@ where width, height, scale_float, - is_created, .. } => { let Some(unit) = ev.get_mut_unit_with_id(sended_id.unwrap()) else { @@ -278,7 +261,6 @@ where height: *height, fractal_scale: *scale_float, wrapper: unit.gen_wrapper(), - is_created: *is_created, info: unit.get_binding().cloned(), }, )) @@ -328,7 +310,7 @@ where LayershellCustomActionsWithIdInner(id, option_id, action), ) => 'out: { match action { - LayershellCustomActionsWithInfo::AnchorChange(anchor) => { + LayershellCustomActions::AnchorChange(anchor) => { let Some(id) = id else { break 'out; }; @@ -337,7 +319,7 @@ where }; window.set_anchor(anchor); } - LayershellCustomActionsWithInfo::AnchorSizeChange(anchor, size) => { + LayershellCustomActions::AnchorSizeChange(anchor, size) => { let Some(id) = id else { break 'out; }; @@ -346,7 +328,7 @@ where }; window.set_anchor_with_size(anchor, size); } - LayershellCustomActionsWithInfo::LayerChange(layer) => { + LayershellCustomActions::LayerChange(layer) => { let Some(id) = id else { break 'out; }; @@ -355,7 +337,7 @@ where }; window.set_layer(layer); } - LayershellCustomActionsWithInfo::MarginChange(margin) => { + LayershellCustomActions::MarginChange(margin) => { let Some(id) = id else { break 'out; }; @@ -364,7 +346,7 @@ where }; window.set_margin(margin); } - LayershellCustomActionsWithInfo::SizeChange((width, height)) => { + LayershellCustomActions::SizeChange((width, height)) => { let Some(id) = id else { break 'out; }; @@ -373,7 +355,7 @@ where }; window.set_size((width, height)); } - LayershellCustomActionsWithInfo::VirtualKeyboardPressed { time, key } => { + LayershellCustomActions::VirtualKeyboardPressed { time, key } => { use layershellev::reexport::wayland_client::KeyState; let ky = ev.get_virtual_keyboard().unwrap(); ky.key(time, key, KeyState::Pressed.into()); @@ -390,15 +372,17 @@ where ) .ok(); } - LayershellCustomActionsWithInfo::NewLayerShell { - settings, info, .. + LayershellCustomActions::NewLayerShell { + settings, id: info, .. } => { + let id = layershellev::id::Id::unique(); ev.append_return_data(ReturnData::NewLayerShell(( settings, + id, Some(info), ))); } - LayershellCustomActionsWithInfo::RemoveWindow(id) => { + LayershellCustomActions::RemoveWindow(id) => { ev.remove_shell(option_id.unwrap()); event_sender .start_send(MultiWindowIcedLayerEvent( @@ -407,23 +391,25 @@ where )) .ok(); } - LayershellCustomActionsWithInfo::NewPopUp { + LayershellCustomActions::NewPopUp { settings: menusettings, - info, + id: info, } => { let IcedNewPopupSettings { size, position } = menusettings; let Some(id) = ev.current_surface_id() else { break 'out; }; let popup_settings = NewPopUpSettings { size, position, id }; + let id = layershellev::id::Id::unique(); ev.append_return_data(ReturnData::NewPopUp(( popup_settings, + id, Some(info), ))); } - LayershellCustomActionsWithInfo::NewMenu { + LayershellCustomActions::NewMenu { settings: menusetting, - info, + id: info, } => { let Some(id) = ev.current_surface_id() else { break 'out; @@ -435,7 +421,7 @@ where )) .expect("Cannot send"); } - LayershellCustomActionsWithInfo::ForgetLastOutput => { + LayershellCustomActions::ForgetLastOutput => { ev.forget_last_output(); } } @@ -446,7 +432,8 @@ where break 'out; }; let popup_settings = NewPopUpSettings { size, position, id }; - ev.append_return_data(ReturnData::NewPopUp((popup_settings, Some(info)))) + let id = layershellev::id::Id::unique(); + ev.append_return_data(ReturnData::NewPopUp((popup_settings, id, Some(info)))) } LayerShellAction::Mouse(mouse) => { let Some(pointer) = ev.get_pointer() else { @@ -479,10 +466,8 @@ async fn run_instance( compositor_settings: iced_graphics::Settings, mut runtime: MultiRuntime, mut debug: Debug, - mut event_receiver: mpsc::UnboundedReceiver< - MultiWindowIcedLayerEvent, A::WindowInfo>, - >, - mut control_sender: mpsc::UnboundedSender>, + mut event_receiver: mpsc::UnboundedReceiver>>, + mut control_sender: mpsc::UnboundedSender, window: Arc, fonts: Vec>, is_background_mode: bool, @@ -491,9 +476,7 @@ async fn run_instance( E: Executor + 'static, C: Compositor + 'static, A::Theme: DefaultStyle, - A::WindowInfo: Clone + PartialEq + IsSingleton + TryFrom, - A::Message: - 'static + TryInto, Error = A::Message>, + A::Message: 'static + TryInto, { use iced::window; use iced_core::Event; @@ -522,8 +505,6 @@ async fn run_instance( let mut should_exit = false; let mut messages = Vec::new(); - let mut singleton_layers = vec![]; - while let Some(event) = event_receiver.next().await { match event { MultiWindowIcedLayerEvent( @@ -533,14 +514,14 @@ async fn run_instance( height, fractal_scale, wrapper, - is_created, info, + .. }, ) => { let mut is_new_window = false; let (id, window) = if window_manager.get_mut_alias(wrapper.id()).is_none() { is_new_window = true; - let id = window::Id::unique(); + let id = info.unwrap_or(window::Id::unique()); let window = window_manager.insert( id, @@ -664,36 +645,6 @@ async fn run_instance( }, } } - - if is_new_window { - if is_created { - let cached_interfaces: HashMap = - ManuallyDrop::into_inner(user_interfaces) - .drain() - .map(|(id, ui)| (id, ui.into_cache())) - .collect(); - application.set_id_info(id, info.unwrap().clone()); - user_interfaces = ManuallyDrop::new(build_user_interfaces( - &application, - &mut debug, - &mut window_manager, - cached_interfaces, - )); - } else if let Ok(info) = MainWindowInfo.try_into() { - let cached_interfaces: HashMap = - ManuallyDrop::into_inner(user_interfaces) - .drain() - .map(|(id, ui)| (id, ui.into_cache())) - .collect(); - application.set_id_info(id, info); - user_interfaces = ManuallyDrop::new(build_user_interfaces( - &application, - &mut debug, - &mut window_manager, - cached_interfaces, - )); - } - } } MultiWindowIcedLayerEvent(None, IcedLayerEvent::Window(event)) => { let Some((_id, window)) = window_manager.first_window() else { @@ -734,7 +685,6 @@ async fn run_instance( &mut messages, &mut clipboard, &mut custom_actions, - &mut singleton_layers, &mut should_exit, &mut debug, &mut window_manager, @@ -856,11 +806,7 @@ async fn run_instance( .drain() .map(|(id, ui)| (id, ui.into_cache())) .collect(); - if let Some(info) = application.id_info(id) { - if let Some(index) = singleton_layers.iter().position(|layer| *layer == info) { - singleton_layers.remove(index); - } - } + application.remove_id(id); window_manager.remove(id); cached_interfaces.remove(&id); @@ -973,7 +919,6 @@ pub(crate) fn update( ) where A::Theme: DefaultStyle, A::Message: 'static, - A::WindowInfo: Clone + 'static, { for message in messages.drain(..) { debug.log_message(&message); @@ -1000,8 +945,7 @@ pub(crate) fn run_action( event: Action, messages: &mut Vec, clipboard: &mut LayerShellClipboard, - custom_actions: &mut Vec>, - singleton_layers: &mut Vec, + custom_actions: &mut Vec, should_exit: &mut bool, debug: &mut Debug, window_manager: &mut WindowManager, @@ -1010,9 +954,7 @@ pub(crate) fn run_action( A: Application, C: Compositor + 'static, A::Theme: DefaultStyle, - A::Message: - 'static + TryInto, Error = A::Message>, - A::WindowInfo: Clone + 'static + PartialEq + IsSingleton, + A::Message: 'static + TryInto, { use iced_core::widget::operation; use iced_runtime::clipboard; @@ -1022,15 +964,9 @@ pub(crate) fn run_action( match event { Action::Output(stream) => match stream.try_into() { Ok(action) => { - let action: LayershellCustomActionsWithIdAndInfo = action; - if let LayershellCustomActionsWithInfo::NewLayerShell { info, .. } = &action.1 { - if info.is_singleton() && singleton_layers.contains(info) { - return; - } - singleton_layers.push(info.clone()); - } - let option_id = if let LayershellCustomActionsWithInfo::RemoveWindow(id) = action.1 - { + let action: LayershellCustomActionsWithId = action; + + let option_id = if let LayershellCustomActions::RemoveWindow(id) = action.1 { let option_id = window_manager.get_layer_id(id); if option_id.is_none() { return; @@ -1043,7 +979,7 @@ pub(crate) fn run_action( LayershellCustomActionsWithIdInner( action.0.and_then(|id| window_manager.get_layer_id(id)), option_id, - action.1.clone(), + action.1, ), )); } @@ -1100,7 +1036,7 @@ pub(crate) fn run_action( LayershellCustomActionsWithIdInner( Some(layerid), Some(layerid), - LayershellCustomActionsWithInfo::RemoveWindow(id), + LayershellCustomActions::RemoveWindow(id), ), )) } diff --git a/iced_layershell/tests/test_macro.rs b/iced_layershell/tests/test_macro.rs index b837549..671cf2a 100644 --- a/iced_layershell/tests/test_macro.rs +++ b/iced_layershell/tests/test_macro.rs @@ -1,5 +1,4 @@ -use iced_layershell::actions::{IsSingleton, MainWindowInfo}; -use iced_layershell::{to_layer_message, WindowInfoMarker}; +use iced_layershell::to_layer_message; #[test] fn test_layer_message_macro() { @@ -11,30 +10,3 @@ fn test_layer_message_macro() { let e = TestEnum::SizeChange((10, 10)); let _ = e.clone(); } - -#[test] -fn test_layersingleton_derive() { - #[allow(unused)] - #[derive(WindowInfoMarker)] - enum SingleToneTest { - #[singleton] - SingleTon, - NotSingleTon, - #[singleton] - SingleTonTwo { - field: bool, - }, - #[singleton] - SingleTonThird(i32), - #[main] - Main, - } - assert!(SingleToneTest::SingleTon.is_singleton()); - assert!(!SingleToneTest::NotSingleTon.is_singleton()); - assert!(SingleToneTest::SingleTonTwo { field: false }.is_singleton()); - assert!(SingleToneTest::SingleTonThird(10).is_singleton()); - assert!(matches!( - MainWindowInfo.try_into().unwrap(), - SingleToneTest::Main - )) -} diff --git a/iced_layershell_macros/src/lib.rs b/iced_layershell_macros/src/lib.rs index 7902d04..ecd33cf 100644 --- a/iced_layershell_macros/src/lib.rs +++ b/iced_layershell_macros/src/lib.rs @@ -3,98 +3,11 @@ use darling::{ util::{Flag, Ignored}, FromDeriveInput, FromMeta, }; -use proc_macro::TokenStream; -use proc_macro2::{Span, TokenStream as TokenStream2}; -use syn::{ - parse_macro_input, Attribute, Data as DataOrigin, DataEnum, DeriveInput, Generics, Ident, - LitStr, Variant, Visibility, -}; +use proc_macro2::TokenStream as TokenStream2; +use syn::{DeriveInput, Generics, Ident, Variant, Visibility}; use quote::quote; -#[inline] -fn is_singleton_attr(attr: &Attribute) -> bool { - attr.path().is_ident("singleton") -} - -#[inline] -fn is_mainwindow_attr(attr: &Attribute) -> bool { - attr.path().is_ident("main") -} - -/// WindowInfoMarker, it is a derive to mark the WIndowInfo of MultiApplication. -/// There are two attributes: singleton and main -/// Singleton is used to mark the window can only exist once, -/// main is used to get the id of the main window -#[proc_macro_derive(WindowInfoMarker, attributes(singleton, main))] -pub fn window_info_marker(input: TokenStream) -> TokenStream { - // Parse the input as a DeriveInput - let input = parse_macro_input!(input as DeriveInput); - - // Get the name of the enum - let name = input.ident.clone(); - - // Ensure the macro is applied to an enum - let variants = if let DataOrigin::Enum(DataEnum { variants, .. }) = input.data { - variants - } else { - return syn::Error::new_spanned(input, "Singleton macro can only be applied to enums") - .to_compile_error() - .into(); - }; - - // Generate the implementation of `IsSingleton` - let is_singleton_arms = variants.iter().map(|variant| { - let variant_name = &variant.ident; - - // Check if the variant has the `#[singleton]` attribute - let is_singleton = variant.attrs.iter().any(is_singleton_attr); - - match &variant.fields { - syn::Fields::Unit => quote! { Self::#variant_name => #is_singleton, }, - syn::Fields::Unnamed(_) => quote! { Self::#variant_name(..) => #is_singleton, }, - syn::Fields::Named(_) => quote! { Self::#variant_name { .. } => #is_singleton, }, - } - }); - - let try_from_mainwindow = variants - .iter() - .find(|variant| variant.attrs.iter().any(is_mainwindow_attr)) - .map(|variant| { - let variant_name = &variant.ident; - quote! { - impl TryFrom for #name { - type Error = (); - fn try_from(_val: iced_layershell::actions::MainWindowInfo) -> Result { - Ok(Self::#variant_name) - } - } - } - }) - .unwrap_or(quote! { - impl TryFrom for #name { - type Error = (); - fn try_from(_val: iced_layershell::actions::MainWindowInfo) -> Result { - Err(()) - } - } - }); - - // Generate the final implementation - let expanded = quote! { - impl iced_layershell::actions::IsSingleton for #name { - fn is_singleton(&self) -> bool { - match self { - #(#is_singleton_arms)* - } - } - } - #try_from_mainwindow - }; - - TokenStream::from(expanded) -} - /// to_layer_message is to convert a normal enum to the enum usable in iced_layershell /// It impl the try_into trait for the enum and make it can be convert to the actions in /// layershell. @@ -105,7 +18,7 @@ pub fn window_info_marker(input: TokenStream) -> TokenStream { pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Result { let meta = NestedMeta::parse_meta_list(attr)?; - let ToLayerMessageAttr { multi, info_name } = ToLayerMessageAttr::from_list(&meta)?; + let ToLayerMessageAttr { multi } = ToLayerMessageAttr::from_list(&meta)?; let is_multi = multi.is_present(); @@ -123,9 +36,6 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res let (additional_variants, try_into_impl) = match is_multi { true => { - let info_name = info_name.expect("Should set the info_name").value(); - let info = Ident::new(&info_name, Span::call_site()); - let additional_variants = quote! { AnchorChange{id: iced::window::Id, anchor: iced_layershell::reexport::Anchor}, AnchorSizeChange{id: iced::window::Id, anchor:iced_layershell::reexport::Anchor, size: (u32, u32)}, @@ -136,42 +46,40 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res time: u32, key: u32, }, - NewLayerShell { settings: iced_layershell::reexport::NewLayerShellSettings, info: #info }, - NewPopUp { settings: iced_layershell::actions::IcedNewPopupSettings, info: #info }, - NewMenu { settings: iced_layershell::actions::IcedNewMenuSettings, info: #info }, + NewLayerShell { settings: iced_layershell::reexport::NewLayerShellSettings, id: iced::window::Id }, + NewPopUp { settings: iced_layershell::actions::IcedNewPopupSettings, id: iced::window::Id }, + NewMenu { settings: iced_layershell::actions::IcedNewMenuSettings, id: iced::window::Id }, RemoveWindow(iced::window::Id), ForgetLastOutput, }; - let try_into_impl = quote! { - impl #impl_gen TryInto> for #ident #ty_gen #where_gen { + impl #impl_gen TryInto for #ident #ty_gen #where_gen { type Error = Self; - fn try_into(self) -> Result, Self::Error> { - type InnerLayerActionId = iced_layershell::actions::LayershellCustomActionsWithIdAndInfo<#info>; - type InnerLayerAction = iced_layershell::actions::LayershellCustomActionsWithInfo<#info>; + fn try_into(self) -> Result { + use iced_layershell::actions::LayershellCustomActions; + use iced_layershell::actions::LayershellCustomActionsWithId; match self { - Self::AnchorChange { id, anchor } => Ok(InnerLayerActionId::new(Some(id), InnerLayerAction::AnchorChange(anchor))), - Self::AnchorSizeChange { id, anchor, size } => Ok(InnerLayerActionId::new(Some(id), InnerLayerAction::AnchorSizeChange(anchor, size))), - Self::LayerChange { id, layer } => Ok(InnerLayerActionId::new(Some(id), InnerLayerAction::LayerChange(layer))), - Self::MarginChange { id, margin } => Ok(InnerLayerActionId::new(Some(id), InnerLayerAction::MarginChange(margin))), - Self::SizeChange { id, size } => Ok(InnerLayerActionId::new(Some(id), InnerLayerAction::SizeChange(size))), - Self::VirtualKeyboardPressed { time, key } => Ok(InnerLayerActionId::new( + Self::AnchorChange { id, anchor } => Ok(LayershellCustomActionsWithId::new(Some(id), LayershellCustomActions::AnchorChange(anchor))), + Self::AnchorSizeChange { id, anchor, size } => Ok(LayershellCustomActionsWithId::new(Some(id), LayershellCustomActions::AnchorSizeChange(anchor, size))), + Self::LayerChange { id, layer } => Ok(LayershellCustomActionsWithId::new(Some(id), LayershellCustomActions::LayerChange(layer))), + Self::MarginChange { id, margin } => Ok(LayershellCustomActionsWithId::new(Some(id), LayershellCustomActions::MarginChange(margin))), + Self::SizeChange { id, size } => Ok(LayershellCustomActionsWithId::new(Some(id), LayershellCustomActions::SizeChange(size))), + Self::VirtualKeyboardPressed { time, key } => Ok(LayershellCustomActionsWithId::new( None, - InnerLayerAction::VirtualKeyboardPressed { time, key }) + LayershellCustomActions::VirtualKeyboardPressed { time, key }) ), - Self::NewLayerShell {settings, info } => Ok(InnerLayerActionId::new(None, InnerLayerAction::NewLayerShell { settings, info })), - Self::NewPopUp { settings, info } => Ok(InnerLayerActionId::new(None, InnerLayerAction::NewPopUp { settings, info })), - Self::NewMenu { settings, info } => Ok(InnerLayerActionId::new(None, InnerLayerAction::NewMenu {settings, info })), - Self::RemoveWindow(id) => Ok(InnerLayerActionId::new(None, InnerLayerAction::RemoveWindow(id))), - Self::ForgetLastOutput => Ok(InnerLayerActionId::new(None, InnerLayerAction::ForgetLastOutput)), + Self::NewLayerShell {settings, id } => Ok(LayershellCustomActionsWithId::new(None, LayershellCustomActions::NewLayerShell { settings, id })), + Self::NewPopUp { settings, id } => Ok(LayershellCustomActionsWithId::new(None, LayershellCustomActions::NewPopUp { settings, id })), + Self::NewMenu { settings, id } => Ok(LayershellCustomActionsWithId::new(None, LayershellCustomActions::NewMenu {settings, id })), + Self::RemoveWindow(id) => Ok(LayershellCustomActionsWithId::new(None, LayershellCustomActions::RemoveWindow(id))), + Self::ForgetLastOutput => Ok(LayershellCustomActionsWithId::new(None, LayershellCustomActions::ForgetLastOutput)), _ => Err(self) } } } }; - (additional_variants, try_into_impl) } false => { @@ -228,7 +136,6 @@ pub fn to_layer_message(attr: TokenStream2, input: TokenStream2) -> manyhow::Res #[derive(FromMeta)] struct ToLayerMessageAttr { multi: Flag, - info_name: Option, } #[derive(FromDeriveInput)] diff --git a/layershellev/src/events.rs b/layershellev/src/events.rs index ed772e9..b60d063 100644 --- a/layershellev/src/events.rs +++ b/layershellev/src/events.rs @@ -133,8 +133,8 @@ pub enum ReturnData { RedrawAllRequest, RedrawIndexRequest(Id), RequestSetCursorShape((String, WlPointer, u32)), - NewLayerShell((NewLayerShellSettings, Option)), - NewPopUp((NewPopUpSettings, Option)), + NewLayerShell((NewLayerShellSettings, id::Id, Option)), + NewPopUp((NewPopUpSettings, id::Id, Option)), None, } diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index cf6f45d..978e2cf 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -2435,6 +2435,7 @@ impl WindowState { use_last_output, events_transparent, }, + id, info, )) => { let pos = self.surface_pos(); @@ -2502,7 +2503,7 @@ impl WindowState { // like if you want to reset anchor or KeyboardInteractivity or resize, commit is needed self.units.push(WindowStateUnit { - id: id::Id::unique(), + id, display: connection.display(), wl_surface, size: (0, 0), @@ -2523,6 +2524,7 @@ impl WindowState { position: (x, y), id, }, + targetid, info, )) => { let Some(index) = self @@ -2559,7 +2561,7 @@ impl WindowState { .as_ref() .map(|viewport| viewport.get_viewport(&wl_surface, &qh, ())); self.units.push(WindowStateUnit { - id: id::Id::unique(), + id: targetid, display: connection.display(), wl_surface, size: (width, height),