From 641d08ce7eba1464c535feb04513374cde22ed17 Mon Sep 17 00:00:00 2001 From: Versus Void Date: Fri, 6 Oct 2017 09:07:08 +0300 Subject: Transform hotspot with cursor Fix #188 --- include/backend/wayland.h | 3 ++- include/wlr/interfaces/wlr_output.h | 3 ++- include/wlr/types/wlr_output.h | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 752dab69..508a7f52 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -67,7 +67,8 @@ struct wlr_wl_pointer { }; void wlr_wl_registry_poll(struct wlr_wl_backend *backend); -void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output, uint32_t serial); +void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output, + uint32_t serial, int32_t hotspot_x, int32_t hotspot_y); struct wlr_wl_backend_output *wlr_wl_output_for_surface( struct wlr_wl_backend *backend, struct wl_surface *surface); diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index 7ed19ed9..7d2821e0 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -10,7 +10,8 @@ struct wlr_output_impl { void (*transform)(struct wlr_output *output, enum wl_output_transform transform); bool (*set_cursor)(struct wlr_output *output, const uint8_t *buf, - int32_t stride, uint32_t width, uint32_t height); + int32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y); bool (*move_cursor)(struct wlr_output *output, int x, int y); void (*destroy)(struct wlr_output *output); void (*make_current)(struct wlr_output *output); diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 3208acac..1fa6ad9e 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -45,6 +45,7 @@ struct wlr_output { bool is_sw; int32_t x, y; uint32_t width, height; + int32_t hotspot_x, hotspot_y; struct wlr_renderer *renderer; struct wlr_texture *texture; } cursor; @@ -58,7 +59,8 @@ bool wlr_output_set_mode(struct wlr_output *output, void wlr_output_transform(struct wlr_output *output, enum wl_output_transform transform); bool wlr_output_set_cursor(struct wlr_output *output, - const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height); + const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height, + int32_t hotspot_x, int32_t hotspot_y); bool wlr_output_move_cursor(struct wlr_output *output, int x, int y); void wlr_output_destroy(struct wlr_output *output); void wlr_output_effective_resolution(struct wlr_output *output, -- cgit v1.2.3 From 972e9dbd1b2eb2853a60632d279bd754daf7c440 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 15:39:39 +0200 Subject: Add close command, add close for xwayland --- include/rootston/input.h | 2 +- include/rootston/view.h | 2 ++ rootston/cursor.c | 1 + rootston/desktop.c | 6 ++++++ rootston/keyboard.c | 4 ++++ rootston/xwayland.c | 21 ++++++++++++++------- 6 files changed, 28 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/rootston/input.h b/include/rootston/input.h index ae3e3b80..09509e85 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -81,7 +81,7 @@ struct roots_input { struct wlr_seat *wl_seat; enum roots_cursor_mode mode; - struct roots_view *active_view; + struct roots_view *active_view, *last_active_view; int offs_x, offs_y; int view_x, view_y, view_width, view_height; float view_rotation; diff --git a/include/rootston/view.h b/include/rootston/view.h index 39ff80db..64aad45e 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -65,11 +65,13 @@ struct roots_view { void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box); void (*activate)(struct roots_view *view, bool active); void (*resize)(struct roots_view *view, uint32_t width, uint32_t height); + void (*close)(struct roots_view *view); }; void view_get_size(struct roots_view *view, struct wlr_box *box); void view_get_input_bounds(struct roots_view *view, struct wlr_box *box); void view_activate(struct roots_view *view, bool active); void view_resize(struct roots_view *view, uint32_t width, uint32_t height); +void view_close(struct roots_view *view); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index 0ca45f16..9c4b0dd8 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -133,6 +133,7 @@ static void set_view_focus(struct roots_input *input, if (!view) { return; } + input->last_active_view = view; size_t index = 0; for (size_t i = 0; i < desktop->views->length; ++i) { diff --git a/rootston/desktop.c b/rootston/desktop.c index f99afaf5..d214e280 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -58,6 +58,12 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) { } } +void view_close(struct roots_view *view) { + if (view->close) { + view->close(view); + } +} + static struct wlr_subsurface *subsurface_at(struct wlr_surface *surface, double sx, double sy, double *sub_x, double *sub_y) { struct wlr_subsurface *subsurface; diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 8488e208..6f4334af 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -28,6 +28,10 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, struct roots_server *server = keyboard->input->server; if (strcmp(command, "exit") == 0) { wl_display_terminate(server->wl_display); + } else if (strcmp(command, "close") == 0) { + if (keyboard->input->last_active_view != NULL) { + view_close(keyboard->input->last_active_view); + } } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { const char *shell_cmd = command + strlen(exec_prefix); pid_t pid = fork(); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index bb8ced8e..4b833ef1 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -9,13 +9,6 @@ #include "rootston/desktop.h" #include "rootston/server.h" -static void resize(struct roots_view *view, uint32_t width, uint32_t height) { - assert(view->type == ROOTS_XWAYLAND_VIEW); - struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; - wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - xwayland_surface->x, xwayland_surface->y, width, height); -} - static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); @@ -39,6 +32,7 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { } static void activate(struct roots_view *view, bool active) { + assert(view->type == ROOTS_XWAYLAND_VIEW); if (active) { wlr_xwayland_surface_activate(view->desktop->xwayland, view->xwayland_surface); @@ -47,6 +41,18 @@ static void activate(struct roots_view *view, bool active) { } } +static void resize(struct roots_view *view, uint32_t width, uint32_t height) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, + xwayland_surface->x, xwayland_surface->y, width, height); +} + +static void close(struct roots_view *view) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + wlr_xwayland_surface_close(view->desktop->xwayland, view->xwayland_surface); +} + void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, xwayland_surface); @@ -82,6 +88,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; view->activate = activate; view->resize = resize; + view->close = close; roots_surface->view = view; list_add(desktop->views, view); } -- cgit v1.2.3 From 69aff9b35e0e5ce1031aaa65a0166423bc95d192 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 6 Oct 2017 15:58:49 +0200 Subject: Implement wlr_xdg_toplevel_v6_send_close --- include/wlr/types/wlr_xdg_shell_v6.h | 5 +++++ rootston/xdg_shell_v6.c | 9 +++++++++ types/wlr_xdg_shell_v6.c | 5 +++++ 3 files changed, 19 insertions(+) (limited to 'include') diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index cc52d9c7..de8dfca7 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -172,4 +172,9 @@ void wlr_xdg_toplevel_v6_set_fullscreen(struct wlr_xdg_surface_v6 *surface, void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, bool resizing); +/** + * Request that this toplevel surface closes. + */ +void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface); + #endif diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ab34f52a..c7072354 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -33,6 +33,14 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) { } } +static void close(struct roots_view *view) { + assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); + struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; + if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + wlr_xdg_toplevel_v6_send_close(surf); + } +} + static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, request_move); @@ -107,6 +115,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { view->get_size = get_size; view->activate = activate; view->resize = resize; + view->close = close; view->desktop = desktop; roots_surface->view = view; list_add(desktop->views, view); diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index c30291d1..fc029f2d 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -807,3 +807,8 @@ void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, wlr_xdg_surface_v6_schedule_configure(surface, false); } + +void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) { + assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL); + zxdg_toplevel_v6_send_close(surface->toplevel_state->resource); +} -- cgit v1.2.3 From 568b270cdfcee0f1427417510ef868d54fd8c223 Mon Sep 17 00:00:00 2001 From: Versus Void Date: Fri, 6 Oct 2017 12:03:34 +0300 Subject: Use xkb_state_update_mask() with Wayland backend Fix #158 --- backend/libinput/keyboard.c | 3 ++- backend/wayland/wl_seat.c | 7 +++++-- backend/x11/backend.c | 4 +++- include/wlr/interfaces/wlr_keyboard.h | 5 ++++- include/wlr/types/wlr_keyboard.h | 1 + types/wlr_keyboard.c | 18 ++++++++++++++---- 6 files changed, 29 insertions(+), 9 deletions(-) (limited to 'include') diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index 53c3a61b..00a7ecdf 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -67,5 +67,6 @@ void handle_keyboard_key(struct libinput_event *event, wlr_event.state = WLR_KEY_PRESSED; break; } - wlr_keyboard_update_state(wlr_dev->keyboard, &wlr_event); + wlr_event.update_state = true; + wlr_keyboard_notify_key(wlr_dev->keyboard, &wlr_event); } diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index ba3feb8d..fcfcc1d0 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -149,13 +149,16 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *wl_keyboard, wlr_event.state = state; wlr_event.time_sec = time / 1000; wlr_event.time_usec = time * 1000; - wlr_keyboard_update_state(dev->keyboard, &wlr_event); + wlr_keyboard_notify_key(dev->keyboard, &wlr_event); } static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group) { - + struct wlr_input_device *dev = data; + assert(dev && dev->keyboard); + wlr_keyboard_notify_modifiers(dev->keyboard, mods_depressed, mods_latched, + mods_locked, group); } static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard, diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 88c022d1..ed88064e 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -51,9 +51,11 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e .keycode = ev->detail - 8, .state = event->response_type == XCB_KEY_PRESS ? WLR_KEY_PRESSED : WLR_KEY_RELEASED, + .update_state = true, }; - wl_signal_emit(&x11->keyboard.events.key, &key); + // TODO use xcb-xkb for more precise modifiers state? + wlr_keyboard_notify_key(&x11->keyboard, &key); x11->time = ev->time; break; } diff --git a/include/wlr/interfaces/wlr_keyboard.h b/include/wlr/interfaces/wlr_keyboard.h index 78c1f753..570f5721 100644 --- a/include/wlr/interfaces/wlr_keyboard.h +++ b/include/wlr/interfaces/wlr_keyboard.h @@ -11,7 +11,10 @@ struct wlr_keyboard_impl { void wlr_keyboard_init(struct wlr_keyboard *keyboard, struct wlr_keyboard_impl *impl); void wlr_keyboard_destroy(struct wlr_keyboard *keyboard); -void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, +void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event); +void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard, + uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, + uint32_t group); #endif diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index 9ec8ddd4..99a624c2 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -65,6 +65,7 @@ struct wlr_event_keyboard_key { uint32_t time_sec; uint64_t time_usec; uint32_t keycode; + bool update_state; enum wlr_key_state state; }; diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 5dbcf064..f37895b0 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -45,11 +45,21 @@ static void keyboard_modifier_update(struct wlr_keyboard *keyboard) { wl_signal_emit(&keyboard->events.modifiers, keyboard); } -void wlr_keyboard_update_state(struct wlr_keyboard *keyboard, +void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard, + uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, + uint32_t group) { + xkb_state_update_mask(keyboard->xkb_state, mods_depressed, mods_latched, + mods_locked, 0, 0, group); + keyboard_modifier_update(keyboard); +} + +void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, struct wlr_event_keyboard_key *event) { - uint32_t keycode = event->keycode + 8; - xkb_state_update_key(keyboard->xkb_state, keycode, - event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); + if (event->update_state) { + uint32_t keycode = event->keycode + 8; + xkb_state_update_key(keyboard->xkb_state, keycode, + event->state == WLR_KEY_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); + } keyboard_led_update(keyboard); keyboard_modifier_update(keyboard); wl_signal_emit(&keyboard->events.key, event); -- cgit v1.2.3