|
|
@ -1,5 +1,6 @@
|
|
|
|
#include <assert.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <wlr/interfaces/wlr_pointer.h>
|
|
|
|
#include <wlr/types/wlr_seat.h>
|
|
|
|
#include <wlr/types/wlr_seat.h>
|
|
|
|
#include <wlr/types/wlr_virtual_pointer_v1.h>
|
|
|
|
#include <wlr/types/wlr_virtual_pointer_v1.h>
|
|
|
|
#include <wlr/types/wlr_pointer.h>
|
|
|
|
#include <wlr/types/wlr_pointer.h>
|
|
|
@ -7,17 +8,18 @@
|
|
|
|
#include "util/signal.h"
|
|
|
|
#include "util/signal.h"
|
|
|
|
#include "wlr-virtual-pointer-unstable-v1-protocol.h"
|
|
|
|
#include "wlr-virtual-pointer-unstable-v1-protocol.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void input_device_destroy(struct wlr_input_device *dev) {
|
|
|
|
static void pointer_destroy(struct wlr_pointer *pointer) {
|
|
|
|
struct wlr_virtual_pointer_v1 *pointer =
|
|
|
|
struct wlr_virtual_pointer_v1 *virtual_pointer =
|
|
|
|
(struct wlr_virtual_pointer_v1 *)dev;
|
|
|
|
(struct wlr_virtual_pointer_v1 *)pointer;
|
|
|
|
wl_resource_set_user_data(pointer->resource, NULL);
|
|
|
|
|
|
|
|
wlr_signal_emit_safe(&pointer->events.destroy, pointer);
|
|
|
|
wl_resource_set_user_data(virtual_pointer->resource, NULL);
|
|
|
|
wl_list_remove(&pointer->link);
|
|
|
|
wlr_signal_emit_safe(&virtual_pointer->events.destroy, virtual_pointer);
|
|
|
|
free(pointer);
|
|
|
|
wl_list_remove(&virtual_pointer->link);
|
|
|
|
|
|
|
|
free(virtual_pointer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct wlr_input_device_impl input_device_impl = {
|
|
|
|
static const struct wlr_pointer_impl pointer_impl = {
|
|
|
|
.destroy = input_device_destroy
|
|
|
|
.destroy = pointer_destroy,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const struct zwlr_virtual_pointer_v1_interface virtual_pointer_impl;
|
|
|
|
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) {
|
|
|
|
if (pointer == NULL) {
|
|
|
|
return;
|
|
|
|
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 = {
|
|
|
|
struct wlr_event_pointer_motion event = {
|
|
|
|
.device = wlr_dev,
|
|
|
|
.device = wlr_dev,
|
|
|
|
.time_msec = time,
|
|
|
|
.time_msec = time,
|
|
|
@ -46,7 +48,7 @@ static void virtual_pointer_motion(struct wl_client *client,
|
|
|
|
.unaccel_dx = wl_fixed_to_double(dx),
|
|
|
|
.unaccel_dx = wl_fixed_to_double(dx),
|
|
|
|
.unaccel_dy = wl_fixed_to_double(dy),
|
|
|
|
.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,
|
|
|
|
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) {
|
|
|
|
if (x_extent == 0 || y_extent == 0) {
|
|
|
|
return;
|
|
|
|
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 = {
|
|
|
|
struct wlr_event_pointer_motion_absolute event = {
|
|
|
|
.device = wlr_dev,
|
|
|
|
.device = wlr_dev,
|
|
|
|
.time_msec = time,
|
|
|
|
.time_msec = time,
|
|
|
@ -78,7 +80,7 @@ static void virtual_pointer_button(struct wl_client *client,
|
|
|
|
if (pointer == NULL) {
|
|
|
|
if (pointer == NULL) {
|
|
|
|
return;
|
|
|
|
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 = {
|
|
|
|
struct wlr_event_pointer_button event = {
|
|
|
|
.device = wlr_dev,
|
|
|
|
.device = wlr_dev,
|
|
|
|
.time_msec = time,
|
|
|
|
.time_msec = time,
|
|
|
@ -102,7 +104,7 @@ static void virtual_pointer_axis(struct wl_client *client,
|
|
|
|
if (pointer == NULL) {
|
|
|
|
if (pointer == NULL) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->input_device;
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->pointer.base;
|
|
|
|
pointer->axis = axis;
|
|
|
|
pointer->axis = axis;
|
|
|
|
pointer->axis_valid[pointer->axis] = true;
|
|
|
|
pointer->axis_valid[pointer->axis] = true;
|
|
|
|
pointer->axis_event[pointer->axis].device = wlr_dev;
|
|
|
|
pointer->axis_event[pointer->axis].device = wlr_dev;
|
|
|
@ -118,7 +120,7 @@ static void virtual_pointer_frame(struct wl_client *client,
|
|
|
|
if (pointer == NULL) {
|
|
|
|
if (pointer == NULL) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->input_device;
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->pointer.base;
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0;
|
|
|
|
for (size_t i = 0;
|
|
|
|
i < sizeof(pointer->axis_valid) / sizeof(pointer->axis_valid[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) {
|
|
|
|
if (pointer == NULL) {
|
|
|
|
return;
|
|
|
|
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].device = wlr_dev;
|
|
|
|
pointer->axis_event[pointer->axis].source = source;
|
|
|
|
pointer->axis_event[pointer->axis].source = source;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -166,7 +168,7 @@ static void virtual_pointer_axis_stop(struct wl_client *client,
|
|
|
|
if (pointer == NULL) {
|
|
|
|
if (pointer == NULL) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->input_device;
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->pointer.base;
|
|
|
|
pointer->axis = axis;
|
|
|
|
pointer->axis = axis;
|
|
|
|
pointer->axis_valid[pointer->axis] = true;
|
|
|
|
pointer->axis_valid[pointer->axis] = true;
|
|
|
|
pointer->axis_event[pointer->axis].device = wlr_dev;
|
|
|
|
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) {
|
|
|
|
if (pointer == NULL) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->input_device;
|
|
|
|
struct wlr_input_device *wlr_dev = &pointer->pointer.base;
|
|
|
|
pointer->axis = axis;
|
|
|
|
pointer->axis = axis;
|
|
|
|
pointer->axis_valid[pointer->axis] = true;
|
|
|
|
pointer->axis_valid[pointer->axis] = true;
|
|
|
|
pointer->axis_event[pointer->axis].device = wlr_dev;
|
|
|
|
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 =
|
|
|
|
struct wlr_virtual_pointer_v1 *pointer =
|
|
|
|
virtual_pointer_from_resource(resource);
|
|
|
|
virtual_pointer_from_resource(resource);
|
|
|
|
if (pointer != NULL) {
|
|
|
|
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;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct wlr_pointer *pointer = calloc(1, sizeof(struct wlr_pointer));
|
|
|
|
wlr_pointer_init(&virtual_pointer->pointer, &pointer_impl,
|
|
|
|
if (!pointer) {
|
|
|
|
"virtual-pointer");
|
|
|
|
wlr_log(WLR_ERROR, "Cannot allocate wlr_pointer");
|
|
|
|
|
|
|
|
free(virtual_pointer);
|
|
|
|
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wlr_pointer_init(pointer, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct wl_resource *pointer_resource = wl_resource_create(client,
|
|
|
|
struct wl_resource *pointer_resource = wl_resource_create(client,
|
|
|
|
&zwlr_virtual_pointer_v1_interface, wl_resource_get_version(resource),
|
|
|
|
&zwlr_virtual_pointer_v1_interface, wl_resource_get_version(resource),
|
|
|
|
id);
|
|
|
|
id);
|
|
|
|
if (!pointer_resource) {
|
|
|
|
if (!pointer_resource) {
|
|
|
|
free(pointer);
|
|
|
|
|
|
|
|
free(virtual_pointer);
|
|
|
|
free(virtual_pointer);
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
wl_client_post_no_memory(client);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -269,9 +264,6 @@ static void virtual_pointer_manager_create_virtual_pointer_with_output(
|
|
|
|
wl_resource_set_implementation(pointer_resource, &virtual_pointer_impl,
|
|
|
|
wl_resource_set_implementation(pointer_resource, &virtual_pointer_impl,
|
|
|
|
virtual_pointer, virtual_pointer_destroy_resource);
|
|
|
|
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 = {
|
|
|
|
struct wlr_virtual_pointer_v1_new_pointer_event event = {
|
|
|
|
.new_pointer = virtual_pointer,
|
|
|
|
.new_pointer = virtual_pointer,
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -287,7 +279,6 @@ static void virtual_pointer_manager_create_virtual_pointer_with_output(
|
|
|
|
event.suggested_output = wlr_output;
|
|
|
|
event.suggested_output = wlr_output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
virtual_pointer->input_device.pointer = pointer;
|
|
|
|
|
|
|
|
virtual_pointer->resource = pointer_resource;
|
|
|
|
virtual_pointer->resource = pointer_resource;
|
|
|
|
wl_signal_init(&virtual_pointer->events.destroy);
|
|
|
|
wl_signal_init(&virtual_pointer->events.destroy);
|
|
|
|
|
|
|
|
|
|
|
|