backend/x11: add one pointer per output

This commit is contained in:
emersion 2018-04-29 14:46:29 +01:00
parent ddac792b61
commit 62d7337d00
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 40 additions and 68 deletions

View file

@ -33,38 +33,6 @@ struct wlr_x11_output *get_x11_output_from_window_id(struct wlr_x11_backend *x11
return NULL; return NULL;
} }
void get_x11_output_layout_box(struct wlr_x11_backend *backend,
struct wlr_box *box) {
int min_x = INT_MAX, min_y = INT_MAX;
int max_x = INT_MIN, max_y = INT_MIN;
struct wlr_x11_output *output;
wl_list_for_each(output, &backend->outputs, link) {
struct wlr_output *wlr_output = &output->wlr_output;
int width, height;
wlr_output_effective_resolution(wlr_output, &width, &height);
if (wlr_output->lx < min_x) {
min_x = wlr_output->lx;
}
if (wlr_output->ly < min_y) {
min_y = wlr_output->ly;
}
if (wlr_output->lx + width > max_x) {
max_x = wlr_output->lx + width;
}
if (wlr_output->ly + height > max_y) {
max_y = wlr_output->ly + height;
}
}
box->x = min_x;
box->y = min_y;
box->width = max_x - min_x;
box->height = max_y - min_y;
}
static void handle_x11_event(struct wlr_x11_backend *x11, static void handle_x11_event(struct wlr_x11_backend *x11,
xcb_generic_event_t *event) { xcb_generic_event_t *event) {
handle_x11_input_event(x11, event); handle_x11_input_event(x11, event);
@ -200,7 +168,6 @@ static bool backend_start(struct wlr_backend *backend) {
#endif #endif
wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->keyboard_dev); wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->keyboard_dev);
wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->pointer_dev);
for (size_t i = 0; i < x11->requested_outputs; ++i) { for (size_t i = 0; i < x11->requested_outputs; ++i) {
wlr_x11_output_create(&x11->backend); wlr_x11_output_create(&x11->backend);
@ -221,11 +188,7 @@ static void backend_destroy(struct wlr_backend *backend) {
wlr_output_destroy(&output->wlr_output); wlr_output_destroy(&output->wlr_output);
} }
wlr_signal_emit_safe(&x11->pointer_dev.events.destroy, &x11->pointer_dev);
wlr_signal_emit_safe(&x11->keyboard_dev.events.destroy, &x11->keyboard_dev);
wlr_input_device_destroy(&x11->keyboard_dev); wlr_input_device_destroy(&x11->keyboard_dev);
wlr_input_device_destroy(&x11->pointer_dev);
wlr_signal_emit_safe(&backend->events.destroy, backend); wlr_signal_emit_safe(&backend->events.destroy, backend);
@ -320,11 +283,6 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_display *display,
wlr_keyboard_init(&x11->keyboard, &keyboard_impl); wlr_keyboard_init(&x11->keyboard, &keyboard_impl);
x11->keyboard_dev.keyboard = &x11->keyboard; x11->keyboard_dev.keyboard = &x11->keyboard;
wlr_input_device_init(&x11->pointer_dev, WLR_INPUT_DEVICE_POINTER,
&input_device_impl, "X11 pointer", 0, 0);
wlr_pointer_init(&x11->pointer, &pointer_impl);
x11->pointer_dev.pointer = &x11->pointer;
x11->display_destroy.notify = handle_display_destroy; x11->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &x11->display_destroy); wl_display_add_destroy_listener(display, &x11->display_destroy);

View file

@ -33,25 +33,16 @@ static void x11_handle_pointer_position(struct wlr_x11_output *output,
struct wlr_x11_backend *x11 = output->x11; struct wlr_x11_backend *x11 = output->x11;
struct wlr_output *wlr_output = &output->wlr_output; struct wlr_output *wlr_output = &output->wlr_output;
struct wlr_box box = { .x = x, .y = y }; int output_width, output_height;
wlr_box_transform(&box, wlr_output->transform, wlr_output->width, wlr_output_effective_resolution(wlr_output, &output_width, &output_height);
wlr_output->height, &box);
box.x /= wlr_output->scale;
box.y /= wlr_output->scale;
struct wlr_box layout_box; struct wlr_event_pointer_motion_absolute event = {
get_x11_output_layout_box(x11, &layout_box); .device = &output->pointer_dev,
double ox = wlr_output->lx / (double)layout_box.width;
double oy = wlr_output->ly / (double)layout_box.height;
struct wlr_event_pointer_motion_absolute wlr_event = {
.device = &x11->pointer_dev,
.time_msec = time, .time_msec = time,
.x = box.x / (double)layout_box.width + ox, .x = (double)x / output_width,
.y = box.y / (double)layout_box.height + oy, .y = (double)y / output_height,
}; };
wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &wlr_event); wlr_signal_emit_safe(&output->pointer.events.motion_absolute, &event);
x11->time = time; x11->time = time;
} }
@ -78,17 +69,23 @@ void handle_x11_input_event(struct wlr_x11_backend *x11,
case XCB_BUTTON_PRESS: { case XCB_BUTTON_PRESS: {
xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event; xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event;
struct wlr_x11_output *output =
get_x11_output_from_window_id(x11, ev->event);
if (output == NULL) {
break;
}
if (ev->detail == XCB_BUTTON_INDEX_4 || if (ev->detail == XCB_BUTTON_INDEX_4 ||
ev->detail == XCB_BUTTON_INDEX_5) { ev->detail == XCB_BUTTON_INDEX_5) {
double delta = (ev->detail == XCB_BUTTON_INDEX_4 ? -15 : 15); double delta = (ev->detail == XCB_BUTTON_INDEX_4 ? -15 : 15);
struct wlr_event_pointer_axis axis = { struct wlr_event_pointer_axis axis = {
.device = &x11->pointer_dev, .device = &output->pointer_dev,
.time_msec = ev->time, .time_msec = ev->time,
.source = WLR_AXIS_SOURCE_WHEEL, .source = WLR_AXIS_SOURCE_WHEEL,
.orientation = WLR_AXIS_ORIENTATION_VERTICAL, .orientation = WLR_AXIS_ORIENTATION_VERTICAL,
.delta = delta, .delta = delta,
}; };
wlr_signal_emit_safe(&x11->pointer.events.axis, &axis); wlr_signal_emit_safe(&output->pointer.events.axis, &axis);
x11->time = ev->time; x11->time = ev->time;
break; break;
} }
@ -97,17 +94,23 @@ void handle_x11_input_event(struct wlr_x11_backend *x11,
case XCB_BUTTON_RELEASE: { case XCB_BUTTON_RELEASE: {
xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event; xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event;
struct wlr_x11_output *output =
get_x11_output_from_window_id(x11, ev->event);
if (output == NULL) {
break;
}
if (ev->detail != XCB_BUTTON_INDEX_4 && if (ev->detail != XCB_BUTTON_INDEX_4 &&
ev->detail != XCB_BUTTON_INDEX_5) { ev->detail != XCB_BUTTON_INDEX_5) {
struct wlr_event_pointer_button button = { struct wlr_event_pointer_button button = {
.device = &x11->pointer_dev, .device = &output->pointer_dev,
.time_msec = ev->time, .time_msec = ev->time,
.button = xcb_button_to_wl(ev->detail), .button = xcb_button_to_wl(ev->detail),
.state = event->response_type == XCB_BUTTON_PRESS ? .state = event->response_type == XCB_BUTTON_PRESS ?
WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED, WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED,
}; };
wlr_signal_emit_safe(&x11->pointer.events.button, &button); wlr_signal_emit_safe(&output->pointer.events.button, &button);
} }
x11->time = ev->time; x11->time = ev->time;
return; return;

View file

@ -1,6 +1,9 @@
#define _POSIX_C_SOURCE 200809L
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_output.h>
#include <wlr/interfaces/wlr_pointer.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "backend/x11.h" #include "backend/x11.h"
#include "util/signal.h" #include "util/signal.h"
@ -59,6 +62,8 @@ static void output_destroy(struct wlr_output *wlr_output) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output; struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;
struct wlr_x11_backend *x11 = output->x11; struct wlr_x11_backend *x11 = output->x11;
wlr_input_device_destroy(&output->pointer_dev);
wl_list_remove(&output->link); wl_list_remove(&output->link);
wl_event_source_remove(output->frame_timer); wl_event_source_remove(output->frame_timer);
wlr_egl_destroy_surface(&x11->egl, output->surf); wlr_egl_destroy_surface(&x11->egl, output->surf);
@ -155,11 +160,19 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
struct wl_event_loop *ev = wl_display_get_event_loop(x11->wl_display); struct wl_event_loop *ev = wl_display_get_event_loop(x11->wl_display);
output->frame_timer = wl_event_loop_add_timer(ev, signal_frame, output); output->frame_timer = wl_event_loop_add_timer(ev, signal_frame, output);
wl_list_insert(&x11->outputs, &output->link);
wl_event_source_timer_update(output->frame_timer, output->frame_delay); wl_event_source_timer_update(output->frame_timer, output->frame_delay);
wlr_output_update_enabled(wlr_output, true); wlr_output_update_enabled(wlr_output, true);
wl_list_insert(&x11->outputs, &output->link); wlr_input_device_init(&output->pointer_dev, WLR_INPUT_DEVICE_POINTER,
&input_device_impl, "X11 pointer", 0, 0);
wlr_pointer_init(&output->pointer, &pointer_impl);
output->pointer_dev.pointer = &output->pointer;
output->pointer_dev.output_name = strdup(wlr_output->name);
wlr_signal_emit_safe(&x11->backend.events.new_output, wlr_output); wlr_signal_emit_safe(&x11->backend.events.new_output, wlr_output);
wlr_signal_emit_safe(&x11->backend.events.new_input, &output->pointer_dev);
return wlr_output; return wlr_output;
} }

View file

@ -24,6 +24,9 @@ struct wlr_x11_output {
xcb_window_t win; xcb_window_t win;
EGLSurface surf; EGLSurface surf;
struct wlr_pointer pointer;
struct wlr_input_device pointer_dev;
struct wl_event_source *frame_timer; struct wl_event_source *frame_timer;
int frame_delay; int frame_delay;
}; };
@ -43,9 +46,6 @@ struct wlr_x11_backend {
struct wlr_keyboard keyboard; struct wlr_keyboard keyboard;
struct wlr_input_device keyboard_dev; struct wlr_input_device keyboard_dev;
struct wlr_pointer pointer;
struct wlr_input_device pointer_dev;
struct wlr_egl egl; struct wlr_egl egl;
struct wlr_renderer *renderer; struct wlr_renderer *renderer;
struct wl_event_source *event_source; struct wl_event_source *event_source;
@ -74,8 +74,6 @@ struct wlr_x11_backend {
struct wlr_x11_output *get_x11_output_from_window_id(struct wlr_x11_backend *x11, struct wlr_x11_output *get_x11_output_from_window_id(struct wlr_x11_backend *x11,
xcb_window_t window); xcb_window_t window);
void get_x11_output_layout_box(struct wlr_x11_backend *backend,
struct wlr_box *box);
extern const struct wlr_keyboard_impl keyboard_impl; extern const struct wlr_keyboard_impl keyboard_impl;
extern const struct wlr_pointer_impl pointer_impl; extern const struct wlr_pointer_impl pointer_impl;