Skip to content

Commit

Permalink
Make frame a seperate method of PointerTarget/PointerGrab
Browse files Browse the repository at this point in the history
Input handling in compositors will have to emit this appropriatly. But
then other methods don't have to map perfectly to frames.

Meant to address Smithay#1126.
  • Loading branch information
ids1024 committed Sep 21, 2023
1 parent 58d5bdc commit 4c37923
Show file tree
Hide file tree
Showing 20 changed files with 146 additions and 22 deletions.
7 changes: 7 additions & 0 deletions anvil/src/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ impl<BackendData: Backend> PointerTarget<AnvilState<BackendData>> for FocusTarge
FocusTarget::Popup(p) => PointerTarget::axis(p.wl_surface(), seat, data, frame),
}
}
fn frame(&self, seat: &Seat<AnvilState<BackendData>>, data: &mut AnvilState<BackendData>) {
match self {
FocusTarget::Window(w) => PointerTarget::frame(w, seat, data),
FocusTarget::LayerSurface(l) => PointerTarget::frame(l, seat, data),
FocusTarget::Popup(p) => PointerTarget::frame(p.wl_surface(), seat, data),
}
}
fn leave(
&self,
seat: &Seat<AnvilState<BackendData>>,
Expand Down
13 changes: 13 additions & 0 deletions anvil/src/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ impl<BackendData: Backend> AnvilState<BackendData> {
}
let pointer = self.pointer.clone();
pointer.axis(self, frame);
pointer.frame(self);
}
}
}
Expand Down Expand Up @@ -537,6 +538,7 @@ impl<Backend: crate::state::Backend> AnvilState<Backend> {
time: evt.time_msec(),
},
);
pointer.frame(self);
}
}

Expand Down Expand Up @@ -574,6 +576,7 @@ impl AnvilState<UdevData> {
time: 0,
},
);
pointer.frame(self);
}
}
KeyAction::ScaleUp => {
Expand Down Expand Up @@ -611,6 +614,7 @@ impl AnvilState<UdevData> {
time: 0,
},
);
pointer.frame(self);
self.backend_data.reset_buffers(&output);
}
}
Expand Down Expand Up @@ -649,6 +653,7 @@ impl AnvilState<UdevData> {
time: 0,
},
);
pointer.frame(self);
self.backend_data.reset_buffers(&output);
}
}
Expand Down Expand Up @@ -777,6 +782,7 @@ impl AnvilState<UdevData> {

// If pointer is locked, only emit relative motion
if pointer_locked {
pointer.frame(self);
return;
}

Expand All @@ -792,10 +798,12 @@ impl AnvilState<UdevData> {
if pointer_confined {
if let Some((surface, surface_loc)) = &under {
if new_under.as_ref().and_then(|(under, _)| under.wl_surface()) != surface.wl_surface() {
pointer.frame(self);
return;
}
if let Some(region) = confine_region {
if !region.contains(pointer_location.to_i32_round() - *surface_loc) {
pointer.frame(self);
return;
}
}
Expand All @@ -811,6 +819,7 @@ impl AnvilState<UdevData> {
time: evt.time_msec(),
},
);
pointer.frame(self);

// If pointer is now in a constraint region, activate it
// TODO Anywhere else pointer is moved needs to do this
Expand Down Expand Up @@ -866,6 +875,7 @@ impl AnvilState<UdevData> {
time: evt.time_msec(),
},
);
pointer.frame(self);
}

fn on_tablet_tool_axis<B: InputBackend>(&mut self, evt: B::TabletToolAxisEvent) {
Expand Down Expand Up @@ -923,6 +933,8 @@ impl AnvilState<UdevData> {
evt.time_msec(),
);
}

pointer.frame(self);
}
}

Expand Down Expand Up @@ -959,6 +971,7 @@ impl AnvilState<UdevData> {
time: 0,
},
);
pointer.frame(self);

if let (Some(under), Some(tablet), Some(tool)) = (
under.and_then(|(f, loc)| f.wl_surface().map(|s| (s, loc))),
Expand Down
10 changes: 10 additions & 0 deletions anvil/src/shell/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ impl<Backend: crate::state::Backend> PointerTarget<AnvilState<Backend>> for Wind
}
}
}
fn frame(&self, seat: &Seat<AnvilState<Backend>>, data: &mut AnvilState<Backend>) {
let state = self.decoration_state();
if !state.is_ssd || state.ptr_entered_window {
match self {
WindowElement::Wayland(w) => PointerTarget::frame(w, seat, data),
#[cfg(feature = "xwayland")]
WindowElement::X11(w) => PointerTarget::frame(w, seat, data),
}
}
}
fn leave(
&self,
seat: &Seat<AnvilState<Backend>>,
Expand Down
16 changes: 16 additions & 0 deletions anvil/src/shell/grabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ impl<BackendData: Backend> PointerGrab<AnvilState<BackendData>> for MoveSurfaceG
handle.axis(data, details)
}

fn frame(
&mut self,
data: &mut AnvilState<BackendData>,
handle: &mut PointerInnerHandle<'_, AnvilState<BackendData>>,
) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut AnvilState<BackendData>,
Expand Down Expand Up @@ -432,6 +440,14 @@ impl<BackendData: Backend> PointerGrab<AnvilState<BackendData>> for ResizeSurfac
handle.axis(data, details)
}

fn frame(
&mut self,
data: &mut AnvilState<BackendData>,
handle: &mut PointerInnerHandle<'_, AnvilState<BackendData>>,
) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut AnvilState<BackendData>,
Expand Down
4 changes: 4 additions & 0 deletions smallvil/src/grabs/move_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ impl PointerGrab<Smallvil> for MoveSurfaceGrab {
handle.axis(data, details)
}

fn frame(&mut self, data: &mut Smallvil, handle: &mut PointerInnerHandle<'_, Smallvil>) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut Smallvil,
Expand Down
4 changes: 4 additions & 0 deletions smallvil/src/grabs/resize_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ impl PointerGrab<Smallvil> for ResizeSurfaceGrab {
handle.axis(data, details)
}

fn frame(&mut self, data: &mut Smallvil, handle: &mut PointerInnerHandle<'_, Smallvil>) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut Smallvil,
Expand Down
6 changes: 5 additions & 1 deletion smallvil/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ impl Smallvil {
time: event.time_msec(),
},
);
pointer.frame(self);
}
InputEvent::PointerButton { event, .. } => {
let pointer = self.seat.get_pointer().unwrap();
Expand Down Expand Up @@ -92,6 +93,7 @@ impl Smallvil {
time: event.time_msec(),
},
);
pointer.frame(self);
}
InputEvent::PointerAxis { event, .. } => {
let source = event.source();
Expand Down Expand Up @@ -128,7 +130,9 @@ impl Smallvil {
}
}

self.seat.get_pointer().unwrap().axis(self, frame);
let pointer = self.seat.get_pointer().unwrap();
pointer.axis(self, frame);
pointer.frame(self);
}
_ => {}
}
Expand Down
5 changes: 5 additions & 0 deletions src/desktop/wayland/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,11 @@ impl<D: SeatHandler + 'static> PointerTarget<D> for LayerSurface {
PointerTarget::<D>::axis(surface, seat, data, frame)
}
}
fn frame(&self, seat: &Seat<D>, data: &mut D) {
if let Some(surface) = self.0.focused_surface.lock().unwrap().as_ref() {
PointerTarget::<D>::frame(surface, seat, data)
}
}
fn leave(&self, seat: &Seat<D>, data: &mut D, serial: Serial, time: u32) {
if let Some(surface) = self.0.focused_surface.lock().unwrap().take() {
PointerTarget::<D>::leave(&surface, seat, data, serial, time)
Expand Down
4 changes: 4 additions & 0 deletions src/desktop/wayland/popup/grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ where
handle.axis(data, details);
}

fn frame(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut D,
Expand Down
7 changes: 6 additions & 1 deletion src/desktop/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl<D: SeatHandler + 'static> PointerTarget<D> for Window {
PointerTarget::<D>::leave(&old_surface, seat, data, event.serial, event.time);
PointerTarget::<D>::enter(&surface, seat, data, &new_event);
} else {
PointerTarget::<D>::motion(&surface, seat, data, &new_event)
PointerTarget::<D>::motion(&surface, seat, data, &new_event);
}
} else {
PointerTarget::<D>::enter(&surface, seat, data, &new_event)
Expand All @@ -322,6 +322,11 @@ impl<D: SeatHandler + 'static> PointerTarget<D> for Window {
PointerTarget::<D>::axis(surface, seat, data, frame)
}
}
fn frame(&self, seat: &Seat<D>, data: &mut D) {
if let Some(surface) = self.0.focused_surface.lock().unwrap().as_ref() {
PointerTarget::<D>::frame(surface, seat, data)
}
}
fn leave(&self, seat: &Seat<D>, data: &mut D, serial: Serial, time: u32) {
if let Some(surface) = self.0.focused_surface.lock().unwrap().take() {
PointerTarget::<D>::leave(&surface, seat, data, serial, time)
Expand Down
3 changes: 3 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
//! # fn relative_motion(&self, seat: &Seat<State>, data: &mut State, event: &RelativeMotionEvent) {}
//! # fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {}
//! # fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {}
//! # fn frame(&self, seat: &Seat<State>, data: &mut State) {}
//! # fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {}
//! # fn gesture_swipe_begin(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeBeginEvent) {}
//! # fn gesture_swipe_update(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeUpdateEvent) {}
Expand Down Expand Up @@ -326,6 +327,7 @@ impl<D: SeatHandler + 'static> Seat<D> {
/// # fn relative_motion(&self, seat: &Seat<State>, data: &mut State, event: &RelativeMotionEvent) {}
/// # fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {}
/// # fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {}
/// # fn frame(&self, seat: &Seat<State>, data: &mut State) {}
/// # fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {}
/// # fn gesture_swipe_begin(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeBeginEvent) {}
/// # fn gesture_swipe_update(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeUpdateEvent) {}
Expand Down Expand Up @@ -435,6 +437,7 @@ impl<D: SeatHandler + 'static> Seat<D> {
/// # fn relative_motion(&self, seat: &Seat<State>, data: &mut State, event: &RelativeMotionEvent) {}
/// # fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {}
/// # fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {}
/// # fn frame(&self, seat: &Seat<State>, data: &mut State) {}
/// # fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {}
/// # fn gesture_swipe_begin(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeBeginEvent) {}
/// # fn gesture_swipe_update(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeUpdateEvent) {}
Expand Down
12 changes: 12 additions & 0 deletions src/input/pointer/grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ pub trait PointerGrab<D: SeatHandler>: Send {
/// You generally will want to invoke `PointerInnerHandle::axis()` as part of your processing. If you
/// don't, the rest of the compositor will behave as if the axis event never occurred.
fn axis(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>, details: AxisFrame);
/// End of a pointer frame
///
/// A frame groups associated events. This terminates the frame.
fn frame(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>);
/// A pointer of a given seat started a swipe gesture
///
/// This method allows you attach additional behavior to a swipe gesture begin event, possibly altering it.
Expand Down Expand Up @@ -260,6 +264,10 @@ impl<D: SeatHandler + 'static> PointerGrab<D> for DefaultGrab {
handle.axis(data, details);
}

fn frame(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut D,
Expand Down Expand Up @@ -379,6 +387,10 @@ impl<D: SeatHandler + 'static> PointerGrab<D> for ClickGrab<D> {
handle.axis(data, details);
}

fn frame(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut D,
Expand Down
23 changes: 23 additions & 0 deletions src/input/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ where
fn button(&self, seat: &Seat<D>, data: &mut D, event: &ButtonEvent);
/// A pointer of a given seat scrolled on an axis
fn axis(&self, seat: &Seat<D>, data: &mut D, frame: AxisFrame);
/// End of a pointer frame
fn frame(&self, seat: &Seat<D>, data: &mut D);
/// A pointer of a given seat started a swipe gesture
fn gesture_swipe_begin(&self, seat: &Seat<D>, data: &mut D, event: &GestureSwipeBeginEvent);
/// A pointer of a given seat updated a swipe gesture
Expand Down Expand Up @@ -283,6 +285,17 @@ impl<D: SeatHandler + 'static> PointerHandle<D> {
});
}

/// End of a pointer frame
///
/// A frame groups associated events. This terminates the frame.
#[instrument(level = "trace", parent = &self.span, skip(self, data))]
pub fn frame(&self, data: &mut D) {
let seat = self.get_seat(data);
self.inner.lock().unwrap().with_grab(&seat, |mut handle, grab| {
grab.frame(data, &mut handle);
});
}

/// Notify about swipe gesture begin
///
/// This will internally send the appropriate event to the client
Expand Down Expand Up @@ -547,6 +560,16 @@ impl<'a, D: SeatHandler + 'static> PointerInnerHandle<'a, D> {
}
}

/// End of a pointer frame
///
/// This will internally send the appropriate frame event to the client
/// objects matching with the currently focused surface.
pub fn frame(&mut self, data: &mut D) {
if let Some((focused, _)) = self.inner.focus.as_mut() {
focused.frame(self.seat, data);
}
}

/// Notify about swipe gesture begin
///
/// This will internally send the appropriate button event to the client
Expand Down
4 changes: 4 additions & 0 deletions src/wayland/data_device/dnd_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ where
handle.axis(data, details);
}

fn frame(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut D,
Expand Down
4 changes: 4 additions & 0 deletions src/wayland/data_device/server_dnd_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ where
handle.axis(data, details);
}

fn frame(&mut self, data: &mut D, handle: &mut PointerInnerHandle<'_, D>) {
handle.frame(data);
}

fn gesture_swipe_begin(
&mut self,
data: &mut D,
Expand Down
1 change: 1 addition & 0 deletions src/wayland/pointer_gestures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
//! # fn relative_motion(&self, seat: &Seat<State>, data: &mut State, event: &RelativeMotionEvent) {}
//! # fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {}
//! # fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {}
//! # fn frame(&self, seat: &Seat<State>, data: &mut State) {}
//! # fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {}
//! # fn gesture_swipe_begin(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeBeginEvent) {}
//! # fn gesture_swipe_update(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeUpdateEvent) {}
Expand Down
1 change: 1 addition & 0 deletions src/wayland/relative_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
//! # fn relative_motion(&self, seat: &Seat<State>, data: &mut State, event: &RelativeMotionEvent) {}
//! # fn button(&self, seat: &Seat<State>, data: &mut State, event: &ButtonEvent) {}
//! # fn axis(&self, seat: &Seat<State>, data: &mut State, frame: AxisFrame) {}
//! # fn frame(&self, seat: &Seat<State>, data: &mut State) {}
//! # fn leave(&self, seat: &Seat<State>, data: &mut State, serial: Serial, time: u32) {}
//! # fn gesture_swipe_begin(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeBeginEvent) {}
//! # fn gesture_swipe_update(&self, seat: &Seat<State>, data: &mut State, event: &GestureSwipeUpdateEvent) {}
Expand Down
Loading

0 comments on commit 4c37923

Please sign in to comment.