1
0
Fork 0
forked from wry/wry

Merge pull request #121 from mahkoh/jorth/input-region

tree: implement surface input regions
This commit is contained in:
mahkoh 2024-03-04 20:11:34 +01:00 committed by GitHub
commit 1540b4e90f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 58 additions and 33 deletions

View file

@ -134,7 +134,7 @@ pub struct WlSurface {
visible: Cell<bool>,
role: Cell<SurfaceRole>,
pending: PendingState,
input_region: Cell<Option<Rc<Region>>>,
input_region: CloneCell<Option<Rc<Region>>>,
opaque_region: Cell<Option<Rc<Region>>>,
buffer_points: RefCell<BufferPoints>,
pub buffer_points_norm: RefCell<SampleRect>,
@ -894,13 +894,25 @@ impl WlSurface {
Ok(())
}
fn find_surface_at(self: &Rc<Self>, x: i32, y: i32) -> Option<(Rc<Self>, i32, i32)> {
fn accepts_input_at(&self, x: i32, y: i32) -> bool {
let rect = self.buffer_abs_pos.get().at_point(0, 0);
if !rect.contains(x, y) {
return false;
}
if let Some(ir) = self.input_region.get() {
if !ir.contains(x, y) {
return false;
}
}
true
}
fn find_surface_at(self: &Rc<Self>, x: i32, y: i32) -> Option<(Rc<Self>, i32, i32)> {
let children = self.children.borrow();
let children = match children.deref() {
Some(c) => c,
_ => {
return if rect.contains(x, y) {
return if self.accepts_input_at(x, y) {
Some((self.clone(), x, y))
} else {
None
@ -925,7 +937,7 @@ impl WlSurface {
if let Some(res) = ss(&children.above) {
return Some(res);
}
if rect.contains(x, y) {
if self.accepts_input_at(x, y) {
return Some((self.clone(), x, y));
}
if let Some(res) = ss(&children.below) {

View file

@ -322,6 +322,10 @@ impl Node for Xwindow {
seat.focus_toplevel(self.clone());
}
fn node_active_changed(&self, active: bool) {
self.toplevel_data.update_self_active(self, active);
}
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
let rect = self.x.surface.buffer_abs_pos.get();
if x < rect.width() && y < rect.height() {

View file

@ -511,6 +511,10 @@ impl Node for XdgToplevel {
seat.focus_toplevel(self.clone());
}
fn node_active_changed(&self, active: bool) {
self.toplevel_data.update_self_active(self, active);
}
fn node_find_tree_at(&self, x: i32, y: i32, tree: &mut Vec<FoundNode>) -> FindTreeResult {
self.xdg.find_tree_at(x, y, tree)
}