Skip to content

Commit 07e57c2

Browse files
committed
feat: support change region for wlr_layer
1 parent 36a3906 commit 07e57c2

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/platform/wayland.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,16 @@ impl EventLoopBuilderExtWayland for EventLoopBuilder {
7777
/// Additional methods on [`Window`] that are specific to Wayland.
7878
///
7979
/// [`Window`]: crate::window::Window
80-
pub trait WindowExtWayland {}
80+
pub trait WindowExtWayland {
81+
fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>);
82+
}
8183

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

8491
/// Additional methods on [`WindowAttributes`] that are specific to Wayland.
8592
pub trait WindowAttributesExtWayland {

src/platform_impl/linux/wayland/window/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use std::sync::atomic::{AtomicBool, Ordering};
44
use std::sync::{Arc, Mutex};
55

6+
use dpi::LogicalPosition;
67
use sctk::compositor::{CompositorState, Region, SurfaceData};
78
use sctk::reexports::client::protocol::wl_display::WlDisplay;
89
use sctk::reexports::client::protocol::wl_surface::WlSurface;
@@ -332,6 +333,22 @@ impl Window {
332333
pub fn set_layer(&self, layer: Layer) {
333334
self.window.set_layer(layer);
334335
}
336+
337+
#[inline]
338+
pub fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>) {
339+
match self.window {
340+
WindowShell::WlrLayer { surface } => {
341+
if let Some((pos, size)) = region {
342+
let region = Region::new(self.compositor.as_ref()).unwrap();
343+
region.add(pos.x, pos.y, size.width, size.height);
344+
surface.set_input_region(Some(region.wl_region()));
345+
} else {
346+
surface.set_input_region(None);
347+
}
348+
},
349+
WindowShell::Xdg { .. } => warn!("Region is ignored for XDG windows"),
350+
}
351+
}
335352
}
336353

337354
impl Drop for Window {

0 commit comments

Comments
 (0)