From 048e19d0466fc113887c1e4b2d944352837e9dae Mon Sep 17 00:00:00 2001 From: faervan Date: Wed, 8 Jan 2025 23:55:13 +0100 Subject: [PATCH 1/4] feat: add get_output task to receive a WlOutput --- examples/sctk_lazy/Cargo.toml | 1 + examples/sctk_lazy/src/main.rs | 38 +++++++++++++++++-- .../wayland/layer_surface.rs | 27 +++++++++++-- runtime/src/platform_specific/wayland/mod.rs | 11 ++++++ .../platform_specific/wayland/commands/mod.rs | 1 + .../wayland/commands/output.rs | 15 ++++++++ .../wayland/event_loop/state.rs | 4 ++ 7 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 winit/src/platform_specific/wayland/commands/output.rs diff --git a/examples/sctk_lazy/Cargo.toml b/examples/sctk_lazy/Cargo.toml index 512c00a0e2..c655595f80 100644 --- a/examples/sctk_lazy/Cargo.toml +++ b/examples/sctk_lazy/Cargo.toml @@ -15,3 +15,4 @@ iced = { path = "../..", features = [ "tiny-skia", "advanced", ], default-features = false } +tokio = { workspace = true, features = ["time"] } diff --git a/examples/sctk_lazy/src/main.rs b/examples/sctk_lazy/src/main.rs index 47560ee39d..6a158b9d7f 100644 --- a/examples/sctk_lazy/src/main.rs +++ b/examples/sctk_lazy/src/main.rs @@ -4,16 +4,19 @@ use iced::platform_specific::shell::commands::layer_surface::{ get_layer_surface, KeyboardInteractivity, }; +use iced::platform_specific::shell::commands::output::get_output; +use iced::runtime::platform_specific::wayland::layer_surface::IcedOutput; use iced::widget::{ button, column, horizontal_space, lazy, pick_list, row, scrollable, text, text_input, }; use iced::window::Id; -use iced::Task; +use iced::{stream, Task}; use iced::{Element, Length}; use std::collections::HashSet; use std::hash::Hash; +use std::sync::Arc; pub fn main() -> iced::Result { iced::daemon(App::title, App::update, App::view).run_with(App::new) @@ -126,10 +129,27 @@ enum Message { DeleteItem(Item), AddItem(String), ItemColorChanged(Item, Color), + GotOutput(Option), } impl App { fn new() -> (App, Task) { + (Self::default(), App::try_get_output()) + } + + fn try_get_output() -> Task { + let monitor = std::env::var("WL_OUTPUT").expect("Provide an Output (Monitor name) by setting env WL_OUTPUT!"); + get_output(move |output_state| { + output_state.outputs().find(|o| + output_state + .info(o) + .map(|info| info.name.as_ref() == Some(&monitor)) + .unwrap_or(false) + ).clone() + }).map(|optn| Message::GotOutput(optn.map(|output| IcedOutput::Output(output)))) + } + + fn open(output: IcedOutput) -> Task { let mut initial_surface = SctkLayerSurfaceSettings::default(); initial_surface.keyboard_interactivity = KeyboardInteractivity::OnDemand; @@ -139,14 +159,15 @@ impl App { .max_height(500.0) .max_width(900.0); initial_surface.size = Some((Some(500), Some(500))); - (Self::default(), get_layer_surface(initial_surface)) + initial_surface.output = output; + get_layer_surface(initial_surface) } fn title(&self, _id: Id) -> String { String::from("Lazy - Iced") } - fn update(&mut self, message: Message) { + fn update(&mut self, message: Message) -> Task { match message { Message::InputChanged(input) => { self.input = input; @@ -176,7 +197,18 @@ impl App { }); } } + Message::GotOutput(optn) => { + return match optn { + Some(output) => App::open(output), + None => Task::stream(stream::channel(1, |_s| async { + tokio::time::sleep(std::time::Duration::from_secs(1)).await + })) + .chain(App::try_get_output() + ) + } + } } + Task::none() } fn view(&self, _: Id) -> Element { diff --git a/runtime/src/platform_specific/wayland/layer_surface.rs b/runtime/src/platform_specific/wayland/layer_surface.rs index f4419c96c0..f65515d677 100644 --- a/runtime/src/platform_specific/wayland/layer_surface.rs +++ b/runtime/src/platform_specific/wayland/layer_surface.rs @@ -1,15 +1,14 @@ -use std::fmt; +use std::{fmt, sync::Arc}; use iced_core::layout::Limits; use cctk::sctk::{ - reexports::client::protocol::wl_output::WlOutput, - shell::wlr_layer::{Anchor, KeyboardInteractivity, Layer}, + output::OutputState, reexports::client::protocol::wl_output::WlOutput, shell::wlr_layer::{Anchor, KeyboardInteractivity, Layer} }; use iced_core::window::Id; /// output for layer surface -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum IcedOutput { /// show on all outputs All, @@ -17,6 +16,8 @@ pub enum IcedOutput { Active, /// show on a specific output Output(WlOutput), + // decide on which output to show + GetOutput(Arc, &OutputState) -> Option + Send + Sync>), } impl Default for IcedOutput { @@ -25,6 +26,24 @@ impl Default for IcedOutput { } } +impl fmt::Debug for IcedOutput { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + IcedOutput::All => write!(f, "IcedOutput::All"), + IcedOutput::Active => write!(f, "IcedOutput::Active"), + IcedOutput::Output(output) => write!( + f, + "IcedOutput::Output({:?})", + output + ), + IcedOutput::GetOutput(_) => write!( + f, + "IcedOutput::GetOutput(Arc, &OutputState) -> Option + Send + Sync>)" + ), + } + } +} + /// margins of the layer surface #[derive(Debug, Clone, Copy, Default)] pub struct IcedMargin { diff --git a/runtime/src/platform_specific/wayland/mod.rs b/runtime/src/platform_specific/wayland/mod.rs index 41b21c527e..c9ba40d743 100644 --- a/runtime/src/platform_specific/wayland/mod.rs +++ b/runtime/src/platform_specific/wayland/mod.rs @@ -2,8 +2,11 @@ use std::fmt::Debug; +use cctk::{sctk::output::OutputState, wayland_client::protocol::wl_output::WlOutput}; use iced_core::window::Id; +use crate::oneshot; + /// activation Actions pub mod activation; @@ -26,6 +29,11 @@ pub enum Action { SessionLock(session_lock::Action), /// Overlap Notify OverlapNotify(Id, bool), + // WlOutput getter + GetOutput { + f: Box Option + Send + Sync>, + channel: oneshot::Sender>, + }, } impl Debug for Action { @@ -44,6 +52,9 @@ impl Debug for Action { Action::OverlapNotify(id, _) => { f.debug_tuple("OverlapNotify").field(id).finish() } + Action::GetOutput {..} => { + f.debug_tuple("GetOutput").finish() + } } } } diff --git a/winit/src/platform_specific/wayland/commands/mod.rs b/winit/src/platform_specific/wayland/commands/mod.rs index 85ba1000f6..65cac2c635 100644 --- a/winit/src/platform_specific/wayland/commands/mod.rs +++ b/winit/src/platform_specific/wayland/commands/mod.rs @@ -5,3 +5,4 @@ pub mod layer_surface; pub mod overlap_notify; pub mod popup; pub mod session_lock; +pub mod output; diff --git a/winit/src/platform_specific/wayland/commands/output.rs b/winit/src/platform_specific/wayland/commands/output.rs new file mode 100644 index 0000000000..5f93d19191 --- /dev/null +++ b/winit/src/platform_specific/wayland/commands/output.rs @@ -0,0 +1,15 @@ +use cctk::sctk::output::OutputState; +use iced_runtime::{platform_specific::{self, wayland}, task, Action, Task}; +use wayland_client::protocol::wl_output::WlOutput; + + +pub fn get_output(f: F) -> Task> where F: Fn(&OutputState) -> Option + Send + Sync + 'static { + task::oneshot(|channel| Action::PlatformSpecific( + platform_specific::Action::Wayland( + wayland::Action::GetOutput { + f: Box::new(f), + channel, + } + ) + )) +} diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index 89a9167090..b012a8d6ac 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -758,6 +758,7 @@ impl SctkState { IcedOutput::All => None, // TODO IcedOutput::Active => None, IcedOutput::Output(output) => Some(output), + IcedOutput::GetOutput(f) => f(&self.outputs, &self.output_state), }; let layer_shell = self @@ -1208,6 +1209,9 @@ impl SctkState { tracing::error!("Overlap notify subscription cannot be created for surface. No matching layer surface found."); } }, + Action::GetOutput { f, channel } => { + channel.send(f(&self.output_state)); + } }; Ok(()) } From c1396a31fd3c883a72d510fd3da4d2e9587a64c9 Mon Sep 17 00:00:00 2001 From: faervan Date: Thu, 9 Jan 2025 09:29:04 +0100 Subject: [PATCH 2/4] fix: unused err warning --- winit/src/platform_specific/wayland/event_loop/state.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index b012a8d6ac..4c1de0cacb 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -1210,7 +1210,7 @@ impl SctkState { } }, Action::GetOutput { f, channel } => { - channel.send(f(&self.output_state)); + let _ = channel.send(f(&self.output_state)); } }; Ok(()) From 2a942f43aa17999fd268a55e7efbea7ae8930ba0 Mon Sep 17 00:00:00 2001 From: faervan Date: Thu, 9 Jan 2025 16:41:23 +0100 Subject: [PATCH 3/4] feat: add OutputInfo getter --- runtime/src/platform_specific/wayland/mod.rs | 12 ++++++++++-- .../platform_specific/wayland/commands/output.rs | 14 ++++++++++++-- .../platform_specific/wayland/event_loop/state.rs | 3 +++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/runtime/src/platform_specific/wayland/mod.rs b/runtime/src/platform_specific/wayland/mod.rs index c9ba40d743..c3aeea0222 100644 --- a/runtime/src/platform_specific/wayland/mod.rs +++ b/runtime/src/platform_specific/wayland/mod.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; -use cctk::{sctk::output::OutputState, wayland_client::protocol::wl_output::WlOutput}; +use cctk::{sctk::output::{OutputInfo, OutputState}, wayland_client::protocol::wl_output::WlOutput}; use iced_core::window::Id; use crate::oneshot; @@ -34,6 +34,11 @@ pub enum Action { f: Box Option + Send + Sync>, channel: oneshot::Sender>, }, + // OutputInfo getter + GetOutputInfo { + f: Box Option + Send + Sync>, + channel: oneshot::Sender>, + } } impl Debug for Action { @@ -52,9 +57,12 @@ impl Debug for Action { Action::OverlapNotify(id, _) => { f.debug_tuple("OverlapNotify").field(id).finish() } - Action::GetOutput {..} => { + Action::GetOutput { .. } => { f.debug_tuple("GetOutput").finish() } + Action::GetOutputInfo { .. } => { + f.debug_tuple("GetOutputInfo").finish() + } } } } diff --git a/winit/src/platform_specific/wayland/commands/output.rs b/winit/src/platform_specific/wayland/commands/output.rs index 5f93d19191..58d6a9e77e 100644 --- a/winit/src/platform_specific/wayland/commands/output.rs +++ b/winit/src/platform_specific/wayland/commands/output.rs @@ -1,8 +1,7 @@ -use cctk::sctk::output::OutputState; +use cctk::sctk::output::{OutputInfo, OutputState}; use iced_runtime::{platform_specific::{self, wayland}, task, Action, Task}; use wayland_client::protocol::wl_output::WlOutput; - pub fn get_output(f: F) -> Task> where F: Fn(&OutputState) -> Option + Send + Sync + 'static { task::oneshot(|channel| Action::PlatformSpecific( platform_specific::Action::Wayland( @@ -13,3 +12,14 @@ pub fn get_output(f: F) -> Task> where F: Fn(&OutputState) - ) )) } + +pub fn get_output_info(f: F) -> Task> where F: Fn(&OutputState) -> Option + Send + Sync + 'static { + task::oneshot(|channel| Action::PlatformSpecific( + platform_specific::Action::Wayland( + wayland::Action::GetOutputInfo { + f: Box::new(f), + channel, + } + ) + )) +} diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index 4c1de0cacb..6c951ceb3e 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -1212,6 +1212,9 @@ impl SctkState { Action::GetOutput { f, channel } => { let _ = channel.send(f(&self.output_state)); } + Action::GetOutputInfo { f, channel } => { + let _ = channel.send(f(&self.output_state)); + } }; Ok(()) } From fdd3da6605e59cb44960356af785fce9d609b76c Mon Sep 17 00:00:00 2001 From: faervan Date: Thu, 9 Jan 2025 22:58:46 +0100 Subject: [PATCH 4/4] feat: add custom output example --- examples/sctk_custom_output/Cargo.toml | 17 +++ examples/sctk_custom_output/src/main.rs | 130 ++++++++++++++++++ examples/sctk_lazy/Cargo.toml | 1 - examples/sctk_lazy/src/main.rs | 38 +---- runtime/src/platform_specific/wayland/mod.rs | 22 +-- .../src/platform_specific/wayland/output.rs | 30 ++++ .../wayland/commands/output.rs | 49 ++++--- .../wayland/event_loop/state.rs | 12 +- 8 files changed, 225 insertions(+), 74 deletions(-) create mode 100644 examples/sctk_custom_output/Cargo.toml create mode 100644 examples/sctk_custom_output/src/main.rs create mode 100644 runtime/src/platform_specific/wayland/output.rs diff --git a/examples/sctk_custom_output/Cargo.toml b/examples/sctk_custom_output/Cargo.toml new file mode 100644 index 0000000000..1561938535 --- /dev/null +++ b/examples/sctk_custom_output/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "sctk_custom_output" +version = "0.1.0" +edition.workspace = true +license.workspace = true + +[dependencies] +iced = { path = "../..", features = [ + "debug", + "lazy", + "wayland", + "winit", + "tokio", + "tiny-skia", + "advanced", +], default-features = false } +tokio = { workspace = true, features = ["time"] } diff --git a/examples/sctk_custom_output/src/main.rs b/examples/sctk_custom_output/src/main.rs new file mode 100644 index 0000000000..aa0f988008 --- /dev/null +++ b/examples/sctk_custom_output/src/main.rs @@ -0,0 +1,130 @@ +use std::env; +use std::time::Duration; + +use iced::platform_specific::shell::commands::layer_surface::get_layer_surface; +use iced::platform_specific::shell::commands::output::{ + get_output, get_output_info, +}; +use iced::runtime::platform_specific::wayland::layer_surface::SctkLayerSurfaceSettings; +use iced::widget::text; +use iced::{daemon, stream}; +use iced::{ + platform_specific::shell::commands::output::OutputInfo, + runtime::platform_specific::wayland::layer_surface::IcedOutput, Element, + Task, +}; + +use iced::window::Id; +use tokio::time::sleep; + +fn main() -> iced::Result { + daemon("Custom Output", App::update, App::view).run_with(App::new) +} + +#[derive(Debug)] +enum Message { + Output(Option), + OutputInfo(Option), +} + +#[derive(Debug)] +struct App { + monitor: Option, + output: IcedOutput, + logical_size: Option<(i32, i32)>, +} + +impl App { + fn new() -> (App, Task) { + let app = App { + monitor: env::var("WL_OUTPUT").ok(), + output: IcedOutput::Active, + logical_size: None, + }; + + let task = match &app.monitor { + Some(_) => app.try_get_output(), + None => app.open(), + }; + + (app, task) + } + + fn try_get_output(&self) -> Task { + let monitor = self.monitor.clone(); + get_output(move |output_state| { + output_state + .outputs() + .find(|o| { + output_state + .info(o) + .map(|info| info.name == monitor) + .unwrap_or(false) + }) + .clone() + }) + .map(|optn| Message::Output(optn.map(IcedOutput::Output))) + } + + fn try_get_output_info(&self) -> Task { + let monitor = self.monitor.clone(); + get_output_info(move |output_state| { + output_state + .outputs() + .find(|o| { + output_state + .info(o) + .map(|info| info.name == monitor) + .unwrap_or(false) + }) + .and_then(|o| output_state.info(&o)) + .clone() + }) + .map(Message::OutputInfo) + } + + fn open(&self) -> Task { + get_layer_surface(SctkLayerSurfaceSettings { + output: self.output.clone(), + size: match self.logical_size { + Some(size) => { + Some((Some((size.0 / 2) as u32), Some((size.1 / 2) as u32))) + } + None => Some((Some(800), Some(500))), + }, + ..Default::default() + }) + } + + fn update(&mut self, msg: Message) -> Task { + match msg { + Message::Output(optn) => match optn { + Some(output) => { + self.output = output; + self.try_get_output_info() + } + None => Task::stream(stream::channel(1, |_| async { + sleep(Duration::from_millis(500)).await; + })) + .chain(self.try_get_output()), + }, + Message::OutputInfo(optn) => match optn { + Some(info) => { + self.logical_size = info.logical_size; + self.open() + } + None => Task::stream(stream::channel(1, |_| async { + sleep(Duration::from_millis(500)).await; + })) + .chain(self.try_get_output_info()), + }, + } + } + + fn view(&self, _window_id: Id) -> Element { + match &self.monitor { + Some(monitor) => text!("Opened on monitor {monitor}\nSize: {:?}", self.logical_size), + None => text!("No output specified, try setting WL_OUTPUT=YourMonitor\nDefaulting to size 800x500"), + }.into() + } +} diff --git a/examples/sctk_lazy/Cargo.toml b/examples/sctk_lazy/Cargo.toml index c655595f80..512c00a0e2 100644 --- a/examples/sctk_lazy/Cargo.toml +++ b/examples/sctk_lazy/Cargo.toml @@ -15,4 +15,3 @@ iced = { path = "../..", features = [ "tiny-skia", "advanced", ], default-features = false } -tokio = { workspace = true, features = ["time"] } diff --git a/examples/sctk_lazy/src/main.rs b/examples/sctk_lazy/src/main.rs index 6a158b9d7f..47560ee39d 100644 --- a/examples/sctk_lazy/src/main.rs +++ b/examples/sctk_lazy/src/main.rs @@ -4,19 +4,16 @@ use iced::platform_specific::shell::commands::layer_surface::{ get_layer_surface, KeyboardInteractivity, }; -use iced::platform_specific::shell::commands::output::get_output; -use iced::runtime::platform_specific::wayland::layer_surface::IcedOutput; use iced::widget::{ button, column, horizontal_space, lazy, pick_list, row, scrollable, text, text_input, }; use iced::window::Id; -use iced::{stream, Task}; +use iced::Task; use iced::{Element, Length}; use std::collections::HashSet; use std::hash::Hash; -use std::sync::Arc; pub fn main() -> iced::Result { iced::daemon(App::title, App::update, App::view).run_with(App::new) @@ -129,27 +126,10 @@ enum Message { DeleteItem(Item), AddItem(String), ItemColorChanged(Item, Color), - GotOutput(Option), } impl App { fn new() -> (App, Task) { - (Self::default(), App::try_get_output()) - } - - fn try_get_output() -> Task { - let monitor = std::env::var("WL_OUTPUT").expect("Provide an Output (Monitor name) by setting env WL_OUTPUT!"); - get_output(move |output_state| { - output_state.outputs().find(|o| - output_state - .info(o) - .map(|info| info.name.as_ref() == Some(&monitor)) - .unwrap_or(false) - ).clone() - }).map(|optn| Message::GotOutput(optn.map(|output| IcedOutput::Output(output)))) - } - - fn open(output: IcedOutput) -> Task { let mut initial_surface = SctkLayerSurfaceSettings::default(); initial_surface.keyboard_interactivity = KeyboardInteractivity::OnDemand; @@ -159,15 +139,14 @@ impl App { .max_height(500.0) .max_width(900.0); initial_surface.size = Some((Some(500), Some(500))); - initial_surface.output = output; - get_layer_surface(initial_surface) + (Self::default(), get_layer_surface(initial_surface)) } fn title(&self, _id: Id) -> String { String::from("Lazy - Iced") } - fn update(&mut self, message: Message) -> Task { + fn update(&mut self, message: Message) { match message { Message::InputChanged(input) => { self.input = input; @@ -197,18 +176,7 @@ impl App { }); } } - Message::GotOutput(optn) => { - return match optn { - Some(output) => App::open(output), - None => Task::stream(stream::channel(1, |_s| async { - tokio::time::sleep(std::time::Duration::from_secs(1)).await - })) - .chain(App::try_get_output() - ) - } - } } - Task::none() } fn view(&self, _: Id) -> Element { diff --git a/runtime/src/platform_specific/wayland/mod.rs b/runtime/src/platform_specific/wayland/mod.rs index c3aeea0222..c2f2e0955d 100644 --- a/runtime/src/platform_specific/wayland/mod.rs +++ b/runtime/src/platform_specific/wayland/mod.rs @@ -2,7 +2,6 @@ use std::fmt::Debug; -use cctk::{sctk::output::{OutputInfo, OutputState}, wayland_client::protocol::wl_output::WlOutput}; use iced_core::window::Id; use crate::oneshot; @@ -16,6 +15,8 @@ pub mod layer_surface; pub mod popup; /// session locks pub mod session_lock; +/// Output (monitor) getters +pub mod output; /// Platform specific actions defined for wayland pub enum Action { @@ -29,16 +30,8 @@ pub enum Action { SessionLock(session_lock::Action), /// Overlap Notify OverlapNotify(Id, bool), - // WlOutput getter - GetOutput { - f: Box Option + Send + Sync>, - channel: oneshot::Sender>, - }, - // OutputInfo getter - GetOutputInfo { - f: Box Option + Send + Sync>, - channel: oneshot::Sender>, - } + /// Output (monitor) getters + Output(output::Action), } impl Debug for Action { @@ -57,11 +50,8 @@ impl Debug for Action { Action::OverlapNotify(id, _) => { f.debug_tuple("OverlapNotify").field(id).finish() } - Action::GetOutput { .. } => { - f.debug_tuple("GetOutput").finish() - } - Action::GetOutputInfo { .. } => { - f.debug_tuple("GetOutputInfo").finish() + Action::Output(arg0) => { + f.debug_tuple("GetOutput").field(arg0).finish() } } } diff --git a/runtime/src/platform_specific/wayland/output.rs b/runtime/src/platform_specific/wayland/output.rs new file mode 100644 index 0000000000..2fcc175992 --- /dev/null +++ b/runtime/src/platform_specific/wayland/output.rs @@ -0,0 +1,30 @@ +use std::fmt; + +use cctk::{ + sctk::output::{OutputInfo, OutputState}, + wayland_client::protocol::wl_output::WlOutput, +}; + +use crate::oneshot; + +pub enum Action { + // WlOutput getter + GetOutput { + f: Box Option + Send + Sync>, + channel: oneshot::Sender>, + }, + // OutputInfo getter + GetOutputInfo { + f: Box Option + Send + Sync>, + channel: oneshot::Sender>, + }, +} + +impl fmt::Debug for Action { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Action::GetOutput { .. } => write!(f, "Action::GetOutput"), + Action::GetOutputInfo { .. } => write!(f, "Action::GetOutputInfo",), + } + } +} diff --git a/winit/src/platform_specific/wayland/commands/output.rs b/winit/src/platform_specific/wayland/commands/output.rs index 58d6a9e77e..74049c9868 100644 --- a/winit/src/platform_specific/wayland/commands/output.rs +++ b/winit/src/platform_specific/wayland/commands/output.rs @@ -1,25 +1,40 @@ -use cctk::sctk::output::{OutputInfo, OutputState}; -use iced_runtime::{platform_specific::{self, wayland}, task, Action, Task}; -use wayland_client::protocol::wl_output::WlOutput; +pub use cctk::sctk::output::{OutputInfo, OutputState}; +use iced_runtime::{ + platform_specific::{self, wayland}, + task, Action, Task, +}; +pub use wayland_client::protocol::wl_output::WlOutput; -pub fn get_output(f: F) -> Task> where F: Fn(&OutputState) -> Option + Send + Sync + 'static { - task::oneshot(|channel| Action::PlatformSpecific( - platform_specific::Action::Wayland( - wayland::Action::GetOutput { +/// Get a +/// [WlOutput](https://docs.rs/wayland-client/latest/wayland_client/protocol/wl_output/struct.WlOutput.html) by calling a closure on a +/// [&OutputState](https://docs.rs/smithay-client-toolkit/latest/smithay_client_toolkit/output/struct.OutputState.html) +pub fn get_output(f: F) -> Task> +where + F: Fn(&OutputState) -> Option + Send + Sync + 'static, +{ + task::oneshot(|channel| { + Action::PlatformSpecific(platform_specific::Action::Wayland( + wayland::Action::Output(wayland::output::Action::GetOutput { f: Box::new(f), channel, - } - ) - )) + }), + )) + }) } -pub fn get_output_info(f: F) -> Task> where F: Fn(&OutputState) -> Option + Send + Sync + 'static { - task::oneshot(|channel| Action::PlatformSpecific( - platform_specific::Action::Wayland( - wayland::Action::GetOutputInfo { +/// Get a +/// [OutputInfo](https://docs.rs/smithay-client-toolkit/latest/smithay_client_toolkit/output/struct.OutputInfo.html) by calling a closure on a +/// [&OutputState](https://docs.rs/smithay-client-toolkit/latest/smithay_client_toolkit/output/struct.OutputState.html) +pub fn get_output_info(f: F) -> Task> +where + F: Fn(&OutputState) -> Option + Send + Sync + 'static, +{ + task::oneshot(|channel| { + Action::PlatformSpecific(platform_specific::Action::Wayland( + wayland::Action::Output(wayland::output::Action::GetOutputInfo { f: Box::new(f), channel, - } - ) - )) + }), + )) + }) } diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index 6c951ceb3e..37a3209b0e 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -1209,11 +1209,13 @@ impl SctkState { tracing::error!("Overlap notify subscription cannot be created for surface. No matching layer surface found."); } }, - Action::GetOutput { f, channel } => { - let _ = channel.send(f(&self.output_state)); - } - Action::GetOutputInfo { f, channel } => { - let _ = channel.send(f(&self.output_state)); + Action::Output(action) => match action { + platform_specific::wayland::output::Action::GetOutput { f, channel } => { + let _ = channel.send(f(&self.output_state)); + } + platform_specific::wayland::output::Action::GetOutputInfo { f, channel } => { + let _ = channel.send(f(&self.output_state)); + } } }; Ok(())