2017-08-20 22:02:39 +02:00
|
|
|
#include <assert.h>
|
2017-08-27 23:35:12 +02:00
|
|
|
#include <limits.h>
|
2018-04-27 18:26:33 +02:00
|
|
|
#include <math.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <stdlib.h>
|
2019-07-27 10:53:54 +02:00
|
|
|
#include <wayland-server-core.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/types/wlr_cursor.h>
|
2017-08-20 22:02:39 +02:00
|
|
|
#include <wlr/types/wlr_input_device.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/types/wlr_output_layout.h>
|
|
|
|
#include <wlr/types/wlr_output.h>
|
2020-11-11 14:16:41 +01:00
|
|
|
#include <wlr/types/wlr_pointer.h>
|
|
|
|
#include <wlr/types/wlr_tablet_tool.h>
|
|
|
|
#include <wlr/types/wlr_touch.h>
|
2021-07-01 22:36:01 +02:00
|
|
|
#include <wlr/util/box.h>
|
2018-02-12 21:29:23 +01:00
|
|
|
#include <wlr/util/log.h>
|
2017-08-20 22:02:39 +02:00
|
|
|
|
|
|
|
struct wlr_cursor_device {
|
|
|
|
struct wlr_cursor *cursor;
|
|
|
|
struct wlr_input_device *device;
|
|
|
|
struct wl_list link;
|
2017-08-24 20:35:55 +02:00
|
|
|
struct wlr_output *mapped_output;
|
2022-01-29 21:25:12 +01:00
|
|
|
struct wlr_box mapped_box; // empty if unset
|
2017-08-20 22:02:39 +02:00
|
|
|
|
|
|
|
struct wl_listener motion;
|
|
|
|
struct wl_listener motion_absolute;
|
|
|
|
struct wl_listener button;
|
|
|
|
struct wl_listener axis;
|
2019-01-26 11:04:05 +01:00
|
|
|
struct wl_listener frame;
|
2019-01-25 23:51:38 +01:00
|
|
|
struct wl_listener swipe_begin;
|
|
|
|
struct wl_listener swipe_update;
|
|
|
|
struct wl_listener swipe_end;
|
|
|
|
struct wl_listener pinch_begin;
|
|
|
|
struct wl_listener pinch_update;
|
|
|
|
struct wl_listener pinch_end;
|
2021-07-12 19:51:40 +02:00
|
|
|
struct wl_listener hold_begin;
|
|
|
|
struct wl_listener hold_end;
|
2017-08-27 17:34:25 +02:00
|
|
|
|
|
|
|
struct wl_listener touch_down;
|
|
|
|
struct wl_listener touch_up;
|
|
|
|
struct wl_listener touch_motion;
|
|
|
|
struct wl_listener touch_cancel;
|
2021-06-30 11:40:15 +02:00
|
|
|
struct wl_listener touch_frame;
|
2017-08-28 14:42:39 +02:00
|
|
|
|
|
|
|
struct wl_listener tablet_tool_axis;
|
|
|
|
struct wl_listener tablet_tool_proximity;
|
|
|
|
struct wl_listener tablet_tool_tip;
|
|
|
|
struct wl_listener tablet_tool_button;
|
2017-08-28 16:29:53 +02:00
|
|
|
|
|
|
|
struct wl_listener destroy;
|
2017-08-20 22:02:39 +02:00
|
|
|
};
|
|
|
|
|
2017-10-29 09:09:21 +01:00
|
|
|
struct wlr_cursor_output_cursor {
|
|
|
|
struct wlr_cursor *cursor;
|
|
|
|
struct wlr_output_cursor *output_cursor;
|
|
|
|
struct wl_list link;
|
2017-10-29 11:20:11 +01:00
|
|
|
|
|
|
|
struct wl_listener layout_output_destroy;
|
2017-10-29 09:09:21 +01:00
|
|
|
};
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
struct wlr_cursor_state {
|
2017-09-05 13:48:28 +02:00
|
|
|
struct wlr_cursor *cursor;
|
2017-10-29 09:09:21 +01:00
|
|
|
struct wl_list devices; // wlr_cursor_device::link
|
|
|
|
struct wl_list output_cursors; // wlr_cursor_output_cursor::link
|
2017-08-20 22:02:39 +02:00
|
|
|
struct wlr_output_layout *layout;
|
2017-08-24 18:30:34 +02:00
|
|
|
struct wlr_output *mapped_output;
|
2022-01-29 21:25:12 +01:00
|
|
|
struct wlr_box mapped_box; // empty if unset
|
2017-09-05 13:48:28 +02:00
|
|
|
|
2017-10-29 11:20:11 +01:00
|
|
|
struct wl_listener layout_add;
|
2017-09-05 13:48:28 +02:00
|
|
|
struct wl_listener layout_change;
|
|
|
|
struct wl_listener layout_destroy;
|
2017-08-20 22:02:39 +02:00
|
|
|
};
|
|
|
|
|
2018-05-31 02:11:57 +02:00
|
|
|
struct wlr_cursor *wlr_cursor_create(void) {
|
2017-08-20 22:02:39 +02:00
|
|
|
struct wlr_cursor *cur = calloc(1, sizeof(struct wlr_cursor));
|
|
|
|
if (!cur) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate wlr_cursor");
|
2017-08-20 22:02:39 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cur->state = calloc(1, sizeof(struct wlr_cursor_state));
|
|
|
|
if (!cur->state) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate wlr_cursor_state");
|
2017-08-28 17:07:54 +02:00
|
|
|
free(cur);
|
2017-08-20 22:02:39 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:48:28 +02:00
|
|
|
cur->state->cursor = cur;
|
2017-08-24 18:30:34 +02:00
|
|
|
cur->state->mapped_output = NULL;
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
wl_list_init(&cur->state->devices);
|
2017-10-29 11:20:11 +01:00
|
|
|
wl_list_init(&cur->state->output_cursors);
|
2017-08-20 22:02:39 +02:00
|
|
|
|
2017-08-27 17:34:25 +02:00
|
|
|
// pointer signals
|
2017-08-20 22:02:39 +02:00
|
|
|
wl_signal_init(&cur->events.motion);
|
|
|
|
wl_signal_init(&cur->events.motion_absolute);
|
|
|
|
wl_signal_init(&cur->events.button);
|
|
|
|
wl_signal_init(&cur->events.axis);
|
2019-01-26 11:04:05 +01:00
|
|
|
wl_signal_init(&cur->events.frame);
|
2019-01-25 23:51:38 +01:00
|
|
|
wl_signal_init(&cur->events.swipe_begin);
|
|
|
|
wl_signal_init(&cur->events.swipe_update);
|
|
|
|
wl_signal_init(&cur->events.swipe_end);
|
|
|
|
wl_signal_init(&cur->events.pinch_begin);
|
|
|
|
wl_signal_init(&cur->events.pinch_update);
|
|
|
|
wl_signal_init(&cur->events.pinch_end);
|
2021-07-12 19:51:40 +02:00
|
|
|
wl_signal_init(&cur->events.hold_begin);
|
|
|
|
wl_signal_init(&cur->events.hold_end);
|
2017-08-20 22:02:39 +02:00
|
|
|
|
2017-08-27 17:34:25 +02:00
|
|
|
// touch signals
|
|
|
|
wl_signal_init(&cur->events.touch_up);
|
|
|
|
wl_signal_init(&cur->events.touch_down);
|
|
|
|
wl_signal_init(&cur->events.touch_motion);
|
|
|
|
wl_signal_init(&cur->events.touch_cancel);
|
2021-06-30 11:40:15 +02:00
|
|
|
wl_signal_init(&cur->events.touch_frame);
|
2017-08-27 17:34:25 +02:00
|
|
|
|
2017-08-28 14:42:39 +02:00
|
|
|
// tablet tool signals
|
|
|
|
wl_signal_init(&cur->events.tablet_tool_tip);
|
|
|
|
wl_signal_init(&cur->events.tablet_tool_axis);
|
|
|
|
wl_signal_init(&cur->events.tablet_tool_button);
|
|
|
|
wl_signal_init(&cur->events.tablet_tool_proximity);
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
cur->x = 100;
|
|
|
|
cur->y = 100;
|
|
|
|
|
|
|
|
return cur;
|
|
|
|
}
|
|
|
|
|
2017-10-31 14:58:58 +01:00
|
|
|
static void output_cursor_destroy(
|
2017-10-29 20:03:56 +01:00
|
|
|
struct wlr_cursor_output_cursor *output_cursor) {
|
2017-10-31 14:21:12 +01:00
|
|
|
wl_list_remove(&output_cursor->layout_output_destroy.link);
|
2017-10-29 20:03:56 +01:00
|
|
|
wl_list_remove(&output_cursor->link);
|
|
|
|
wlr_output_cursor_destroy(output_cursor->output_cursor);
|
|
|
|
free(output_cursor);
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
static void cursor_detach_output_layout(struct wlr_cursor *cur) {
|
2017-09-05 13:48:28 +02:00
|
|
|
if (!cur->state->layout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-31 14:58:58 +01:00
|
|
|
struct wlr_cursor_output_cursor *output_cursor, *tmp;
|
|
|
|
wl_list_for_each_safe(output_cursor, tmp, &cur->state->output_cursors,
|
|
|
|
link) {
|
|
|
|
output_cursor_destroy(output_cursor);
|
2017-10-29 20:03:56 +01:00
|
|
|
}
|
|
|
|
|
2017-09-05 13:48:28 +02:00
|
|
|
wl_list_remove(&cur->state->layout_destroy.link);
|
|
|
|
wl_list_remove(&cur->state->layout_change.link);
|
2017-10-29 11:20:11 +01:00
|
|
|
wl_list_remove(&cur->state->layout_add.link);
|
2017-09-05 13:48:28 +02:00
|
|
|
|
|
|
|
cur->state->layout = NULL;
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
static void cursor_device_destroy(struct wlr_cursor_device *c_device) {
|
2017-10-29 20:58:58 +01:00
|
|
|
struct wlr_input_device *dev = c_device->device;
|
|
|
|
if (dev->type == WLR_INPUT_DEVICE_POINTER) {
|
|
|
|
wl_list_remove(&c_device->motion.link);
|
|
|
|
wl_list_remove(&c_device->motion_absolute.link);
|
|
|
|
wl_list_remove(&c_device->button.link);
|
|
|
|
wl_list_remove(&c_device->axis.link);
|
2019-01-26 11:04:05 +01:00
|
|
|
wl_list_remove(&c_device->frame.link);
|
2019-01-25 23:51:38 +01:00
|
|
|
wl_list_remove(&c_device->swipe_begin.link);
|
|
|
|
wl_list_remove(&c_device->swipe_update.link);
|
|
|
|
wl_list_remove(&c_device->swipe_end.link);
|
|
|
|
wl_list_remove(&c_device->pinch_begin.link);
|
|
|
|
wl_list_remove(&c_device->pinch_update.link);
|
|
|
|
wl_list_remove(&c_device->pinch_end.link);
|
2021-07-12 19:51:40 +02:00
|
|
|
wl_list_remove(&c_device->hold_begin.link);
|
|
|
|
wl_list_remove(&c_device->hold_end.link);
|
2017-10-29 20:58:58 +01:00
|
|
|
} else if (dev->type == WLR_INPUT_DEVICE_TOUCH) {
|
|
|
|
wl_list_remove(&c_device->touch_down.link);
|
|
|
|
wl_list_remove(&c_device->touch_up.link);
|
|
|
|
wl_list_remove(&c_device->touch_motion.link);
|
|
|
|
wl_list_remove(&c_device->touch_cancel.link);
|
2021-06-30 11:40:15 +02:00
|
|
|
wl_list_remove(&c_device->touch_frame.link);
|
2017-10-29 20:58:58 +01:00
|
|
|
} else if (dev->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
|
|
|
wl_list_remove(&c_device->tablet_tool_axis.link);
|
|
|
|
wl_list_remove(&c_device->tablet_tool_proximity.link);
|
|
|
|
wl_list_remove(&c_device->tablet_tool_tip.link);
|
|
|
|
wl_list_remove(&c_device->tablet_tool_button.link);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_remove(&c_device->link);
|
|
|
|
wl_list_remove(&c_device->destroy.link);
|
|
|
|
free(c_device);
|
|
|
|
}
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
void wlr_cursor_destroy(struct wlr_cursor *cur) {
|
2018-04-26 00:51:00 +02:00
|
|
|
cursor_detach_output_layout(cur);
|
2017-09-05 13:48:28 +02:00
|
|
|
|
2017-08-24 20:35:55 +02:00
|
|
|
struct wlr_cursor_device *device, *device_tmp = NULL;
|
|
|
|
wl_list_for_each_safe(device, device_tmp, &cur->state->devices, link) {
|
2018-04-26 00:51:00 +02:00
|
|
|
cursor_device_destroy(device);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-31 14:58:58 +01:00
|
|
|
free(cur->state);
|
2017-08-20 22:02:39 +02:00
|
|
|
free(cur);
|
|
|
|
}
|
|
|
|
|
2017-08-24 20:35:55 +02:00
|
|
|
static struct wlr_cursor_device *get_cursor_device(struct wlr_cursor *cur,
|
|
|
|
struct wlr_input_device *device) {
|
|
|
|
struct wlr_cursor_device *c_device, *ret = NULL;
|
|
|
|
wl_list_for_each(c_device, &cur->state->devices, link) {
|
|
|
|
if (c_device->device == device) {
|
|
|
|
ret = c_device;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
static void cursor_warp_unchecked(struct wlr_cursor *cur,
|
2018-04-27 18:26:33 +02:00
|
|
|
double lx, double ly) {
|
2017-08-28 02:10:46 +02:00
|
|
|
assert(cur->state->layout);
|
2022-09-21 19:41:48 +02:00
|
|
|
if (!isfinite(lx) || !isfinite(ly)) {
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
}
|
2017-08-27 23:35:12 +02:00
|
|
|
|
2017-10-29 09:09:21 +01:00
|
|
|
struct wlr_cursor_output_cursor *output_cursor;
|
|
|
|
wl_list_for_each(output_cursor, &cur->state->output_cursors, link) {
|
2018-04-27 18:26:33 +02:00
|
|
|
double output_x = lx, output_y = ly;
|
2017-08-27 23:35:12 +02:00
|
|
|
wlr_output_layout_output_coords(cur->state->layout,
|
2017-10-29 09:09:21 +01:00
|
|
|
output_cursor->output_cursor->output, &output_x, &output_y);
|
2018-04-27 18:26:33 +02:00
|
|
|
wlr_output_cursor_move(output_cursor->output_cursor,
|
|
|
|
output_x, output_y);
|
2017-08-27 23:35:12 +02:00
|
|
|
}
|
2017-08-29 18:48:45 +02:00
|
|
|
|
2018-04-27 18:26:33 +02:00
|
|
|
cur->x = lx;
|
|
|
|
cur->y = ly;
|
2017-08-27 23:35:12 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 02:10:46 +02:00
|
|
|
/**
|
|
|
|
* Get the most specific mapping box for the device in this order:
|
|
|
|
*
|
|
|
|
* 1. device geometry mapping
|
|
|
|
* 2. device output mapping
|
|
|
|
* 3. cursor geometry mapping
|
|
|
|
* 4. cursor output mapping
|
|
|
|
*
|
|
|
|
* Absolute movement for touch and pen devices will be relative to this box and
|
|
|
|
* pointer movement will be constrained to this box.
|
|
|
|
*
|
2022-08-30 18:18:42 +02:00
|
|
|
* If none of these are set, the box is empty and absolute movement should be
|
2017-08-28 02:10:46 +02:00
|
|
|
* relative to the extents of the layout.
|
|
|
|
*/
|
2022-01-29 21:06:09 +01:00
|
|
|
static void get_mapping(struct wlr_cursor *cur,
|
|
|
|
struct wlr_input_device *dev, struct wlr_box *box) {
|
2017-08-24 16:53:11 +02:00
|
|
|
assert(cur->state->layout);
|
2017-08-24 20:35:55 +02:00
|
|
|
|
2022-08-30 18:18:42 +02:00
|
|
|
memset(box, 0, sizeof(*box));
|
|
|
|
|
|
|
|
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
2017-08-28 02:10:46 +02:00
|
|
|
if (c_device) {
|
2022-01-29 21:25:12 +01:00
|
|
|
if (!wlr_box_empty(&c_device->mapped_box)) {
|
|
|
|
*box = c_device->mapped_box;
|
2022-01-31 18:55:52 +01:00
|
|
|
return;
|
2022-08-30 18:18:42 +02:00
|
|
|
}
|
|
|
|
if (c_device->mapped_output) {
|
2022-01-29 21:06:09 +01:00
|
|
|
wlr_output_layout_get_box(cur->state->layout,
|
|
|
|
c_device->mapped_output, box);
|
2022-01-31 18:55:52 +01:00
|
|
|
return;
|
2017-08-28 02:10:46 +02:00
|
|
|
}
|
2017-08-24 20:35:55 +02:00
|
|
|
}
|
|
|
|
|
2022-01-29 21:25:12 +01:00
|
|
|
if (!wlr_box_empty(&cur->state->mapped_box)) {
|
|
|
|
*box = cur->state->mapped_box;
|
2022-08-30 18:18:42 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (cur->state->mapped_output) {
|
2022-01-29 21:06:09 +01:00
|
|
|
wlr_output_layout_get_box(cur->state->layout,
|
|
|
|
cur->state->mapped_output, box);
|
2022-08-30 18:18:42 +02:00
|
|
|
return;
|
2017-08-24 16:42:05 +02:00
|
|
|
}
|
2017-08-27 23:35:12 +02:00
|
|
|
}
|
2017-08-20 22:02:39 +02:00
|
|
|
|
2017-08-28 02:10:46 +02:00
|
|
|
bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
2018-04-27 18:26:33 +02:00
|
|
|
double lx, double ly) {
|
2017-08-27 23:35:12 +02:00
|
|
|
assert(cur->state->layout);
|
|
|
|
|
2018-04-27 18:26:33 +02:00
|
|
|
bool result = false;
|
2022-01-29 21:06:09 +01:00
|
|
|
struct wlr_box mapping;
|
|
|
|
get_mapping(cur, dev, &mapping);
|
|
|
|
if (!wlr_box_empty(&mapping)) {
|
|
|
|
result = wlr_box_contains_point(&mapping, lx, ly);
|
2018-04-27 18:26:33 +02:00
|
|
|
} else {
|
|
|
|
result = wlr_output_layout_contains_point(cur->state->layout, NULL,
|
|
|
|
lx, ly);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
cursor_warp_unchecked(cur, lx, ly);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 02:10:46 +02:00
|
|
|
return result;
|
|
|
|
}
|
2017-08-24 16:11:57 +02:00
|
|
|
|
2018-08-10 18:19:16 +02:00
|
|
|
void wlr_cursor_warp_closest(struct wlr_cursor *cur,
|
2018-04-27 18:26:33 +02:00
|
|
|
struct wlr_input_device *dev, double lx, double ly) {
|
2022-01-29 21:06:09 +01:00
|
|
|
struct wlr_box mapping;
|
|
|
|
get_mapping(cur, dev, &mapping);
|
|
|
|
if (!wlr_box_empty(&mapping)) {
|
|
|
|
wlr_box_closest_point(&mapping, lx, ly, &lx, &ly);
|
2022-09-20 20:51:39 +02:00
|
|
|
} else if (!wl_list_empty(&cur->state->layout->outputs)) {
|
2018-04-27 18:26:33 +02:00
|
|
|
wlr_output_layout_closest_point(cur->state->layout, NULL, lx, ly,
|
|
|
|
&lx, &ly);
|
2022-09-20 20:51:39 +02:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* There is no mapping box for the input device and the
|
|
|
|
* output layout is empty. This can happen for example
|
|
|
|
* when external monitors are turned off/disconnected.
|
|
|
|
* In this case, all (x,y) points are equally invalid,
|
|
|
|
* so leave the cursor in its current location (better
|
|
|
|
* from a user standpoint than warping it to (0,0)).
|
|
|
|
*/
|
|
|
|
return;
|
2018-04-27 18:26:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cursor_warp_unchecked(cur, lx, ly);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_cursor_absolute_to_layout_coords(struct wlr_cursor *cur,
|
|
|
|
struct wlr_input_device *dev, double x, double y,
|
|
|
|
double *lx, double *ly) {
|
2017-08-28 02:10:46 +02:00
|
|
|
assert(cur->state->layout);
|
2017-08-24 15:18:42 +02:00
|
|
|
|
2022-01-29 21:06:09 +01:00
|
|
|
struct wlr_box mapping;
|
|
|
|
get_mapping(cur, dev, &mapping);
|
|
|
|
if (wlr_box_empty(&mapping)) {
|
|
|
|
wlr_output_layout_get_box(cur->state->layout, NULL, &mapping);
|
2017-08-24 16:42:05 +02:00
|
|
|
}
|
|
|
|
|
2022-01-29 21:06:09 +01:00
|
|
|
*lx = !isnan(x) ? mapping.width * x + mapping.x : cur->x;
|
|
|
|
*ly = !isnan(y) ? mapping.height * y + mapping.y : cur->y;
|
2018-04-27 18:26:33 +02:00
|
|
|
}
|
2017-08-27 23:35:12 +02:00
|
|
|
|
2018-04-27 18:26:33 +02:00
|
|
|
void wlr_cursor_warp_absolute(struct wlr_cursor *cur,
|
|
|
|
struct wlr_input_device *dev, double x, double y) {
|
|
|
|
assert(cur->state->layout);
|
|
|
|
|
|
|
|
double lx, ly;
|
|
|
|
wlr_cursor_absolute_to_layout_coords(cur, dev, x, y, &lx, &ly);
|
|
|
|
|
2018-08-10 18:19:16 +02:00
|
|
|
wlr_cursor_warp_closest(cur, dev, lx, ly);
|
2017-08-24 16:42:05 +02:00
|
|
|
}
|
|
|
|
|
2017-08-24 20:35:55 +02:00
|
|
|
void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
|
|
|
double delta_x, double delta_y) {
|
2017-08-24 16:42:05 +02:00
|
|
|
assert(cur->state->layout);
|
|
|
|
|
2018-04-27 18:26:33 +02:00
|
|
|
double lx = !isnan(delta_x) ? cur->x + delta_x : cur->x;
|
|
|
|
double ly = !isnan(delta_y) ? cur->y + delta_y : cur->y;
|
2017-08-26 17:55:24 +02:00
|
|
|
|
2018-08-10 18:19:16 +02:00
|
|
|
wlr_cursor_warp_closest(cur, dev, lx, ly);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 09:09:21 +01:00
|
|
|
void wlr_cursor_set_image(struct wlr_cursor *cur, const uint8_t *pixels,
|
|
|
|
int32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x,
|
2017-12-15 01:00:03 +01:00
|
|
|
int32_t hotspot_y, float scale) {
|
2017-10-29 11:20:11 +01:00
|
|
|
struct wlr_cursor_output_cursor *output_cursor;
|
|
|
|
wl_list_for_each(output_cursor, &cur->state->output_cursors, link) {
|
2017-12-15 01:00:03 +01:00
|
|
|
float output_scale = output_cursor->output_cursor->output->scale;
|
|
|
|
if (scale > 0 && output_scale != scale) {
|
2017-11-11 17:27:44 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-10-29 11:20:11 +01:00
|
|
|
wlr_output_cursor_set_image(output_cursor->output_cursor, pixels,
|
|
|
|
stride, width, height, hotspot_x, hotspot_y);
|
|
|
|
}
|
2017-10-29 09:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_cursor_set_surface(struct wlr_cursor *cur, struct wlr_surface *surface,
|
|
|
|
int32_t hotspot_x, int32_t hotspot_y) {
|
2017-10-29 11:20:11 +01:00
|
|
|
struct wlr_cursor_output_cursor *output_cursor;
|
|
|
|
wl_list_for_each(output_cursor, &cur->state->output_cursors, link) {
|
|
|
|
wlr_output_cursor_set_surface(output_cursor->output_cursor, surface,
|
|
|
|
hotspot_x, hotspot_y);
|
|
|
|
}
|
2017-10-29 09:09:21 +01:00
|
|
|
}
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
static void handle_pointer_motion(struct wl_listener *listener, void *data) {
|
2022-06-27 22:56:02 +02:00
|
|
|
struct wlr_pointer_motion_event *event = data;
|
2017-08-29 16:31:39 +02:00
|
|
|
struct wlr_cursor_device *device =
|
|
|
|
wl_container_of(listener, device, motion);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.motion, event);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 16:08:35 +02:00
|
|
|
static void apply_output_transform(double *x, double *y,
|
|
|
|
enum wl_output_transform transform) {
|
2018-09-01 01:36:38 +02:00
|
|
|
double dx = 0.0, dy = 0.0;
|
2018-04-30 16:08:35 +02:00
|
|
|
double width = 1.0, height = 1.0;
|
|
|
|
|
|
|
|
switch (transform) {
|
|
|
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
|
|
|
dx = *x;
|
|
|
|
dy = *y;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_90:
|
2020-02-09 15:57:40 +01:00
|
|
|
dx = height - *y;
|
|
|
|
dy = *x;
|
2018-04-30 16:08:35 +02:00
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_180:
|
|
|
|
dx = width - *x;
|
|
|
|
dy = height - *y;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_270:
|
2020-02-09 15:57:40 +01:00
|
|
|
dx = *y;
|
|
|
|
dy = width - *x;
|
2018-04-30 16:08:35 +02:00
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
|
|
|
dx = width - *x;
|
|
|
|
dy = *y;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
2020-02-09 15:57:40 +01:00
|
|
|
dx = *y;
|
|
|
|
dy = *x;
|
2018-04-30 16:08:35 +02:00
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
|
|
|
dx = *x;
|
|
|
|
dy = height - *y;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
2020-02-09 15:57:40 +01:00
|
|
|
dx = height - *y;
|
|
|
|
dy = width - *x;
|
2018-04-30 16:08:35 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
*x = dx;
|
|
|
|
*y = dy;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct wlr_output *get_mapped_output(struct wlr_cursor_device *cursor_device) {
|
|
|
|
if (cursor_device->mapped_output) {
|
|
|
|
return cursor_device->mapped_output;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wlr_cursor *cursor = cursor_device->cursor;
|
|
|
|
assert(cursor);
|
|
|
|
if (cursor->state->mapped_output) {
|
|
|
|
return cursor->state->mapped_output;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-29 16:31:39 +02:00
|
|
|
static void handle_pointer_motion_absolute(struct wl_listener *listener,
|
|
|
|
void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_motion_absolute_event *event = data;
|
2017-08-29 16:31:39 +02:00
|
|
|
struct wlr_cursor_device *device =
|
|
|
|
wl_container_of(listener, device, motion_absolute);
|
2018-04-30 16:08:35 +02:00
|
|
|
|
|
|
|
struct wlr_output *output =
|
|
|
|
get_mapped_output(device);
|
|
|
|
if (output) {
|
|
|
|
apply_output_transform(&event->x, &event->y, output->transform);
|
|
|
|
}
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.motion_absolute, event);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_button(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_button_event *event = data;
|
2017-08-29 16:31:39 +02:00
|
|
|
struct wlr_cursor_device *device =
|
|
|
|
wl_container_of(listener, device, button);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.button, event);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_axis(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_axis_event *event = data;
|
2017-08-20 22:02:39 +02:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, axis);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.axis, event);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
2019-01-26 11:04:05 +01:00
|
|
|
static void handle_pointer_frame(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, frame);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.frame, device->cursor);
|
2019-01-26 11:04:05 +01:00
|
|
|
}
|
|
|
|
|
2019-01-25 23:51:38 +01:00
|
|
|
static void handle_pointer_swipe_begin(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_swipe_begin_event *event = data;
|
2019-01-25 23:51:38 +01:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, swipe_begin);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.swipe_begin, event);
|
2019-01-25 23:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_swipe_update(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_swipe_update_event *event = data;
|
2019-01-25 23:51:38 +01:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, swipe_update);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.swipe_update, event);
|
2019-01-25 23:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_swipe_end(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_swipe_end_event *event = data;
|
2019-01-25 23:51:38 +01:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, swipe_end);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.swipe_end, event);
|
2019-01-25 23:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_pinch_begin(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_pinch_begin_event *event = data;
|
2019-01-25 23:51:38 +01:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, pinch_begin);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.pinch_begin, event);
|
2019-01-25 23:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_pinch_update(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_pinch_update_event *event = data;
|
2019-01-25 23:51:38 +01:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, pinch_update);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.pinch_update, event);
|
2019-01-25 23:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_pinch_end(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_pinch_end_event *event = data;
|
2019-01-25 23:51:38 +01:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, pinch_end);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.pinch_end, event);
|
2019-01-25 23:51:38 +01:00
|
|
|
}
|
|
|
|
|
2021-07-12 19:51:40 +02:00
|
|
|
static void handle_pointer_hold_begin(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_hold_begin_event *event = data;
|
2021-07-12 19:51:40 +02:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, hold_begin);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.hold_begin, event);
|
2021-07-12 19:51:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_pointer_hold_end(struct wl_listener *listener, void *data) {
|
2022-03-09 20:52:27 +01:00
|
|
|
struct wlr_pointer_hold_end_event *event = data;
|
2021-07-12 19:51:40 +02:00
|
|
|
struct wlr_cursor_device *device = wl_container_of(listener, device, hold_end);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.hold_end, event);
|
2021-07-12 19:51:40 +02:00
|
|
|
}
|
|
|
|
|
2017-08-27 17:34:25 +02:00
|
|
|
static void handle_touch_up(struct wl_listener *listener, void *data) {
|
2022-03-09 22:01:14 +01:00
|
|
|
struct wlr_touch_up_event *event = data;
|
2017-08-27 17:34:25 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, touch_up);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.touch_up, event);
|
2017-08-27 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
2022-03-09 22:01:14 +01:00
|
|
|
struct wlr_touch_down_event *event = data;
|
2017-08-27 17:34:25 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, touch_down);
|
2018-04-30 16:08:35 +02:00
|
|
|
|
|
|
|
struct wlr_output *output =
|
|
|
|
get_mapped_output(device);
|
|
|
|
if (output) {
|
|
|
|
apply_output_transform(&event->x, &event->y, output->transform);
|
|
|
|
}
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.touch_down, event);
|
2017-08-27 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
2022-03-09 22:01:14 +01:00
|
|
|
struct wlr_touch_motion_event *event = data;
|
2017-08-27 17:34:25 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, touch_motion);
|
2018-04-30 16:08:35 +02:00
|
|
|
|
|
|
|
struct wlr_output *output =
|
|
|
|
get_mapped_output(device);
|
|
|
|
if (output) {
|
|
|
|
apply_output_transform(&event->x, &event->y, output->transform);
|
|
|
|
}
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.touch_motion, event);
|
2017-08-27 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_touch_cancel(struct wl_listener *listener, void *data) {
|
2022-03-09 22:01:14 +01:00
|
|
|
struct wlr_touch_cancel_event *event = data;
|
2017-08-27 17:34:25 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, touch_cancel);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.touch_cancel, event);
|
2017-08-27 17:34:25 +02:00
|
|
|
}
|
|
|
|
|
2021-06-30 11:40:15 +02:00
|
|
|
static void handle_touch_frame(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_cursor_device *device =
|
|
|
|
wl_container_of(listener, device, touch_frame);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.touch_frame, NULL);
|
2021-06-30 11:40:15 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 14:42:39 +02:00
|
|
|
static void handle_tablet_tool_tip(struct wl_listener *listener, void *data) {
|
2022-03-09 21:43:28 +01:00
|
|
|
struct wlr_tablet_tool_tip_event *event = data;
|
2017-08-28 14:42:39 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, tablet_tool_tip);
|
2018-04-30 16:08:35 +02:00
|
|
|
|
|
|
|
struct wlr_output *output =
|
|
|
|
get_mapped_output(device);
|
|
|
|
if (output) {
|
|
|
|
apply_output_transform(&event->x, &event->y, output->transform);
|
|
|
|
}
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.tablet_tool_tip, event);
|
2017-08-28 14:42:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) {
|
2022-03-09 21:43:28 +01:00
|
|
|
struct wlr_tablet_tool_axis_event *event = data;
|
2017-08-28 14:42:39 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, tablet_tool_axis);
|
2018-04-30 16:08:35 +02:00
|
|
|
|
2020-04-27 09:13:01 +02:00
|
|
|
struct wlr_output *output = get_mapped_output(device);
|
2018-04-30 16:08:35 +02:00
|
|
|
if (output) {
|
2020-04-27 09:13:01 +02:00
|
|
|
// In the case that only one axis received an event, rotating the input can
|
|
|
|
// cause the change to actually happen on the other axis, as far as clients
|
|
|
|
// are concerned.
|
|
|
|
//
|
|
|
|
// Here, we feed apply_output_transform NAN on the axis that didn't change,
|
|
|
|
// and remap the axes flags based on whether it returns NAN itself.
|
|
|
|
double x = event->updated_axes & WLR_TABLET_TOOL_AXIS_X ? event->x : NAN;
|
|
|
|
double y = event->updated_axes & WLR_TABLET_TOOL_AXIS_Y ? event->y : NAN;
|
|
|
|
|
|
|
|
apply_output_transform(&x, &y, output->transform);
|
|
|
|
|
|
|
|
event->updated_axes &= ~(WLR_TABLET_TOOL_AXIS_X | WLR_TABLET_TOOL_AXIS_Y);
|
|
|
|
event->x = event->y = 0;
|
|
|
|
|
|
|
|
if (!isnan(x)) {
|
|
|
|
event->updated_axes |= WLR_TABLET_TOOL_AXIS_X;
|
|
|
|
event->x = x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isnan(y)) {
|
|
|
|
event->updated_axes |= WLR_TABLET_TOOL_AXIS_Y;
|
|
|
|
event->y = y;
|
|
|
|
}
|
2018-04-30 16:08:35 +02:00
|
|
|
}
|
2020-04-27 09:13:01 +02:00
|
|
|
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.tablet_tool_axis, event);
|
2017-08-28 14:42:39 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 16:31:39 +02:00
|
|
|
static void handle_tablet_tool_button(struct wl_listener *listener,
|
|
|
|
void *data) {
|
2022-03-09 21:43:28 +01:00
|
|
|
struct wlr_tablet_tool_button *event = data;
|
2017-08-28 14:42:39 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, tablet_tool_button);
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.tablet_tool_button, event);
|
2017-08-28 14:42:39 +02:00
|
|
|
}
|
|
|
|
|
2017-08-29 16:31:39 +02:00
|
|
|
static void handle_tablet_tool_proximity(struct wl_listener *listener,
|
|
|
|
void *data) {
|
2022-03-09 21:43:28 +01:00
|
|
|
struct wlr_tablet_tool_proximity_event *event = data;
|
2017-08-28 14:42:39 +02:00
|
|
|
struct wlr_cursor_device *device;
|
|
|
|
device = wl_container_of(listener, device, tablet_tool_proximity);
|
2018-04-30 16:08:35 +02:00
|
|
|
|
|
|
|
struct wlr_output *output =
|
|
|
|
get_mapped_output(device);
|
|
|
|
if (output) {
|
|
|
|
apply_output_transform(&event->x, &event->y, output->transform);
|
|
|
|
}
|
2022-08-18 13:16:16 +02:00
|
|
|
wl_signal_emit_mutable(&device->cursor->events.tablet_tool_proximity, event);
|
2017-08-28 14:42:39 +02:00
|
|
|
}
|
|
|
|
|
2017-08-28 16:29:53 +02:00
|
|
|
static void handle_device_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_cursor_device *c_device;
|
|
|
|
c_device = wl_container_of(listener, c_device, destroy);
|
|
|
|
wlr_cursor_detach_input_device(c_device->cursor, c_device->device);
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
static struct wlr_cursor_device *cursor_device_create(
|
2017-09-05 23:45:05 +02:00
|
|
|
struct wlr_cursor *cursor, struct wlr_input_device *device) {
|
|
|
|
struct wlr_cursor_device *c_device =
|
|
|
|
calloc(1, sizeof(struct wlr_cursor_device));
|
|
|
|
if (!c_device) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate wlr_cursor_device");
|
2017-09-05 23:45:05 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_device->cursor = cursor;
|
|
|
|
c_device->device = device;
|
|
|
|
|
|
|
|
// listen to events
|
|
|
|
wl_signal_add(&device->events.destroy, &c_device->destroy);
|
|
|
|
c_device->destroy.notify = handle_device_destroy;
|
|
|
|
|
|
|
|
if (device->type == WLR_INPUT_DEVICE_POINTER) {
|
2022-06-20 16:57:29 +02:00
|
|
|
struct wlr_pointer *pointer = wlr_pointer_from_input_device(device);
|
|
|
|
|
|
|
|
wl_signal_add(&pointer->events.motion, &c_device->motion);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->motion.notify = handle_pointer_motion;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.motion_absolute,
|
2017-09-05 23:45:05 +02:00
|
|
|
&c_device->motion_absolute);
|
|
|
|
c_device->motion_absolute.notify = handle_pointer_motion_absolute;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.button, &c_device->button);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->button.notify = handle_pointer_button;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.axis, &c_device->axis);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->axis.notify = handle_pointer_axis;
|
2019-01-26 11:04:05 +01:00
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.frame, &c_device->frame);
|
2019-01-26 11:04:05 +01:00
|
|
|
c_device->frame.notify = handle_pointer_frame;
|
2019-01-25 23:51:38 +01:00
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.swipe_begin, &c_device->swipe_begin);
|
2019-01-25 23:51:38 +01:00
|
|
|
c_device->swipe_begin.notify = handle_pointer_swipe_begin;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.swipe_update, &c_device->swipe_update);
|
2019-01-25 23:51:38 +01:00
|
|
|
c_device->swipe_update.notify = handle_pointer_swipe_update;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.swipe_end, &c_device->swipe_end);
|
2019-01-25 23:51:38 +01:00
|
|
|
c_device->swipe_end.notify = handle_pointer_swipe_end;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.pinch_begin, &c_device->pinch_begin);
|
2019-01-25 23:51:38 +01:00
|
|
|
c_device->pinch_begin.notify = handle_pointer_pinch_begin;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.pinch_update, &c_device->pinch_update);
|
2019-01-25 23:51:38 +01:00
|
|
|
c_device->pinch_update.notify = handle_pointer_pinch_update;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.pinch_end, &c_device->pinch_end);
|
2019-01-25 23:51:38 +01:00
|
|
|
c_device->pinch_end.notify = handle_pointer_pinch_end;
|
2021-07-12 19:51:40 +02:00
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.hold_begin, &c_device->hold_begin);
|
2021-07-12 19:51:40 +02:00
|
|
|
c_device->hold_begin.notify = handle_pointer_hold_begin;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&pointer->events.hold_end, &c_device->hold_end);
|
2021-07-12 19:51:40 +02:00
|
|
|
c_device->hold_end.notify = handle_pointer_hold_end;
|
2017-09-05 23:45:05 +02:00
|
|
|
} else if (device->type == WLR_INPUT_DEVICE_TOUCH) {
|
2022-06-20 16:57:29 +02:00
|
|
|
struct wlr_touch *touch = wlr_touch_from_input_device(device);
|
|
|
|
|
|
|
|
wl_signal_add(&touch->events.motion, &c_device->touch_motion);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->touch_motion.notify = handle_touch_motion;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&touch->events.down, &c_device->touch_down);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->touch_down.notify = handle_touch_down;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&touch->events.up, &c_device->touch_up);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->touch_up.notify = handle_touch_up;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&touch->events.cancel, &c_device->touch_cancel);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->touch_cancel.notify = handle_touch_cancel;
|
2021-06-30 11:40:15 +02:00
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&touch->events.frame, &c_device->touch_frame);
|
2021-06-30 11:40:15 +02:00
|
|
|
c_device->touch_frame.notify = handle_touch_frame;
|
2017-09-05 23:45:05 +02:00
|
|
|
} else if (device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
2022-06-20 16:57:29 +02:00
|
|
|
struct wlr_tablet *tablet = wlr_tablet_from_input_device(device);
|
|
|
|
|
|
|
|
wl_signal_add(&tablet->events.tip, &c_device->tablet_tool_tip);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->tablet_tool_tip.notify = handle_tablet_tool_tip;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&tablet->events.proximity,
|
2017-09-05 23:45:05 +02:00
|
|
|
&c_device->tablet_tool_proximity);
|
|
|
|
c_device->tablet_tool_proximity.notify = handle_tablet_tool_proximity;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&tablet->events.axis, &c_device->tablet_tool_axis);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->tablet_tool_axis.notify = handle_tablet_tool_axis;
|
|
|
|
|
2022-06-20 16:57:29 +02:00
|
|
|
wl_signal_add(&tablet->events.button, &c_device->tablet_tool_button);
|
2017-09-05 23:45:05 +02:00
|
|
|
c_device->tablet_tool_button.notify = handle_tablet_tool_button;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_insert(&cursor->state->devices, &c_device->link);
|
|
|
|
|
|
|
|
return c_device;
|
|
|
|
}
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
void wlr_cursor_attach_input_device(struct wlr_cursor *cur,
|
|
|
|
struct wlr_input_device *dev) {
|
|
|
|
if (dev->type != WLR_INPUT_DEVICE_POINTER &&
|
|
|
|
dev->type != WLR_INPUT_DEVICE_TOUCH &&
|
|
|
|
dev->type != WLR_INPUT_DEVICE_TABLET_TOOL) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "only device types of pointer, touch or tablet tool"
|
2017-08-27 17:34:25 +02:00
|
|
|
"are supported");
|
2017-08-20 22:02:39 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// make sure it is not already attached
|
|
|
|
struct wlr_cursor_device *_dev;
|
|
|
|
wl_list_for_each(_dev, &cur->state->devices, link) {
|
|
|
|
if (_dev->device == dev) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
cursor_device_create(cur, dev);
|
2017-09-05 23:45:05 +02:00
|
|
|
}
|
2017-08-28 16:29:53 +02:00
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
void wlr_cursor_detach_input_device(struct wlr_cursor *cur,
|
|
|
|
struct wlr_input_device *dev) {
|
2017-09-05 23:45:05 +02:00
|
|
|
struct wlr_cursor_device *c_device, *tmp = NULL;
|
|
|
|
wl_list_for_each_safe(c_device, tmp, &cur->state->devices, link) {
|
|
|
|
if (c_device->device == dev) {
|
2018-04-26 00:51:00 +02:00
|
|
|
cursor_device_destroy(c_device);
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:48:28 +02:00
|
|
|
static void handle_layout_destroy(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_cursor_state *state =
|
2018-01-22 09:29:52 +01:00
|
|
|
wl_container_of(listener, state, layout_destroy);
|
2018-04-26 00:51:00 +02:00
|
|
|
cursor_detach_output_layout(state->cursor);
|
2017-09-05 13:48:28 +02:00
|
|
|
}
|
|
|
|
|
2017-10-29 11:20:11 +01:00
|
|
|
static void handle_layout_output_destroy(struct wl_listener *listener,
|
|
|
|
void *data) {
|
|
|
|
struct wlr_cursor_output_cursor *output_cursor =
|
|
|
|
wl_container_of(listener, output_cursor, layout_output_destroy);
|
|
|
|
//struct wlr_output_layout_output *l_output = data;
|
2017-10-31 14:58:58 +01:00
|
|
|
output_cursor_destroy(output_cursor);
|
2017-10-29 11:20:11 +01:00
|
|
|
}
|
|
|
|
|
2017-10-29 20:03:56 +01:00
|
|
|
static void layout_add(struct wlr_cursor_state *state,
|
|
|
|
struct wlr_output_layout_output *l_output) {
|
2018-10-19 14:50:35 +02:00
|
|
|
struct wlr_cursor_output_cursor *output_cursor;
|
|
|
|
wl_list_for_each(output_cursor, &state->output_cursors, link) {
|
|
|
|
if (output_cursor->output_cursor->output == l_output->output) {
|
|
|
|
return; // already added
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output_cursor = calloc(1, sizeof(struct wlr_cursor_output_cursor));
|
2017-10-29 11:20:11 +01:00
|
|
|
if (output_cursor == NULL) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Failed to allocate wlr_cursor_output_cursor");
|
2017-10-29 11:20:11 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
output_cursor->cursor = state->cursor;
|
|
|
|
|
|
|
|
output_cursor->output_cursor = wlr_output_cursor_create(l_output->output);
|
|
|
|
if (output_cursor->output_cursor == NULL) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Failed to create wlr_output_cursor");
|
2017-10-29 11:20:11 +01:00
|
|
|
free(output_cursor);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_cursor->layout_output_destroy.notify = handle_layout_output_destroy;
|
|
|
|
wl_signal_add(&l_output->events.destroy,
|
|
|
|
&output_cursor->layout_output_destroy);
|
|
|
|
|
2017-10-31 14:58:58 +01:00
|
|
|
wl_list_insert(&state->output_cursors, &output_cursor->link);
|
2017-10-29 11:20:11 +01:00
|
|
|
}
|
|
|
|
|
2017-10-29 20:03:56 +01:00
|
|
|
static void handle_layout_add(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_cursor_state *state =
|
|
|
|
wl_container_of(listener, state, layout_add);
|
|
|
|
struct wlr_output_layout_output *l_output = data;
|
|
|
|
layout_add(state, l_output);
|
|
|
|
}
|
|
|
|
|
2017-09-05 13:48:28 +02:00
|
|
|
static void handle_layout_change(struct wl_listener *listener, void *data) {
|
|
|
|
struct wlr_cursor_state *state =
|
|
|
|
wl_container_of(listener, state, layout_change);
|
|
|
|
struct wlr_output_layout *layout = data;
|
2017-10-29 11:20:11 +01:00
|
|
|
|
2017-09-05 13:48:28 +02:00
|
|
|
if (!wlr_output_layout_contains_point(layout, NULL, state->cursor->x,
|
2022-09-20 20:51:39 +02:00
|
|
|
state->cursor->y) && !wl_list_empty(&layout->outputs)) {
|
2017-09-05 13:48:28 +02:00
|
|
|
// the output we were on has gone away so go to the closest boundary
|
2022-09-20 20:51:39 +02:00
|
|
|
// point (unless the layout is empty; compare warp_closest())
|
2017-09-05 13:48:28 +02:00
|
|
|
double x, y;
|
|
|
|
wlr_output_layout_closest_point(layout, NULL, state->cursor->x,
|
|
|
|
state->cursor->y, &x, &y);
|
|
|
|
|
2018-04-26 00:51:00 +02:00
|
|
|
cursor_warp_unchecked(state->cursor, x, y);
|
2017-09-05 13:48:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
void wlr_cursor_attach_output_layout(struct wlr_cursor *cur,
|
|
|
|
struct wlr_output_layout *l) {
|
2018-04-26 00:51:00 +02:00
|
|
|
cursor_detach_output_layout(cur);
|
2017-09-05 13:48:28 +02:00
|
|
|
|
|
|
|
if (l == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-29 11:20:11 +01:00
|
|
|
wl_signal_add(&l->events.add, &cur->state->layout_add);
|
|
|
|
cur->state->layout_add.notify = handle_layout_add;
|
2017-09-05 13:48:28 +02:00
|
|
|
wl_signal_add(&l->events.change, &cur->state->layout_change);
|
|
|
|
cur->state->layout_change.notify = handle_layout_change;
|
|
|
|
wl_signal_add(&l->events.destroy, &cur->state->layout_destroy);
|
|
|
|
cur->state->layout_destroy.notify = handle_layout_destroy;
|
|
|
|
|
2017-08-20 22:02:39 +02:00
|
|
|
cur->state->layout = l;
|
2017-10-29 20:03:56 +01:00
|
|
|
|
|
|
|
struct wlr_output_layout_output *l_output;
|
|
|
|
wl_list_for_each(l_output, &l->outputs, link) {
|
|
|
|
layout_add(cur->state, l_output);
|
|
|
|
}
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_cursor_map_to_output(struct wlr_cursor *cur,
|
|
|
|
struct wlr_output *output) {
|
2017-08-24 18:30:34 +02:00
|
|
|
cur->state->mapped_output = output;
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_cursor_map_input_to_output(struct wlr_cursor *cur,
|
|
|
|
struct wlr_input_device *dev, struct wlr_output *output) {
|
2017-08-24 20:35:55 +02:00
|
|
|
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
|
|
|
if (!c_device) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Cannot map device \"%s\" to output"
|
2021-11-28 17:56:09 +01:00
|
|
|
" (not found in this cursor)", dev->name);
|
2017-08-24 20:35:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
c_device->mapped_output = output;
|
2017-08-20 22:02:39 +02:00
|
|
|
}
|
2017-08-25 19:26:13 +02:00
|
|
|
|
2017-08-29 16:31:39 +02:00
|
|
|
void wlr_cursor_map_to_region(struct wlr_cursor *cur,
|
2022-02-05 16:32:38 +01:00
|
|
|
const struct wlr_box *box) {
|
2022-08-30 18:18:42 +02:00
|
|
|
memset(&cur->state->mapped_box, 0, sizeof(cur->state->mapped_box));
|
|
|
|
|
2022-01-29 21:25:12 +01:00
|
|
|
if (box) {
|
|
|
|
if (wlr_box_empty(box)) {
|
|
|
|
wlr_log(WLR_ERROR, "cannot map cursor to an empty region");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cur->state->mapped_box = *box;
|
2017-08-28 02:10:46 +02:00
|
|
|
}
|
2017-08-25 19:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void wlr_cursor_map_input_to_region(struct wlr_cursor *cur,
|
2022-02-05 16:32:38 +01:00
|
|
|
struct wlr_input_device *dev, const struct wlr_box *box) {
|
2022-08-30 18:18:42 +02:00
|
|
|
memset(&cur->state->mapped_box, 0, sizeof(cur->state->mapped_box));
|
|
|
|
|
2017-08-25 19:26:13 +02:00
|
|
|
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
|
|
|
if (!c_device) {
|
2018-07-09 23:49:54 +02:00
|
|
|
wlr_log(WLR_ERROR, "Cannot map device \"%s\" to geometry (not found in"
|
2017-08-28 02:10:46 +02:00
|
|
|
"this cursor)", dev->name);
|
2017-08-25 19:26:13 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-08-28 02:10:46 +02:00
|
|
|
|
2022-01-29 21:25:12 +01:00
|
|
|
if (box) {
|
|
|
|
if (wlr_box_empty(box)) {
|
|
|
|
wlr_log(WLR_ERROR,
|
|
|
|
"cannot map device \"%s\" input to an empty region",
|
|
|
|
dev->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
c_device->mapped_box = *box;
|
|
|
|
}
|
2017-08-25 19:26:13 +02:00
|
|
|
}
|