backend/x11: fix input events

master
emersion 7 years ago
parent 0a7a8cbd1c
commit aa6ae710f7
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

@ -1,4 +1,5 @@
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -32,6 +33,38 @@ struct wlr_x11_output *x11_output_from_window_id(struct wlr_x11_backend *x11,
return NULL; return NULL;
} }
void x11_output_layout_get_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 bool handle_x11_event(struct wlr_x11_backend *x11, static bool handle_x11_event(struct wlr_x11_backend *x11,
xcb_generic_event_t *event) { xcb_generic_event_t *event) {
if (x11_handle_input_event(x11, event)) { if (x11_handle_input_event(x11, event)) {

@ -87,15 +87,29 @@ bool x11_handle_input_event(struct wlr_x11_backend *x11,
if (output == NULL) { if (output == NULL) {
return false; return false;
} }
struct wlr_output *wlr_output = &output->wlr_output;
struct wlr_event_pointer_motion_absolute abs = { struct wlr_box box = { .x = ev->event_x, .y = ev->event_y };
wlr_box_transform(&box, wlr_output->transform, wlr_output->width,
wlr_output->height, &box);
box.x /= wlr_output->scale;
box.y /= wlr_output->scale;
struct wlr_box layout_box;
x11_output_layout_get_box(x11, &layout_box);
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, .device = &x11->pointer_dev,
.time_msec = ev->time, .time_msec = ev->time,
.x = (double)ev->event_x / output->wlr_output.width, .x = box.x / (double)layout_box.width + ox,
.y = (double)ev->event_y / output->wlr_output.height, .y = box.y / (double)layout_box.height + oy,
}; };
wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &wlr_event);
x11->time = ev->time; x11->time = ev->time;
return true; return true;
} }

@ -69,6 +69,8 @@ struct wlr_x11_backend {
struct wlr_x11_output *x11_output_from_window_id(struct wlr_x11_backend *x11, struct wlr_x11_output *x11_output_from_window_id(struct wlr_x11_backend *x11,
xcb_window_t window); xcb_window_t window);
void x11_output_layout_get_box(struct wlr_x11_backend *backend,
struct wlr_box *box);
const struct wlr_input_device_impl input_device_impl; const struct wlr_input_device_impl input_device_impl;

Loading…
Cancel
Save