From 63a366f85fbc3959dd985601953671b0e8a0409f Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 17 Nov 2024 10:24:08 +0900 Subject: [PATCH] feat: support events transparent --- iced_layershell/src/application.rs | 1 + iced_layershell/src/multi_window.rs | 1 + iced_layershell/src/settings.rs | 3 +++ layershellev/src/events.rs | 2 ++ layershellev/src/lib.rs | 28 +++++++++++++++++++++++++++- 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index a6894c2..25ba749 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -161,6 +161,7 @@ where .with_use_display_handle(true) .with_option_size(settings.layer_settings.size) .with_layer(settings.layer_settings.layer) + .with_events_transparent(settings.layer_settings.events_transparent) .with_anchor(settings.layer_settings.anchor) .with_exclusize_zone(settings.layer_settings.exclusive_zone) .with_margin(settings.layer_settings.margin) diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index 6cc6517..45fe5c0 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -189,6 +189,7 @@ where let ev: WindowState = layershellev::WindowState::new(&application.namespace()) .with_start_mode(settings.layer_settings.start_mode) .with_use_display_handle(true) + .with_events_transparent(settings.layer_settings.events_transparent) .with_option_size(settings.layer_settings.size) .with_layer(settings.layer_settings.layer) .with_anchor(settings.layer_settings.anchor) diff --git a/iced_layershell/src/settings.rs b/iced_layershell/src/settings.rs index 5047bac..e438f1b 100644 --- a/iced_layershell/src/settings.rs +++ b/iced_layershell/src/settings.rs @@ -83,6 +83,7 @@ pub struct LayerShellSettings { pub margin: (i32, i32, i32, i32), pub keyboard_interactivity: KeyboardInteractivity, pub start_mode: StartMode, + pub events_transparent: bool } impl Default for LayerShellSettings { @@ -94,6 +95,7 @@ impl Default for LayerShellSettings { size: None, margin: (0, 0, 0, 0), keyboard_interactivity: KeyboardInteractivity::OnDemand, + events_transparent: false, start_mode: StartMode::default(), } } @@ -159,6 +161,7 @@ mod tests { margin: (10, 10, 10, 10), keyboard_interactivity: KeyboardInteractivity::None, start_mode: StartMode::TargetScreen("HDMI-1".to_string()), + events_transparent: false, }; assert_eq!(layer_settings.anchor, Anchor::Top | Anchor::Left); diff --git a/layershellev/src/events.rs b/layershellev/src/events.rs index 757af85..8bde73c 100644 --- a/layershellev/src/events.rs +++ b/layershellev/src/events.rs @@ -82,6 +82,7 @@ pub struct NewLayerShellSettings { /// 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, } /// be used to create a new popup @@ -105,6 +106,7 @@ impl Default for NewLayerShellSettings { margin: Some((0, 0, 0, 0)), keyboard_interactivity: KeyboardInteractivity::OnDemand, use_last_output: false, + events_transparent: false } } } diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index 218ef54..4e33184 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -624,6 +624,7 @@ pub struct WindowState { start_mode: StartMode, init_finished: bool, + events_transparent: bool, } impl WindowState { @@ -831,6 +832,11 @@ impl WindowState { self } + pub fn with_events_transparent(mut self, transparent: bool) -> Self { + self.events_transparent = transparent; + 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_active(mut self) -> Self { @@ -990,6 +996,7 @@ impl Default for WindowState { start_mode: StartMode::Active, init_finished: false, + events_transparent: false, } } } @@ -1826,7 +1833,11 @@ impl WindowState { //let (init_w, init_h) = self.size; // this example is ok for both xdg_surface and layer_shell if self.is_background() { - self.background_surface = Some(wmcompositer.create_surface(&qh, ())); + let background_surface = wmcompositer.create_surface(&qh, ()); + if self.events_transparent { + background_surface.set_opaque_region(None); + } + self.background_surface = Some(background_surface); } else if !self.is_allscreens() { let mut output = None; @@ -1878,6 +1889,10 @@ impl WindowState { layer.set_margin(top, right, bottom, left); } + if self.events_transparent { + wl_surface.set_opaque_region(None); + } + wl_surface.commit(); let mut fractional_scale = None; @@ -1936,6 +1951,9 @@ impl WindowState { layer.set_margin(top, right, bottom, left); } + if self.events_transparent { + wl_surface.set_opaque_region(None); + } wl_surface.commit(); let zxdgoutput = xdg_output_manager.get_xdg_output(output_display, &qh, ()); @@ -2164,6 +2182,9 @@ impl WindowState { layer.set_margin(top, right, bottom, left); } + if self.events_transparent { + wl_surface.set_opaque_region(None); + } wl_surface.commit(); let zxdgoutput = xdg_output_manager.get_xdg_output(output_display, &qh, ()); @@ -2409,6 +2430,7 @@ impl WindowState { margin, keyboard_interactivity, use_last_output, + events_transparent }, info, )) => { @@ -2453,6 +2475,10 @@ impl WindowState { layer.set_margin(top, right, bottom, left); } + if events_transparent { + wl_surface.set_opaque_region(None); + } + wl_surface.commit(); let mut fractional_scale = None;