From fac4ca260e007f3d5ea08af896ef6817b6d11b48 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 2 Feb 2020 12:41:35 +0300 Subject: [PATCH 1/2] anvil.shell: store input_region in SurfaceData This is the most up-to-date committed input region. --- anvil/src/shell.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index ba63613..2baf3cf 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -13,7 +13,7 @@ use smithay::{ }, utils::Rectangle, wayland::{ - compositor::{compositor_init, CompositorToken, SurfaceAttributes, SurfaceEvent}, + compositor::{compositor_init, CompositorToken, RegionAttributes, SurfaceAttributes, SurfaceEvent}, data_device::DnDIconRole, seat::CursorImageRole, shell::{ @@ -138,17 +138,21 @@ pub fn init_shell( pub struct SurfaceData { pub buffer: Option, pub texture: Option, + pub input_region: Option, } fn surface_commit(surface: &wl_surface::WlSurface, token: CompositorToken) { - // we retrieve the contents of the associated buffer and copy it token.with_surface_data(surface, |attributes| { attributes.user_data.insert_if_missing(SurfaceData::default); + let data = attributes.user_data.get_mut::().unwrap(); + + data.input_region = attributes.input_region.clone(); + + // we retrieve the contents of the associated buffer and copy it match attributes.buffer.take() { Some(Some((buffer, (_x, _y)))) => { // new contents // TODO: handle hotspot coordinates - let data = attributes.user_data.get_mut::().unwrap(); if let Some(old_buffer) = data.buffer.replace(buffer) { old_buffer.release(); } @@ -156,7 +160,6 @@ fn surface_commit(surface: &wl_surface::WlSurface, token: CompositorToken } Some(None) => { // erase the contents - let data = attributes.user_data.get_mut::().unwrap(); if let Some(old_buffer) = data.buffer.take() { old_buffer.release(); } From 13cac4f693edf45a423f75a18a026baf674b81ff Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 2 Feb 2020 12:42:23 +0300 Subject: [PATCH 2/2] anvil.shell: use correct region in contains_point The one in SurfaceAttributes has potentially not been committed yet, and the one in SurfaceData is the most up-to-date committed one. --- anvil/src/shell.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index 2baf3cf..21ddb8e 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -200,10 +200,12 @@ fn contains_point(attrs: &SurfaceAttributes, point: (f64, f64)) -> bool { return false; } + let input_region = &attrs.user_data.get::().unwrap().input_region; + // If there's no input region, we're done. - if attrs.input_region.is_none() { + if input_region.is_none() { return true; } - attrs.input_region.as_ref().unwrap().contains(point) + input_region.as_ref().unwrap().contains(point) }