Skip to content

Commit

Permalink
feat: support events transparent
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Nov 17, 2024
1 parent 0cb7a19 commit 4c56fbd
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions iced_examples/zbus_invoked_widget/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl TryInto<LaLaShellIdAction> for Message {
margin: Some((100, 100, 100, 100)),
keyboard_interactivity: KeyboardInteractivity::OnDemand,
use_last_output: false,
..Default::default()
},
(),
)),
Expand Down
1 change: 1 addition & 0 deletions iced_layershell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ where
let ev: WindowState<A::WindowInfo> = 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)
Expand Down
3 changes: 3 additions & 0 deletions iced_layershell/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions layershellev/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}
}
Expand Down
28 changes: 27 additions & 1 deletion layershellev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ pub struct WindowState<T> {

start_mode: StartMode,
init_finished: bool,
events_transparent: bool,
}

impl<T> WindowState<T> {
Expand Down Expand Up @@ -831,6 +832,11 @@ impl<T> WindowState<T> {
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 {
Expand Down Expand Up @@ -990,6 +996,7 @@ impl<T> Default for WindowState<T> {

start_mode: StartMode::Active,
init_finished: false,
events_transparent: false,
}
}
}
Expand Down Expand Up @@ -1826,7 +1833,11 @@ impl<T: 'static> WindowState<T> {
//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;

Expand Down Expand Up @@ -1878,6 +1889,10 @@ impl<T: 'static> WindowState<T> {
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;
Expand Down Expand Up @@ -1936,6 +1951,9 @@ impl<T: 'static> WindowState<T> {
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, ());
Expand Down Expand Up @@ -2164,6 +2182,9 @@ impl<T: 'static> WindowState<T> {
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, ());
Expand Down Expand Up @@ -2409,6 +2430,7 @@ impl<T: 'static> WindowState<T> {
margin,
keyboard_interactivity,
use_last_output,
events_transparent,
},
info,
)) => {
Expand Down Expand Up @@ -2453,6 +2475,10 @@ impl<T: 'static> WindowState<T> {
layer.set_margin(top, right, bottom, left);
}

if events_transparent {
wl_surface.set_opaque_region(None);
}

wl_surface.commit();

let mut fractional_scale = None;
Expand Down

0 comments on commit 4c56fbd

Please sign in to comment.