Skip to content

Commit

Permalink
Merge pull request #188 from mahkoh/jorth/gestures
Browse files Browse the repository at this point in the history
wayland: implement pointer-gestures-unstable-v1
  • Loading branch information
mahkoh authored Apr 27, 2024
2 parents afc360e + ee24971 commit 55d55bf
Show file tree
Hide file tree
Showing 24 changed files with 1,589 additions and 18 deletions.
1 change: 1 addition & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Jay supports the following wayland protocols:
| zwp_input_method_manager_v2 | 1 | Yes |
| zwp_linux_dmabuf_v1 | 5 | |
| zwp_pointer_constraints_v1 | 1 | |
| zwp_pointer_gestures_v1 | 3 | |
| zwp_primary_selection_device_manager_v1 | 1 | |
| zwp_relative_pointer_manager_v1 | 1 | |
| zwp_text_input_manager_v3 | 1 | |
Expand Down
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Add support for ext-transient-seat-v1.
- Add support for wp-drm-lease-v1.
- Focus-follows-mouse can now be disabled.
- Add support for pointer-gestures-unstable-v1.

# 1.1.0 (2024-04-22)

Expand Down
40 changes: 40 additions & 0 deletions src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,46 @@ pub enum InputEvent {
AxisFrame {
time_usec: u64,
},
SwipeBegin {
time_usec: u64,
finger_count: u32,
},
SwipeUpdate {
time_usec: u64,
dx: Fixed,
dy: Fixed,
dx_unaccelerated: Fixed,
dy_unaccelerated: Fixed,
},
SwipeEnd {
time_usec: u64,
cancelled: bool,
},
PinchBegin {
time_usec: u64,
finger_count: u32,
},
PinchUpdate {
time_usec: u64,
dx: Fixed,
dy: Fixed,
dx_unaccelerated: Fixed,
dy_unaccelerated: Fixed,
scale: Fixed,
rotation: Fixed,
},
PinchEnd {
time_usec: u64,
cancelled: bool,
},
HoldBegin {
time_usec: u64,
finger_count: u32,
},
HoldEnd {
time_usec: u64,
cancelled: bool,
},
}

pub enum DrmEvent {
Expand Down
80 changes: 80 additions & 0 deletions src/backends/metal/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ impl MetalBackend {
c::LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS => {
self.handle_pointer_axis(event, AxisSource::Continuous)
}
c::LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN => self.handle_gesture_swipe_begin(event),
c::LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE => self.handle_gesture_swipe_update(event),
c::LIBINPUT_EVENT_GESTURE_SWIPE_END => self.handle_gesture_swipe_end(event),
c::LIBINPUT_EVENT_GESTURE_PINCH_BEGIN => self.handle_gesture_pinch_begin(event),
c::LIBINPUT_EVENT_GESTURE_PINCH_UPDATE => self.handle_gesture_pinch_update(event),
c::LIBINPUT_EVENT_GESTURE_PINCH_END => self.handle_gesture_pinch_end(event),
c::LIBINPUT_EVENT_GESTURE_HOLD_BEGIN => self.handle_gesture_hold_begin(event),
c::LIBINPUT_EVENT_GESTURE_HOLD_END => self.handle_gesture_hold_end(event),
_ => {}
}
}
Expand Down Expand Up @@ -217,4 +225,76 @@ impl MetalBackend {
dy_unaccelerated: Fixed::from_f64(dy_unaccelerated),
});
}

fn handle_gesture_swipe_begin(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::SwipeBegin {
time_usec: event.time_usec(),
finger_count: event.finger_count(),
});
}

fn handle_gesture_swipe_update(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::SwipeUpdate {
time_usec: event.time_usec(),
dx: Fixed::from_f64(event.dx()),
dy: Fixed::from_f64(event.dy()),
dx_unaccelerated: Fixed::from_f64(event.dx_unaccelerated()),
dy_unaccelerated: Fixed::from_f64(event.dy_unaccelerated()),
});
}

fn handle_gesture_swipe_end(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::SwipeEnd {
time_usec: event.time_usec(),
cancelled: event.cancelled(),
});
}

fn handle_gesture_pinch_begin(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::PinchBegin {
time_usec: event.time_usec(),
finger_count: event.finger_count(),
});
}

fn handle_gesture_pinch_update(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::PinchUpdate {
time_usec: event.time_usec(),
dx: Fixed::from_f64(event.dx()),
dy: Fixed::from_f64(event.dy()),
dx_unaccelerated: Fixed::from_f64(event.dx_unaccelerated()),
dy_unaccelerated: Fixed::from_f64(event.dy_unaccelerated()),
scale: Fixed::from_f64(event.scale()),
rotation: Fixed::from_f64(event.angle_delta()),
});
}

fn handle_gesture_pinch_end(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::PinchEnd {
time_usec: event.time_usec(),
cancelled: event.cancelled(),
});
}

fn handle_gesture_hold_begin(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::HoldBegin {
time_usec: event.time_usec(),
finger_count: event.finger_count(),
});
}

fn handle_gesture_hold_end(self: &Rc<Self>, event: LibInputEvent) {
let (event, dev) = unpack!(self, event, gesture_event);
dev.event(InputEvent::HoldEnd {
time_usec: event.time_usec(),
cancelled: event.cancelled(),
});
}
}
117 changes: 115 additions & 2 deletions src/cli/seat_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use {
wire::{
jay_compositor::{GetSeats, Seat, SeatEvents},
jay_seat_events::{
Axis120, AxisFrame, AxisInverted, AxisPx, AxisSource, AxisStop, Button, Key,
Modifiers, PointerAbs, PointerRel,
Axis120, AxisFrame, AxisInverted, AxisPx, AxisSource, AxisStop, Button, HoldBegin,
HoldEnd, Key, Modifiers, PinchBegin, PinchEnd, PinchUpdate, PointerAbs, PointerRel,
SwipeBegin, SwipeEnd, SwipeUpdate,
},
},
},
Expand Down Expand Up @@ -211,6 +212,118 @@ async fn run(seat_test: Rc<SeatTest>) {
println!();
}
});
let st = seat_test.clone();
SwipeBegin::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!(
"Time: {:.4}, Swipe Begin: {} fingers",
time(ev.time_usec),
ev.fingers,
);
}
});
let st = seat_test.clone();
SwipeUpdate::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!(
"Time: {:.4}, Swipe Update: {}x{}, Unaccelerated: {}x{}",
time(ev.time_usec),
ev.dx,
ev.dy,
ev.dx_unaccelerated,
ev.dy_unaccelerated,
);
}
});
let st = seat_test.clone();
SwipeEnd::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
print!("Time: {:.4}, Swipe End", time(ev.time_usec),);
if ev.cancelled != 0 {
print!(", cancelled");
}
println!();
}
});
let st = seat_test.clone();
PinchBegin::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!(
"Time: {:.4}, Pinch Begin: {} fingers",
time(ev.time_usec),
ev.fingers,
);
}
});
let st = seat_test.clone();
PinchUpdate::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!(
"Time: {:.4}, Pinch Update: {}x{}, Unaccelerated: {}x{}, Scale: {}, Rotation: {}",
time(ev.time_usec),
ev.dx,
ev.dy,
ev.dx_unaccelerated,
ev.dy_unaccelerated,
ev.scale,
ev.rotation,
);
}
});
let st = seat_test.clone();
PinchEnd::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
print!("Time: {:.4}, Pinch End", time(ev.time_usec));
if ev.cancelled != 0 {
print!(", cancelled");
}
println!();
}
});
let st = seat_test.clone();
HoldBegin::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
println!(
"Time: {:.4}, Hold Begin: {} fingers",
time(ev.time_usec),
ev.fingers,
);
}
});
let st = seat_test.clone();
HoldEnd::handle(tc, se, (), move |_, ev| {
if all || ev.seat == seat {
if all {
print!("Seat: {}, ", st.name(ev.seat));
}
print!("Time: {:.4}, Hold End", time(ev.time_usec));
if ev.cancelled != 0 {
print!(", cancelled");
}
println!();
}
});
pending::<()>().await;
}

Expand Down
2 changes: 2 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use {
zwp_text_input_manager_v3::ZwpTextInputManagerV3Global,
},
zwp_pointer_constraints_v1::ZwpPointerConstraintsV1Global,
zwp_pointer_gestures_v1::ZwpPointerGesturesV1Global,
zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1Global,
zwp_virtual_keyboard_manager_v1::ZwpVirtualKeyboardManagerV1Global,
WlSeatGlobal,
Expand Down Expand Up @@ -192,6 +193,7 @@ impl Globals {
add_singleton!(WpSecurityContextManagerV1Global);
add_singleton!(XdgWmDialogV1Global);
add_singleton!(ExtTransientSeatManagerV1Global);
add_singleton!(ZwpPointerGesturesV1Global);
}

pub fn add_backend_singletons(&self, backend: &Rc<dyn Backend>) {
Expand Down
Loading

0 comments on commit 55d55bf

Please sign in to comment.