aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/backend.c6
-rw-r--r--backend/headless/output.c6
-rw-r--r--backend/libinput/backend.c4
-rw-r--r--backend/x11/input_device.c70
-rw-r--r--backend/x11/output.c40
5 files changed, 74 insertions, 52 deletions
diff --git a/backend/backend.c b/backend/backend.c
index 93d7e0df..b583855e 100644
--- a/backend/backend.c
+++ b/backend/backend.c
@@ -91,6 +91,7 @@ static struct wlr_backend *attempt_wl_backend(struct wl_display *display) {
return backend;
}
+#ifdef WLR_HAS_X11_BACKEND
static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
const char *x11_display) {
struct wlr_backend *backend = wlr_x11_backend_create(display, x11_display);
@@ -105,6 +106,7 @@ static struct wlr_backend *attempt_x11_backend(struct wl_display *display,
return backend;
}
+#endif
struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
struct wlr_backend *backend = wlr_multi_backend_create(display);
@@ -182,7 +184,3 @@ struct wlr_backend *wlr_backend_autocreate(struct wl_display *display) {
return backend;
}
-
-uint32_t usec_to_msec(uint64_t usec) {
- return (uint32_t)(usec / 1000);
-}
diff --git a/backend/headless/output.c b/backend/headless/output.c
index a13ed22c..583e521e 100644
--- a/backend/headless/output.c
+++ b/backend/headless/output.c
@@ -25,6 +25,10 @@ static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
(struct wlr_headless_output *)wlr_output;
struct wlr_headless_backend *backend = output->backend;
+ if (refresh == 0) {
+ refresh = HEADLESS_DEFAULT_REFRESH;
+ }
+
if (output->egl_surface) {
eglDestroySurface(backend->egl.display, output->egl_surface);
}
@@ -114,7 +118,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend,
goto error;
}
- output_set_custom_mode(wlr_output, width, height, 60*1000);
+ output_set_custom_mode(wlr_output, width, height, 0);
strncpy(wlr_output->make, "headless", sizeof(wlr_output->make));
strncpy(wlr_output->model, "headless", sizeof(wlr_output->model));
snprintf(wlr_output->name, sizeof(wlr_output->name), "HEADLESS-%d",
diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c
index 1e7c1ad4..ef33df0a 100644
--- a/backend/libinput/backend.c
+++ b/backend/libinput/backend.c
@@ -191,3 +191,7 @@ struct libinput_device *wlr_libinput_get_device_handle(struct wlr_input_device *
struct wlr_libinput_input_device *dev = (struct wlr_libinput_input_device *)_dev;
return dev->handle;
}
+
+uint32_t usec_to_msec(uint64_t usec) {
+ return (uint32_t)(usec / 1000);
+}
diff --git a/backend/x11/input_device.c b/backend/x11/input_device.c
index 6c7c444c..55e543e6 100644
--- a/backend/x11/input_device.c
+++ b/backend/x11/input_device.c
@@ -1,3 +1,4 @@
+#include <stdlib.h>
#include <wlr/config.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_keyboard.h>
@@ -27,6 +28,34 @@ static uint32_t xcb_button_to_wl(uint32_t button) {
}
}
+static void x11_handle_pointer_position(struct wlr_x11_output *output,
+ int16_t x, int16_t y, xcb_timestamp_t time) {
+ struct wlr_x11_backend *x11 = output->x11;
+ struct wlr_output *wlr_output = &output->wlr_output;
+
+ struct wlr_box box = { .x = x, .y = 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,
+ .time_msec = time,
+ .x = box.x / (double)layout_box.width + ox,
+ .y = box.y / (double)layout_box.height + oy,
+ };
+ wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &wlr_event);
+
+ x11->time = time;
+}
+
bool x11_handle_input_event(struct wlr_x11_backend *x11,
xcb_generic_event_t *event) {
switch (event->response_type & XCB_EVENT_RESPONSE_TYPE_MASK) {
@@ -91,30 +120,8 @@ bool x11_handle_input_event(struct wlr_x11_backend *x11,
if (output == NULL) {
return false;
}
- struct wlr_output *wlr_output = &output->wlr_output;
-
- 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,
- .time_msec = ev->time,
- .x = box.x / (double)layout_box.width + ox,
- .y = box.y / (double)layout_box.height + oy,
- };
-
- wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &wlr_event);
-
- x11->time = ev->time;
+ x11_handle_pointer_position(output, ev->event_x, ev->event_y, ev->time);
return true;
}
default:
@@ -135,6 +142,23 @@ bool x11_handle_input_event(struct wlr_x11_backend *x11,
const struct wlr_input_device_impl input_device_impl = { 0 };
+void x11_update_pointer_position(struct wlr_x11_output *output,
+ xcb_timestamp_t time) {
+ struct wlr_x11_backend *x11 = output->x11;
+
+ xcb_query_pointer_cookie_t cookie =
+ xcb_query_pointer(x11->xcb_conn, output->win);
+ xcb_query_pointer_reply_t *reply =
+ xcb_query_pointer_reply(x11->xcb_conn, cookie, NULL);
+ if (!reply) {
+ return;
+ }
+
+ x11_handle_pointer_position(output, reply->win_x, reply->win_y, time);
+
+ free(reply);
+}
+
bool wlr_input_device_is_x11(struct wlr_input_device *wlr_dev) {
return wlr_dev->impl == &input_device_impl;
}
diff --git a/backend/x11/output.c b/backend/x11/output.c
index 4a8ac84c..a2d8ba2d 100644
--- a/backend/x11/output.c
+++ b/backend/x11/output.c
@@ -23,14 +23,25 @@ static void parse_xcb_setup(struct wlr_output *output, xcb_connection_t *xcb_con
xcb_setup->protocol_minor_version);
}
-static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width,
- int32_t height, int32_t refresh) {
+static void output_set_refresh(struct wlr_output *wlr_output, int32_t refresh) {
struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;
- struct wlr_x11_backend *x11 = output->x11;
+
+ if (refresh == 0) {
+ refresh = X11_DEFAULT_REFRESH;
+ }
wlr_output_update_custom_mode(&output->wlr_output, wlr_output->width,
wlr_output->height, refresh);
+
output->frame_delay = 1000000 / refresh;
+}
+
+static bool output_set_custom_mode(struct wlr_output *wlr_output,
+ int32_t width, int32_t height, int32_t refresh) {
+ struct wlr_x11_output *output = (struct wlr_x11_output *)wlr_output;
+ struct wlr_x11_backend *x11 = output->x11;
+
+ output_set_refresh(&output->wlr_output, refresh);
const uint32_t values[] = { width, height };
xcb_configure_window(x11->xcb_conn, output->win,
@@ -97,8 +108,7 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
struct wlr_output *wlr_output = &output->wlr_output;
wlr_output_init(wlr_output, &x11->backend, &output_impl, x11->wl_display);
- wlr_output->refresh = 60 * 1000000;
- output->frame_delay = 16; // 60 Hz
+ output_set_refresh(&output->wlr_output, 0);
snprintf(wlr_output->name, sizeof(wlr_output->name), "X11-%d",
wl_list_length(&x11->outputs) + 1);
@@ -157,29 +167,11 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) {
void x11_output_handle_configure_notify(struct wlr_x11_output *output,
xcb_configure_notify_event_t *ev) {
- struct wlr_x11_backend *x11 = output->x11;
-
wlr_output_update_custom_mode(&output->wlr_output, ev->width,
ev->height, output->wlr_output.refresh);
// Move the pointer to its new location
- xcb_query_pointer_cookie_t cookie =
- xcb_query_pointer(x11->xcb_conn, output->win);
- xcb_query_pointer_reply_t *pointer =
- xcb_query_pointer_reply(x11->xcb_conn, cookie, NULL);
- if (!pointer) {
- return;
- }
-
- struct wlr_event_pointer_motion_absolute abs = {
- .device = &x11->pointer_dev,
- .time_msec = x11->time,
- .x = (double)pointer->root_x / output->wlr_output.width,
- .y = (double)pointer->root_y / output->wlr_output.height,
- };
-
- wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs);
- free(pointer);
+ x11_update_pointer_position(output, output->x11->time);
}
bool wlr_output_is_x11(struct wlr_output *wlr_output) {