Implement pointer-gestures-unstable-v1

This commit is contained in:
Marten Ringwelski 2021-02-14 19:32:04 +01:00 committed by Isaac Freund
parent 6470d8c776
commit 870f0b746e
4 changed files with 99 additions and 2 deletions

View file

@ -40,6 +40,7 @@ pub fn build(b: *zbs.Builder) !void {
const scanner = ScanProtocolsStep.create(b);
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
scanner.addSystemProtocol("unstable/xdg-output/xdg-output-unstable-v1.xml");
scanner.addProtocolPath("protocol/river-control-unstable-v1.xml");
scanner.addProtocolPath("protocol/river-options-unstable-v1.xml");

2
deps/zig-wayland vendored

@ -1 +1 @@
Subproject commit 6880196f57df7f4d8b783bbab94b1bf5c3e38453
Subproject commit 5def9c58107c4803847e37511d16c15ff294b62d

2
deps/zig-wlroots vendored

@ -1 +1 @@
Subproject commit 5bc7fcf94e1d488a8e2316ff7ebdd0ca193d0309
Subproject commit b38d3d5d2d9a5e4c748b8c01ed0d3861241661a6

View file

@ -57,6 +57,7 @@ mode: Mode = .passthrough,
seat: *Seat,
wlr_cursor: *wlr.Cursor,
pointer_gestures: *wlr.PointerGesturesV1,
xcursor_manager: *wlr.XcursorManager,
/// Number of distinct buttons currently pressed
@ -71,8 +72,20 @@ motion_absolute: wl.Listener(*wlr.Pointer.event.MotionAbsolute) =
wl.Listener(*wlr.Pointer.event.MotionAbsolute).init(handleMotionAbsolute),
motion: wl.Listener(*wlr.Pointer.event.Motion) =
wl.Listener(*wlr.Pointer.event.Motion).init(handleMotion),
pinch_begin: wl.Listener(*wlr.Pointer.event.PinchBegin) =
wl.Listener(*wlr.Pointer.event.PinchBegin).init(handlePinchBegin),
pinch_update: wl.Listener(*wlr.Pointer.event.PinchUpdate) =
wl.Listener(*wlr.Pointer.event.PinchUpdate).init(handlePinchUpdate),
pinch_end: wl.Listener(*wlr.Pointer.event.PinchEnd) =
wl.Listener(*wlr.Pointer.event.PinchEnd).init(handlePinchEnd),
request_set_cursor: wl.Listener(*wlr.Seat.event.RequestSetCursor) =
wl.Listener(*wlr.Seat.event.RequestSetCursor).init(handleRequestSetCursor),
swipe_begin: wl.Listener(*wlr.Pointer.event.SwipeBegin) =
wl.Listener(*wlr.Pointer.event.SwipeBegin).init(handleSwipeBegin),
swipe_update: wl.Listener(*wlr.Pointer.event.SwipeUpdate) =
wl.Listener(*wlr.Pointer.event.SwipeUpdate).init(handleSwipeUpdate),
swipe_end: wl.Listener(*wlr.Pointer.event.SwipeEnd) =
wl.Listener(*wlr.Pointer.event.SwipeEnd).init(handleSwipeEnd),
// zig fmt: on
pub fn init(self: *Self, seat: *Seat) !void {
@ -89,6 +102,7 @@ pub fn init(self: *Self, seat: *Seat) !void {
self.* = .{
.seat = seat,
.wlr_cursor = wlr_cursor,
.pointer_gestures = try wlr.PointerGesturesV1.create(seat.input_manager.server.wl_server),
.xcursor_manager = xcursor_manager,
};
try self.setTheme(null, null);
@ -104,6 +118,12 @@ pub fn init(self: *Self, seat: *Seat) !void {
wlr_cursor.events.frame.add(&self.frame);
wlr_cursor.events.motion_absolute.add(&self.motion_absolute);
wlr_cursor.events.motion.add(&self.motion);
wlr_cursor.events.swipe_begin.add(&self.swipe_begin);
wlr_cursor.events.swipe_update.add(&self.swipe_update);
wlr_cursor.events.swipe_end.add(&self.swipe_end);
wlr_cursor.events.pinch_begin.add(&self.pinch_begin);
wlr_cursor.events.pinch_update.add(&self.pinch_update);
wlr_cursor.events.pinch_end.add(&self.pinch_end);
seat.wlr_seat.events.request_set_cursor.add(&self.request_set_cursor);
}
@ -240,6 +260,82 @@ fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.P
}
}
fn handlePinchBegin(
listener: *wl.Listener(*wlr.Pointer.event.PinchBegin),
event: *wlr.Pointer.event.PinchBegin,
) void {
const self = @fieldParentPtr(Self, "pinch_begin", listener);
self.pointer_gestures.sendPinchBegin(
self.seat.wlr_seat,
event.time_msec,
event.fingers,
);
}
fn handlePinchUpdate(
listener: *wl.Listener(*wlr.Pointer.event.PinchUpdate),
event: *wlr.Pointer.event.PinchUpdate,
) void {
const self = @fieldParentPtr(Self, "pinch_update", listener);
self.pointer_gestures.sendPinchUpdate(
self.seat.wlr_seat,
event.time_msec,
event.dx,
event.dy,
event.scale,
event.rotation,
);
}
fn handlePinchEnd(
listener: *wl.Listener(*wlr.Pointer.event.PinchEnd),
event: *wlr.Pointer.event.PinchEnd,
) void {
const self = @fieldParentPtr(Self, "pinch_end", listener);
self.pointer_gestures.sendPinchEnd(
self.seat.wlr_seat,
event.time_msec,
event.cancelled,
);
}
fn handleSwipeBegin(
listener: *wl.Listener(*wlr.Pointer.event.SwipeBegin),
event: *wlr.Pointer.event.SwipeBegin,
) void {
const self = @fieldParentPtr(Self, "swipe_begin", listener);
self.pointer_gestures.sendSwipeBegin(
self.seat.wlr_seat,
event.time_msec,
event.fingers,
);
}
fn handleSwipeUpdate(
listener: *wl.Listener(*wlr.Pointer.event.SwipeUpdate),
event: *wlr.Pointer.event.SwipeUpdate,
) void {
const self = @fieldParentPtr(Self, "swipe_update", listener);
self.pointer_gestures.sendSwipeUpdate(
self.seat.wlr_seat,
event.time_msec,
event.dx,
event.dy,
);
}
fn handleSwipeEnd(
listener: *wl.Listener(*wlr.Pointer.event.SwipeEnd),
event: *wlr.Pointer.event.SwipeEnd,
) void {
const self = @fieldParentPtr(Self, "swipe_end", listener);
self.pointer_gestures.sendSwipeEnd(
self.seat.wlr_seat,
event.time_msec,
event.cancelled,
);
}
/// Handle the mapping for the passed button if any. Returns true if there
/// was a mapping and the button was handled.
fn handlePointerMapping(self: *Self, event: *wlr.Pointer.event.Button, view: *View) bool {