aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Zeni <simon@bl4ckb0ne.ca>2022-01-31 10:20:01 -0500
committerKirill Primak <vyivel@eclair.cafe>2022-02-21 17:11:32 +0000
commitd5480efc7a03641600df411dea93308e5edc8b27 (patch)
tree377e16476b41a7740a3cb88b5e3338da95eac6a3
parenta1978b1299952586a2fd016aab682c7fdbe735ee (diff)
types/wlr_pointer: add base wlr_input_device
wlr_pointer owns its wlr_input_device. It will be initialized when the pointer is initialized, and finished when the pointer is destroyed.
-rw-r--r--backend/libinput/pointer.c5
-rw-r--r--backend/wayland/seat.c8
-rw-r--r--backend/x11/input_device.c8
-rw-r--r--backend/x11/output.c11
-rw-r--r--include/backend/x11.h3
-rw-r--r--include/wlr/interfaces/wlr_pointer.h2
-rw-r--r--include/wlr/types/wlr_pointer.h2
-rw-r--r--include/wlr/types/wlr_virtual_pointer_v1.h3
-rw-r--r--types/wlr_pointer.c7
-rw-r--r--types/wlr_virtual_pointer_v1.c55
10 files changed, 53 insertions, 51 deletions
diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c
index 520f98dc..305c43d9 100644
--- a/backend/libinput/pointer.c
+++ b/backend/libinput/pointer.c
@@ -16,7 +16,10 @@ struct wlr_pointer *create_libinput_pointer(
wlr_log(WLR_ERROR, "Unable to allocate wlr_pointer");
return NULL;
}
- wlr_pointer_init(wlr_pointer, NULL);
+ const char *name = libinput_device_get_name(libinput_dev);
+ wlr_pointer_init(wlr_pointer, NULL, name);
+ wlr_pointer->base.vendor = libinput_device_get_id_vendor(libinput_dev);
+ wlr_pointer->base.product = libinput_device_get_id_product(libinput_dev);
return wlr_pointer;
}
diff --git a/backend/wayland/seat.c b/backend/wayland/seat.c
index 90a99950..633e585a 100644
--- a/backend/wayland/seat.c
+++ b/backend/wayland/seat.c
@@ -532,6 +532,10 @@ static void pointer_destroy(struct wlr_pointer *wlr_pointer) {
zwp_relative_pointer_v1_destroy(pointer->relative_pointer);
}
+ wlr_input_device_finish(&pointer->input_device->wlr_input_device);
+ wl_list_remove(&pointer->input_device->link);
+ free(pointer->input_device);
+
wl_list_remove(&pointer->output_destroy.link);
free(pointer);
}
@@ -705,7 +709,7 @@ static void pointer_handle_output_destroy(struct wl_listener *listener,
void *data) {
struct wlr_wl_pointer *pointer =
wl_container_of(listener, pointer, output_destroy);
- wlr_input_device_destroy(&pointer->input_device->wlr_input_device);
+ wlr_pointer_destroy(&pointer->wlr_pointer);
}
void create_wl_pointer(struct wlr_wl_seat *seat, struct wlr_wl_output *output) {
@@ -743,7 +747,7 @@ void create_wl_pointer(struct wlr_wl_seat *seat, struct wlr_wl_output *output) {
struct wlr_input_device *wlr_dev = &dev->wlr_input_device;
wlr_dev->pointer = &pointer->wlr_pointer;
wlr_dev->output_name = strdup(output->wlr_output.name);
- wlr_pointer_init(wlr_dev->pointer, &pointer_impl);
+ wlr_pointer_init(wlr_dev->pointer, &pointer_impl, wlr_dev->name);
if (backend->zwp_pointer_gestures_v1) {
uint32_t version = zwp_pointer_gestures_v1_get_version(
diff --git a/backend/x11/input_device.c b/backend/x11/input_device.c
index 94b70524..5ca3e956 100644
--- a/backend/x11/input_device.c
+++ b/backend/x11/input_device.c
@@ -33,7 +33,7 @@ static void send_key_event(struct wlr_x11_backend *x11, uint32_t key,
static void send_button_event(struct wlr_x11_output *output, uint32_t key,
enum wlr_button_state st, xcb_timestamp_t time) {
struct wlr_event_pointer_button ev = {
- .device = &output->pointer_dev,
+ .device = &output->pointer.base,
.time_msec = time,
.button = key,
.state = st,
@@ -45,7 +45,7 @@ static void send_button_event(struct wlr_x11_output *output, uint32_t key,
static void send_axis_event(struct wlr_x11_output *output, int32_t delta,
xcb_timestamp_t time) {
struct wlr_event_pointer_axis ev = {
- .device = &output->pointer_dev,
+ .device = &output->pointer.base,
.time_msec = time,
.source = WLR_AXIS_SOURCE_WHEEL,
.orientation = WLR_AXIS_ORIENTATION_VERTICAL,
@@ -60,7 +60,7 @@ static void send_axis_event(struct wlr_x11_output *output, int32_t delta,
static void send_pointer_position_event(struct wlr_x11_output *output,
int16_t x, int16_t y, xcb_timestamp_t time) {
struct wlr_event_pointer_motion_absolute ev = {
- .device = &output->pointer_dev,
+ .device = &output->pointer.base,
.time_msec = time,
.x = (double)x / output->wlr_output.width,
.y = (double)y / output->wlr_output.height,
@@ -339,6 +339,8 @@ bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) {
switch (wlr_dev->type) {
case WLR_INPUT_DEVICE_KEYBOARD:
return wlr_dev->keyboard->impl == &keyboard_impl;
+ case WLR_INPUT_DEVICE_POINTER:
+ return wlr_dev->pointer->impl == &pointer_impl;
default:
return wlr_dev->impl == &input_device_impl;
}
diff --git a/backend/x11/output.c b/backend/x11/output.c
index d500795f..19eb5d55 100644
--- a/backend/x11/output.c
+++ b/backend/x11/output.c
@@ -76,7 +76,7 @@ static void output_destroy(struct wlr_output *wlr_output) {
pixman_region32_fini(&output->exposed);
- wlr_input_device_destroy(&output->pointer_dev);
+ wlr_pointer_destroy(&output->pointer);
wlr_input_device_destroy(&output->touch_dev);
struct wlr_x11_buffer *buffer, *buffer_tmp;
@@ -573,11 +573,8 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
wlr_output_update_enabled(wlr_output, true);
- wlr_input_device_init(&output->pointer_dev, WLR_INPUT_DEVICE_POINTER,
- &input_device_impl, "X11 pointer");
- wlr_pointer_init(&output->pointer, &pointer_impl);
- output->pointer_dev.pointer = &output->pointer;
- output->pointer_dev.output_name = strdup(wlr_output->name);
+ wlr_pointer_init(&output->pointer, &pointer_impl, "x11-pointer");
+ output->pointer.base.output_name = strdup(wlr_output->name);
wlr_input_device_init(&output->touch_dev, WLR_INPUT_DEVICE_TOUCH,
&input_device_impl, "X11 touch");
@@ -587,7 +584,7 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
wl_list_init(&output->touchpoints);
wlr_signal_emit_safe(&x11->backend.events.new_output, wlr_output);
- wlr_signal_emit_safe(&x11->backend.events.new_input, &output->pointer_dev);
+ wlr_signal_emit_safe(&x11->backend.events.new_input, &output->pointer.base);
wlr_signal_emit_safe(&x11->backend.events.new_input, &output->touch_dev);
// Start the rendering loop by requesting the compositor to render a frame
diff --git a/include/backend/x11.h b/include/backend/x11.h
index b5c430fb..ee484654 100644
--- a/include/backend/x11.h
+++ b/include/backend/x11.h
@@ -18,8 +18,8 @@
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
#include <wlr/interfaces/wlr_output.h>
-#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_touch.h>
+#include <wlr/types/wlr_pointer.h>
#include <wlr/render/drm_format_set.h>
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
@@ -35,7 +35,6 @@ struct wlr_x11_output {
xcb_present_event_t present_event_id;
struct wlr_pointer pointer;
- struct wlr_input_device pointer_dev;
struct wlr_touch touch;
struct wlr_input_device touch_dev;
diff --git a/include/wlr/interfaces/wlr_pointer.h b/include/wlr/interfaces/wlr_pointer.h
index fd3ab102..e3950017 100644
--- a/include/wlr/interfaces/wlr_pointer.h
+++ b/include/wlr/interfaces/wlr_pointer.h
@@ -16,7 +16,7 @@ struct wlr_pointer_impl {
};
void wlr_pointer_init(struct wlr_pointer *pointer,
- const struct wlr_pointer_impl *impl);
+ const struct wlr_pointer_impl *impl, const char *name);
void wlr_pointer_destroy(struct wlr_pointer *pointer);
#endif
diff --git a/include/wlr/types/wlr_pointer.h b/include/wlr/types/wlr_pointer.h
index bcfb2ad3..a5850718 100644
--- a/include/wlr/types/wlr_pointer.h
+++ b/include/wlr/types/wlr_pointer.h
@@ -17,6 +17,8 @@
struct wlr_pointer_impl;
struct wlr_pointer {
+ struct wlr_input_device base;
+
const struct wlr_pointer_impl *impl;
struct {
diff --git a/include/wlr/types/wlr_virtual_pointer_v1.h b/include/wlr/types/wlr_virtual_pointer_v1.h
index ede9bebf..307d6158 100644
--- a/include/wlr/types/wlr_virtual_pointer_v1.h
+++ b/include/wlr/types/wlr_virtual_pointer_v1.h
@@ -11,7 +11,6 @@
#include <wayland-server-core.h>
#include <wayland-server-protocol.h>
-#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/interfaces/wlr_output.h>
@@ -28,7 +27,7 @@ struct wlr_virtual_pointer_manager_v1 {
};
struct wlr_virtual_pointer_v1 {
- struct wlr_input_device input_device;
+ struct wlr_pointer pointer;
struct wl_resource *resource;
/* Vertical and horizontal */
struct wlr_event_pointer_axis axis_event[2];
diff --git a/types/wlr_pointer.c b/types/wlr_pointer.c
index a6590e73..d6237c73 100644
--- a/types/wlr_pointer.c
+++ b/types/wlr_pointer.c
@@ -1,11 +1,15 @@
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
+#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/types/wlr_pointer.h>
void wlr_pointer_init(struct wlr_pointer *pointer,
- const struct wlr_pointer_impl *impl) {
+ const struct wlr_pointer_impl *impl, const char *name) {
+ wlr_input_device_init(&pointer->base, WLR_INPUT_DEVICE_POINTER, NULL, name);
+ pointer->base.pointer = pointer;
+
pointer->impl = impl;
wl_signal_init(&pointer->events.motion);
wl_signal_init(&pointer->events.motion_absolute);
@@ -26,6 +30,7 @@ void wlr_pointer_destroy(struct wlr_pointer *pointer) {
if (!pointer) {
return;
}
+ wlr_input_device_finish(&pointer->base);
if (pointer->impl && pointer->impl->destroy) {
pointer->impl->destroy(pointer);
} else {
diff --git a/types/wlr_virtual_pointer_v1.c b/types/wlr_virtual_pointer_v1.c
index bb1b31dd..6215bbff 100644
--- a/types/wlr_virtual_pointer_v1.c
+++ b/types/wlr_virtual_pointer_v1.c
@@ -1,5 +1,6 @@
#include <assert.h>
#include <stdlib.h>
+#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_virtual_pointer_v1.h>
#include <wlr/types/wlr_pointer.h>
@@ -7,17 +8,18 @@
#include "util/signal.h"
#include "wlr-virtual-pointer-unstable-v1-protocol.h"
-static void input_device_destroy(struct wlr_input_device *dev) {
- struct wlr_virtual_pointer_v1 *pointer =
- (struct wlr_virtual_pointer_v1 *)dev;
- wl_resource_set_user_data(pointer->resource, NULL);
- wlr_signal_emit_safe(&pointer->events.destroy, pointer);
- wl_list_remove(&pointer->link);
- free(pointer);
+static void pointer_destroy(struct wlr_pointer *pointer) {
+ struct wlr_virtual_pointer_v1 *virtual_pointer =
+ (struct wlr_virtual_pointer_v1 *)pointer;
+
+ wl_resource_set_user_data(virtual_pointer->resource, NULL);
+ wlr_signal_emit_safe(&virtual_pointer->events.destroy, virtual_pointer);
+ wl_list_remove(&virtual_pointer->link);
+ free(virtual_pointer);
}
-static const struct wlr_input_device_impl input_device_impl = {
- .destroy = input_device_destroy
+static const struct wlr_pointer_impl pointer_impl = {
+ .destroy = pointer_destroy,
};
static const struct zwlr_virtual_pointer_v1_interface virtual_pointer_impl;
@@ -37,7 +39,7 @@ static void virtual_pointer_motion(struct wl_client *client,
if (pointer == NULL) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
struct wlr_event_pointer_motion event = {
.device = wlr_dev,
.time_msec = time,
@@ -46,7 +48,7 @@ static void virtual_pointer_motion(struct wl_client *client,
.unaccel_dx = wl_fixed_to_double(dx),
.unaccel_dy = wl_fixed_to_double(dy),
};
- wlr_signal_emit_safe(&wlr_dev->pointer->events.motion, &event);
+ wlr_signal_emit_safe(&pointer->pointer.events.motion, &event);
}
static void virtual_pointer_motion_absolute(struct wl_client *client,
@@ -60,7 +62,7 @@ static void virtual_pointer_motion_absolute(struct wl_client *client,
if (x_extent == 0 || y_extent == 0) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
struct wlr_event_pointer_motion_absolute event = {
.device = wlr_dev,
.time_msec = time,
@@ -78,7 +80,7 @@ static void virtual_pointer_button(struct wl_client *client,
if (pointer == NULL) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
struct wlr_event_pointer_button event = {
.device = wlr_dev,
.time_msec = time,
@@ -102,7 +104,7 @@ static void virtual_pointer_axis(struct wl_client *client,
if (pointer == NULL) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
pointer->axis = axis;
pointer->axis_valid[pointer->axis] = true;
pointer->axis_event[pointer->axis].device = wlr_dev;
@@ -118,7 +120,7 @@ static void virtual_pointer_frame(struct wl_client *client,
if (pointer == NULL) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
for (size_t i = 0;
i < sizeof(pointer->axis_valid) / sizeof(pointer->axis_valid[0]);
@@ -148,7 +150,7 @@ static void virtual_pointer_axis_source(struct wl_client *client,
if (pointer == NULL) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
pointer->axis_event[pointer->axis].device = wlr_dev;
pointer->axis_event[pointer->axis].source = source;
}
@@ -166,7 +168,7 @@ static void virtual_pointer_axis_stop(struct wl_client *client,
if (pointer == NULL) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
pointer->axis = axis;
pointer->axis_valid[pointer->axis] = true;
pointer->axis_event[pointer->axis].device = wlr_dev;
@@ -190,7 +192,7 @@ static void virtual_pointer_axis_discrete(struct wl_client *client,
if (pointer == NULL) {
return;
}
- struct wlr_input_device *wlr_dev = &pointer->input_device;
+ struct wlr_input_device *wlr_dev = &pointer->pointer.base;
pointer->axis = axis;
pointer->axis_valid[pointer->axis] = true;
pointer->axis_event[pointer->axis].device = wlr_dev;
@@ -204,7 +206,7 @@ static void virtual_pointer_destroy_resource(struct wl_resource *resource) {
struct wlr_virtual_pointer_v1 *pointer =
virtual_pointer_from_resource(resource);
if (pointer != NULL) {
- wlr_input_device_destroy(&pointer->input_device);
+ wlr_pointer_destroy(&pointer->pointer);
}
}
@@ -247,20 +249,13 @@ static void virtual_pointer_manager_create_virtual_pointer_with_output(
return;
}
- struct wlr_pointer *pointer = calloc(1, sizeof(struct wlr_pointer));
- if (!pointer) {
- wlr_log(WLR_ERROR, "Cannot allocate wlr_pointer");
- free(virtual_pointer);
- wl_client_post_no_memory(client);
- return;
- }
- wlr_pointer_init(pointer, NULL);
+ wlr_pointer_init(&virtual_pointer->pointer, &pointer_impl,
+ "virtual-pointer");
struct wl_resource *pointer_resource = wl_resource_create(client,
&zwlr_virtual_pointer_v1_interface, wl_resource_get_version(resource),
id);
if (!pointer_resource) {
- free(pointer);
free(virtual_pointer);
wl_client_post_no_memory(client);
return;
@@ -269,9 +264,6 @@ static void virtual_pointer_manager_create_virtual_pointer_with_output(
wl_resource_set_implementation(pointer_resource, &virtual_pointer_impl,
virtual_pointer, virtual_pointer_destroy_resource);
- wlr_input_device_init(&virtual_pointer->input_device,
- WLR_INPUT_DEVICE_POINTER, &input_device_impl, "virtual pointer");
-
struct wlr_virtual_pointer_v1_new_pointer_event event = {
.new_pointer = virtual_pointer,
};
@@ -287,7 +279,6 @@ static void virtual_pointer_manager_create_virtual_pointer_with_output(
event.suggested_output = wlr_output;
}
- virtual_pointer->input_device.pointer = pointer;
virtual_pointer->resource = pointer_resource;
wl_signal_init(&virtual_pointer->events.destroy);