mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-25 16:42:26 +00:00
implement wlr_cursor_map_input_to_output
This commit is contained in:
parent
13e895d943
commit
98f4cdfccb
@ -30,6 +30,7 @@ void handle_pointer_motion(struct libinput_event *event,
|
||||
struct libinput_event_pointer *pevent =
|
||||
libinput_event_get_pointer_event(event);
|
||||
struct wlr_event_pointer_motion wlr_event = { 0 };
|
||||
wlr_event.device = wlr_dev;
|
||||
wlr_event.time_sec = libinput_event_pointer_get_time(pevent);
|
||||
wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent);
|
||||
wlr_event.delta_x = libinput_event_pointer_get_dx(pevent);
|
||||
@ -48,6 +49,7 @@ void handle_pointer_motion_abs(struct libinput_event *event,
|
||||
struct libinput_event_pointer *pevent =
|
||||
libinput_event_get_pointer_event(event);
|
||||
struct wlr_event_pointer_motion_absolute wlr_event = { 0 };
|
||||
wlr_event.device = wlr_dev;
|
||||
wlr_event.time_sec = libinput_event_pointer_get_time(pevent);
|
||||
wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent);
|
||||
wlr_event.x_mm = libinput_event_pointer_get_absolute_x(pevent);
|
||||
@ -67,6 +69,7 @@ void handle_pointer_button(struct libinput_event *event,
|
||||
struct libinput_event_pointer *pevent =
|
||||
libinput_event_get_pointer_event(event);
|
||||
struct wlr_event_pointer_button wlr_event = { 0 };
|
||||
wlr_event.device = wlr_dev;
|
||||
wlr_event.time_sec = libinput_event_pointer_get_time(pevent);
|
||||
wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent);
|
||||
wlr_event.button = libinput_event_pointer_get_button(pevent);
|
||||
@ -92,6 +95,7 @@ void handle_pointer_axis(struct libinput_event *event,
|
||||
struct libinput_event_pointer *pevent =
|
||||
libinput_event_get_pointer_event(event);
|
||||
struct wlr_event_pointer_axis wlr_event = { 0 };
|
||||
wlr_event.device = wlr_dev;
|
||||
wlr_event.time_sec = libinput_event_pointer_get_time(pevent);
|
||||
wlr_event.time_usec = libinput_event_pointer_get_time_usec(pevent);
|
||||
switch (libinput_event_pointer_get_axis_source(pevent)) {
|
||||
|
@ -51,6 +51,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
|
||||
wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window,
|
||||
&width, &height);
|
||||
struct wlr_event_pointer_motion_absolute wlr_event;
|
||||
wlr_event.device = dev;
|
||||
wlr_event.time_sec = time / 1000;
|
||||
wlr_event.time_usec = time * 1000;
|
||||
wlr_event.width_mm = width;
|
||||
@ -66,6 +67,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer,
|
||||
assert(dev && dev->pointer);
|
||||
|
||||
struct wlr_event_pointer_button wlr_event;
|
||||
wlr_event.device = dev;
|
||||
wlr_event.button = button;
|
||||
wlr_event.state = state;
|
||||
wlr_event.time_sec = time / 1000;
|
||||
@ -80,6 +82,7 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
|
||||
struct wlr_wl_pointer *wlr_wl_pointer = (struct wlr_wl_pointer *)dev->pointer;
|
||||
|
||||
struct wlr_event_pointer_axis wlr_event;
|
||||
wlr_event.device = dev;
|
||||
wlr_event.delta = value;
|
||||
wlr_event.orientation = axis;
|
||||
wlr_event.time_sec = time / 1000;
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include "shared.h"
|
||||
#include "cat.h"
|
||||
|
||||
struct sample_input_device {
|
||||
struct wlr_input_device *device;
|
||||
struct wl_list link;
|
||||
};
|
||||
|
||||
struct sample_state {
|
||||
struct compositor_state *compositor;
|
||||
struct example_config *config;
|
||||
@ -33,6 +38,7 @@ struct sample_state {
|
||||
float default_color[4];
|
||||
float clear_color[4];
|
||||
struct wlr_output_layout *layout;
|
||||
struct wl_list devices;
|
||||
|
||||
struct wl_listener cursor_motion;
|
||||
struct wl_listener cursor_motion_absolute;
|
||||
@ -63,6 +69,16 @@ static void handle_output_add(struct output_state *ostate) {
|
||||
sample->layout = configure_layout(sample->config, &ostate->compositor->outputs);
|
||||
wlr_cursor_attach_output_layout(sample->cursor, sample->layout);
|
||||
|
||||
/*
|
||||
// TODO configuration
|
||||
if (strcmp("DP-1", ostate->output->name) == 0) {
|
||||
struct sample_input_device *dev;
|
||||
wl_list_for_each(dev, &sample->devices, link) {
|
||||
wlr_cursor_map_input_to_output(sample->cursor, dev->device, ostate->output);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (!wlr_output_set_cursor(wlr_output, image->buffer,
|
||||
image->width, image->width, image->height)) {
|
||||
wlr_log(L_DEBUG, "Failed to set hardware cursor");
|
||||
@ -94,6 +110,20 @@ static void handle_input_add(struct compositor_state *state, struct
|
||||
|
||||
// TODO handle other input devices
|
||||
if (device->type == WLR_INPUT_DEVICE_POINTER) {
|
||||
struct sample_input_device *s_device = calloc(1, sizeof(struct sample_input_device));
|
||||
s_device->device = device;
|
||||
wl_list_insert(&sample->devices, &s_device->link);
|
||||
|
||||
/*
|
||||
// TODO configuration
|
||||
struct output_state *ostate;
|
||||
wl_list_for_each(ostate, &sample->compositor->outputs, link) {
|
||||
if (strcmp(ostate->output->name, "DP-1") == 0) {
|
||||
wlr_cursor_map_input_to_output(sample->cursor, device, ostate->output);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
wlr_cursor_attach_input_device(sample->cursor, device);
|
||||
}
|
||||
}
|
||||
@ -101,7 +131,7 @@ static void handle_input_add(struct compositor_state *state, struct
|
||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||
struct sample_state *sample = wl_container_of(listener, sample, cursor_motion);
|
||||
struct wlr_event_pointer_motion *event = data;
|
||||
wlr_cursor_move(sample->cursor, event->delta_x, event->delta_y);
|
||||
wlr_cursor_move(sample->cursor, event->device, event->delta_x, event->delta_y);
|
||||
}
|
||||
|
||||
static void handle_cursor_motion_absolute(struct wl_listener *listener, void *data) {
|
||||
@ -163,6 +193,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
state.config = parse_args(argc, argv);
|
||||
state.cursor = wlr_cursor_init();
|
||||
wl_list_init(&state.devices);
|
||||
|
||||
wl_signal_add(&state.cursor->events.motion, &state.cursor_motion);
|
||||
state.cursor_motion.notify = handle_cursor_motion;
|
||||
|
@ -32,14 +32,22 @@ void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur);
|
||||
* Warp the cursor to the given x and y in layout coordinates. If x and y are
|
||||
* out of the layout boundaries or constraints, no warp will happen.
|
||||
*
|
||||
* `dev` may be passed to respect device mapping constraints. If `dev` is NULL,
|
||||
* device mapping constraints will be ignored.
|
||||
*
|
||||
* Returns true when the mouse warp was successful.
|
||||
*/
|
||||
bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y);
|
||||
bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
||||
double x, double y);
|
||||
|
||||
/**
|
||||
* Move the cursor in the direction of the given x and y coordinates.
|
||||
*
|
||||
* `dev` may be passed to respect device mapping constraints. If `dev` is NULL,
|
||||
* device mapping constraints will be ignored.
|
||||
*/
|
||||
void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y);
|
||||
void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
||||
double delta_x, double delta_y);
|
||||
|
||||
/**
|
||||
* Attaches this input device to this cursor. The input device must be one of:
|
||||
|
@ -20,12 +20,14 @@ struct wlr_pointer {
|
||||
};
|
||||
|
||||
struct wlr_event_pointer_motion {
|
||||
struct wlr_input_device *device;
|
||||
uint32_t time_sec;
|
||||
uint64_t time_usec;
|
||||
double delta_x, delta_y;
|
||||
};
|
||||
|
||||
struct wlr_event_pointer_motion_absolute {
|
||||
struct wlr_input_device *device;
|
||||
uint32_t time_sec;
|
||||
uint64_t time_usec;
|
||||
double x_mm, y_mm;
|
||||
@ -33,6 +35,7 @@ struct wlr_event_pointer_motion_absolute {
|
||||
};
|
||||
|
||||
struct wlr_event_pointer_button {
|
||||
struct wlr_input_device *device;
|
||||
uint32_t time_sec;
|
||||
uint64_t time_usec;
|
||||
uint32_t button;
|
||||
@ -52,6 +55,7 @@ enum wlr_axis_orientation {
|
||||
};
|
||||
|
||||
struct wlr_event_pointer_axis {
|
||||
struct wlr_input_device *device;
|
||||
uint32_t time_sec;
|
||||
uint64_t time_usec;
|
||||
enum wlr_axis_source source;
|
||||
|
@ -11,6 +11,7 @@ struct wlr_cursor_device {
|
||||
struct wlr_cursor *cursor;
|
||||
struct wlr_input_device *device;
|
||||
struct wl_list link;
|
||||
struct wlr_output *mapped_output;
|
||||
|
||||
struct wl_listener motion;
|
||||
struct wl_listener motion_absolute;
|
||||
@ -54,8 +55,8 @@ struct wlr_cursor *wlr_cursor_init() {
|
||||
}
|
||||
|
||||
void wlr_cursor_destroy(struct wlr_cursor *cur) {
|
||||
struct wlr_cursor_device *device, *tmp = NULL;
|
||||
wl_list_for_each_safe(device, tmp, &cur->state->devices, link) {
|
||||
struct wlr_cursor_device *device, *device_tmp = NULL;
|
||||
wl_list_for_each_safe(device, device_tmp, &cur->state->devices, link) {
|
||||
wl_list_remove(&device->link);
|
||||
free(device);
|
||||
}
|
||||
@ -67,18 +68,41 @@ void wlr_cursor_set_xcursor(struct wlr_cursor *cur, struct wlr_xcursor *xcur) {
|
||||
cur->state->xcursor = xcur;
|
||||
}
|
||||
|
||||
bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y) {
|
||||
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;
|
||||
}
|
||||
|
||||
bool wlr_cursor_warp(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
||||
double x, double y) {
|
||||
assert(cur->state->layout);
|
||||
struct wlr_output *output;
|
||||
output = wlr_output_layout_output_at(cur->state->layout, x, y);
|
||||
|
||||
struct wlr_output *mapped_output = NULL;
|
||||
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
||||
|
||||
if (c_device && c_device->mapped_output) {
|
||||
mapped_output = c_device->mapped_output;
|
||||
} else {
|
||||
mapped_output = cur->state->mapped_output;
|
||||
}
|
||||
|
||||
if (!output) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cur->state->mapped_output &&
|
||||
!wlr_output_layout_contains_point(cur->state->layout,
|
||||
cur->state->mapped_output, x, y)) {
|
||||
if (mapped_output &&
|
||||
!wlr_output_layout_contains_point(cur->state->layout, mapped_output,
|
||||
x, y)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -106,8 +130,17 @@ bool wlr_cursor_warp(struct wlr_cursor *cur, double x, double y) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) {
|
||||
void wlr_cursor_move(struct wlr_cursor *cur, struct wlr_input_device *dev,
|
||||
double delta_x, double delta_y) {
|
||||
assert(cur->state->layout);
|
||||
struct wlr_output *mapped_output = NULL;
|
||||
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
||||
|
||||
if (c_device && c_device->mapped_output) {
|
||||
mapped_output = c_device->mapped_output;
|
||||
} else {
|
||||
mapped_output = cur->state->mapped_output;
|
||||
}
|
||||
|
||||
double x = cur->x + delta_x;
|
||||
double y = cur->y + delta_y;
|
||||
@ -115,15 +148,15 @@ void wlr_cursor_move(struct wlr_cursor *cur, double delta_x, double delta_y) {
|
||||
struct wlr_output *output;
|
||||
output = wlr_output_layout_output_at(cur->state->layout, x, y);
|
||||
|
||||
if (!output || (cur->state->mapped_output && cur->state->mapped_output != output)) {
|
||||
if (!output || (mapped_output && mapped_output != output)) {
|
||||
double closest_x, closest_y;
|
||||
wlr_output_layout_closest_boundary(cur->state->layout,
|
||||
cur->state->mapped_output, x, y, &closest_x, &closest_y);
|
||||
wlr_output_layout_closest_boundary(cur->state->layout, mapped_output, x,
|
||||
y, &closest_x, &closest_y);
|
||||
x = closest_x;
|
||||
y = closest_y;
|
||||
}
|
||||
|
||||
if (wlr_cursor_warp(cur, x, y)) {
|
||||
if (wlr_cursor_warp(cur, dev, x, y)) {
|
||||
cur->x = x;
|
||||
cur->y = y;
|
||||
}
|
||||
@ -230,5 +263,11 @@ void wlr_cursor_map_to_output(struct wlr_cursor *cur,
|
||||
|
||||
void wlr_cursor_map_input_to_output(struct wlr_cursor *cur,
|
||||
struct wlr_input_device *dev, struct wlr_output *output) {
|
||||
wlr_log(L_DEBUG, "TODO map input to output");
|
||||
struct wlr_cursor_device *c_device = get_cursor_device(cur, dev);
|
||||
if (!c_device) {
|
||||
wlr_log(L_ERROR, "Cannot map device \"%s\" to output (not found in this cursor)", dev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
c_device->mapped_output = output;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user