Support pointer-gestures on Wayland backend
This commit is contained in:
parent
5027b23dc2
commit
d80acadfd8
|
@ -17,6 +17,7 @@
|
|||
#include "backend/wayland.h"
|
||||
#include "util/signal.h"
|
||||
#include "xdg-decoration-unstable-v1-client-protocol.h"
|
||||
#include "pointer-gestures-unstable-v1-client-protocol.h"
|
||||
#include "xdg-shell-client-protocol.h"
|
||||
|
||||
struct wlr_wl_backend *get_wl_backend_from_backend(struct wlr_backend *backend) {
|
||||
|
@ -77,6 +78,9 @@ static void registry_global(void *data, struct wl_registry *registry,
|
|||
} else if (strcmp(iface, zxdg_decoration_manager_v1_interface.name) == 0) {
|
||||
wl->zxdg_decoration_manager_v1 = wl_registry_bind(registry, name,
|
||||
&zxdg_decoration_manager_v1_interface, 1);
|
||||
} else if (strcmp(iface, zwp_pointer_gestures_v1_interface.name) == 0) {
|
||||
wl->zwp_pointer_gestures_v1 = wl_registry_bind(registry, name,
|
||||
&zwp_pointer_gestures_v1_interface, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,6 +153,9 @@ static void backend_destroy(struct wlr_backend *backend) {
|
|||
if (wl->zxdg_decoration_manager_v1) {
|
||||
zxdg_decoration_manager_v1_destroy(wl->zxdg_decoration_manager_v1);
|
||||
}
|
||||
if (wl->zwp_pointer_gestures_v1) {
|
||||
zwp_pointer_gestures_v1_destroy(wl->zwp_pointer_gestures_v1);
|
||||
}
|
||||
xdg_wm_base_destroy(wl->xdg_wm_base);
|
||||
wl_compositor_destroy(wl->compositor);
|
||||
wl_registry_destroy(wl->registry);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <wlr/interfaces/wlr_touch.h>
|
||||
#include <wlr/util/log.h>
|
||||
|
||||
#include "pointer-gestures-unstable-v1-client-protocol.h"
|
||||
#include "backend/wayland.h"
|
||||
#include "util/signal.h"
|
||||
|
||||
|
@ -344,6 +345,107 @@ static struct wlr_pointer_impl pointer_impl = {
|
|||
.destroy = pointer_destroy,
|
||||
};
|
||||
|
||||
static void gesture_swipe_begin(void *data,
|
||||
struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
|
||||
uint32_t serial, uint32_t time,
|
||||
struct wl_surface *surface, uint32_t fingers) {
|
||||
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
|
||||
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
|
||||
struct wlr_event_pointer_swipe_begin wlr_event = {
|
||||
.device = wlr_dev,
|
||||
.time_msec = time,
|
||||
.fingers = fingers,
|
||||
};
|
||||
input_device->fingers = fingers;
|
||||
wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_begin, &wlr_event);
|
||||
}
|
||||
|
||||
static void gesture_swipe_update(void *data,
|
||||
struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
|
||||
uint32_t time, wl_fixed_t dx, wl_fixed_t dy) {
|
||||
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
|
||||
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
|
||||
struct wlr_event_pointer_swipe_update wlr_event = {
|
||||
.device = wlr_dev,
|
||||
.time_msec = time,
|
||||
.fingers = input_device->fingers,
|
||||
.dx = wl_fixed_to_double(dx),
|
||||
.dy = wl_fixed_to_double(dy),
|
||||
};
|
||||
wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_update, &wlr_event);
|
||||
}
|
||||
|
||||
static void gesture_swipe_end(void *data,
|
||||
struct zwp_pointer_gesture_swipe_v1 *zwp_pointer_gesture_swipe_v1,
|
||||
uint32_t serial, uint32_t time, int32_t cancelled) {
|
||||
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
|
||||
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
|
||||
struct wlr_event_pointer_swipe_end wlr_event = {
|
||||
.device = wlr_dev,
|
||||
.time_msec = time,
|
||||
.cancelled = cancelled,
|
||||
};
|
||||
wlr_signal_emit_safe(&wlr_dev->pointer->events.swipe_end, &wlr_event);
|
||||
}
|
||||
|
||||
static struct zwp_pointer_gesture_swipe_v1_listener gesture_swipe_impl = {
|
||||
.begin = gesture_swipe_begin,
|
||||
.update = gesture_swipe_update,
|
||||
.end = gesture_swipe_end,
|
||||
};
|
||||
|
||||
static void gesture_pinch_begin(void *data,
|
||||
struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1,
|
||||
uint32_t serial, uint32_t time,
|
||||
struct wl_surface *surface, uint32_t fingers) {
|
||||
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
|
||||
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
|
||||
struct wlr_event_pointer_pinch_begin wlr_event = {
|
||||
.device = wlr_dev,
|
||||
.time_msec = time,
|
||||
.fingers = fingers,
|
||||
};
|
||||
input_device->fingers = fingers;
|
||||
wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_begin, &wlr_event);
|
||||
}
|
||||
|
||||
static void gesture_pinch_update(void *data,
|
||||
struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1,
|
||||
uint32_t time, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t scale, wl_fixed_t rotation) {
|
||||
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
|
||||
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
|
||||
struct wlr_event_pointer_pinch_update wlr_event = {
|
||||
.device = wlr_dev,
|
||||
.time_msec = time,
|
||||
.fingers = input_device->fingers,
|
||||
.dx = wl_fixed_to_double(dx),
|
||||
.dy = wl_fixed_to_double(dy),
|
||||
.scale = wl_fixed_to_double(scale),
|
||||
.rotation = wl_fixed_to_double(rotation),
|
||||
};
|
||||
wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_update, &wlr_event);
|
||||
}
|
||||
|
||||
static void gesture_pinch_end(void *data,
|
||||
struct zwp_pointer_gesture_pinch_v1 *zwp_pointer_gesture_pinch_v1,
|
||||
uint32_t serial, uint32_t time, int32_t cancelled) {
|
||||
struct wlr_wl_input_device *input_device = (struct wlr_wl_input_device *)data;
|
||||
struct wlr_input_device *wlr_dev = &input_device->wlr_input_device;
|
||||
struct wlr_event_pointer_pinch_end wlr_event = {
|
||||
.device = wlr_dev,
|
||||
.time_msec = time,
|
||||
.cancelled = cancelled,
|
||||
};
|
||||
wlr_signal_emit_safe(&wlr_dev->pointer->events.pinch_end, &wlr_event);
|
||||
}
|
||||
|
||||
static struct zwp_pointer_gesture_pinch_v1_listener gesture_pinch_impl = {
|
||||
.begin = gesture_pinch_begin,
|
||||
.update = gesture_pinch_update,
|
||||
.end = gesture_pinch_end,
|
||||
};
|
||||
|
||||
|
||||
static void pointer_handle_output_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_wl_pointer *pointer =
|
||||
|
@ -390,6 +492,15 @@ void create_wl_pointer(struct wl_pointer *wl_pointer, struct wlr_wl_output *outp
|
|||
wlr_dev->output_name = strdup(output->wlr_output.name);
|
||||
wlr_pointer_init(wlr_dev->pointer, &pointer_impl);
|
||||
|
||||
if (backend->zwp_pointer_gestures_v1) {
|
||||
pointer->gesture_swipe = zwp_pointer_gestures_v1_get_swipe_gesture(
|
||||
backend->zwp_pointer_gestures_v1, wl_pointer);
|
||||
zwp_pointer_gesture_swipe_v1_add_listener(pointer->gesture_swipe, &gesture_swipe_impl, dev);
|
||||
pointer->gesture_pinch = zwp_pointer_gestures_v1_get_pinch_gesture(
|
||||
backend->zwp_pointer_gestures_v1, wl_pointer);
|
||||
zwp_pointer_gesture_pinch_v1_add_listener(pointer->gesture_pinch, &gesture_pinch_impl, dev);
|
||||
}
|
||||
|
||||
wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ struct wlr_wl_backend {
|
|||
struct wl_compositor *compositor;
|
||||
struct xdg_wm_base *xdg_wm_base;
|
||||
struct zxdg_decoration_manager_v1 *zxdg_decoration_manager_v1;
|
||||
struct zwp_pointer_gestures_v1 *zwp_pointer_gestures_v1;
|
||||
struct wl_seat *seat;
|
||||
struct wl_pointer *pointer;
|
||||
struct wl_keyboard *keyboard;
|
||||
|
@ -66,6 +67,7 @@ struct wlr_wl_output {
|
|||
|
||||
struct wlr_wl_input_device {
|
||||
struct wlr_input_device wlr_input_device;
|
||||
uint32_t fingers;
|
||||
|
||||
struct wlr_wl_backend *backend;
|
||||
void *resource;
|
||||
|
@ -76,6 +78,8 @@ struct wlr_wl_pointer {
|
|||
|
||||
struct wlr_wl_input_device *input_device;
|
||||
struct wl_pointer *wl_pointer;
|
||||
struct zwp_pointer_gesture_swipe_v1 *gesture_swipe;
|
||||
struct zwp_pointer_gesture_pinch_v1 *gesture_pinch;
|
||||
enum wlr_axis_source axis_source;
|
||||
int32_t axis_discrete;
|
||||
struct wlr_wl_output *output;
|
||||
|
|
|
@ -44,6 +44,7 @@ client_protocols = [
|
|||
[wl_protocol_dir, 'stable/xdg-shell/xdg-shell.xml'],
|
||||
[wl_protocol_dir, 'unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'],
|
||||
[wl_protocol_dir, 'unstable/pointer-constraints/pointer-constraints-unstable-v1.xml'],
|
||||
[wl_protocol_dir, 'unstable/pointer-gestures/pointer-gestures-unstable-v1.xml'],
|
||||
[wl_protocol_dir, 'unstable/relative-pointer/relative-pointer-unstable-v1.xml'],
|
||||
[wl_protocol_dir, 'unstable/text-input/text-input-unstable-v3.xml'],
|
||||
[wl_protocol_dir, 'unstable/xdg-decoration/xdg-decoration-unstable-v1.xml'],
|
||||
|
|
Loading…
Reference in New Issue