Skip to content

Commit

Permalink
feat: support change region for wlr_layer
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioRibera committed Feb 3, 2025
1 parent 36a3906 commit 07e57c2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/platform/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,16 @@ impl EventLoopBuilderExtWayland for EventLoopBuilder {
/// Additional methods on [`Window`] that are specific to Wayland.
///
/// [`Window`]: crate::window::Window
pub trait WindowExtWayland {}
pub trait WindowExtWayland {
fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>);
}

impl WindowExtWayland for dyn CoreWindow + '_ {}
impl WindowExtWayland for dyn CoreWindow + '_ {
fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>) {
let window = self.as_any().downcast_ref::<crate::platform_impl::wayland::Window>().unwrap();
window.set_region(region);
}
}

/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
pub trait WindowAttributesExtWayland {
Expand Down
17 changes: 17 additions & 0 deletions src/platform_impl/linux/wayland/window/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};

use dpi::LogicalPosition;
use sctk::compositor::{CompositorState, Region, SurfaceData};
use sctk::reexports::client::protocol::wl_display::WlDisplay;
use sctk::reexports::client::protocol::wl_surface::WlSurface;
Expand Down Expand Up @@ -332,6 +333,22 @@ impl Window {
pub fn set_layer(&self, layer: Layer) {
self.window.set_layer(layer);
}

#[inline]
pub fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>) {
match self.window {
WindowShell::WlrLayer { surface } => {
if let Some((pos, size)) = region {
let region = Region::new(self.compositor.as_ref()).unwrap();
region.add(pos.x, pos.y, size.width, size.height);
surface.set_input_region(Some(region.wl_region()));
} else {
surface.set_input_region(None);
}
},
WindowShell::Xdg { .. } => warn!("Region is ignored for XDG windows"),
}
}
}

impl Drop for Window {
Expand Down

0 comments on commit 07e57c2

Please sign in to comment.