From 9609985f2976373772733d35f29fb682c144a261 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 3 Apr 2018 13:32:24 -0400 Subject: backend/x11: fix cursor position when receiving configure event --- backend/x11/input_device.c | 70 +++++++++++++++++++++++++++++++--------------- backend/x11/output.c | 20 +------------ 2 files changed, 48 insertions(+), 42 deletions(-) (limited to 'backend') 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 #include #include #include @@ -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..07dbe868 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -157,29 +157,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) { -- cgit v1.2.3 From 56deff41b6c2c6190894068994ba403978068bad Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 3 Apr 2018 12:50:05 -0400 Subject: Implement input inhibit in rootston --- backend/backend.c | 4 ---- backend/libinput/backend.c | 4 ++++ include/backend/libinput.h | 2 ++ include/rootston/desktop.h | 2 ++ include/rootston/seat.h | 9 +++++++ include/wlr/backend.h | 2 -- include/wlr/types/wlr_seat.h | 3 ++- rootston/cursor.c | 7 ++++-- rootston/desktop.c | 26 ++++++++++++++++++++ rootston/seat.c | 57 +++++++++++++++++++++++++++++++++++++++++++- 10 files changed, 106 insertions(+), 10 deletions(-) (limited to 'backend') diff --git a/backend/backend.c b/backend/backend.c index 93d7e0df..23e212b6 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -182,7 +182,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/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/include/backend/libinput.h b/include/backend/libinput.h index f828c310..4eee7eb8 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -29,6 +29,8 @@ struct wlr_libinput_input_device { struct libinput_device *handle; }; +uint32_t usec_to_msec(uint64_t usec); + void wlr_libinput_event(struct wlr_libinput_backend *state, struct libinput_event *event); diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index d07cb99b..f150147b 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -59,6 +59,8 @@ struct roots_desktop { struct wl_listener wl_shell_surface; struct wl_listener layer_shell_surface; struct wl_listener decoration_new; + struct wl_listener input_inhibit_activate; + struct wl_listener input_inhibit_deactivate; #ifdef WLR_HAS_XWAYLAND struct wlr_xwayland *xwayland; diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 6f482723..d2ef90f3 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -19,6 +19,9 @@ struct roots_seat { // If the focused layer is set, views cannot receive keyboard focus struct wlr_layer_surface *focused_layer; + // If non-null, only this client can receive input events + struct wl_client *exclusive_client; + struct wl_list views; // roots_seat_view::link bool has_focus; @@ -125,4 +128,10 @@ void roots_drag_icon_update_position(struct roots_drag_icon *icon); void roots_drag_icon_damage_whole(struct roots_drag_icon *icon); +void roots_seat_set_exclusive_client(struct roots_seat *seat, + struct wl_client *client); + +bool roots_seat_allow_input(struct roots_seat *seat, + struct wl_resource *resource); + #endif diff --git a/include/wlr/backend.h b/include/wlr/backend.h index e3b14add..f5482e04 100644 --- a/include/wlr/backend.h +++ b/include/wlr/backend.h @@ -46,6 +46,4 @@ struct wlr_egl *wlr_backend_get_egl(struct wlr_backend *backend); */ struct wlr_renderer *wlr_backend_get_renderer(struct wlr_backend *backend); -uint32_t usec_to_msec(uint64_t usec); - #endif diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index 124c1cb8..4c7e34b9 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -530,6 +530,7 @@ bool wlr_seat_touch_has_grab(struct wlr_seat *seat); */ bool wlr_seat_validate_grab_serial(struct wlr_seat *seat, uint32_t serial); -struct wlr_seat_client *wlr_seat_client_from_resource(struct wl_resource *resource); +struct wlr_seat_client *wlr_seat_client_from_resource( + struct wl_resource *resource); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index ac46ff5d..21e32a09 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -111,6 +111,9 @@ static void roots_passthrough_cursor(struct roots_cursor *cursor, if (surface) { client = wl_resource_get_client(surface->resource); } + if (surface && !roots_seat_allow_input(cursor->seat, surface->resource)) { + return; + } if (cursor->cursor_client != client) { wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, @@ -327,7 +330,7 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor, desktop, lx, ly, &sx, &sy, NULL); uint32_t serial = 0; - if (surface) { + if (surface && roots_seat_allow_input(cursor->seat, surface->resource)) { serial = wlr_seat_touch_notify_down(cursor->seat->seat, surface, event->time_msec, event->touch_id, sx, sy); } @@ -378,7 +381,7 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, struct wlr_surface *surface = desktop_surface_at( desktop, lx, ly, &sx, &sy, NULL); - if (surface) { + if (surface && roots_seat_allow_input(cursor->seat, surface->resource)) { wlr_seat_touch_point_focus(cursor->seat->seat, surface, event->time_msec, event->touch_id, sx, sy); wlr_seat_touch_notify_motion(cursor->seat->seat, event->time_msec, diff --git a/rootston/desktop.c b/rootston/desktop.c index ed4abf0a..f6801332 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -756,6 +756,25 @@ static void handle_layout_change(struct wl_listener *listener, void *data) { } } +static void input_inhibit_activate(struct wl_listener *listener, void *data) { + struct roots_desktop *desktop = wl_container_of( + listener, desktop, input_inhibit_activate); + struct roots_seat *seat; + wl_list_for_each(seat, &desktop->server->input->seats, link) { + roots_seat_set_exclusive_client(seat, + desktop->input_inhibit->active_client); + } +} + +static void input_inhibit_deactivate(struct wl_listener *listener, void *data) { + struct roots_desktop *desktop = wl_container_of( + listener, desktop, input_inhibit_deactivate); + struct roots_seat *seat; + wl_list_for_each(seat, &desktop->server->input->seats, link) { + roots_seat_set_exclusive_client(seat, NULL); + } +} + struct roots_desktop *desktop_create(struct roots_server *server, struct roots_config *config) { wlr_log(L_DEBUG, "Initializing roots desktop"); @@ -855,8 +874,15 @@ struct roots_desktop *desktop_create(struct roots_server *server, wlr_primary_selection_device_manager_create(server->wl_display); desktop->idle = wlr_idle_create(server->wl_display); desktop->idle_inhibit = wlr_idle_inhibit_v1_create(server->wl_display); + desktop->input_inhibit = wlr_input_inhibit_manager_create(server->wl_display); + desktop->input_inhibit_activate.notify = input_inhibit_activate; + wl_signal_add(&desktop->input_inhibit->events.activate, + &desktop->input_inhibit_activate); + desktop->input_inhibit_deactivate.notify = input_inhibit_deactivate; + wl_signal_add(&desktop->input_inhibit->events.deactivate, + &desktop->input_inhibit_deactivate); struct wlr_egl *egl = wlr_backend_get_egl(server->backend); desktop->linux_dmabuf = wlr_linux_dmabuf_create(server->wl_display, egl); diff --git a/rootston/seat.c b/rootston/seat.c index cfdeab00..e12df7d6 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -1,6 +1,8 @@ +#define _POSIX_C_SOURCE 199309L #include #include #include +#include #include #include #include @@ -716,7 +718,17 @@ struct roots_seat_view *roots_seat_view_from_view( return seat_view; } +bool roots_seat_allow_input(struct roots_seat *seat, + struct wl_resource *resource) { + return !seat->exclusive_client || + wl_resource_get_client(resource) == seat->exclusive_client; +} + void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { + if (view && !roots_seat_allow_input(seat, view->wlr_surface->resource)) { + return; + } + // Make sure the view will be rendered on top of others, even if it's // already focused in this seat if (view != NULL) { @@ -811,11 +823,14 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) { */ void roots_seat_set_focus_layer(struct roots_seat *seat, struct wlr_layer_surface *layer) { - struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); if (!layer) { seat->focused_layer = NULL; return; } + struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat->seat); + if (!roots_seat_allow_input(seat, layer->resource)) { + return; + } if (seat->has_focus) { struct roots_view *prev_focus = roots_seat_get_focus(seat); wlr_seat_keyboard_clear_focus(seat->seat); @@ -835,6 +850,46 @@ void roots_seat_set_focus_layer(struct roots_seat *seat, } } +void roots_seat_set_exclusive_client(struct roots_seat *seat, + struct wl_client *client) { + if (!client) { + seat->exclusive_client = client; + // Triggers a refocus of the topmost surface layer if necessary + // TODO: Make layer surface focus per-output based on cursor position + struct roots_output *output; + wl_list_for_each(output, &seat->input->server->desktop->outputs, link) { + arrange_layers(output); + } + return; + } + if (seat->focused_layer) { + if (wl_resource_get_client(seat->focused_layer->resource) != client) { + roots_seat_set_focus_layer(seat, NULL); + } + } + if (seat->has_focus) { + struct roots_view *focus = roots_seat_get_focus(seat); + if (wl_resource_get_client(focus->wlr_surface->resource) != client) { + roots_seat_set_focus(seat, NULL); + } + } + if (seat->seat->pointer_state.focused_client) { + if (seat->seat->pointer_state.focused_client->client != client) { + wlr_seat_pointer_clear_focus(seat->seat); + } + } + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + struct wlr_touch_point *point; + wl_list_for_each(point, &seat->seat->touch_state.touch_points, link) { + if (point->client->client != client) { + wlr_seat_touch_point_clear_focus(seat->seat, + now.tv_nsec / 1000, point->touch_id); + } + } + seat->exclusive_client = client; +} + void roots_seat_cycle_focus(struct roots_seat *seat) { if (wl_list_empty(&seat->views)) { return; -- cgit v1.2.3 From 2d6bbf12f8dc9217f86ec232b7343ad3284863f5 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 3 Apr 2018 22:54:01 -0400 Subject: backend/{x11,headless}: fix refresh rate --- backend/headless/output.c | 6 +++++- backend/x11/output.c | 20 +++++++++++++++----- include/backend/headless.h | 2 ++ include/backend/x11.h | 2 ++ 4 files changed, 24 insertions(+), 6 deletions(-) (limited to 'backend') 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/x11/output.c b/backend/x11/output.c index 07dbe868..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); diff --git a/include/backend/headless.h b/include/backend/headless.h index e130bae1..add4c4e8 100644 --- a/include/backend/headless.h +++ b/include/backend/headless.h @@ -4,6 +4,8 @@ #include #include +#define HEADLESS_DEFAULT_REFRESH (60 * 1000) // 60 Hz + struct wlr_headless_backend { struct wlr_backend backend; struct wlr_egl egl; diff --git a/include/backend/x11.h b/include/backend/x11.h index 2fce409e..1c88cefc 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -12,6 +12,8 @@ #define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f +#define X11_DEFAULT_REFRESH (60 * 1000) // 60 Hz + struct wlr_x11_backend; struct wlr_x11_output { -- cgit v1.2.3 From 68ad7e5092c1fb64fb26fa34bb6368fcd558f736 Mon Sep 17 00:00:00 2001 From: Tancredi Orlando Date: Wed, 4 Apr 2018 19:59:47 +0200 Subject: Add ifdef to build without X11 --- backend/backend.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backend') diff --git a/backend/backend.c b/backend/backend.c index 23e212b6..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); -- cgit v1.2.3