Skip to content

Commit

Permalink
chore: adjust the settings of iced_layershell
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Oct 6, 2024
1 parent c9d7791 commit 2d5acdb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 29 deletions.
9 changes: 7 additions & 2 deletions iced_examples/counter/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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()
Expand Down
9 changes: 7 additions & 2 deletions iced_layershell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
Expand All @@ -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");

Expand Down
3 changes: 1 addition & 2 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ where
));

let ev: WindowState<A::WindowInfo> = 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)
Expand Down
20 changes: 11 additions & 9 deletions iced_layershell/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<String>,
pub monitor_all_screen: bool,
pub start_mode: StartMode,
}

impl Default for LayerShellSettings {
Expand All @@ -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(),
}
}
}
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);
Expand All @@ -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())
);
}
}
36 changes: 22 additions & 14 deletions layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,19 @@ 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),
}

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)
Expand Down Expand Up @@ -715,8 +716,8 @@ impl<T> WindowState<T> {
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()
Expand Down Expand Up @@ -788,17 +789,22 @@ impl<T> WindowState<T> {
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<String>) -> Self {
pub fn with_active_or_xdg_output_name(self, binded_output_name: Option<String>) -> 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(),
}
}

Expand All @@ -814,19 +820,21 @@ impl<T> WindowState<T> {
};
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;
Expand Down Expand Up @@ -942,7 +950,7 @@ impl<T> Default for WindowState<T> {
// is not binded
xdg_info_cache: Vec::new(),

start_mode: StartMode::Single,
start_mode: StartMode::CurrentActive,
init_finished: false,
}
}
Expand Down

0 comments on commit 2d5acdb

Please sign in to comment.