Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fcc5c0a

Browse files
committedMar 19, 2025
feat: support create region from winit
1 parent 08d03de commit fcc5c0a

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed
 

‎src/platform/wayland.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
//! * `wayland-csd-adwaita-crossfont`.
1515
//! * `wayland-csd-adwaita-notitle`.
1616
#[cfg(wayland_platform)]
17-
use sctk::shell::wlr_layer::{Anchor, KeyboardInteractivity, Layer};
17+
pub use sctk::{
18+
compositor::Region,
19+
shell::wlr_layer::{Anchor, KeyboardInteractivity, Layer},
20+
};
1821

1922
use crate::dpi::{LogicalPosition, LogicalSize};
23+
use crate::error::RequestError;
2024
use crate::event_loop::{ActiveEventLoop, EventLoop, EventLoopBuilder};
2125
use crate::monitor::MonitorHandle;
2226
pub use crate::window::Theme;
@@ -78,11 +82,27 @@ impl EventLoopBuilderExtWayland for EventLoopBuilder {
7882
///
7983
/// [`Window`]: crate::window::Window
8084
pub trait WindowExtWayland {
81-
fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>);
85+
fn create_region(
86+
&self,
87+
position: LogicalPosition<i32>,
88+
size: LogicalSize<i32>,
89+
) -> Result<Region, RequestError>;
90+
fn set_region(&self, region: Option<&Region>);
8291
}
8392

8493
impl WindowExtWayland for dyn CoreWindow + '_ {
85-
fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>) {
94+
fn create_region(
95+
&self,
96+
pos: LogicalPosition<i32>,
97+
size: LogicalSize<i32>,
98+
) -> Result<Region, RequestError> {
99+
let window = self.as_any().downcast_ref::<crate::platform_impl::wayland::Window>().unwrap();
100+
let region = window.create_region()?;
101+
region.add(pos.x, pos.y, size.width, size.height);
102+
Ok(region)
103+
}
104+
105+
fn set_region(&self, region: Option<&Region>) {
86106
let window = self.as_any().downcast_ref::<crate::platform_impl::wayland::Window>().unwrap();
87107
window.set_region(region);
88108
}

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -335,16 +335,15 @@ impl Window {
335335
}
336336

337337
#[inline]
338-
pub fn set_region(&self, region: Option<(LogicalPosition<i32>, LogicalSize<i32>)>) {
338+
pub fn create_region(&self) -> Result<Region, RequestError> {
339+
Ok(Region::new(&*self.compositor).map_err(|err| os_error!(err))?)
340+
}
341+
342+
#[inline]
343+
pub fn set_region(&self, region: Option<&Region>) {
339344
match &self.window {
340345
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-
}
346+
surface.set_input_region(region.map(|r| r.wl_region()));
348347
},
349348
WindowShell::Xdg { .. } => warn!("Region is ignored for XDG windows"),
350349
}

0 commit comments

Comments
 (0)
Please sign in to comment.