diff --git a/Cargo.lock b/Cargo.lock index 3942ea8..20934ee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -207,9 +207,9 @@ dependencies = [ [[package]] name = "async-io" -version = "2.3.4" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444b0228950ee6501b3568d3c93bf1176a1fdbc3b758dcd9475046d30f4dc7e8" +checksum = "43a2b323ccce0a1d90b449fd71f2a06ca7faa7c54c2751f06c9bd851fc061059" dependencies = [ "async-lock", "cfg-if", @@ -460,29 +460,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" -[[package]] -name = "cairo-rs" -version = "0.20.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7fa699e1d7ae691001a811dda5ef0e3e42e1d4119b26426352989df9e94e3e6" -dependencies = [ - "bitflags 2.6.0", - "cairo-sys-rs", - "glib", - "libc", -] - -[[package]] -name = "cairo-sys-rs" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "428290f914b9b86089f60f5d8a9f6e440508e1bcff23b25afd51502b0a2da88f" -dependencies = [ - "glib-sys", - "libc", - "system-deps", -] - [[package]] name = "calloop" version = "0.13.0" @@ -806,6 +783,7 @@ dependencies = [ "iced", "iced_layershell", "iced_runtime", + "iced_wayland_subscriber", ] [[package]] @@ -1908,6 +1886,18 @@ dependencies = [ "xkbcommon", ] +[[package]] +name = "iced_wayland_subscriber" +version = "0.9.7" +dependencies = [ + "async-io", + "futures", + "iced", + "wayland-client", + "wayland-protocols", + "wayland-protocols-wlr", +] + [[package]] name = "iced_wgpu" version = "0.13.5" @@ -2014,12 +2004,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "itoa" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" - [[package]] name = "jni" version = "0.21.1" @@ -2782,56 +2766,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "pango" -version = "0.20.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa26aa54b11094d72141a754901cd71d9356432bb8147f9cace8d9c7ba95f356" -dependencies = [ - "gio", - "glib", - "libc", - "pango-sys", -] - -[[package]] -name = "pango-sys" -version = "0.20.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84fd65917bf12f06544ae2bbc200abf9fc0a513a5a88a0fa81013893aef2b838" -dependencies = [ - "glib-sys", - "gobject-sys", - "libc", - "system-deps", -] - -[[package]] -name = "pangocairo" -version = "0.20.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4291ca8cdd05e4330752bf8a450d3a4e701ca48fd9aad2b3566e92849ee4055e" -dependencies = [ - "cairo-rs", - "glib", - "libc", - "pango", - "pangocairo-sys", -] - -[[package]] -name = "pangocairo-sys" -version = "0.20.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be0ed959258ea648a49bde7dfdbaa98310717cb15159b421fa76510c45ec306e" -dependencies = [ - "cairo-sys-rs", - "glib-sys", - "libc", - "pango-sys", - "system-deps", -] - [[package]] name = "parking" version = "2.2.1" @@ -3340,12 +3274,6 @@ dependencies = [ "unicode-script", ] -[[package]] -name = "ryu" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" - [[package]] name = "same-file" version = "1.0.6" @@ -3406,18 +3334,6 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "serde_json" -version = "1.0.132" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" -dependencies = [ - "itoa", - "memchr", - "ryu", - "serde", -] - [[package]] name = "serde_repr" version = "0.1.19" @@ -3641,22 +3557,6 @@ dependencies = [ "bitflags 2.6.0", ] -[[package]] -name = "starcolorkeyboard" -version = "0.9.7" -dependencies = [ - "bitflags 2.6.0", - "cairo-rs", - "layershellev", - "memmap2", - "pango", - "pangocairo", - "serde", - "serde_json", - "tempfile", - "xkbcommon", -] - [[package]] name = "static_assertions" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index ccfc9c3..ab34d83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ "iced_layershell_macros", "iced_sessionlock", "iced_sessionlock_macros", - "starcolorkeyboard", + "iced_wayland_subscriber", "sessionlockev", "waycrate_xkbkeycode", "iced_examples/*", @@ -28,6 +28,7 @@ readme = "README.md" [workspace.dependencies] layershellev = { version = "0.9.7", path = "./layershellev" } sessionlockev = { version = "0.9.7", path = "./sessionlockev" } +iced_wayland_subscriber = { version = "0.9.7", path = "./iced_wayland_subscriber" } iced_layershell = { version = "0.9.7", path = "./iced_layershell" } iced_layershell_macros = { version = "0.9.7", path = "./iced_layershell_macros" } @@ -79,7 +80,7 @@ bitflags = "2.6.0" log = "0.4.22" xkbcommon-dl = "0.4.2" -smol_str = "0.2.2" #NOTE: follow iced +smol_str = "0.2.2" #NOTE: follow iced memmap2 = "0.9.5" tracing = "0.1.40" diff --git a/iced_examples/counter_muti/Cargo.toml b/iced_examples/counter_muti/Cargo.toml index 128fa4d..be32818 100644 --- a/iced_examples/counter_muti/Cargo.toml +++ b/iced_examples/counter_muti/Cargo.toml @@ -15,3 +15,5 @@ readme.workspace = true iced.workspace = true iced_runtime.workspace = true iced_layershell.workspace = true + +iced_wayland_subscriber.workspace = true diff --git a/iced_examples/counter_muti/src/main.rs b/iced_examples/counter_muti/src/main.rs index 9a4a87e..54b1c72 100644 --- a/iced_examples/counter_muti/src/main.rs +++ b/iced_examples/counter_muti/src/main.rs @@ -7,11 +7,15 @@ use iced_layershell::actions::{IcedNewMenuSettings, MenuDirection}; use iced_runtime::window::Action as WindowAction; use iced_runtime::{task, Action}; -use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; +use iced_layershell::reexport::{ + Anchor, KeyboardInteractivity, Layer, LayerOutputSetting, NewLayerShellSettings, +}; use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; use iced_layershell::to_layer_message; use iced_layershell::MultiApplication; +use iced_wayland_subscriber::WaylandEvents; + pub fn main() -> Result<(), iced_layershell::Error> { Counter::run(Settings { layer_settings: LayerShellSettings { @@ -36,6 +40,7 @@ enum WindowInfo { Left, Right, PopUp, + TopBar, } #[derive(Debug, Clone, Copy)] @@ -57,6 +62,7 @@ enum Message { TextInput(String), Direction(WindowDirection), IcedEvent(Event), + Wayland(WaylandEvents), } impl Counter { @@ -105,7 +111,10 @@ impl MultiApplication for Counter { } fn subscription(&self) -> iced::Subscription { - event::listen().map(Message::IcedEvent) + iced::Subscription::batch([ + event::listen().map(Message::IcedEvent), + iced_wayland_subscriber::listen().map(Message::Wayland), + ]) } fn update(&mut self, message: Message) -> Command { @@ -180,7 +189,7 @@ impl MultiApplication for Counter { layer: Layer::Top, margin: None, keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, + output_setting: LayerOutputSetting::None, ..Default::default() }, info: WindowInfo::Left, @@ -193,12 +202,27 @@ impl MultiApplication for Counter { layer: Layer::Top, margin: None, keyboard_interactivity: KeyboardInteractivity::Exclusive, - use_last_output: false, + output_setting: LayerOutputSetting::None, ..Default::default() }, info: WindowInfo::Right, }), Message::Close(id) => task::effect(Action::Window(WindowAction::Close(id))), + Message::Wayland(WaylandEvents::OutputInsert(output)) => { + Command::done(Message::NewLayerShell { + settings: NewLayerShellSettings { + size: Some((0, 20)), + exclusive_zone: Some(20), + anchor: Anchor::Top | Anchor::Right | Anchor::Left, + layer: Layer::Top, + margin: None, + keyboard_interactivity: KeyboardInteractivity::None, + output_setting: LayerOutputSetting::ChosenOutput(output), + ..Default::default() + }, + info: WindowInfo::TopBar, + }) + } _ => unreachable!(), } } @@ -210,6 +234,9 @@ impl MultiApplication for Counter { if let Some(WindowInfo::Right) = self.id_info(id) { return button("close right").on_press(Message::Close(id)).into(); } + if let Some(WindowInfo::TopBar) = self.id_info(id) { + return text("hello here is topbar").into(); + } if let Some(WindowInfo::PopUp) = self.id_info(id) { return container(button("close PopUp").on_press(Message::Close(id))) .center_x(Length::Fill) diff --git a/iced_examples/zbus_invoked_widget/src/main.rs b/iced_examples/zbus_invoked_widget/src/main.rs index a93f818..01d8a24 100644 --- a/iced_examples/zbus_invoked_widget/src/main.rs +++ b/iced_examples/zbus_invoked_widget/src/main.rs @@ -8,7 +8,9 @@ use iced_layershell::actions::{ use iced_runtime::window::Action as WindowAction; use iced_runtime::Action; -use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; +use iced_layershell::reexport::{ + Anchor, KeyboardInteractivity, Layer, LayerOutputSetting, NewLayerShellSettings, +}; use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; use iced_layershell::MultiApplication; use zbus::{connection, interface}; @@ -53,7 +55,7 @@ impl TryInto for Message { layer: Layer::Top, margin: Some((100, 100, 100, 100)), keyboard_interactivity: KeyboardInteractivity::OnDemand, - use_last_output: false, + output_setting: LayerOutputSetting::None, ..Default::default() }, (), diff --git a/iced_layershell/src/actions.rs b/iced_layershell/src/actions.rs index 45eea50..1947828 100644 --- a/iced_layershell/src/actions.rs +++ b/iced_layershell/src/actions.rs @@ -34,7 +34,7 @@ pub struct IcedNewMenuSettings { pub direction: MenuDirection, } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub enum LayershellCustomActionsWithInfo { AnchorChange(Anchor), LayerChange(Layer), @@ -55,7 +55,7 @@ pub enum LayershellCustomActionsWithInfo { pub type LayershellCustomActions = LayershellCustomActionsWithInfo<()>; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub struct LayershellCustomActionsWithIdAndInfo( pub Option, pub LayershellCustomActionsWithInfo, @@ -70,7 +70,7 @@ impl LayershellCustomActionsWithIdAndInfo { pub type LayershellCustomActionsWithId = LayershellCustomActionsWithIdAndInfo<()>; // first one means -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone)] pub(crate) struct LayershellCustomActionsWithIdInner( pub Option, // come from pub Option, // target if has one diff --git a/iced_layershell/src/lib.rs b/iced_layershell/src/lib.rs index e5fba2d..1439667 100644 --- a/iced_layershell/src/lib.rs +++ b/iced_layershell/src/lib.rs @@ -16,6 +16,7 @@ pub mod reexport { pub use layershellev::reexport::Anchor; pub use layershellev::reexport::KeyboardInteractivity; pub use layershellev::reexport::Layer; + pub use layershellev::LayerOutputSetting; pub use layershellev::NewLayerShellSettings; } diff --git a/iced_wayland_subscriber/.gitignore b/iced_wayland_subscriber/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/iced_wayland_subscriber/.gitignore @@ -0,0 +1 @@ +/target diff --git a/iced_wayland_subscriber/Cargo.lock b/iced_wayland_subscriber/Cargo.lock new file mode 100644 index 0000000..9e09fd0 --- /dev/null +++ b/iced_wayland_subscriber/Cargo.lock @@ -0,0 +1,677 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + +[[package]] +name = "autocfg" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" + +[[package]] +name = "backtrace" +version = "0.3.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets", +] + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "bytes" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" + +[[package]] +name = "cc" +version = "1.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +dependencies = [ + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "dlib" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +dependencies = [ + "libloading", +] + +[[package]] +name = "downcast-rs" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "gimli" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "libc" +version = "0.2.161" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" + +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "lock_api" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + +[[package]] +name = "mio" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" +dependencies = [ + "hermit-abi", + "libc", + "wasi", + "windows-sys 0.52.0", +] + +[[package]] +name = "nix" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "object" +version = "0.36.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" + +[[package]] +name = "parking_lot" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + +[[package]] +name = "proc-macro2" +version = "1.0.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.36.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7649a7b4df05aed9ea7ec6f628c67c9953a43869b8bc50929569b2999d443fe" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "socket2" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "syn" +version = "2.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + +[[package]] +name = "tokio" +version = "1.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.52.0", +] + +[[package]] +name = "tokio-macros" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wayland-backend" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "056535ced7a150d45159d3a8dc30f91a2e2d588ca0b23f70e56033622b8016f6" +dependencies = [ + "cc", + "downcast-rs", + "rustix", + "scoped-tls", + "smallvec", + "wayland-sys", +] + +[[package]] +name = "wayland-client" +version = "0.31.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b66249d3fc69f76fd74c82cc319300faa554e9d865dab1f7cd66cc20db10b280" +dependencies = [ + "bitflags", + "rustix", + "wayland-backend", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols" +version = "0.32.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd0ade57c4e6e9a8952741325c30bf82f4246885dca8bf561898b86d0c1f58e" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-scanner", +] + +[[package]] +name = "wayland-protocols-wlr" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "782e12f6cd923c3c316130d56205ebab53f55d6666b7faddfad36cecaeeb4022" +dependencies = [ + "bitflags", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + +[[package]] +name = "wayland-scanner" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597f2001b2e5fc1121e3d5b9791d3e78f05ba6bfa4641053846248e3a13661c3" +dependencies = [ + "proc-macro2", + "quick-xml", + "quote", +] + +[[package]] +name = "wayland-sys" +version = "0.31.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efa8ac0d8e8ed3e3b5c9fc92c7881406a268e11555abe36493efabe649a29e09" +dependencies = [ + "dlib", + "log", + "pkg-config", +] + +[[package]] +name = "waylandtrain" +version = "0.1.0" +dependencies = [ + "futures", + "nix", + "tempfile", + "tokio", + "wayland-client", + "wayland-protocols", + "wayland-protocols-wlr", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/iced_wayland_subscriber/Cargo.toml b/iced_wayland_subscriber/Cargo.toml new file mode 100644 index 0000000..686d4ed --- /dev/null +++ b/iced_wayland_subscriber/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "iced_wayland_subscriber" +version.workspace = true +edition.workspace = true + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +futures.workspace = true +#nix = { version = "0.29.0", features = ["poll"] } +iced = { workspace = true, features = ["advanced"] } +wayland-client.workspace = true + +wayland-protocols.workspace = true +wayland-protocols-wlr.workspace = true +async-io = "2.4.0" diff --git a/iced_wayland_subscriber/src/lib.rs b/iced_wayland_subscriber/src/lib.rs new file mode 100644 index 0000000..0884774 --- /dev/null +++ b/iced_wayland_subscriber/src/lib.rs @@ -0,0 +1,123 @@ +use futures::SinkExt; +use wayland_client::{ + delegate_noop, + globals::{registry_queue_init, GlobalListContents}, + protocol::{ + wl_output::{self, WlOutput}, + wl_registry, + }, + Connection, Dispatch, Proxy, +}; + +use wayland_protocols::xdg::xdg_output::zv1::client::{ + zxdg_output_manager_v1::ZxdgOutputManagerV1, zxdg_output_v1, +}; + +#[derive(Debug)] +struct BaseState; + +// so interesting, it is just need to invoke once, it just used to get the globals +impl Dispatch for BaseState { + fn event( + _state: &mut Self, + _proxy: &wl_registry::WlRegistry, + _event: ::Event, + _data: &GlobalListContents, + _conn: &Connection, + _qh: &wayland_client::QueueHandle, + ) { + } +} + +#[derive(Debug, Default)] +struct SubscribeState { + events: Vec, + padding_wloutputs: Vec, +} + +impl Dispatch for SubscribeState { + fn event( + state: &mut Self, + proxy: &wl_registry::WlRegistry, + event: ::Event, + _data: &(), + _conn: &Connection, + qh: &wayland_client::QueueHandle, + ) { + match event { + wl_registry::Event::Global { + name, + interface, + version, + } => { + if interface == wl_output::WlOutput::interface().name { + let output = proxy.bind::(name, version, qh, ()); + state.padding_wloutputs.push(output); + } + } + wl_registry::Event::GlobalRemove { .. } => {} + _ => unreachable!(), + } + } +} +impl Dispatch for SubscribeState { + fn event( + state: &mut Self, + _proxy: &zxdg_output_v1::ZxdgOutputV1, + event: ::Event, + _data: &(), + _conn: &Connection, + _qhandle: &wayland_client::QueueHandle, + ) { + if let zxdg_output_v1::Event::Name { name } = event { + state.events.push(WaylandEvents::OutputInsert(name)); + } + } +} +delegate_noop!(SubscribeState: ignore WlOutput); // output is need to place layer_shell, although here +delegate_noop!(SubscribeState: ignore ZxdgOutputManagerV1); + +#[derive(Debug, Clone)] +pub enum WaylandEvents { + OutputInsert(String), +} + +pub fn listen() -> iced::Subscription { + iced::Subscription::run(|| { + iced::stream::channel(100, |mut output| async move { + let connection = Connection::connect_to_env().unwrap(); + let (globals, _) = registry_queue_init::(&connection).unwrap(); // We just need the + // global, the + // event_queue is + // not needed, we + // do not need + // BaseState after + + let mut state = SubscribeState::default(); + + let mut event_queue = connection.new_event_queue::(); + let qhandle = event_queue.handle(); + let display = connection.display(); + + let xdg_output_manager = globals + .bind::(&qhandle, 1..=3, ()) + .unwrap(); // b + display.get_registry(&qhandle, ()); + loop { + event_queue.blocking_dispatch(&mut state).unwrap(); + let mut current_outputs = vec![]; + std::mem::swap(&mut current_outputs, &mut state.padding_wloutputs); + for output in current_outputs { + xdg_output_manager.get_xdg_output(&output, &qhandle, ()); + } + + let mut current_events = vec![]; + std::mem::swap(&mut current_events, &mut state.events); + for event in current_events { + output.send(event).await.ok(); + } + async_io::Timer::after(std::time::Duration::from_millis(10)).await; + } + }) + }) +} diff --git a/layershellev/src/events.rs b/layershellev/src/events.rs index e9022c0..9f0b35b 100644 --- a/layershellev/src/events.rs +++ b/layershellev/src/events.rs @@ -68,8 +68,16 @@ pub enum LayerEvent<'a, T, Message> { UserEvent(Message), } +/// This allow the new layershell can be selected on target output +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum LayerOutputSetting { + ChosenOutput(String), + FollowLastOutput, + None, +} + /// layershell settings to create a new layershell surface -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct NewLayerShellSettings { /// the size of the layershell, optional. pub size: Option<(u32, u32)>, @@ -81,8 +89,8 @@ pub struct NewLayerShellSettings { /// follow the last output of the activated surface, used to create some thing like mako, who /// will show on the same window, only when the notifications is cleared, it will change the /// wl_output. - pub use_last_output: bool, pub events_transparent: bool, + pub output_setting: LayerOutputSetting, } /// be used to create a new popup @@ -105,8 +113,8 @@ impl Default for NewLayerShellSettings { size: None, margin: Some((0, 0, 0, 0)), keyboard_interactivity: KeyboardInteractivity::OnDemand, - use_last_output: false, events_transparent: false, + output_setting: LayerOutputSetting::None, } } } diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index 5f00e35..88305cc 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -111,6 +111,7 @@ //! } //! ``` //! +pub use events::LayerOutputSetting; pub use events::NewLayerShellSettings; pub use events::NewPopUpSettings; pub use waycrate_xkbkeycode::keyboard; @@ -1662,31 +1663,6 @@ impl Dispatch for WindowState { _conn: &Connection, _qhandle: &QueueHandle, ) { - if state.is_with_target() && !state.init_finished { - let Some((_, xdg_info)) = state - .xdg_info_cache - .iter_mut() - .find(|(_, info)| info.zxdgoutput == *proxy) - else { - return; - }; - match event { - zxdg_output_v1::Event::LogicalSize { width, height } => { - xdg_info.logical_size = (width, height); - } - zxdg_output_v1::Event::LogicalPosition { x, y } => { - xdg_info.position = (x, y); - } - zxdg_output_v1::Event::Name { name } => { - xdg_info.name = name; - } - zxdg_output_v1::Event::Description { description } => { - xdg_info.description = description; - } - _ => {} - }; - return; - } let Some(index) = state.units.iter().position(|info| { info.zxdgoutput .as_ref() @@ -1694,23 +1670,34 @@ impl Dispatch for WindowState { }) else { return; }; + let Some((_, xdg_info_cached)) = state + .xdg_info_cache + .iter_mut() + .find(|(_, info)| info.zxdgoutput == *proxy) + else { + return; + }; let info = &mut state.units[index]; let xdg_info = info.zxdgoutput.as_mut().unwrap(); let change_type = match event { zxdg_output_v1::Event::LogicalSize { width, height } => { xdg_info.logical_size = (width, height); + xdg_info_cached.logical_size = (width, height); XdgInfoChangedType::Size } zxdg_output_v1::Event::LogicalPosition { x, y } => { xdg_info.position = (x, y); + xdg_info_cached.position = (x, y); XdgInfoChangedType::Position } zxdg_output_v1::Event::Name { name } => { - xdg_info.name = name; + xdg_info.name = name.clone(); + xdg_info_cached.name = name; XdgInfoChangedType::Name } zxdg_output_v1::Event::Description { description } => { - xdg_info.description = description; + xdg_info.description = description.clone(); + xdg_info_cached.description = description; XdgInfoChangedType::Description } _ => { @@ -1859,7 +1846,6 @@ impl WindowState { // clear binded_output_name, it is not used anymore } - self.xdg_info_cache.clear(); let binded_output = output.as_ref().map(|(output, _)| output); let binded_xdginfo = output.as_ref().map(|(_, xdginfo)| xdginfo); @@ -2429,15 +2415,13 @@ impl WindowState { exclusive_zone, margin, keyboard_interactivity, - use_last_output, events_transparent, + output_setting, }, info, )) => { let pos = self.surface_pos(); - let mut output = pos.and_then(|p| self.units[p].wl_output.as_ref()); - if self.last_wloutput.is_none() && self.outputs.len() > self.last_unit_index { @@ -2445,9 +2429,19 @@ impl WindowState { Some(self.outputs[self.last_unit_index].1.clone()); } - if use_last_output { - output = self.last_wloutput.as_ref(); - } + let output = match output_setting { + events::LayerOutputSetting::None => { + pos.and_then(|p| self.units[p].wl_output.as_ref()).cloned() + } + events::LayerOutputSetting::FollowLastOutput => { + self.last_wloutput.clone() + } + events::LayerOutputSetting::ChosenOutput(output) => self + .xdg_info_cache + .iter() + .find(|(_, xdg_output_info)| xdg_output_info.name == output) + .map(|(output, _)| output.clone()), + }; let wl_surface = wmcompositer.create_surface(&qh, ()); // and create a surface. if two or more, let layer_shell = globals @@ -2455,7 +2449,7 @@ impl WindowState { .unwrap(); let layer = layer_shell.get_layer_surface( &wl_surface, - output, + output.as_ref(), layer, self.namespace.clone(), &qh, @@ -2509,7 +2503,7 @@ impl WindowState { fractional_scale, viewport, becreated: true, - wl_output: output.cloned(), + wl_output: output, binding: info, scale: 120, });