From a1f2e00b8a45abc4584f0c53771e33d5415f2a7c Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 5 Oct 2024 12:52:29 +0900 Subject: [PATCH 1/9] feat: add startmode to layershellev use enum to split the mode --- iced_layershell/src/application.rs | 3 +- iced_layershell/src/multi_window.rs | 5 +- iced_layershell/src/settings.rs | 3 + layershellev/examples/simplelayer.rs | 2 +- layershellev/src/lib.rs | 112 +++++++++++++++++++++------ starcolorkeyboard/src/main.rs | 2 +- 6 files changed, 99 insertions(+), 28 deletions(-) diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index adb121e..5fa812f 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -150,7 +150,6 @@ where }; let ev = layershellev::WindowStateSimple::new(&application.namespace()) - .with_single(true) .with_use_display_handle(true) .with_option_size(settings.layer_settings.size) .with_layer(settings.layer_settings.layer) @@ -158,7 +157,7 @@ where .with_exclusize_zone(settings.layer_settings.exclusive_zone) .with_margin(settings.layer_settings.margin) .with_keyboard_interacivity(settings.layer_settings.keyboard_interactivity) - .with_xdg_output_name(settings.layer_settings.binded_output_name) + .with_single_or_xdg_output_name(settings.layer_settings.binded_output_name) .build() .expect("Cannot create layershell"); diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index f837e34..f6ebd23 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -188,8 +188,9 @@ where )); let ev: WindowState = layershellev::WindowState::new(&application.namespace()) - .with_single(false) - .with_background(A::BACKGROUND_MODE) + .with_allscreen_or_single(settings.layer_settings.monitor_all_screen) + .with_xdg_output_name_or_not(settings.layer_settings.binded_output_name) + .with_background_or_not(A::BACKGROUND_MODE) .with_use_display_handle(true) .with_option_size(settings.layer_settings.size) .with_layer(settings.layer_settings.layer) diff --git a/iced_layershell/src/settings.rs b/iced_layershell/src/settings.rs index 5feeef3..0ec207d 100644 --- a/iced_layershell/src/settings.rs +++ b/iced_layershell/src/settings.rs @@ -81,6 +81,7 @@ pub struct LayerShellSettings { pub margin: (i32, i32, i32, i32), pub keyboard_interactivity: KeyboardInteractivity, pub binded_output_name: Option, + pub monitor_all_screen: bool, } impl Default for LayerShellSettings { @@ -93,6 +94,7 @@ impl Default for LayerShellSettings { margin: (0, 0, 0, 0), keyboard_interactivity: KeyboardInteractivity::OnDemand, binded_output_name: None, + monitor_all_screen: false, } } } @@ -154,6 +156,7 @@ mod tests { margin: (10, 10, 10, 10), keyboard_interactivity: KeyboardInteractivity::None, binded_output_name: Some("HDMI-1".to_string()), + monitor_all_screen: false, }; assert_eq!(layer_settings.anchor, Anchor::Top | Anchor::Left); diff --git a/layershellev/examples/simplelayer.rs b/layershellev/examples/simplelayer.rs index 57fd788..341f644 100644 --- a/layershellev/examples/simplelayer.rs +++ b/layershellev/examples/simplelayer.rs @@ -7,7 +7,7 @@ use layershellev::*; fn main() { let ev: WindowState<()> = WindowState::new("Hello") - .with_single(false) + .with_allscreen() .with_size((0, 400)) .with_layer(Layer::Top) .with_margin((20, 20, 100, 20)) diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index caa424c..24e34c1 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -543,8 +543,6 @@ impl WindowStateUnit { pub struct WindowState { outputs: Vec<(u32, wl_output::WlOutput)>, current_surface: Option, - is_single: bool, - is_background: bool, units: Vec>, message: Vec<(Option, DispatchMessageInner)>, @@ -590,8 +588,9 @@ pub struct WindowState { last_touch_location: (f64, f64), last_touch_id: i32, - binded_output_name: Option, xdg_info_cache: Vec<(wl_output::WlOutput, ZxdgOutputInfo)>, + + start_mode: StartMode, } impl WindowState { @@ -649,6 +648,29 @@ pub struct WindowWrapper { wl_surface: WlSurface, } +#[derive(Debug, Clone)] +pub enum StartMode { + Single, + Background, + AllScreen, + TargetScreen(String), +} + +impl StartMode { + fn is_single(&self) -> bool { + matches!(self, Self::Single) + } + fn is_background(&self) -> bool { + matches!(self, Self::Background) + } + fn is_allscreen(&self) -> bool { + matches!(self, Self::AllScreen) + } + fn is_with_target(&self) -> bool { + matches!(self, Self::TargetScreen(_)) + } +} + impl WindowWrapper { pub fn id(&self) -> id::Id { self.id @@ -681,7 +703,7 @@ impl WindowState { /// gen the wrapper to the main window /// used to get display and etc pub fn gen_main_wrapper(&self) -> WindowWrapper { - if self.is_background { + if self.is_background() { return WindowWrapper { id: id::Id::MAIN, display: self.display.as_ref().unwrap().clone(), @@ -690,6 +712,18 @@ impl WindowState { } self.main_window().gen_wrapper() } + fn is_single(&self) -> bool { + self.start_mode.is_single() + } + fn is_background(&self) -> bool { + self.start_mode.is_background() + } + fn is_allscreen(&self) -> bool { + self.start_mode.is_allscreen() + } + fn is_with_target(&self) -> bool { + self.start_mode.is_with_target() + } } impl WindowWrapper { @@ -746,20 +780,59 @@ impl WindowState { /// suggest to bind to specific output /// if there is no such output , it will bind the output which now is focused, /// same with when binded_output_name is None - pub fn with_xdg_output_name(mut self, binded_output_name: Option) -> Self { - self.binded_output_name = binded_output_name; + pub fn with_xdg_output_name(mut self, binded_output_name: String) -> Self { + self.start_mode = StartMode::TargetScreen(binded_output_name); self } /// if the shell is a single one, only display on one screen, /// fi true, the layer will binding to current screen - pub fn with_single(mut self, single: bool) -> Self { - self.is_single = single; + pub fn with_single(mut self) -> Self { + self.start_mode = StartMode::Single; + self + } + + pub fn with_single_or_xdg_output_name(self, binded_output_name: Option) -> Self { + match binded_output_name { + Some(binded_output_name) => self.with_xdg_output_name(binded_output_name), + None => self.with_single(), + } + } + + pub fn with_allscreen_or_xdg_output_name(self, binded_output_name: Option) -> Self { + match binded_output_name { + Some(binded_output_name) => self.with_xdg_output_name(binded_output_name), + None => self.with_allscreen(), + } + } + pub fn with_xdg_output_name_or_not(self, binded_output_name: Option) -> Self { + let Some(binded_output_name) = binded_output_name else { + return self; + }; + self.with_xdg_output_name(binded_output_name) + } + pub fn with_allscreen_or_single(mut self, allscreen: bool) -> Self { + if allscreen { + self.start_mode = StartMode::AllScreen; + } else { + self.start_mode = StartMode::Single; + } + + self + } + pub fn with_allscreen(mut self) -> Self { + self.start_mode = StartMode::AllScreen; self } + pub fn with_background_or_not(self, background_mode: bool) -> Self { + if !background_mode { + return self; + } + self.with_background() + } - pub fn with_background(mut self, background: bool) -> Self { - self.is_background = background; + pub fn with_background(mut self) -> Self { + self.start_mode = StartMode::Background; self } @@ -823,8 +896,6 @@ impl Default for WindowState { Self { outputs: Vec::new(), current_surface: None, - is_single: true, - is_background: false, units: Vec::new(), message: Vec::new(), @@ -866,8 +937,9 @@ impl Default for WindowState { last_touch_id: 0, // NOTE: if is some, means it is to be binded, but not now it // is not binded - binded_output_name: None, xdg_info_cache: Vec::new(), + + start_mode: StartMode::Single, } } } @@ -1491,7 +1563,7 @@ impl Dispatch for WindowState { _conn: &Connection, _qhandle: &QueueHandle, ) { - if state.binded_output_name.is_some() { + if state.is_with_target() { let Some((_, xdg_info)) = state .xdg_info_cache .iter_mut() @@ -1657,12 +1729,12 @@ impl WindowState { // finally thing to remember is to commit the surface, make the shell to init. //let (init_w, init_h) = self.size; // this example is ok for both xdg_surface and layer_shell - if self.is_background { + if self.is_background() { self.background_surface = Some(wmcompositer.create_surface(&qh, ())); - } else if self.is_single { + } else if !self.is_allscreen() { let mut output = None; - if let Some(name) = self.binded_output_name.clone() { + if let StartMode::TargetScreen(name) = self.start_mode.clone() { for (_, output_display) in &self.outputs { let zxdgoutput = xdg_output_manager.get_xdg_output(output_display, &qh, ()); self.xdg_info_cache @@ -1678,7 +1750,6 @@ impl WindowState { output = Some(cache.clone()); } // clear binded_output_name, it is not used anymore - self.binded_output_name.take(); } self.xdg_info_cache.clear(); @@ -1932,7 +2003,7 @@ impl WindowState { ); } (_, DispatchMessageInner::NewDisplay(output_display)) => { - if self.is_single || self.is_background { + if self.is_single() || self.is_background() { continue; } let wl_surface = wmcompositer.create_surface(&qh, ()); // and create a surface. if two or more, @@ -2195,9 +2266,6 @@ impl WindowState { }, info, )) => { - if self.is_single { - continue; - } let pos = self.surface_pos(); let mut output = pos.and_then(|p| self.units[p].wl_output.as_ref()); diff --git a/starcolorkeyboard/src/main.rs b/starcolorkeyboard/src/main.rs index 195dfe0..c5939ae 100644 --- a/starcolorkeyboard/src/main.rs +++ b/starcolorkeyboard/src/main.rs @@ -82,7 +82,7 @@ pub fn get_keymap_as_file() -> (File, u32) { fn main() { let ev: WindowState = WindowState::new("precure") - .with_single(false) + .with_allscreen() .with_size((0, 300)) .with_layer(Layer::Top) .with_anchor(Anchor::Bottom | Anchor::Left | Anchor::Right) From a4ba70504db78251a6f087b282a7097108f94af1 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 5 Oct 2024 12:59:03 +0900 Subject: [PATCH 2/9] chore: add init finished check --- layershellev/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index 24e34c1..854e344 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -591,6 +591,7 @@ pub struct WindowState { xdg_info_cache: Vec<(wl_output::WlOutput, ZxdgOutputInfo)>, start_mode: StartMode, + init_finished: bool, } impl WindowState { @@ -940,6 +941,7 @@ impl Default for WindowState { xdg_info_cache: Vec::new(), start_mode: StartMode::Single, + init_finished: false, } } } @@ -1563,7 +1565,7 @@ impl Dispatch for WindowState { _conn: &Connection, _qhandle: &QueueHandle, ) { - if state.is_with_target() { + if state.is_with_target() && !state.init_finished { let Some((_, xdg_info)) = state .xdg_info_cache .iter_mut() @@ -1864,6 +1866,7 @@ impl WindowState { } self.message.clear(); } + self.init_finished = true; self.event_queue = Some(event_queue); self.globals = Some(globals); self.wl_compositor = Some(wmcompositer); From dd9672ef6b14214b882df25af853dc742f66d10f Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 5 Oct 2024 13:01:48 +0900 Subject: [PATCH 3/9] fix: only monitor allscreen do newdisplay event --- layershellev/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index 854e344..3dcac7d 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -658,6 +658,7 @@ pub enum StartMode { } impl StartMode { + #[allow(unused)] fn is_single(&self) -> bool { matches!(self, Self::Single) } @@ -713,6 +714,7 @@ impl WindowState { } self.main_window().gen_wrapper() } + #[allow(unused)] fn is_single(&self) -> bool { self.start_mode.is_single() } @@ -2006,7 +2008,7 @@ impl WindowState { ); } (_, DispatchMessageInner::NewDisplay(output_display)) => { - if self.is_single() || self.is_background() { + if !self.is_allscreen() { continue; } let wl_surface = wmcompositer.create_surface(&qh, ()); // and create a surface. if two or more, From c9d7791698ed6d49a5ead3b382d4608632d8dcd8 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 5 Oct 2024 13:09:48 +0900 Subject: [PATCH 4/9] fix: test --- layershellev/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index 3dcac7d..aaa457c 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -12,7 +12,7 @@ //! //! fn main() { //! let mut ev: WindowState<()> = WindowState::new("Hello") -//! .with_single(false) +//! .with_allscreen() //! .with_size((0, 400)) //! .with_layer(Layer::Top) //! .with_margin((20, 20, 100, 20)) From 2d5acdb278269d4897a0156c8fd66dd6e0e77769 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 6 Oct 2024 22:13:25 +0900 Subject: [PATCH 5/9] chore: adjust the settings of iced_layershell --- iced_examples/counter/src/main.rs | 9 ++++++-- iced_layershell/src/application.rs | 9 ++++++-- iced_layershell/src/multi_window.rs | 3 +-- iced_layershell/src/settings.rs | 20 ++++++++-------- layershellev/src/lib.rs | 36 ++++++++++++++++++----------- 5 files changed, 48 insertions(+), 29 deletions(-) diff --git a/iced_examples/counter/src/main.rs b/iced_examples/counter/src/main.rs index 49c76f3..c5e9732 100644 --- a/iced_examples/counter/src/main.rs +++ b/iced_examples/counter/src/main.rs @@ -1,7 +1,7 @@ use iced::widget::{button, column, row, text, text_input}; use iced::{event, Alignment, Color, Element, Event, Length, Task as Command, Theme}; use iced_layershell::reexport::Anchor; -use iced_layershell::settings::{LayerShellSettings, Settings}; +use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; use iced_layershell::to_layer_message; use iced_layershell::Application; @@ -13,12 +13,17 @@ pub fn main() -> Result<(), iced_layershell::Error> { binded_output_name = Some(args[1].to_string()) } + let start_mode = match binded_output_name { + Some(output) => StartMode::TargetScreen(output), + None => StartMode::AllScreen, + }; + Counter::run(Settings { layer_settings: LayerShellSettings { size: Some((0, 400)), exclusive_zone: 400, anchor: Anchor::Bottom | Anchor::Left | Anchor::Right, - binded_output_name, + start_mode, ..Default::default() }, ..Default::default() diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index 5fa812f..1984329 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -23,7 +23,7 @@ use iced_futures::{Executor, Runtime, Subscription}; use layershellev::{ calloop::timer::{TimeoutAction, Timer}, reexport::zwp_virtual_keyboard_v1, - LayerEvent, ReturnData, WindowWrapper, + LayerEvent, ReturnData, StartMode, WindowWrapper, }; use futures::{channel::mpsc, StreamExt}; @@ -149,6 +149,11 @@ where runtime.enter(|| A::new(flags)) }; + assert!(!matches!( + settings.layer_settings.start_mode, + StartMode::AllScreen | StartMode::Background + )); + let ev = layershellev::WindowStateSimple::new(&application.namespace()) .with_use_display_handle(true) .with_option_size(settings.layer_settings.size) @@ -157,7 +162,7 @@ where .with_exclusize_zone(settings.layer_settings.exclusive_zone) .with_margin(settings.layer_settings.margin) .with_keyboard_interacivity(settings.layer_settings.keyboard_interactivity) - .with_single_or_xdg_output_name(settings.layer_settings.binded_output_name) + .with_start_mode(settings.layer_settings.start_mode) .build() .expect("Cannot create layershell"); diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index f6ebd23..32ef4d7 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -188,8 +188,7 @@ where )); let ev: WindowState = layershellev::WindowState::new(&application.namespace()) - .with_allscreen_or_single(settings.layer_settings.monitor_all_screen) - .with_xdg_output_name_or_not(settings.layer_settings.binded_output_name) + .with_start_mode(settings.layer_settings.start_mode) .with_background_or_not(A::BACKGROUND_MODE) .with_use_display_handle(true) .with_option_size(settings.layer_settings.size) diff --git a/iced_layershell/src/settings.rs b/iced_layershell/src/settings.rs index 0ec207d..26c4284 100644 --- a/iced_layershell/src/settings.rs +++ b/iced_layershell/src/settings.rs @@ -4,6 +4,8 @@ use iced::{Font, Pixels}; use crate::reexport::{Anchor, KeyboardInteractivity, Layer}; +pub use layershellev::StartMode; + use layershellev::reexport::wayland_client::wl_keyboard::KeymapFormat; #[derive(Debug)] @@ -80,8 +82,7 @@ pub struct LayerShellSettings { pub size: Option<(u32, u32)>, pub margin: (i32, i32, i32, i32), pub keyboard_interactivity: KeyboardInteractivity, - pub binded_output_name: Option, - pub monitor_all_screen: bool, + pub start_mode: StartMode, } impl Default for LayerShellSettings { @@ -93,8 +94,7 @@ impl Default for LayerShellSettings { size: None, margin: (0, 0, 0, 0), keyboard_interactivity: KeyboardInteractivity::OnDemand, - binded_output_name: None, - monitor_all_screen: false, + start_mode: StartMode::default(), } } } @@ -127,7 +127,10 @@ mod tests { settings.layer_settings.keyboard_interactivity, KeyboardInteractivity::OnDemand ); - assert!(settings.layer_settings.binded_output_name.is_none()); + assert!(matches!( + settings.layer_settings.start_mode, + StartMode::CurrentActive + )); } #[test] @@ -155,8 +158,7 @@ mod tests { size: Some((1920, 1080)), margin: (10, 10, 10, 10), keyboard_interactivity: KeyboardInteractivity::None, - binded_output_name: Some("HDMI-1".to_string()), - monitor_all_screen: false, + start_mode: StartMode::TargetScreen("HDMI-1".to_string()), }; assert_eq!(layer_settings.anchor, Anchor::Top | Anchor::Left); @@ -169,8 +171,8 @@ mod tests { KeyboardInteractivity::None ); assert_eq!( - layer_settings.binded_output_name, - Some("HDMI-1".to_string()) + layer_settings.start_mode, + StartMode::TargetScreen("HDMI-1".to_string()) ); } } diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index aaa457c..f9e3f77 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -649,9 +649,10 @@ pub struct WindowWrapper { wl_surface: WlSurface, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default, PartialEq, Eq)] pub enum StartMode { - Single, + #[default] + CurrentActive, Background, AllScreen, TargetScreen(String), @@ -659,8 +660,8 @@ pub enum StartMode { impl StartMode { #[allow(unused)] - fn is_single(&self) -> bool { - matches!(self, Self::Single) + fn is_current_active(&self) -> bool { + matches!(self, Self::CurrentActive) } fn is_background(&self) -> bool { matches!(self, Self::Background) @@ -715,8 +716,8 @@ impl WindowState { self.main_window().gen_wrapper() } #[allow(unused)] - fn is_single(&self) -> bool { - self.start_mode.is_single() + fn is_current_active(&self) -> bool { + self.start_mode.is_current_active() } fn is_background(&self) -> bool { self.start_mode.is_background() @@ -788,17 +789,22 @@ impl WindowState { self } + pub fn with_start_mode(mut self, mode: StartMode) -> Self { + self.start_mode = mode; + self + } + /// if the shell is a single one, only display on one screen, /// fi true, the layer will binding to current screen - pub fn with_single(mut self) -> Self { - self.start_mode = StartMode::Single; + pub fn with_active(mut self) -> Self { + self.start_mode = StartMode::CurrentActive; self } - pub fn with_single_or_xdg_output_name(self, binded_output_name: Option) -> Self { + pub fn with_active_or_xdg_output_name(self, binded_output_name: Option) -> Self { match binded_output_name { Some(binded_output_name) => self.with_xdg_output_name(binded_output_name), - None => self.with_single(), + None => self.with_active(), } } @@ -814,19 +820,21 @@ impl WindowState { }; self.with_xdg_output_name(binded_output_name) } - pub fn with_allscreen_or_single(mut self, allscreen: bool) -> Self { + + pub fn with_allscreen_or_active(mut self, allscreen: bool) -> Self { if allscreen { self.start_mode = StartMode::AllScreen; } else { - self.start_mode = StartMode::Single; + self.start_mode = StartMode::CurrentActive; } - self } + pub fn with_allscreen(mut self) -> Self { self.start_mode = StartMode::AllScreen; self } + pub fn with_background_or_not(self, background_mode: bool) -> Self { if !background_mode { return self; @@ -942,7 +950,7 @@ impl Default for WindowState { // is not binded xdg_info_cache: Vec::new(), - start_mode: StartMode::Single, + start_mode: StartMode::CurrentActive, init_finished: false, } } From 5c7bdee3a900613decb398327b4fad08050d9cc4 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 6 Oct 2024 22:22:49 +0900 Subject: [PATCH 6/9] chore: adjust background logic --- iced_examples/zbus_invoked_widget/src/main.rs | 12 ++++++++---- iced_layershell/src/lib.rs | 4 ---- iced_layershell/src/multi_window.rs | 10 +++++----- layershellev/src/lib.rs | 9 ++++----- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/iced_examples/zbus_invoked_widget/src/main.rs b/iced_examples/zbus_invoked_widget/src/main.rs index c4bc32d..5d9827a 100644 --- a/iced_examples/zbus_invoked_widget/src/main.rs +++ b/iced_examples/zbus_invoked_widget/src/main.rs @@ -9,7 +9,7 @@ use iced_runtime::window::Action as WindowAction; use iced_runtime::Action; use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; -use iced_layershell::settings::Settings; +use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; use iced_layershell::MultiApplication; use zbus::{interface, ConnectionBuilder}; @@ -23,7 +23,13 @@ struct Counter { text: String, } pub fn main() -> Result<(), iced_layershell::Error> { - Counter::run(Settings::default()) + Counter::run(Settings { + layer_settings: LayerShellSettings { + start_mode: StartMode::Background, + ..Default::default() + }, + ..Default::default() + }) } #[derive(Debug, Clone)] @@ -64,8 +70,6 @@ impl MultiApplication for Counter { type Executor = iced::executor::Default; type WindowInfo = (); - const BACKGROUND_MODE: bool = true; - fn set_id_info(&mut self, _id: iced_runtime::core::window::Id, _info: Self::WindowInfo) { self.window_shown = true; } diff --git a/iced_layershell/src/lib.rs b/iced_layershell/src/lib.rs index fd3fe70..81a9b40 100644 --- a/iced_layershell/src/lib.rs +++ b/iced_layershell/src/lib.rs @@ -260,8 +260,6 @@ pub trait MultiApplication: Sized { type Theme: Default + DefaultStyle; - const BACKGROUND_MODE: bool = false; - /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -409,8 +407,6 @@ where type WindowInfo = A::WindowInfo; - const BACKGROUND_MODE: bool = A::BACKGROUND_MODE; - fn new(flags: Self::Flags) -> (Self, Task) { let (app, command) = A::new(flags); diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index 32ef4d7..22c25bb 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -63,8 +63,6 @@ where type WindowInfo; - const BACKGROUND_MODE: bool; - /// Initializes the [`Application`] with the flags provided to /// [`run`] as part of the [`Settings`]. /// @@ -187,9 +185,9 @@ where runtime.enter(|| application.subscription().map(Action::Output)), )); + 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_background_or_not(A::BACKGROUND_MODE) .with_use_display_handle(true) .with_option_size(settings.layer_settings.size) .with_layer(settings.layer_settings.layer) @@ -215,6 +213,7 @@ where event_receiver, control_sender, window, + is_background_mode, )); let mut context = task::Context::from_waker(task::noop_waker_ref()); @@ -461,6 +460,7 @@ async fn run_instance( >, mut control_sender: mpsc::UnboundedSender>, window: Arc, + is_background_mode: bool, ) where A: Application + 'static, E: Executor + 'static, @@ -746,7 +746,7 @@ async fn run_instance( // HACK: this logic is just from iced, but seems if there is no main window, // any window will not get Outdated state. // So here just check if there is window_events - if A::BACKGROUND_MODE && has_window_event { + if is_background_mode && has_window_event { custom_actions.push(LayerShellActions::RedrawAll); } @@ -765,7 +765,7 @@ async fn run_instance( window.state.synchronize(&application); } - if !A::BACKGROUND_MODE { + if !is_background_mode { custom_actions.push(LayerShellActions::RedrawAll); } diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index f9e3f77..d3ac426 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -659,17 +659,16 @@ pub enum StartMode { } impl StartMode { - #[allow(unused)] - fn is_current_active(&self) -> bool { + pub fn is_current_active(&self) -> bool { matches!(self, Self::CurrentActive) } - fn is_background(&self) -> bool { + pub fn is_background(&self) -> bool { matches!(self, Self::Background) } - fn is_allscreen(&self) -> bool { + pub fn is_allscreen(&self) -> bool { matches!(self, Self::AllScreen) } - fn is_with_target(&self) -> bool { + pub fn is_with_target(&self) -> bool { matches!(self, Self::TargetScreen(_)) } } From 8f86831da58ecd7525eefa34833659fb433c9bbb Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 6 Oct 2024 22:31:05 +0900 Subject: [PATCH 7/9] chore: adjust the field name of StartMode --- iced_examples/counter/src/main.rs | 2 +- iced_layershell/src/application.rs | 2 +- iced_layershell/src/settings.rs | 2 +- layershellev/src/lib.rs | 31 +++++++++++++++--------------- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/iced_examples/counter/src/main.rs b/iced_examples/counter/src/main.rs index c5e9732..9104ccc 100644 --- a/iced_examples/counter/src/main.rs +++ b/iced_examples/counter/src/main.rs @@ -15,7 +15,7 @@ pub fn main() -> Result<(), iced_layershell::Error> { let start_mode = match binded_output_name { Some(output) => StartMode::TargetScreen(output), - None => StartMode::AllScreen, + None => StartMode::AllScreens, }; Counter::run(Settings { diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index 1984329..d4d3e48 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -151,7 +151,7 @@ where assert!(!matches!( settings.layer_settings.start_mode, - StartMode::AllScreen | StartMode::Background + StartMode::AllScreens | StartMode::Background )); let ev = layershellev::WindowStateSimple::new(&application.namespace()) diff --git a/iced_layershell/src/settings.rs b/iced_layershell/src/settings.rs index 26c4284..5047bac 100644 --- a/iced_layershell/src/settings.rs +++ b/iced_layershell/src/settings.rs @@ -129,7 +129,7 @@ mod tests { ); assert!(matches!( settings.layer_settings.start_mode, - StartMode::CurrentActive + StartMode::Active )); } diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index d3ac426..c9e746c 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -652,21 +652,21 @@ pub struct WindowWrapper { #[derive(Debug, Clone, Default, PartialEq, Eq)] pub enum StartMode { #[default] - CurrentActive, + Active, Background, - AllScreen, + AllScreens, TargetScreen(String), } impl StartMode { - pub fn is_current_active(&self) -> bool { - matches!(self, Self::CurrentActive) + pub fn is_active(&self) -> bool { + matches!(self, Self::Active) } pub fn is_background(&self) -> bool { matches!(self, Self::Background) } pub fn is_allscreen(&self) -> bool { - matches!(self, Self::AllScreen) + matches!(self, Self::AllScreens) } pub fn is_with_target(&self) -> bool { matches!(self, Self::TargetScreen(_)) @@ -714,17 +714,16 @@ impl WindowState { } self.main_window().gen_wrapper() } - #[allow(unused)] - fn is_current_active(&self) -> bool { - self.start_mode.is_current_active() + pub fn is_active(&self) -> bool { + self.start_mode.is_active() } - fn is_background(&self) -> bool { + pub fn is_background(&self) -> bool { self.start_mode.is_background() } - fn is_allscreen(&self) -> bool { + pub fn is_allscreen(&self) -> bool { self.start_mode.is_allscreen() } - fn is_with_target(&self) -> bool { + pub fn is_with_target(&self) -> bool { self.start_mode.is_with_target() } } @@ -796,7 +795,7 @@ impl WindowState { /// if the shell is a single one, only display on one screen, /// fi true, the layer will binding to current screen pub fn with_active(mut self) -> Self { - self.start_mode = StartMode::CurrentActive; + self.start_mode = StartMode::Active; self } @@ -822,15 +821,15 @@ impl WindowState { pub fn with_allscreen_or_active(mut self, allscreen: bool) -> Self { if allscreen { - self.start_mode = StartMode::AllScreen; + self.start_mode = StartMode::AllScreens; } else { - self.start_mode = StartMode::CurrentActive; + self.start_mode = StartMode::Active; } self } pub fn with_allscreen(mut self) -> Self { - self.start_mode = StartMode::AllScreen; + self.start_mode = StartMode::AllScreens; self } @@ -949,7 +948,7 @@ impl Default for WindowState { // is not binded xdg_info_cache: Vec::new(), - start_mode: StartMode::CurrentActive, + start_mode: StartMode::Active, init_finished: false, } } From 5a621d807650ab11536974839b444a9df2e301da Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 6 Oct 2024 22:36:37 +0900 Subject: [PATCH 8/9] fix: examples --- iced_examples/counter/src/main.rs | 2 +- iced_examples/counter_muti/src/main.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/iced_examples/counter/src/main.rs b/iced_examples/counter/src/main.rs index 9104ccc..2366f5f 100644 --- a/iced_examples/counter/src/main.rs +++ b/iced_examples/counter/src/main.rs @@ -15,7 +15,7 @@ pub fn main() -> Result<(), iced_layershell::Error> { let start_mode = match binded_output_name { Some(output) => StartMode::TargetScreen(output), - None => StartMode::AllScreens, + None => StartMode::Active, }; Counter::run(Settings { diff --git a/iced_examples/counter_muti/src/main.rs b/iced_examples/counter_muti/src/main.rs index a52f795..c8a7f76 100644 --- a/iced_examples/counter_muti/src/main.rs +++ b/iced_examples/counter_muti/src/main.rs @@ -8,15 +8,17 @@ use iced_runtime::window::Action as WindowAction; use iced_runtime::{task, Action}; use iced_layershell::reexport::{Anchor, KeyboardInteractivity, Layer, NewLayerShellSettings}; -use iced_layershell::settings::{LayerShellSettings, Settings}; +use iced_layershell::settings::{LayerShellSettings, Settings, StartMode}; use iced_layershell::to_layer_message; use iced_layershell::MultiApplication; + pub fn main() -> Result<(), iced_layershell::Error> { Counter::run(Settings { layer_settings: LayerShellSettings { size: Some((0, 400)), exclusive_zone: 400, anchor: Anchor::Bottom | Anchor::Left | Anchor::Right, + start_mode: StartMode::AllScreens, ..Default::default() }, ..Default::default() From 28f4b886010824263d15a13014723ec2f6028bb3 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 6 Oct 2024 22:42:07 +0900 Subject: [PATCH 9/9] chore: adjust function name --- layershellev/examples/simplelayer.rs | 2 +- layershellev/src/lib.rs | 20 ++++++++++---------- starcolorkeyboard/src/main.rs | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/layershellev/examples/simplelayer.rs b/layershellev/examples/simplelayer.rs index 341f644..c024733 100644 --- a/layershellev/examples/simplelayer.rs +++ b/layershellev/examples/simplelayer.rs @@ -7,7 +7,7 @@ use layershellev::*; fn main() { let ev: WindowState<()> = WindowState::new("Hello") - .with_allscreen() + .with_allscreens() .with_size((0, 400)) .with_layer(Layer::Top) .with_margin((20, 20, 100, 20)) diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index c9e746c..da07aad 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -12,7 +12,7 @@ //! //! fn main() { //! let mut ev: WindowState<()> = WindowState::new("Hello") -//! .with_allscreen() +//! .with_allscreens() //! .with_size((0, 400)) //! .with_layer(Layer::Top) //! .with_margin((20, 20, 100, 20)) @@ -665,7 +665,7 @@ impl StartMode { pub fn is_background(&self) -> bool { matches!(self, Self::Background) } - pub fn is_allscreen(&self) -> bool { + pub fn is_allscreens(&self) -> bool { matches!(self, Self::AllScreens) } pub fn is_with_target(&self) -> bool { @@ -720,8 +720,8 @@ impl WindowState { pub fn is_background(&self) -> bool { self.start_mode.is_background() } - pub fn is_allscreen(&self) -> bool { - self.start_mode.is_allscreen() + pub fn is_allscreens(&self) -> bool { + self.start_mode.is_allscreens() } pub fn is_with_target(&self) -> bool { self.start_mode.is_with_target() @@ -806,10 +806,10 @@ impl WindowState { } } - pub fn with_allscreen_or_xdg_output_name(self, binded_output_name: Option) -> Self { + pub fn with_allscreens_or_xdg_output_name(self, binded_output_name: Option) -> Self { match binded_output_name { Some(binded_output_name) => self.with_xdg_output_name(binded_output_name), - None => self.with_allscreen(), + None => self.with_allscreens(), } } pub fn with_xdg_output_name_or_not(self, binded_output_name: Option) -> Self { @@ -819,7 +819,7 @@ impl WindowState { self.with_xdg_output_name(binded_output_name) } - pub fn with_allscreen_or_active(mut self, allscreen: bool) -> Self { + pub fn with_allscreens_or_active(mut self, allscreen: bool) -> Self { if allscreen { self.start_mode = StartMode::AllScreens; } else { @@ -828,7 +828,7 @@ impl WindowState { self } - pub fn with_allscreen(mut self) -> Self { + pub fn with_allscreens(mut self) -> Self { self.start_mode = StartMode::AllScreens; self } @@ -1741,7 +1741,7 @@ impl WindowState { // this example is ok for both xdg_surface and layer_shell if self.is_background() { self.background_surface = Some(wmcompositer.create_surface(&qh, ())); - } else if !self.is_allscreen() { + } else if !self.is_allscreens() { let mut output = None; if let StartMode::TargetScreen(name) = self.start_mode.clone() { @@ -2014,7 +2014,7 @@ impl WindowState { ); } (_, DispatchMessageInner::NewDisplay(output_display)) => { - if !self.is_allscreen() { + if !self.is_allscreens() { continue; } let wl_surface = wmcompositer.create_surface(&qh, ()); // and create a surface. if two or more, diff --git a/starcolorkeyboard/src/main.rs b/starcolorkeyboard/src/main.rs index c5939ae..53afe13 100644 --- a/starcolorkeyboard/src/main.rs +++ b/starcolorkeyboard/src/main.rs @@ -82,7 +82,7 @@ pub fn get_keymap_as_file() -> (File, u32) { fn main() { let ev: WindowState = WindowState::new("precure") - .with_allscreen() + .with_allscreens() .with_size((0, 300)) .with_layer(Layer::Top) .with_anchor(Anchor::Bottom | Anchor::Left | Anchor::Right)