From 2d5acdb278269d4897a0156c8fd66dd6e0e77769 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 6 Oct 2024 22:13:25 +0900 Subject: [PATCH] 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, } }