aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorScott Anderson <ascent12@hotmail.com>2017-09-28 23:48:54 +1300
committerScott Anderson <ascent12@hotmail.com>2017-09-29 16:15:09 +1300
commitabe549e01d3a7ef37644f0f6177f41f3829d6423 (patch)
tree5d7237211f7be8c9a365a6b838f2debb45786b79 /backend
parent22d5652599ec3efa618e54ee6357122d7de54588 (diff)
Cleanup x11 event handler
Diffstat (limited to 'backend')
-rw-r--r--backend/x11/backend.c106
1 files changed, 41 insertions, 65 deletions
diff --git a/backend/x11/backend.c b/backend/x11/backend.c
index 908df362..fd47295a 100644
--- a/backend/x11/backend.c
+++ b/backend/x11/backend.c
@@ -2,7 +2,6 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
-#include <time.h>
#include <EGL/egl.h>
#include <wayland-server.h>
#include <xcb/xcb.h>
@@ -24,96 +23,73 @@ static struct wlr_input_device_impl input_impl;
static struct wlr_keyboard_impl keyboard_impl;
static struct wlr_pointer_impl pointer_impl;
+static uint32_t xcb_button_to_wl(uint32_t button) {
+ switch (button) {
+ case XCB_BUTTON_INDEX_1: return BTN_LEFT;
+ case XCB_BUTTON_INDEX_2: return BTN_MIDDLE;
+ case XCB_BUTTON_INDEX_3: return BTN_RIGHT;
+ // XXX: I'm not sure the scroll-wheel direction is right
+ case XCB_BUTTON_INDEX_4: return BTN_GEAR_UP;
+ case XCB_BUTTON_INDEX_5: return BTN_GEAR_DOWN;
+ default: return 0;
+ }
+}
+
static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *event) {
struct wlr_x11_output *output = &x11->output;
- struct timespec ts;
- clock_gettime(CLOCK_MONOTONIC, &ts);
-
switch (event->response_type) {
- case XCB_EXPOSE:
+ case XCB_EXPOSE: {
wl_signal_emit(&output->wlr_output.events.frame, output);
break;
- case XCB_KEY_PRESS: {
- xcb_key_press_event_t *press = (xcb_key_press_event_t *)event;
+ xcb_key_press_event_t *ev = (xcb_key_press_event_t *)event;
struct wlr_event_keyboard_key key = {
- .time_sec = ts.tv_sec,
- .time_usec = ts.tv_nsec / 1000,
- .keycode = press->detail - 8,
+ .time_sec = ev->time / 1000,
+ .time_usec = (ev->time % 1000) * 1000,
+ .keycode = ev->detail - 8,
.state = WLR_KEY_PRESSED,
};
wl_signal_emit(&x11->keyboard.events.key, &key);
break;
}
+ case XCB_KEY_PRESS:
case XCB_KEY_RELEASE: {
- xcb_key_release_event_t *press = (xcb_key_release_event_t *)event;
+ xcb_key_press_event_t *ev = (xcb_key_press_event_t *)event;
struct wlr_event_keyboard_key key = {
- .time_sec = ts.tv_sec,
- .time_usec = ts.tv_nsec / 1000,
- .keycode = press->detail - 8,
- .state = WLR_KEY_RELEASED,
+ .time_sec = ev->time / 1000,
+ .time_usec = (ev->time % 1000) * 1000,
+ .keycode = ev->detail - 8,
+ .state = event->response_type == XCB_KEY_PRESS ?
+ WLR_KEY_PRESSED : WLR_KEY_RELEASED,
};
wl_signal_emit(&x11->keyboard.events.key, &key);
break;
}
- case XCB_BUTTON_PRESS: {
- xcb_button_press_event_t *press = (xcb_button_press_event_t *)event;
- struct wlr_event_pointer_button button = {
- .device = &x11->pointer_dev,
- .time_sec = ts.tv_sec,
- .time_usec = ts.tv_nsec / 1000,
- .state = WLR_BUTTON_PRESSED,
- };
-
- switch (press->detail) {
- case XCB_BUTTON_INDEX_1:
- button.button = BTN_LEFT;
- break;
- case XCB_BUTTON_INDEX_2:
- button.button = BTN_MIDDLE;
- break;
- case XCB_BUTTON_INDEX_3:
- button.button = BTN_RIGHT;
- break;
- }
-
- wl_signal_emit(&x11->pointer.events.button, &button);
- break;
- }
+ case XCB_BUTTON_PRESS:
case XCB_BUTTON_RELEASE: {
- xcb_button_release_event_t *press = (xcb_button_release_event_t *)event;
+ xcb_button_press_event_t *ev = (xcb_button_press_event_t *)event;
struct wlr_event_pointer_button button = {
.device = &x11->pointer_dev,
- .time_sec = ts.tv_sec,
- .time_usec = ts.tv_nsec / 1000,
- .state = WLR_BUTTON_RELEASED,
+ .time_sec = ev->time / 1000,
+ .time_usec = (ev->time % 1000) * 1000,
+ .button = xcb_button_to_wl(ev->detail),
+ .state = event->response_type == XCB_BUTTON_PRESS ?
+ WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED,
};
- switch (press->detail) {
- case XCB_BUTTON_INDEX_1:
- button.button = BTN_LEFT;
- break;
- case XCB_BUTTON_INDEX_2:
- button.button = BTN_MIDDLE;
- break;
- case XCB_BUTTON_INDEX_3:
- button.button = BTN_RIGHT;
- break;
- }
-
wl_signal_emit(&x11->pointer.events.button, &button);
break;
}
case XCB_MOTION_NOTIFY: {
- xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)event;
+ xcb_motion_notify_event_t *ev = (xcb_motion_notify_event_t *)event;
struct wlr_event_pointer_motion_absolute abs = {
.device = &x11->pointer_dev,
- .time_sec = ts.tv_sec,
- .time_usec = ts.tv_nsec / 1000,
- .x_mm = motion->event_x,
- .y_mm = motion->event_y,
+ .time_sec = ev->time / 1000,
+ .time_usec = (ev->time % 1000) * 1000,
+ .x_mm = ev->event_x,
+ .y_mm = ev->event_y,
.width_mm = output->wlr_output.width,
.height_mm = output->wlr_output.height,
};
@@ -122,10 +98,10 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
break;
}
case XCB_CONFIGURE_NOTIFY: {
- xcb_configure_notify_event_t *conf = (xcb_configure_notify_event_t *)event;
+ xcb_configure_notify_event_t *ev = (xcb_configure_notify_event_t *)event;
- output->wlr_output.width = conf->width;
- output->wlr_output.height = conf->height;
+ output->wlr_output.width = ev->width;
+ output->wlr_output.height = ev->height;
wlr_output_update_matrix(&output->wlr_output);
wl_signal_emit(&output->wlr_output.events.resolution, output);
@@ -140,8 +116,8 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e
struct wlr_event_pointer_motion_absolute abs = {
.device = &x11->pointer_dev,
- .time_sec = ts.tv_sec,
- .time_usec = ts.tv_nsec / 1000,
+ //.time_sec = ev->time / 1000,
+ //.time_usec = (ev->time % 1000) * 1000,
.x_mm = pointer->root_x,
.y_mm = pointer->root_y,
.width_mm = output->wlr_output.width,