diff --git a/anvil/src/focus.rs b/anvil/src/focus.rs index 21644906c616..fe71e7c939eb 100644 --- a/anvil/src/focus.rs +++ b/anvil/src/focus.rs @@ -70,6 +70,40 @@ impl From for WlSurface { } } +impl KeyboardFocusTarget { + fn inner_keyboard_target(&self) -> &dyn KeyboardTarget> { + match self { + Self::Window(w) => match w.underlying_surface() { + WindowSurface::Wayland(w) => w.wl_surface(), + #[cfg(feature = "xwayland")] + WindowSurface::X11(s) => s, + }, + Self::LayerSurface(l) => l.wl_surface(), + Self::Popup(p) => p.wl_surface(), + } + } +} + +impl PointerFocusTarget { + fn inner_pointer_target(&self) -> &dyn PointerTarget> { + match self { + Self::WlSurface(w) => w, + #[cfg(feature = "xwayland")] + Self::X11Surface(w) => w, + Self::SSD(w) => w, + } + } + + fn inner_touch_target(&self) -> &dyn TouchTarget> { + match self { + Self::WlSurface(w) => w, + #[cfg(feature = "xwayland")] + Self::X11Surface(w) => w, + Self::SSD(w) => w, + } + } +} + impl PointerTarget> for PointerFocusTarget { fn enter( &self, @@ -77,12 +111,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &MotionEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::enter(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::enter(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::enter(w, seat, data, event), - } + self.inner_pointer_target().enter(seat, data, event) } fn motion( &self, @@ -90,12 +119,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &MotionEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::motion(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::motion(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::motion(w, seat, data, event), - } + self.inner_pointer_target().motion(seat, data, event) } fn relative_motion( &self, @@ -103,12 +127,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &RelativeMotionEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::relative_motion(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::relative_motion(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::relative_motion(w, seat, data, event), - } + self.inner_pointer_target().relative_motion(seat, data, event) } fn button( &self, @@ -116,12 +135,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &ButtonEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::button(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::button(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::button(w, seat, data, event), - } + self.inner_pointer_target().button(seat, data, event) } fn axis( &self, @@ -129,20 +143,10 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, frame: AxisFrame, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::axis(w, seat, data, frame), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::axis(w, seat, data, frame), - PointerFocusTarget::SSD(w) => PointerTarget::axis(w, seat, data, frame), - } + self.inner_pointer_target().axis(seat, data, frame) } fn frame(&self, seat: &Seat>, data: &mut AnvilState) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::frame(w, seat, data), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::frame(w, seat, data), - PointerFocusTarget::SSD(w) => PointerTarget::frame(w, seat, data), - } + self.inner_pointer_target().frame(seat, data) } fn leave( &self, @@ -151,12 +155,7 @@ impl PointerTarget> for PointerFoc serial: Serial, time: u32, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::leave(w, seat, data, serial, time), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::leave(w, seat, data, serial, time), - PointerFocusTarget::SSD(w) => PointerTarget::leave(w, seat, data, serial, time), - } + self.inner_pointer_target().leave(seat, data, serial, time) } fn gesture_swipe_begin( &self, @@ -164,12 +163,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GestureSwipeBeginEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_swipe_begin(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_swipe_begin(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_swipe_begin(w, seat, data, event), - } + self.inner_pointer_target().gesture_swipe_begin(seat, data, event) } fn gesture_swipe_update( &self, @@ -177,12 +171,8 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GestureSwipeUpdateEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_swipe_update(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_swipe_update(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_swipe_update(w, seat, data, event), - } + self.inner_pointer_target() + .gesture_swipe_update(seat, data, event) } fn gesture_swipe_end( &self, @@ -190,12 +180,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GestureSwipeEndEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_swipe_end(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_swipe_end(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_swipe_end(w, seat, data, event), - } + self.inner_pointer_target().gesture_swipe_end(seat, data, event) } fn gesture_pinch_begin( &self, @@ -203,12 +188,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GesturePinchBeginEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_pinch_begin(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_pinch_begin(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_pinch_begin(w, seat, data, event), - } + self.inner_pointer_target().gesture_pinch_begin(seat, data, event) } fn gesture_pinch_update( &self, @@ -216,12 +196,8 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GesturePinchUpdateEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_pinch_update(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_pinch_update(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_pinch_update(w, seat, data, event), - } + self.inner_pointer_target() + .gesture_pinch_update(seat, data, event) } fn gesture_pinch_end( &self, @@ -229,12 +205,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GesturePinchEndEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_pinch_end(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_pinch_end(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_pinch_end(w, seat, data, event), - } + self.inner_pointer_target().gesture_pinch_end(seat, data, event) } fn gesture_hold_begin( &self, @@ -242,12 +213,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GestureHoldBeginEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_hold_begin(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_hold_begin(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_hold_begin(w, seat, data, event), - } + self.inner_pointer_target().gesture_hold_begin(seat, data, event) } fn gesture_hold_end( &self, @@ -255,12 +221,7 @@ impl PointerTarget> for PointerFoc data: &mut AnvilState, event: &GestureHoldEndEvent, ) { - match self { - PointerFocusTarget::WlSurface(w) => PointerTarget::gesture_hold_end(w, seat, data, event), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => PointerTarget::gesture_hold_end(w, seat, data, event), - PointerFocusTarget::SSD(w) => PointerTarget::gesture_hold_end(w, seat, data, event), - } + self.inner_pointer_target().gesture_hold_end(seat, data, event) } } @@ -272,17 +233,7 @@ impl KeyboardTarget> for KeyboardF keys: Vec>, serial: Serial, ) { - match self { - KeyboardFocusTarget::Window(w) => match w.underlying_surface() { - WindowSurface::Wayland(w) => KeyboardTarget::enter(w.wl_surface(), seat, data, keys, serial), - #[cfg(feature = "xwayland")] - WindowSurface::X11(s) => KeyboardTarget::enter(s, seat, data, keys, serial), - }, - KeyboardFocusTarget::LayerSurface(l) => { - KeyboardTarget::enter(l.wl_surface(), seat, data, keys, serial) - } - KeyboardFocusTarget::Popup(p) => KeyboardTarget::enter(p.wl_surface(), seat, data, keys, serial), - } + self.inner_keyboard_target().enter(seat, data, keys, serial) } fn leave( &self, @@ -290,15 +241,7 @@ impl KeyboardTarget> for KeyboardF data: &mut AnvilState, serial: Serial, ) { - match self { - KeyboardFocusTarget::Window(w) => match w.underlying_surface() { - WindowSurface::Wayland(w) => KeyboardTarget::leave(w.wl_surface(), seat, data, serial), - #[cfg(feature = "xwayland")] - WindowSurface::X11(s) => KeyboardTarget::leave(s, seat, data, serial), - }, - KeyboardFocusTarget::LayerSurface(l) => KeyboardTarget::leave(l.wl_surface(), seat, data, serial), - KeyboardFocusTarget::Popup(p) => KeyboardTarget::leave(p.wl_surface(), seat, data, serial), - } + self.inner_keyboard_target().leave(seat, data, serial) } fn key( &self, @@ -309,21 +252,8 @@ impl KeyboardTarget> for KeyboardF serial: Serial, time: u32, ) { - match self { - KeyboardFocusTarget::Window(w) => match w.underlying_surface() { - WindowSurface::Wayland(w) => { - KeyboardTarget::key(w.wl_surface(), seat, data, key, state, serial, time) - } - #[cfg(feature = "xwayland")] - WindowSurface::X11(s) => KeyboardTarget::key(s, seat, data, key, state, serial, time), - }, - KeyboardFocusTarget::LayerSurface(l) => { - KeyboardTarget::key(l.wl_surface(), seat, data, key, state, serial, time) - } - KeyboardFocusTarget::Popup(p) => { - KeyboardTarget::key(p.wl_surface(), seat, data, key, state, serial, time) - } - } + self.inner_keyboard_target() + .key(seat, data, key, state, serial, time) } fn modifiers( &self, @@ -332,21 +262,8 @@ impl KeyboardTarget> for KeyboardF modifiers: ModifiersState, serial: Serial, ) { - match self { - KeyboardFocusTarget::Window(w) => match w.underlying_surface() { - WindowSurface::Wayland(w) => { - KeyboardTarget::modifiers(w.wl_surface(), seat, data, modifiers, serial) - } - #[cfg(feature = "xwayland")] - WindowSurface::X11(s) => KeyboardTarget::modifiers(s, seat, data, modifiers, serial), - }, - KeyboardFocusTarget::LayerSurface(l) => { - KeyboardTarget::modifiers(l.wl_surface(), seat, data, modifiers, serial) - } - KeyboardFocusTarget::Popup(p) => { - KeyboardTarget::modifiers(p.wl_surface(), seat, data, modifiers, serial) - } - } + self.inner_keyboard_target() + .modifiers(seat, data, modifiers, serial) } } @@ -358,12 +275,7 @@ impl TouchTarget> for PointerFocus event: &smithay::input::touch::DownEvent, seq: Serial, ) { - match self { - PointerFocusTarget::WlSurface(w) => TouchTarget::down(w, seat, data, event, seq), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => TouchTarget::down(w, seat, data, event, seq), - PointerFocusTarget::SSD(w) => TouchTarget::down(w, seat, data, event, seq), - } + self.inner_touch_target().down(seat, data, event, seq) } fn up( @@ -373,12 +285,7 @@ impl TouchTarget> for PointerFocus event: &smithay::input::touch::UpEvent, seq: Serial, ) { - match self { - PointerFocusTarget::WlSurface(w) => TouchTarget::up(w, seat, data, event, seq), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => TouchTarget::up(w, seat, data, event, seq), - PointerFocusTarget::SSD(w) => TouchTarget::up(w, seat, data, event, seq), - } + self.inner_touch_target().up(seat, data, event, seq) } fn motion( @@ -388,30 +295,15 @@ impl TouchTarget> for PointerFocus event: &smithay::input::touch::MotionEvent, seq: Serial, ) { - match self { - PointerFocusTarget::WlSurface(w) => TouchTarget::motion(w, seat, data, event, seq), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => TouchTarget::motion(w, seat, data, event, seq), - PointerFocusTarget::SSD(w) => TouchTarget::motion(w, seat, data, event, seq), - } + self.inner_touch_target().motion(seat, data, event, seq) } fn frame(&self, seat: &Seat>, data: &mut AnvilState, seq: Serial) { - match self { - PointerFocusTarget::WlSurface(w) => TouchTarget::frame(w, seat, data, seq), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => TouchTarget::frame(w, seat, data, seq), - PointerFocusTarget::SSD(w) => TouchTarget::frame(w, seat, data, seq), - } + self.inner_touch_target().frame(seat, data, seq) } fn cancel(&self, seat: &Seat>, data: &mut AnvilState, seq: Serial) { - match self { - PointerFocusTarget::WlSurface(w) => TouchTarget::cancel(w, seat, data, seq), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => TouchTarget::cancel(w, seat, data, seq), - PointerFocusTarget::SSD(w) => TouchTarget::cancel(w, seat, data, seq), - } + self.inner_touch_target().cancel(seat, data, seq) } fn shape( @@ -421,12 +313,7 @@ impl TouchTarget> for PointerFocus event: &smithay::input::touch::ShapeEvent, seq: Serial, ) { - match self { - PointerFocusTarget::WlSurface(w) => TouchTarget::shape(w, seat, data, event, seq), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => TouchTarget::shape(w, seat, data, event, seq), - PointerFocusTarget::SSD(w) => TouchTarget::shape(w, seat, data, event, seq), - } + self.inner_touch_target().shape(seat, data, event, seq) } fn orientation( @@ -436,12 +323,7 @@ impl TouchTarget> for PointerFocus event: &smithay::input::touch::OrientationEvent, seq: Serial, ) { - match self { - PointerFocusTarget::WlSurface(w) => TouchTarget::orientation(w, seat, data, event, seq), - #[cfg(feature = "xwayland")] - PointerFocusTarget::X11Surface(w) => TouchTarget::orientation(w, seat, data, event, seq), - PointerFocusTarget::SSD(w) => TouchTarget::orientation(w, seat, data, event, seq), - } + self.inner_touch_target().orientation(seat, data, event, seq) } } diff --git a/src/input/keyboard/mod.rs b/src/input/keyboard/mod.rs index 59b78457a462..95337106ebd5 100644 --- a/src/input/keyboard/mod.rs +++ b/src/input/keyboard/mod.rs @@ -30,7 +30,7 @@ mod xkb_config; pub use xkb_config::XkbConfig; /// Trait representing object that can receive keyboard interactions -pub trait KeyboardTarget: IsAlive + PartialEq + Clone + fmt::Debug + Send +pub trait KeyboardTarget: IsAlive + fmt::Debug + Send where D: SeatHandler, { diff --git a/src/input/mod.rs b/src/input/mod.rs index 3eb66da73716..19617938fdaf 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -144,11 +144,11 @@ pub mod touch; /// Handler trait for Seats pub trait SeatHandler: Sized { /// Type used to represent the target currently holding the keyboard focus - type KeyboardFocus: KeyboardTarget + 'static; + type KeyboardFocus: KeyboardTarget + PartialEq + Clone + 'static; /// Type used to represent the target currently holding the pointer focus - type PointerFocus: PointerTarget + 'static; + type PointerFocus: PointerTarget + PartialEq + Clone + 'static; /// Type used to represent the target currently holding the touch focus - type TouchFocus: TouchTarget + 'static; + type TouchFocus: TouchTarget + PartialEq + Clone + 'static; /// [SeatState] getter fn seat_state(&mut self) -> &mut SeatState; diff --git a/src/input/pointer/mod.rs b/src/input/pointer/mod.rs index e12476bfdfc7..154d34b00601 100644 --- a/src/input/pointer/mod.rs +++ b/src/input/pointer/mod.rs @@ -107,7 +107,7 @@ impl std::cmp::PartialEq for PointerHandle { impl std::cmp::Eq for PointerHandle {} /// Trait representing object that can receive pointer interactions -pub trait PointerTarget: IsAlive + PartialEq + Clone + fmt::Debug + Send +pub trait PointerTarget: IsAlive + fmt::Debug + Send where D: SeatHandler, { diff --git a/src/input/touch/mod.rs b/src/input/touch/mod.rs index 21b4e92c19a2..635c6269adcb 100644 --- a/src/input/touch/mod.rs +++ b/src/input/touch/mod.rs @@ -164,7 +164,7 @@ pub struct OrientationEvent { } /// Trait representing object that can receive touch interactions -pub trait TouchTarget: IsAlive + PartialEq + Clone + fmt::Debug + Send +pub trait TouchTarget: IsAlive + fmt::Debug + Send where D: SeatHandler, {