From 3af91079e9eb40ca8698eed0d944d9ebffd90d0f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2026 14:54:36 +0000 Subject: [PATCH 1/2] Fix crash when opening rofi in wayland backend When `KeyboardFocusTarget` is converted to `PointerFocusTarget` for layer shells or XWayland unmanaged windows like rofi, `w.wl_surface()` can return `None`. Calling `.unwrap()` caused a panic that crashed the compositor. This commit safely handles `Window(w)` by adding it as a variant to `PointerFocusTarget`. This defers the retrieval of the surface until the pointer or touch events are actually dispatched, where it can safely check `if let Some(surface) = w.wl_surface()`. Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com> --- src/backend/wayland/compositor/focus.rs | 218 +++++++++++++++++++++++- 1 file changed, 215 insertions(+), 3 deletions(-) diff --git a/src/backend/wayland/compositor/focus.rs b/src/backend/wayland/compositor/focus.rs index 9d59422c..fec84b97 100644 --- a/src/backend/wayland/compositor/focus.rs +++ b/src/backend/wayland/compositor/focus.rs @@ -42,6 +42,7 @@ impl From for KeyboardFocusTarget { /// target individual surfaces (e.g. subsurfaces within a window). #[derive(Debug, Clone, PartialEq)] pub enum PointerFocusTarget { + Window(Window), WlSurface(WlSurface), Popup(PopupKind), } @@ -55,9 +56,7 @@ impl From for PointerFocusTarget { impl From for PointerFocusTarget { fn from(target: KeyboardFocusTarget) -> Self { match target { - KeyboardFocusTarget::Window(w) => { - PointerFocusTarget::WlSurface(w.wl_surface().unwrap().into_owned()) - } + KeyboardFocusTarget::Window(w) => PointerFocusTarget::Window(w), KeyboardFocusTarget::WlSurface(s) => PointerFocusTarget::WlSurface(s), KeyboardFocusTarget::Popup(p) => PointerFocusTarget::Popup(p), } @@ -79,6 +78,7 @@ impl IsAlive for KeyboardFocusTarget { impl IsAlive for PointerFocusTarget { fn alive(&self) -> bool { match self { + PointerFocusTarget::Window(w) => w.alive(), PointerFocusTarget::WlSurface(s) => s.alive(), PointerFocusTarget::Popup(p) => p.alive(), } @@ -100,6 +100,7 @@ impl WaylandFocus for KeyboardFocusTarget { impl WaylandFocus for PointerFocusTarget { fn wl_surface(&self) -> Option> { match self { + PointerFocusTarget::Window(w) => w.wl_surface(), PointerFocusTarget::WlSurface(s) => Some(Cow::Borrowed(s)), PointerFocusTarget::Popup(p) => Some(Cow::Borrowed(p.wl_surface())), } @@ -253,6 +254,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::MotionEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::enter( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::enter(s, seat, data, event); } @@ -269,6 +280,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::MotionEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::motion( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::motion(s, seat, data, event); } @@ -285,6 +306,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::RelativeMotionEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::relative_motion( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::relative_motion(s, seat, data, event); } @@ -306,6 +337,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::ButtonEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::button( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::button(s, seat, data, event); } @@ -322,6 +363,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget frame: smithay::input::pointer::AxisFrame, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::axis( + surface.as_ref(), + seat, + data, + frame, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::axis(s, seat, data, frame); } @@ -333,6 +384,11 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget fn frame(&self, seat: &Seat, data: &mut WaylandState) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::frame(surface.as_ref(), seat, data); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::frame(s, seat, data); } @@ -349,6 +405,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GestureSwipeBeginEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_swipe_begin( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_swipe_begin(s, seat, data, event); } @@ -370,6 +436,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GestureSwipeUpdateEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_swipe_update( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_swipe_update(s, seat, data, event); } @@ -391,6 +467,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GestureSwipeEndEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_swipe_end( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_swipe_end(s, seat, data, event); } @@ -412,6 +498,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GesturePinchBeginEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_pinch_begin( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_pinch_begin(s, seat, data, event); } @@ -433,6 +529,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GesturePinchUpdateEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_pinch_update( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_pinch_update(s, seat, data, event); } @@ -454,6 +560,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GesturePinchEndEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_pinch_end( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_pinch_end(s, seat, data, event); } @@ -475,6 +591,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GestureHoldBeginEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_hold_begin( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_hold_begin(s, seat, data, event); } @@ -496,6 +622,16 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget event: &smithay::input::pointer::GestureHoldEndEvent, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::gesture_hold_end( + surface.as_ref(), + seat, + data, + event, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::gesture_hold_end(s, seat, data, event); } @@ -512,6 +648,17 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget fn leave(&self, seat: &Seat, data: &mut WaylandState, serial: Serial, time: u32) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::pointer::PointerTarget::leave( + surface.as_ref(), + seat, + data, + serial, + time, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::pointer::PointerTarget::leave(s, seat, data, serial, time); } @@ -539,6 +686,17 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { seq: Serial, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::touch::TouchTarget::down( + surface.as_ref(), + seat, + data, + event, + seq, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::touch::TouchTarget::down(s, seat, data, event, seq); } @@ -556,6 +714,17 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { seq: Serial, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::touch::TouchTarget::up( + surface.as_ref(), + seat, + data, + event, + seq, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::touch::TouchTarget::up(s, seat, data, event, seq); } @@ -573,6 +742,17 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { seq: Serial, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::touch::TouchTarget::motion( + surface.as_ref(), + seat, + data, + event, + seq, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::touch::TouchTarget::motion(s, seat, data, event, seq); } @@ -584,6 +764,11 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { fn frame(&self, seat: &Seat, data: &mut WaylandState, seq: Serial) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::touch::TouchTarget::frame(surface.as_ref(), seat, data, seq); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::touch::TouchTarget::frame(s, seat, data, seq); } @@ -595,6 +780,11 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { fn cancel(&self, seat: &Seat, data: &mut WaylandState, seq: Serial) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::touch::TouchTarget::cancel(surface.as_ref(), seat, data, seq); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::touch::TouchTarget::cancel(s, seat, data, seq); } @@ -612,6 +802,17 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { seq: Serial, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::touch::TouchTarget::shape( + surface.as_ref(), + seat, + data, + event, + seq, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::touch::TouchTarget::shape(s, seat, data, event, seq); } @@ -629,6 +830,17 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { seq: Serial, ) { match self { + PointerFocusTarget::Window(w) => { + if let Some(surface) = w.wl_surface() { + smithay::input::touch::TouchTarget::orientation( + surface.as_ref(), + seat, + data, + event, + seq, + ); + } + } PointerFocusTarget::WlSurface(s) => { smithay::input::touch::TouchTarget::orientation(s, seat, data, event, seq); } From 4bbdfa0e32b6aa1123bc4b5c66846378d5d7a753 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 20 Mar 2026 15:02:40 +0000 Subject: [PATCH 2/2] Refactor PointerFocusTarget to use with_surface helper Following code review feedback, a `with_surface` helper function was added to `PointerFocusTarget`. This centralizes the lookup for `wl_surface()` and reduces the boilerplate previously repeated across all pointer and touch event handlers. It additionally logs a trace message when a surface is missing instead of silently dropping the event, making future diagnostics easier. Co-authored-by: paperbenni <15818888+paperbenni@users.noreply.github.com> --- src/backend/wayland/compositor/focus.rs | 482 ++---------------------- 1 file changed, 38 insertions(+), 444 deletions(-) diff --git a/src/backend/wayland/compositor/focus.rs b/src/backend/wayland/compositor/focus.rs index fec84b97..1f8237e0 100644 --- a/src/backend/wayland/compositor/focus.rs +++ b/src/backend/wayland/compositor/focus.rs @@ -107,6 +107,20 @@ impl WaylandFocus for PointerFocusTarget { } } + +impl PointerFocusTarget { + fn with_surface(&self, f: F) + where + F: FnOnce(&WlSurface), + { + if let Some(surface) = self.wl_surface() { + f(surface.as_ref()); + } else { + log::trace!("PointerFocusTarget has no wl_surface, dropping event"); + } + } +} + // -- KeyboardTarget implementation -- impl smithay::input::keyboard::KeyboardTarget for KeyboardFocusTarget { @@ -253,24 +267,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::MotionEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::enter( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::enter(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::enter(p.wl_surface(), seat, data, event); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::enter(surface, seat, data, event)); } fn motion( @@ -279,24 +276,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::MotionEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::motion( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::motion(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::motion(p.wl_surface(), seat, data, event); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::motion(surface, seat, data, event)); } fn relative_motion( @@ -305,29 +285,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::RelativeMotionEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::relative_motion( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::relative_motion(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::relative_motion( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::relative_motion(surface, seat, data, event)); } fn button( @@ -336,24 +294,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::ButtonEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::button( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::button(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::button(p.wl_surface(), seat, data, event); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::button(surface, seat, data, event)); } fn axis( @@ -362,40 +303,11 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, frame: smithay::input::pointer::AxisFrame, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::axis( - surface.as_ref(), - seat, - data, - frame, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::axis(s, seat, data, frame); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::axis(p.wl_surface(), seat, data, frame); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::axis(surface, seat, data, frame)); } fn frame(&self, seat: &Seat, data: &mut WaylandState) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::frame(surface.as_ref(), seat, data); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::frame(s, seat, data); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::frame(p.wl_surface(), seat, data); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::frame(surface, seat, data)); } fn gesture_swipe_begin( @@ -404,29 +316,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GestureSwipeBeginEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_swipe_begin( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_swipe_begin(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_swipe_begin( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_swipe_begin(surface, seat, data, event)); } fn gesture_swipe_update( @@ -435,29 +325,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GestureSwipeUpdateEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_swipe_update( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_swipe_update(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_swipe_update( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_swipe_update(surface, seat, data, event)); } fn gesture_swipe_end( @@ -466,29 +334,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GestureSwipeEndEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_swipe_end( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_swipe_end(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_swipe_end( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_swipe_end(surface, seat, data, event)); } fn gesture_pinch_begin( @@ -497,29 +343,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GesturePinchBeginEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_pinch_begin( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_pinch_begin(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_pinch_begin( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_pinch_begin(surface, seat, data, event)); } fn gesture_pinch_update( @@ -528,29 +352,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GesturePinchUpdateEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_pinch_update( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_pinch_update(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_pinch_update( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_pinch_update(surface, seat, data, event)); } fn gesture_pinch_end( @@ -559,29 +361,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GesturePinchEndEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_pinch_end( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_pinch_end(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_pinch_end( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_pinch_end(surface, seat, data, event)); } fn gesture_hold_begin( @@ -590,29 +370,7 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GestureHoldBeginEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_hold_begin( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_hold_begin(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_hold_begin( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_hold_begin(surface, seat, data, event)); } fn gesture_hold_end( @@ -621,58 +379,13 @@ impl smithay::input::pointer::PointerTarget for PointerFocusTarget data: &mut WaylandState, event: &smithay::input::pointer::GestureHoldEndEvent, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::gesture_hold_end( - surface.as_ref(), - seat, - data, - event, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::gesture_hold_end(s, seat, data, event); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::gesture_hold_end( - p.wl_surface(), - seat, - data, - event, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::gesture_hold_end(surface, seat, data, event)); } fn leave(&self, seat: &Seat, data: &mut WaylandState, serial: Serial, time: u32) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::pointer::PointerTarget::leave( - surface.as_ref(), - seat, - data, - serial, - time, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::pointer::PointerTarget::leave(s, seat, data, serial, time); - } - PointerFocusTarget::Popup(p) => { - smithay::input::pointer::PointerTarget::leave( - p.wl_surface(), - seat, - data, - serial, - time, - ); - } - } + self.with_surface(|surface| smithay::input::pointer::PointerTarget::leave(surface, seat, data, serial, time)); } + } // -- TouchTarget implementation -- @@ -685,25 +398,7 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { event: &smithay::input::touch::DownEvent, seq: Serial, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::touch::TouchTarget::down( - surface.as_ref(), - seat, - data, - event, - seq, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::touch::TouchTarget::down(s, seat, data, event, seq); - } - PointerFocusTarget::Popup(p) => { - smithay::input::touch::TouchTarget::down(p.wl_surface(), seat, data, event, seq); - } - } + self.with_surface(|surface| smithay::input::touch::TouchTarget::down(surface, seat, data, event, seq)); } fn up( @@ -713,25 +408,7 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { event: &smithay::input::touch::UpEvent, seq: Serial, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::touch::TouchTarget::up( - surface.as_ref(), - seat, - data, - event, - seq, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::touch::TouchTarget::up(s, seat, data, event, seq); - } - PointerFocusTarget::Popup(p) => { - smithay::input::touch::TouchTarget::up(p.wl_surface(), seat, data, event, seq); - } - } + self.with_surface(|surface| smithay::input::touch::TouchTarget::up(surface, seat, data, event, seq)); } fn motion( @@ -741,57 +418,15 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { event: &smithay::input::touch::MotionEvent, seq: Serial, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::touch::TouchTarget::motion( - surface.as_ref(), - seat, - data, - event, - seq, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::touch::TouchTarget::motion(s, seat, data, event, seq); - } - PointerFocusTarget::Popup(p) => { - smithay::input::touch::TouchTarget::motion(p.wl_surface(), seat, data, event, seq); - } - } + self.with_surface(|surface| smithay::input::touch::TouchTarget::motion(surface, seat, data, event, seq)); } fn frame(&self, seat: &Seat, data: &mut WaylandState, seq: Serial) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::touch::TouchTarget::frame(surface.as_ref(), seat, data, seq); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::touch::TouchTarget::frame(s, seat, data, seq); - } - PointerFocusTarget::Popup(p) => { - smithay::input::touch::TouchTarget::frame(p.wl_surface(), seat, data, seq); - } - } + self.with_surface(|surface| smithay::input::touch::TouchTarget::frame(surface, seat, data, seq)); } fn cancel(&self, seat: &Seat, data: &mut WaylandState, seq: Serial) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::touch::TouchTarget::cancel(surface.as_ref(), seat, data, seq); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::touch::TouchTarget::cancel(s, seat, data, seq); - } - PointerFocusTarget::Popup(p) => { - smithay::input::touch::TouchTarget::cancel(p.wl_surface(), seat, data, seq); - } - } + self.with_surface(|surface| smithay::input::touch::TouchTarget::cancel(surface, seat, data, seq)); } fn shape( @@ -801,25 +436,7 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { event: &smithay::input::touch::ShapeEvent, seq: Serial, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::touch::TouchTarget::shape( - surface.as_ref(), - seat, - data, - event, - seq, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::touch::TouchTarget::shape(s, seat, data, event, seq); - } - PointerFocusTarget::Popup(p) => { - smithay::input::touch::TouchTarget::shape(p.wl_surface(), seat, data, event, seq); - } - } + self.with_surface(|surface| smithay::input::touch::TouchTarget::shape(surface, seat, data, event, seq)); } fn orientation( @@ -829,30 +446,7 @@ impl smithay::input::touch::TouchTarget for PointerFocusTarget { event: &smithay::input::touch::OrientationEvent, seq: Serial, ) { - match self { - PointerFocusTarget::Window(w) => { - if let Some(surface) = w.wl_surface() { - smithay::input::touch::TouchTarget::orientation( - surface.as_ref(), - seat, - data, - event, - seq, - ); - } - } - PointerFocusTarget::WlSurface(s) => { - smithay::input::touch::TouchTarget::orientation(s, seat, data, event, seq); - } - PointerFocusTarget::Popup(p) => { - smithay::input::touch::TouchTarget::orientation( - p.wl_surface(), - seat, - data, - event, - seq, - ); - } - } + self.with_surface(|surface| smithay::input::touch::TouchTarget::orientation(surface, seat, data, event, seq)); } + }