From 9ccf66f53d5bf7aba6e2ede28f3bd1964a567ae0 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 24 Oct 2017 21:44:30 +0200 Subject: [PATCH 01/14] Remove gamma_control->link from list in destroy --- types/wlr_gamma_control.c | 1 + 1 file changed, 1 insertion(+) diff --git a/types/wlr_gamma_control.c b/types/wlr_gamma_control.c index 9d74e749..e765c2a5 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -15,6 +15,7 @@ static void gamma_control_destroy(struct wlr_gamma_control *gamma_control) { wl_signal_emit(&gamma_control->events.destroy, gamma_control); wl_list_remove(&gamma_control->output_destroy_listener.link); wl_resource_set_user_data(gamma_control->resource, NULL); + wl_list_remove(&gamma_control->link); free(gamma_control); } From e521b0404bb1a50326404a47bdb510f8fc46898e Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 24 Oct 2017 21:56:18 +0200 Subject: [PATCH 02/14] Add server-decoration skeleton --- include/wlr/types/wlr_server_decoration.h | 29 +++++++ protocol/meson.build | 2 + protocol/server-decoration.xml | 94 +++++++++++++++++++++++ types/meson.build | 1 + types/wlr_server_decoration.c | 64 +++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 include/wlr/types/wlr_server_decoration.h create mode 100644 protocol/server-decoration.xml create mode 100644 types/wlr_server_decoration.c diff --git a/include/wlr/types/wlr_server_decoration.h b/include/wlr/types/wlr_server_decoration.h new file mode 100644 index 00000000..11c2511c --- /dev/null +++ b/include/wlr/types/wlr_server_decoration.h @@ -0,0 +1,29 @@ +#ifndef WLR_TYPES_WLR_SERVER_DECORATION_H +#define WLR_TYPES_WLR_SERVER_DECORATION_H + +#include + +struct wlr_server_decoration_manager { + struct wl_global *wl_global; + struct wl_list decorations; // wlr_server_decoration::link + + void *data; +}; + +struct wlr_server_decoration { + struct wl_resource *resource; + struct wl_list link; + + struct { + struct wl_signal destroy; + } events; + + void *data; +}; + +struct wlr_server_decoration_manager *wlr_server_decoration_manager_create( + struct wl_display *display); +void wlr_server_decoration_manager_destroy( + struct wlr_server_decoration_manager *manager); + +#endif diff --git a/protocol/meson.build b/protocol/meson.build index 2cbb5b6d..ff54815a 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -24,12 +24,14 @@ protocols = [ [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], 'gamma-control.xml', 'screenshooter.xml', + 'server-decoration.xml', ] client_protocols = [ [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], 'gamma-control.xml', 'screenshooter.xml', + 'server-decoration.xml', ] wl_protos_src = [] diff --git a/protocol/server-decoration.xml b/protocol/server-decoration.xml new file mode 100644 index 00000000..45f11284 --- /dev/null +++ b/protocol/server-decoration.xml @@ -0,0 +1,94 @@ + + + . + ]]> + + + This interface allows to coordinate whether the server should create + a server-side window decoration around a wl_surface representing a + shell surface (wl_shell_surface or similar). By announcing support + for this interface the server indicates that it supports server + side decorations. + + + + When a client creates a server-side decoration object it indicates + that it supports the protocol. The client is supposed to tell the + server whether it wants server-side decorations or will provide + client-side decorations. + + If the client does not create a server-side decoration object for + a surface the server interprets this as lack of support for this + protocol and considers it as client-side decorated. Nevertheless a + client-side decorated surface should use this protocol to indicate + to the server that it does not want a server-side deco. + + + + + + + + + + + + + This event is emitted directly after binding the interface. It contains + the default mode for the decoration. When a new server decoration object + is created this new object will be in the default mode until the first + request_mode is requested. + + The server may change the default mode at any time. + + + + + + + + + + + + + + + + + + + + + This event is emitted directly after the decoration is created and + represents the base decoration policy by the server. E.g. a server + which wants all surfaces to be client-side decorated will send Client, + a server which wants server-side decoration will send Server. + + The client can request a different mode through the decoration request. + The server will acknowledge this by another event with the same mode. So + even if a server prefers server-side decoration it's possible to force a + client-side decoration. + + The server may emit this event at any time. In this case the client can + again request a different mode. It's the responsibility of the server to + prevent a feedback loop. + + + + + diff --git a/types/meson.build b/types/meson.build index cc21f209..2603ecfd 100644 --- a/types/meson.build +++ b/types/meson.build @@ -15,6 +15,7 @@ lib_wlr_types = static_library( 'wlr_region.c', 'wlr_screenshooter.c', 'wlr_seat.c', + 'wlr_server_decoration.c', 'wlr_surface.c', 'wlr_tablet_pad.c', 'wlr_tablet_tool.c', diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c new file mode 100644 index 00000000..9c34304b --- /dev/null +++ b/types/wlr_server_decoration.c @@ -0,0 +1,64 @@ +#include +#include +#include +#include + +static const struct org_kde_kwin_server_decoration_manager_interface +server_decoration_manager_impl = { + // TODO +}; + +static void server_decoration_manager_bind(struct wl_client *client, + void *_manager, uint32_t version, uint32_t id) { + struct wlr_server_decoration_manager *manager = _manager; + assert(client && manager); + + struct wl_resource *resource = wl_resource_create(client, + &org_kde_kwin_server_decoration_manager_interface, version, id); + if (resource == NULL) { + wl_client_post_no_memory(client); + return; + } + wl_resource_set_implementation(resource, &server_decoration_manager_impl, + manager, NULL); +} + +static void server_decoration_destroy( + struct wlr_server_decoration *decoration) { + wl_signal_emit(&decoration->events.destroy, decoration); + wl_resource_set_user_data(decoration->resource, NULL); + wl_list_remove(&decoration->link); + free(decoration); +} + +struct wlr_server_decoration_manager *wlr_server_decoration_manager_create( + struct wl_display *display) { + struct wlr_server_decoration_manager *manager = + calloc(1, sizeof(struct wlr_server_decoration_manager)); + if (manager == NULL) { + return NULL; + } + manager->wl_global = wl_global_create(display, + &org_kde_kwin_server_decoration_manager_interface, 1, manager, + server_decoration_manager_bind); + if (manager->wl_global == NULL) { + free(manager); + return NULL; + } + wl_list_init(&manager->decorations); + return manager; +} + +void wlr_server_decoration_manager_destroy( + struct wlr_server_decoration_manager *manager) { + if (manager == NULL) { + return; + } + struct wlr_server_decoration *decoration, *tmp; + wl_list_for_each_safe(decoration, tmp, &manager->decorations, + link) { + server_decoration_destroy(decoration); + } + wl_global_destroy(manager->wl_global); + free(manager); +} From e84d573b9127a431671e1f74773aee53830f8d09 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 24 Oct 2017 23:22:27 +0200 Subject: [PATCH 03/14] Complete server-decoration implementation --- include/wlr/types/wlr_server_decoration.h | 20 +++ types/wlr_server_decoration.c | 144 ++++++++++++++++++++-- 2 files changed, 153 insertions(+), 11 deletions(-) diff --git a/include/wlr/types/wlr_server_decoration.h b/include/wlr/types/wlr_server_decoration.h index 11c2511c..059aa77f 100644 --- a/include/wlr/types/wlr_server_decoration.h +++ b/include/wlr/types/wlr_server_decoration.h @@ -5,25 +5,45 @@ struct wlr_server_decoration_manager { struct wl_global *wl_global; + struct wl_list wl_resources; struct wl_list decorations; // wlr_server_decoration::link + uint32_t default_mode; // enum org_kde_kwin_server_decoration_manager_mode + + struct { + struct wl_signal new_decoration; + } events; + void *data; }; struct wlr_server_decoration { struct wl_resource *resource; + struct wlr_surface *surface; struct wl_list link; + // enum org_kde_kwin_server_decoration_manager_mode + uint32_t requested_mode; + uint32_t sent_mode; + struct { struct wl_signal destroy; + struct wl_signal request_mode; } events; + struct wl_listener surface_destroy_listener; + void *data; }; struct wlr_server_decoration_manager *wlr_server_decoration_manager_create( struct wl_display *display); +void wlr_server_decoration_manager_set_default_mode( + struct wlr_server_decoration_manager *manager, uint32_t default_mode); void wlr_server_decoration_manager_destroy( struct wlr_server_decoration_manager *manager); +void wlr_server_decoration_send_mode(struct wlr_server_decoration *decoration, + uint32_t mode); + #endif diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c index 9c34304b..0d276445 100644 --- a/types/wlr_server_decoration.c +++ b/types/wlr_server_decoration.c @@ -1,13 +1,131 @@ #include #include #include +#include #include +#include + +static void server_decoration_handle_release(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static void server_decoration_handle_request_mode(struct wl_client *client, + struct wl_resource *resource, uint32_t mode) { + struct wlr_server_decoration *decoration = + wl_resource_get_user_data(resource); + decoration->requested_mode = mode; + wl_signal_emit(&decoration->events.request_mode, decoration); +} + +void wlr_server_decoration_send_mode(struct wlr_server_decoration *decoration, + uint32_t mode) { + if (decoration->sent_mode == mode) { + return; + } + org_kde_kwin_server_decoration_send_mode(decoration->resource, mode); + decoration->sent_mode = mode; +} + +static void server_decoration_destroy( + struct wlr_server_decoration *decoration) { + wl_signal_emit(&decoration->events.destroy, decoration); + wl_list_remove(&decoration->surface_destroy_listener.link); + wl_resource_set_user_data(decoration->resource, NULL); + wl_list_remove(&decoration->link); + free(decoration); +} + +static void server_decoration_destroy_resource(struct wl_resource *resource) { + struct wlr_server_decoration *decoration = + wl_resource_get_user_data(resource); + if (decoration != NULL) { + server_decoration_destroy(decoration); + } +} + +static void server_decoration_handle_surface_destroy( + struct wl_listener *listener, void *data) { + struct wlr_server_decoration *decoration = + wl_container_of(listener, decoration, surface_destroy_listener); + server_decoration_destroy(decoration); +} + +static const struct org_kde_kwin_server_decoration_interface +server_decoration_impl = { + .release = server_decoration_handle_release, + .request_mode = server_decoration_handle_request_mode, +}; + +static void server_decoration_manager_handle_create(struct wl_client *client, + struct wl_resource *manager_resource, uint32_t id, + struct wl_resource *surface_resource) { + struct wlr_server_decoration_manager *manager = + wl_resource_get_user_data(manager_resource); + struct wlr_surface *surface = wl_resource_get_user_data(surface_resource); + + struct wlr_server_decoration *decoration = + calloc(1, sizeof(struct wlr_server_decoration)); + if (decoration == NULL) { + wl_client_post_no_memory(client); + return; + } + decoration->surface = surface; + decoration->requested_mode = + ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE; + + int version = wl_resource_get_version(manager_resource); + decoration->resource = wl_resource_create(client, + &org_kde_kwin_server_decoration_interface, version, id); + if (decoration->resource == NULL) { + wl_client_post_no_memory(client); + free(decoration); + return; + } + wl_resource_set_implementation(decoration->resource, + &server_decoration_impl, decoration, + server_decoration_destroy_resource); + + wlr_log(L_DEBUG, "new server_decoration %p (res %p)", decoration, + decoration->resource); + + wl_signal_init(&decoration->events.destroy); + wl_signal_init(&decoration->events.request_mode); + + wl_signal_add(&surface->events.destroy, + &decoration->surface_destroy_listener); + decoration->surface_destroy_listener.notify = + server_decoration_handle_surface_destroy; + + wl_list_insert(&manager->decorations, &decoration->link); + + org_kde_kwin_server_decoration_send_mode(decoration->resource, + manager->default_mode); + decoration->sent_mode = manager->default_mode; + + wl_signal_emit(&manager->events.new_decoration, decoration); +} static const struct org_kde_kwin_server_decoration_manager_interface server_decoration_manager_impl = { - // TODO + .create = server_decoration_manager_handle_create, }; +void wlr_server_decoration_manager_set_default_mode( + struct wlr_server_decoration_manager *manager, uint32_t default_mode) { + manager->default_mode = default_mode; + + struct wl_resource *resource; + wl_resource_for_each(resource, &manager->wl_resources) { + org_kde_kwin_server_decoration_manager_send_default_mode(resource, + manager->default_mode); + } +} + +void server_decoration_manager_destroy_resource(struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); +} + static void server_decoration_manager_bind(struct wl_client *client, void *_manager, uint32_t version, uint32_t id) { struct wlr_server_decoration_manager *manager = _manager; @@ -20,15 +138,12 @@ static void server_decoration_manager_bind(struct wl_client *client, return; } wl_resource_set_implementation(resource, &server_decoration_manager_impl, - manager, NULL); -} + manager, server_decoration_manager_destroy_resource); -static void server_decoration_destroy( - struct wlr_server_decoration *decoration) { - wl_signal_emit(&decoration->events.destroy, decoration); - wl_resource_set_user_data(decoration->resource, NULL); - wl_list_remove(&decoration->link); - free(decoration); + wl_list_insert(&manager->wl_resources, wl_resource_get_link(resource)); + + org_kde_kwin_server_decoration_manager_send_default_mode(resource, + manager->default_mode); } struct wlr_server_decoration_manager *wlr_server_decoration_manager_create( @@ -45,7 +160,10 @@ struct wlr_server_decoration_manager *wlr_server_decoration_manager_create( free(manager); return NULL; } + manager->default_mode = ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE; + wl_list_init(&manager->wl_resources); wl_list_init(&manager->decorations); + wl_signal_init(&manager->events.new_decoration); return manager; } @@ -54,11 +172,15 @@ void wlr_server_decoration_manager_destroy( if (manager == NULL) { return; } - struct wlr_server_decoration *decoration, *tmp; - wl_list_for_each_safe(decoration, tmp, &manager->decorations, + struct wlr_server_decoration *decoration, *tmp_decoration; + wl_list_for_each_safe(decoration, tmp_decoration, &manager->decorations, link) { server_decoration_destroy(decoration); } + struct wl_resource *resource, *tmp_resource; + wl_resource_for_each_safe(resource, tmp_resource, &manager->wl_resources) { + server_decoration_manager_destroy_resource(resource); + } wl_global_destroy(manager->wl_global); free(manager); } From c57267da136cc77ac3cd358090f0f38e16033c4f Mon Sep 17 00:00:00 2001 From: Alexander Taylor Date: Tue, 24 Oct 2017 23:51:53 +0100 Subject: [PATCH 04/14] Fix order of WM_HINTS and WM_PROTOCOLS in xwm atom_map --- xwayland/xwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 935fcd96..499d0bbf 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -16,8 +16,8 @@ const char *atom_map[ATOM_LAST] = { "WL_SURFACE_ID", "WM_DELETE_WINDOW", - "WM_HINTS", "WM_PROTOCOLS", + "WM_HINTS", "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "_MOTIF_WM_HINTS", From 7c85709de19e2cb03209b414ce91039d363972ff Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 25 Oct 2017 20:34:40 +0200 Subject: [PATCH 05/14] Focus last view on close in rootston --- include/rootston/view.h | 3 ++- rootston/desktop.c | 16 ++++++++++++++-- rootston/wl_shell.c | 3 ++- rootston/xdg_shell_v6.c | 3 ++- rootston/xwayland.c | 3 ++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/rootston/view.h b/include/rootston/view.h index 7d297329..9eb7065d 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -80,6 +80,7 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height); void view_set_position(struct roots_view *view, double x, double y); void view_close(struct roots_view *view); bool view_center(struct roots_view *view); -void view_initialize(struct roots_view *view); +void view_setup(struct roots_view *view); +void view_teardown(struct roots_view *view); #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index 40d088b8..315db83a 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -107,14 +107,26 @@ bool view_center(struct roots_view *view) { return true; } -void view_initialize(struct roots_view *view) { +void view_setup(struct roots_view *view) { view_center(view); - struct roots_input *input = view->desktop->server->input; + struct roots_input *input = view->desktop->server->input; set_view_focus(input, view->desktop, view); wlr_seat_keyboard_notify_enter(input->wl_seat, view->wlr_surface); } +void view_teardown(struct roots_view *view) { + struct wlr_list *views = view->desktop->views; + if (views->length < 2 || views->items[views->length-1] != view) { + return; + } + + struct roots_view *prev_view = views->items[views->length-2]; + struct roots_input *input = prev_view->desktop->server->input; + set_view_focus(input, prev_view->desktop, prev_view); + wlr_seat_keyboard_notify_enter(input->wl_seat, prev_view->wlr_surface); +} + struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { for (int i = desktop->views->length - 1; i >= 0; --i) { diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 88397af8..e5366672 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -56,6 +56,7 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_wl_shell_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); + view_teardown(roots_surface->view); wl_list_remove(&roots_surface->destroy.link); wl_list_remove(&roots_surface->request_move.link); wl_list_remove(&roots_surface->request_resize.link); @@ -111,7 +112,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; roots_surface->view = view; wlr_list_add(desktop->views, view); - view_initialize(view); + view_setup(view); if (surface->state == WLR_WL_SHELL_SURFACE_STATE_TRANSIENT) { // we need to map it relative to the parent diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 95b20a8b..85871144 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -74,6 +74,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xdg_surface_v6 *roots_xdg_surface = wl_container_of(listener, roots_xdg_surface, destroy); + view_teardown(roots_xdg_surface->view); wl_list_remove(&roots_xdg_surface->commit.link); wl_list_remove(&roots_xdg_surface->destroy.link); wl_list_remove(&roots_xdg_surface->request_move.link); @@ -126,5 +127,5 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { roots_surface->view = view; wlr_list_add(desktop->views, view); - view_initialize(view); + view_setup(view); } diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 1149b966..8b7c32f4 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -43,6 +43,7 @@ static void close(struct roots_view *view) { static void handle_destroy(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, destroy); + view_teardown(roots_surface->view); wl_list_remove(&roots_surface->destroy.link); view_destroy(roots_surface->view); free(roots_surface); @@ -101,6 +102,6 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wlr_list_add(desktop->views, view); if (!surface->override_redirect) { - view_initialize(view); + view_setup(view); } } From 9d587d759f45fac9bad49b7d1de8a45c4d56d652 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 18:58:44 +0200 Subject: [PATCH 06/14] Do not set hw cursor if disabled when switching VT --- backend/drm/backend.c | 2 +- backend/drm/drm.c | 2 ++ include/backend/drm/drm.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 40b559e2..af2619ff 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -76,7 +76,7 @@ static void session_signal(struct wl_listener *listener, void *data) { struct wlr_drm_plane *plane = conn->crtc->cursor; drm->iface->crtc_set_cursor(drm, conn->crtc, - plane ? plane->cursor_bo : NULL); + (plane && plane->cursor_enabled) ? plane->cursor_bo : NULL); } } else { wlr_log(L_INFO, "DRM fd paused"); diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 441ba24e..a3594bb0 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -505,8 +505,10 @@ static bool wlr_drm_connector_set_cursor(struct wlr_output *output, if (!buf && update_pixels) { // Hide the cursor + plane->cursor_enabled = false; return drm->iface->crtc_set_cursor(drm, crtc, NULL); } + plane->cursor_enabled = true; // We don't have a real cursor plane, so we make a fake one if (!plane) { diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 4d23f963..a6dd247c 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -33,6 +33,7 @@ struct wlr_drm_plane { float matrix[16]; struct wlr_texture *wlr_tex; struct gbm_bo *cursor_bo; + bool cursor_enabled; union wlr_drm_plane_props props; }; From 4e5d23daa9b4d70bf8b614d5375ee1ccdab6771f Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 19:59:32 +0200 Subject: [PATCH 07/14] Per-keyboard configuration --- include/rootston/config.h | 27 ++++++++++---- rootston/config.c | 67 ++++++++++++++++++++++++++++++++--- rootston/cursor.c | 12 +++++-- rootston/keyboard.c | 30 +++++++++++++--- rootston/rootston.ini.example | 2 +- 5 files changed, 118 insertions(+), 20 deletions(-) diff --git a/include/rootston/config.h b/include/rootston/config.h index 5fa4890f..792146fb 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -26,6 +26,17 @@ struct binding_config { struct wl_list link; }; +struct keyboard_config { + char *name; + uint32_t meta_key; + char *rules; + char *model; + char *layout; + char *variant; + char *options; + struct wl_list link; +}; + struct roots_config { bool xwayland; // TODO: Multiple cursors, multiseat @@ -34,13 +45,10 @@ struct roots_config { struct wlr_box *mapped_box; } cursor; - struct { - uint32_t meta_key; - } keyboard; - struct wl_list outputs; struct wl_list devices; struct wl_list bindings; + struct wl_list keyboards; char *config_path; char *startup_cmd; }; @@ -54,13 +62,20 @@ void roots_config_destroy(struct roots_config *config); * NULL. */ struct output_config *config_get_output(struct roots_config *config, - struct wlr_output *output); + struct wlr_output *output); /** * Get configuration for the device. If the device is not configured, returns * NULL. */ struct device_config *config_get_device(struct roots_config *config, - struct wlr_input_device *device); + struct wlr_input_device *device); + +/** + * Get configuration for the keyboard. If the keyboard is not configured, + * returns NULL. + */ +struct keyboard_config *config_get_keyboard(struct roots_config *config, + struct wlr_input_device *device); #endif diff --git a/rootston/config.c b/rootston/config.c index c9c892f9..863adc60 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -149,6 +149,7 @@ void add_binding_config(struct wl_list *bindings, const char* combination, static const char *output_prefix = "output:"; static const char *device_prefix = "device:"; +static const char *keyboard_prefix = "keyboard:"; static int config_ini_handler(void *user, const char *section, const char *name, const char *value) { @@ -219,9 +220,9 @@ static int config_ini_handler(void *user, const char *section, const char *name, } } else if (strncmp(device_prefix, section, strlen(device_prefix)) == 0) { const char *device_name = section + strlen(device_prefix); + struct device_config *dc; bool found = false; - wl_list_for_each(dc, &config->devices, link) { if (strcmp(dc->name, device_name) == 0) { found = true; @@ -244,12 +245,39 @@ static int config_ini_handler(void *user, const char *section, const char *name, } else { wlr_log(L_ERROR, "got unknown device config: %s", name); } - } else if (strcmp(section, "keyboard") == 0) { + } else if (strncmp(keyboard_prefix, section, strlen(keyboard_prefix)) == 0) { + const char *device_name = section + strlen(keyboard_prefix); + + struct keyboard_config *kc; + bool found = false; + wl_list_for_each(kc, &config->keyboards, link) { + if (strcmp(kc->name, device_name) == 0) { + found = true; + break; + } + } + + if (!found) { + kc = calloc(1, sizeof(struct keyboard_config)); + kc->name = strdup(device_name); + wl_list_insert(&config->keyboards, &kc->link); + } + if (strcmp(name, "meta-key") == 0) { - config->keyboard.meta_key = parse_modifier(value); - if (config->keyboard.meta_key == 0) { + kc->meta_key = parse_modifier(value); + if (kc->meta_key == 0) { wlr_log(L_ERROR, "got unknown meta key: %s", name); } + } else if (strcmp(name, "rules") == 0) { + kc->rules = strdup(value); + } else if (strcmp(name, "model") == 0) { + kc->model = strdup(value); + } else if (strcmp(name, "layout") == 0) { + kc->layout = strdup(value); + } else if (strcmp(name, "variant") == 0) { + kc->variant = strdup(value); + } else if (strcmp(name, "options") == 0) { + kc->options = strdup(value); } else { wlr_log(L_ERROR, "got unknown keyboard config: %s", name); } @@ -271,6 +299,7 @@ struct roots_config *parse_args(int argc, char *argv[]) { config->xwayland = true; wl_list_init(&config->outputs); wl_list_init(&config->devices); + wl_list_init(&config->keyboards); wl_list_init(&config->bindings); int c; @@ -305,10 +334,12 @@ struct roots_config *parse_args(int argc, char *argv[]) { if (result == -1) { wlr_log(L_DEBUG, "No config file found. Using sensible defaults."); - config->keyboard.meta_key = WLR_MODIFIER_LOGO; add_binding_config(&config->bindings, "Logo+Shift+E", "exit"); add_binding_config(&config->bindings, "Ctrl+q", "close"); add_binding_config(&config->bindings, "Alt+Tab", "next_window"); + struct keyboard_config *kc = calloc(1, sizeof(struct keyboard_config)); + kc->meta_key = WLR_MODIFIER_LOGO; + wl_list_insert(&config->keyboards, &kc->link); } else if (result == -2) { wlr_log(L_ERROR, "Could not allocate memory to parse config file"); exit(1); @@ -335,6 +366,17 @@ void roots_config_destroy(struct roots_config *config) { free(dc); } + struct keyboard_config *kc, *ktmp = NULL; + wl_list_for_each_safe(kc, ktmp, &config->bindings, link) { + free(kc->name); + free(kc->rules); + free(kc->model); + free(kc->layout); + free(kc->variant); + free(kc->options); + free(kc); + } + struct binding_config *bc, *btmp = NULL; wl_list_for_each_safe(bc, btmp, &config->bindings, link) { free(bc->keysyms); @@ -371,3 +413,18 @@ struct device_config *config_get_device(struct roots_config *config, return NULL; } + +struct keyboard_config *config_get_keyboard(struct roots_config *config, + struct wlr_input_device *device) { + struct keyboard_config *kc; + struct keyboard_config *default_kc = NULL; + wl_list_for_each(kc, &config->keyboards, link) { + if (strcmp(kc->name, "*") == 0) { + default_kc = kc; + } else if (strcmp(kc->name, device->name) == 0) { + return kc; + } + } + + return default_kc; +} diff --git a/rootston/cursor.c b/rootston/cursor.c index b55eab3f..0cbca9f8 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -215,8 +215,14 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { event->orientation, event->delta); } -static bool is_meta_pressed(struct roots_input *input) { - uint32_t meta_key = input->server->config->keyboard.meta_key; +static bool is_meta_pressed(struct roots_input *input, + struct wlr_input_device *device) { + struct keyboard_config *config = config_get_keyboard(input->server->config, + device); + uint32_t meta_key = 0; + if (config != NULL) { + meta_key = config->meta_key; + } if (meta_key == 0) { return false; } @@ -241,7 +247,7 @@ static void do_cursor_button_press(struct roots_input *input, struct roots_view *view = view_at(desktop, input->cursor->x, input->cursor->y, &surface, &sx, &sy); - if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input)) { + if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input, device)) { set_view_focus(input, desktop, view); switch (button) { diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 61604da0..008fba2d 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -137,13 +137,33 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_list_insert(&input->keyboards, &keyboard->link); + struct keyboard_config *config = config_get_keyboard(input->config, + device); + struct xkb_rule_names rules; memset(&rules, 0, sizeof(rules)); - rules.rules = getenv("XKB_DEFAULT_RULES"); - rules.model = getenv("XKB_DEFAULT_MODEL"); - rules.layout = getenv("XKB_DEFAULT_LAYOUT"); - rules.variant = getenv("XKB_DEFAULT_VARIANT"); - rules.options = getenv("XKB_DEFAULT_OPTIONS"); + if (config != NULL) { + rules.rules = config->rules; + rules.model = config->model; + rules.layout = config->layout; + rules.variant = config->variant; + rules.options = config->options; + } + if (rules.rules == NULL) { + rules.rules = getenv("XKB_DEFAULT_RULES"); + } + if (rules.model == NULL) { + rules.model = getenv("XKB_DEFAULT_MODEL"); + } + if (rules.layout == NULL) { + rules.layout = getenv("XKB_DEFAULT_LAYOUT"); + } + if (rules.variant == NULL) { + rules.variant = getenv("XKB_DEFAULT_VARIANT"); + } + if (rules.options == NULL) { + rules.options = getenv("XKB_DEFAULT_OPTIONS"); + } struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (context == NULL) { wlr_log(L_ERROR, "Cannot create XKB context"); diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example index 433dc78f..63fa897c 100644 --- a/rootston/rootston.ini.example +++ b/rootston/rootston.ini.example @@ -29,7 +29,7 @@ map-to-output = VGA-1 # Restrict cursor movements for this mouse to concrete rectangle geometry = 2500x800 -[keyboard] +[keyboard:*] meta-key = Logo # Keybindings From c0c4816b132649d1ffc5435720578286d83a19ef Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 22:38:03 +0200 Subject: [PATCH 08/14] Fix fallback when there are two config blocks for a keyboard --- include/rootston/config.h | 2 +- rootston/config.c | 8 ++--- rootston/cursor.c | 8 +++-- rootston/keyboard.c | 64 ++++++++++++++++++++++++--------------- 4 files changed, 49 insertions(+), 33 deletions(-) diff --git a/include/rootston/config.h b/include/rootston/config.h index 792146fb..ecbdd88b 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -73,7 +73,7 @@ struct device_config *config_get_device(struct roots_config *config, /** * Get configuration for the keyboard. If the keyboard is not configured, - * returns NULL. + * returns NULL. A NULL device returns the default config for keyboards. */ struct keyboard_config *config_get_keyboard(struct roots_config *config, struct wlr_input_device *device); diff --git a/rootston/config.c b/rootston/config.c index 863adc60..7a443151 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -417,14 +417,12 @@ struct device_config *config_get_device(struct roots_config *config, struct keyboard_config *config_get_keyboard(struct roots_config *config, struct wlr_input_device *device) { struct keyboard_config *kc; - struct keyboard_config *default_kc = NULL; wl_list_for_each(kc, &config->keyboards, link) { - if (strcmp(kc->name, "*") == 0) { - default_kc = kc; - } else if (strcmp(kc->name, device->name) == 0) { + if ((device != NULL && strcmp(kc->name, device->name) == 0) || + (device == NULL && strcmp(kc->name, "*") == 0)) { return kc; } } - return default_kc; + return NULL; } diff --git a/rootston/cursor.c b/rootston/cursor.c index 0cbca9f8..7d2548eb 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -217,10 +217,12 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) { static bool is_meta_pressed(struct roots_input *input, struct wlr_input_device *device) { - struct keyboard_config *config = config_get_keyboard(input->server->config, - device); uint32_t meta_key = 0; - if (config != NULL) { + struct keyboard_config *config; + if ((config = config_get_keyboard(input->server->config, device))) { + meta_key = config->meta_key; + } else if (!meta_key && (config = config_get_keyboard(input->server->config, + NULL))) { meta_key = config->meta_key; } if (meta_key == 0) { diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 008fba2d..142e9c71 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -125,6 +125,28 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { } } +static void keyboard_config_merge(struct keyboard_config *config, + struct keyboard_config *fallback) { + if (fallback == NULL) { + return; + } + if (config->rules == NULL) { + config->rules = fallback->rules; + } + if (config->model == NULL) { + config->model = fallback->model; + } + if (config->layout == NULL) { + config->layout = fallback->layout; + } + if (config->variant == NULL) { + config->variant = fallback->variant; + } + if (config->options == NULL) { + config->options = fallback->options; + } +} + void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { struct roots_keyboard *keyboard = calloc(sizeof(struct roots_keyboard), 1); if (keyboard == NULL) { @@ -137,33 +159,27 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { wl_signal_add(&device->keyboard->events.key, &keyboard->key); wl_list_insert(&input->keyboards, &keyboard->link); - struct keyboard_config *config = config_get_keyboard(input->config, - device); + struct keyboard_config config; + memset(&config, 0, sizeof(config)); + keyboard_config_merge(&config, config_get_keyboard(input->config, device)); + keyboard_config_merge(&config, config_get_keyboard(input->config, NULL)); + + struct keyboard_config env_config = { + .rules = getenv("XKB_DEFAULT_RULES"), + .model = getenv("XKB_DEFAULT_MODEL"), + .layout = getenv("XKB_DEFAULT_LAYOUT"), + .variant = getenv("XKB_DEFAULT_VARIANT"), + .options = getenv("XKB_DEFAULT_OPTIONS"), + }; + keyboard_config_merge(&config, &env_config); struct xkb_rule_names rules; memset(&rules, 0, sizeof(rules)); - if (config != NULL) { - rules.rules = config->rules; - rules.model = config->model; - rules.layout = config->layout; - rules.variant = config->variant; - rules.options = config->options; - } - if (rules.rules == NULL) { - rules.rules = getenv("XKB_DEFAULT_RULES"); - } - if (rules.model == NULL) { - rules.model = getenv("XKB_DEFAULT_MODEL"); - } - if (rules.layout == NULL) { - rules.layout = getenv("XKB_DEFAULT_LAYOUT"); - } - if (rules.variant == NULL) { - rules.variant = getenv("XKB_DEFAULT_VARIANT"); - } - if (rules.options == NULL) { - rules.options = getenv("XKB_DEFAULT_OPTIONS"); - } + rules.rules = config.rules; + rules.model = config.model; + rules.layout = config.layout; + rules.variant = config.variant; + rules.options = config.options; struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS); if (context == NULL) { wlr_log(L_ERROR, "Cannot create XKB context"); From 882bda066402b19ac4d8b7470d7fbc63347733e7 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 23:02:24 +0200 Subject: [PATCH 09/14] Rename default keyboard section --- rootston/config.c | 76 +++++++++++++++++++---------------- rootston/rootston.ini.example | 2 +- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/rootston/config.c b/rootston/config.c index 7a443151..6f81170b 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -147,6 +147,43 @@ void add_binding_config(struct wl_list *bindings, const char* combination, } } +static void config_handle_keyboard(struct roots_config *config, + const char *device_name, const char *name, const char *value) { + struct keyboard_config *kc; + bool found = false; + wl_list_for_each(kc, &config->keyboards, link) { + if (strcmp(kc->name, device_name) == 0) { + found = true; + break; + } + } + + if (!found) { + kc = calloc(1, sizeof(struct keyboard_config)); + kc->name = strdup(device_name); + wl_list_insert(&config->keyboards, &kc->link); + } + + if (strcmp(name, "meta-key") == 0) { + kc->meta_key = parse_modifier(value); + if (kc->meta_key == 0) { + wlr_log(L_ERROR, "got unknown meta key: %s", name); + } + } else if (strcmp(name, "rules") == 0) { + kc->rules = strdup(value); + } else if (strcmp(name, "model") == 0) { + kc->model = strdup(value); + } else if (strcmp(name, "layout") == 0) { + kc->layout = strdup(value); + } else if (strcmp(name, "variant") == 0) { + kc->variant = strdup(value); + } else if (strcmp(name, "options") == 0) { + kc->options = strdup(value); + } else { + wlr_log(L_ERROR, "got unknown keyboard config: %s", name); + } +} + static const char *output_prefix = "output:"; static const char *device_prefix = "device:"; static const char *keyboard_prefix = "keyboard:"; @@ -245,42 +282,11 @@ static int config_ini_handler(void *user, const char *section, const char *name, } else { wlr_log(L_ERROR, "got unknown device config: %s", name); } + } else if (strcmp(section, "keyboard") == 0) { + config_handle_keyboard(config, "", name, value); } else if (strncmp(keyboard_prefix, section, strlen(keyboard_prefix)) == 0) { const char *device_name = section + strlen(keyboard_prefix); - - struct keyboard_config *kc; - bool found = false; - wl_list_for_each(kc, &config->keyboards, link) { - if (strcmp(kc->name, device_name) == 0) { - found = true; - break; - } - } - - if (!found) { - kc = calloc(1, sizeof(struct keyboard_config)); - kc->name = strdup(device_name); - wl_list_insert(&config->keyboards, &kc->link); - } - - if (strcmp(name, "meta-key") == 0) { - kc->meta_key = parse_modifier(value); - if (kc->meta_key == 0) { - wlr_log(L_ERROR, "got unknown meta key: %s", name); - } - } else if (strcmp(name, "rules") == 0) { - kc->rules = strdup(value); - } else if (strcmp(name, "model") == 0) { - kc->model = strdup(value); - } else if (strcmp(name, "layout") == 0) { - kc->layout = strdup(value); - } else if (strcmp(name, "variant") == 0) { - kc->variant = strdup(value); - } else if (strcmp(name, "options") == 0) { - kc->options = strdup(value); - } else { - wlr_log(L_ERROR, "got unknown keyboard config: %s", name); - } + config_handle_keyboard(config, device_name, name, value); } else if (strcmp(section, "bindings") == 0) { add_binding_config(&config->bindings, name, value); } else { @@ -419,7 +425,7 @@ struct keyboard_config *config_get_keyboard(struct roots_config *config, struct keyboard_config *kc; wl_list_for_each(kc, &config->keyboards, link) { if ((device != NULL && strcmp(kc->name, device->name) == 0) || - (device == NULL && strcmp(kc->name, "*") == 0)) { + (device == NULL && strcmp(kc->name, "") == 0)) { return kc; } } diff --git a/rootston/rootston.ini.example b/rootston/rootston.ini.example index 63fa897c..433dc78f 100644 --- a/rootston/rootston.ini.example +++ b/rootston/rootston.ini.example @@ -29,7 +29,7 @@ map-to-output = VGA-1 # Restrict cursor movements for this mouse to concrete rectangle geometry = 2500x800 -[keyboard:*] +[keyboard] meta-key = Logo # Keybindings From a43acae0005ec4d635f1477376fad2ff5d12d611 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 00:02:30 +0200 Subject: [PATCH 10/14] Send server-decoration ack event automatically --- include/rootston/desktop.h | 2 ++ include/wlr/types/wlr_server_decoration.h | 9 ++------- rootston/desktop.c | 9 ++++++++- rootston/meson.build | 2 +- types/wlr_server_decoration.c | 22 ++++++++-------------- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index c3859afb..376412fb 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -37,11 +37,13 @@ struct roots_desktop { struct wlr_xdg_shell_v6 *xdg_shell_v6; struct wlr_gamma_control_manager *gamma_control_manager; struct wlr_screenshooter *screenshooter; + struct wlr_server_decoration_manager *server_decoration_manager; struct wl_listener output_add; struct wl_listener output_remove; struct wl_listener xdg_shell_v6_surface; struct wl_listener wl_shell_surface; + struct wl_listener decoration_new; #ifdef HAS_XWAYLAND struct wlr_xwayland *xwayland; diff --git a/include/wlr/types/wlr_server_decoration.h b/include/wlr/types/wlr_server_decoration.h index 059aa77f..b4cac5b7 100644 --- a/include/wlr/types/wlr_server_decoration.h +++ b/include/wlr/types/wlr_server_decoration.h @@ -22,13 +22,11 @@ struct wlr_server_decoration { struct wlr_surface *surface; struct wl_list link; - // enum org_kde_kwin_server_decoration_manager_mode - uint32_t requested_mode; - uint32_t sent_mode; + uint32_t mode; // enum org_kde_kwin_server_decoration_manager_mode struct { struct wl_signal destroy; - struct wl_signal request_mode; + struct wl_signal mode; } events; struct wl_listener surface_destroy_listener; @@ -43,7 +41,4 @@ void wlr_server_decoration_manager_set_default_mode( void wlr_server_decoration_manager_destroy( struct wlr_server_decoration_manager *manager); -void wlr_server_decoration_send_mode(struct wlr_server_decoration *decoration, - uint32_t mode); - #endif diff --git a/rootston/desktop.c b/rootston/desktop.c index 40d088b8..a9d38353 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -7,11 +7,13 @@ #include #include #include +#include #include #include #include #include -#include "rootston/desktop.h" +#include +#include "rootston/server.h" #include "rootston/server.h" void view_destroy(struct roots_view *view) { @@ -252,6 +254,11 @@ struct roots_desktop *desktop_create(struct roots_server *server, server->wl_display); desktop->screenshooter = wlr_screenshooter_create(server->wl_display, server->renderer); + desktop->server_decoration_manager = + wlr_server_decoration_manager_create(server->wl_display); + wlr_server_decoration_manager_set_default_mode( + desktop->server_decoration_manager, + ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_CLIENT); return desktop; } diff --git a/rootston/meson.build b/rootston/meson.build index f2621450..53cab62d 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -17,5 +17,5 @@ if get_option('enable_xwayland') sources += ['xwayland.c'] endif executable( - 'rootston', sources, dependencies: wlroots + 'rootston', sources, dependencies: [wlroots, wlr_protos] ) diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c index 0d276445..0664edfb 100644 --- a/types/wlr_server_decoration.c +++ b/types/wlr_server_decoration.c @@ -14,17 +14,13 @@ static void server_decoration_handle_request_mode(struct wl_client *client, struct wl_resource *resource, uint32_t mode) { struct wlr_server_decoration *decoration = wl_resource_get_user_data(resource); - decoration->requested_mode = mode; - wl_signal_emit(&decoration->events.request_mode, decoration); -} - -void wlr_server_decoration_send_mode(struct wlr_server_decoration *decoration, - uint32_t mode) { - if (decoration->sent_mode == mode) { + if (decoration->mode == mode) { return; } - org_kde_kwin_server_decoration_send_mode(decoration->resource, mode); - decoration->sent_mode = mode; + decoration->mode = mode; + wl_signal_emit(&decoration->events.mode, decoration); + org_kde_kwin_server_decoration_send_mode(decoration->resource, + decoration->mode); } static void server_decoration_destroy( @@ -71,8 +67,7 @@ static void server_decoration_manager_handle_create(struct wl_client *client, return; } decoration->surface = surface; - decoration->requested_mode = - ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_NONE; + decoration->mode = manager->default_mode; int version = wl_resource_get_version(manager_resource); decoration->resource = wl_resource_create(client, @@ -90,7 +85,7 @@ static void server_decoration_manager_handle_create(struct wl_client *client, decoration->resource); wl_signal_init(&decoration->events.destroy); - wl_signal_init(&decoration->events.request_mode); + wl_signal_init(&decoration->events.mode); wl_signal_add(&surface->events.destroy, &decoration->surface_destroy_listener); @@ -100,8 +95,7 @@ static void server_decoration_manager_handle_create(struct wl_client *client, wl_list_insert(&manager->decorations, &decoration->link); org_kde_kwin_server_decoration_send_mode(decoration->resource, - manager->default_mode); - decoration->sent_mode = manager->default_mode; + decoration->mode); wl_signal_emit(&manager->events.new_decoration, decoration); } From ad27cc3bffd459a0162db74eee60deb3ec46dbb0 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 18:41:31 +0200 Subject: [PATCH 11/14] Set compositor cursor for move, resize and rotate --- rootston/cursor.c | 84 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index 7d2548eb..8b269a11 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -31,6 +31,28 @@ const struct roots_input_event *get_input_event(struct roots_input *input, return NULL; } +static void cursor_set_xcursor_image(struct roots_input *input, + struct wlr_xcursor_image *image) { + struct roots_output *output; + wl_list_for_each(output, &input->server->desktop->outputs, link) { + if (!wlr_output_set_cursor(output->wlr_output, image->buffer, + image->width, image->width, image->height, + image->hotspot_x, image->hotspot_y)) { + wlr_log(L_DEBUG, "Failed to set hardware cursor"); + return; + } + } +} + +static void cursor_set_surface(struct roots_input *input, + struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) { + struct roots_output *output; + wl_list_for_each(output, &input->server->desktop->outputs, link) { + wlr_output_set_cursor_surface(output->wlr_output, surface, + hotspot_x, hotspot_y); + } +} + void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view) { input->mode = ROOTS_CURSOR_MOVE; @@ -39,6 +61,35 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, input->view_x = view->x; input->view_y = view->y; wlr_seat_pointer_clear_focus(input->wl_seat); + + struct wlr_xcursor *xcursor = wlr_xcursor_theme_get_cursor(input->theme, + "grabbing"); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); + } +} + +static const char *get_resize_cursor_name(uint32_t edges) { + if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { + if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + return "ne-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + return "nw-resize"; + } + return "n-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { + if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + return "se-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + return "sw-resize"; + } + return "s-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + return "e-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + return "w-resize"; + } + return "se-resize"; // fallback } void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, @@ -54,6 +105,12 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, input->view_height = size.height; input->resize_edges = edges; wlr_seat_pointer_clear_focus(input->wl_seat); + + struct wlr_xcursor *xcursor = wlr_xcursor_theme_get_cursor(input->theme, + get_resize_cursor_name(edges)); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); + } } void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, @@ -63,18 +120,11 @@ void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, input->offs_y = cursor->y; input->view_rotation = view->rotation; wlr_seat_pointer_clear_focus(input->wl_seat); -} -static void cursor_set_xcursor_image(struct roots_input *input, - struct wlr_xcursor_image *image) { - struct roots_output *output; - wl_list_for_each(output, &input->server->desktop->outputs, link) { - if (!wlr_output_set_cursor(output->wlr_output, image->buffer, - image->width, image->width, image->height, - image->hotspot_x, image->hotspot_y)) { - wlr_log(L_DEBUG, "Failed to set hardware cursor"); - return; - } + struct wlr_xcursor *xcursor = wlr_xcursor_theme_get_cursor(input->theme, + "grabbing"); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); } } @@ -94,7 +144,6 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { set_compositor_cursor = view_client != input->cursor_client; } if (set_compositor_cursor) { - wlr_log(L_DEBUG, "Switching to compositor cursor"); cursor_set_xcursor_image(input, input->xcursor->images[0]); input->cursor_client = NULL; } @@ -274,6 +323,7 @@ static void do_cursor_button_press(struct roots_input *input, switch (state) { case WLR_BUTTON_RELEASED: set_view_focus(input, desktop, NULL); + cursor_update_position(input, time); break; case WLR_BUTTON_PRESSED: i = input->input_events_idx; @@ -437,19 +487,13 @@ static void handle_request_set_cursor(struct wl_listener *listener, wl_resource_get_client(focused_surface->resource); ok = event->client == focused_client; } - if (!ok) { + if (!ok || input->mode != ROOTS_CURSOR_PASSTHROUGH) { wlr_log(L_DEBUG, "Denying request to set cursor from unfocused client"); return; } wlr_log(L_DEBUG, "Setting client cursor"); - - struct roots_output *output; - wl_list_for_each(output, &input->server->desktop->outputs, link) { - wlr_output_set_cursor_surface(output->wlr_output, event->surface, - event->hotspot_x, event->hotspot_y); - } - + cursor_set_surface(input, event->surface, event->hotspot_x, event->hotspot_y); input->cursor_client = event->client; } From ec5beeb8b8eec615f74f640f84e8fa8e451ba3bb Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 19:09:38 +0200 Subject: [PATCH 12/14] Move xcursor stuff into its own file --- include/rootston/input.h | 9 +++++++-- rootston/cursor.c | 35 +++++---------------------------- rootston/input.c | 15 +++++++------- rootston/meson.build | 1 + rootston/output.c | 3 ++- rootston/xcursor.c | 42 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 rootston/xcursor.c diff --git a/include/rootston/input.h b/include/rootston/input.h index 33750d7b..9c80be61 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -88,8 +88,7 @@ struct roots_input { // TODO: multiseat, multicursor struct wlr_cursor *cursor; - struct wlr_xcursor_theme *theme; - struct wlr_xcursor *xcursor; + struct wlr_xcursor_theme *xcursor_theme; struct wlr_seat *wl_seat; struct wl_list drag_icons; struct wl_client *cursor_client; @@ -158,6 +157,12 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view, uint32_t edges); +struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme); +struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme); +struct wlr_xcursor *get_resize_xcursor(struct wlr_xcursor_theme *theme, + uint32_t edges); +struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme); + void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, struct roots_view *view); diff --git a/rootston/cursor.c b/rootston/cursor.c index 8b269a11..e8e40aed 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -62,36 +62,12 @@ void view_begin_move(struct roots_input *input, struct wlr_cursor *cursor, input->view_y = view->y; wlr_seat_pointer_clear_focus(input->wl_seat); - struct wlr_xcursor *xcursor = wlr_xcursor_theme_get_cursor(input->theme, - "grabbing"); + struct wlr_xcursor *xcursor = get_move_xcursor(input->xcursor_theme); if (xcursor != NULL) { cursor_set_xcursor_image(input, xcursor->images[0]); } } -static const char *get_resize_cursor_name(uint32_t edges) { - if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { - if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { - return "ne-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - return "nw-resize"; - } - return "n-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { - if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { - return "se-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - return "sw-resize"; - } - return "s-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { - return "e-resize"; - } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { - return "w-resize"; - } - return "se-resize"; // fallback -} - void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, struct roots_view *view, uint32_t edges) { input->mode = ROOTS_CURSOR_RESIZE; @@ -106,8 +82,7 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, input->resize_edges = edges; wlr_seat_pointer_clear_focus(input->wl_seat); - struct wlr_xcursor *xcursor = wlr_xcursor_theme_get_cursor(input->theme, - get_resize_cursor_name(edges)); + struct wlr_xcursor *xcursor = get_resize_xcursor(input->xcursor_theme, edges); if (xcursor != NULL) { cursor_set_xcursor_image(input, xcursor->images[0]); } @@ -121,8 +96,7 @@ void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, input->view_rotation = view->rotation; wlr_seat_pointer_clear_focus(input->wl_seat); - struct wlr_xcursor *xcursor = wlr_xcursor_theme_get_cursor(input->theme, - "grabbing"); + struct wlr_xcursor *xcursor = get_rotate_xcursor(input->xcursor_theme); if (xcursor != NULL) { cursor_set_xcursor_image(input, xcursor->images[0]); } @@ -144,7 +118,8 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { set_compositor_cursor = view_client != input->cursor_client; } if (set_compositor_cursor) { - cursor_set_xcursor_image(input, input->xcursor->images[0]); + struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme); + cursor_set_xcursor_image(input, xcursor->images[0]); input->cursor_client = NULL; } if (view) { diff --git a/rootston/input.c b/rootston/input.c index f424485e..a6792bdb 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -81,16 +81,17 @@ struct roots_input *input_create(struct roots_server *server, input->config = config; input->server = server; - input->theme = wlr_xcursor_theme_load("default", 16); - if (input->theme == NULL) { + input->xcursor_theme = wlr_xcursor_theme_load("default", 16); + if (input->xcursor_theme == NULL) { wlr_log(L_ERROR, "Cannot load xcursor theme"); free(input); return NULL; } - input->xcursor = wlr_xcursor_theme_get_cursor(input->theme, "left_ptr"); - if (input->xcursor == NULL) { + + struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme); + if (xcursor == NULL) { wlr_log(L_ERROR, "Cannot load xcursor from theme"); - wlr_xcursor_theme_destroy(input->theme); + wlr_xcursor_theme_destroy(input->xcursor_theme); free(input); return NULL; } @@ -98,7 +99,7 @@ struct roots_input *input_create(struct roots_server *server, input->wl_seat = wlr_seat_create(server->wl_display, "seat0"); if (input->wl_seat == NULL) { wlr_log(L_ERROR, "Cannot create seat"); - wlr_xcursor_theme_destroy(input->theme); + wlr_xcursor_theme_destroy(input->xcursor_theme); free(input); return NULL; } @@ -117,7 +118,7 @@ struct roots_input *input_create(struct roots_server *server, input->cursor = wlr_cursor_create(); cursor_initialize(input); - wlr_cursor_set_xcursor(input->cursor, input->xcursor); + wlr_cursor_set_xcursor(input->cursor, xcursor); wlr_cursor_attach_output_layout(input->cursor, server->desktop->layout); wlr_cursor_map_to_region(input->cursor, config->cursor.mapped_box); diff --git a/rootston/meson.build b/rootston/meson.build index 53cab62d..d84422d8 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -10,6 +10,7 @@ sources = [ 'pointer.c', 'tablet_tool.c', 'touch.c', + 'xcursor.c', 'xdg_shell_v6.c', 'wl_shell.c', ] diff --git a/rootston/output.c b/rootston/output.c index 89e1475b..5fcd02a2 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -200,7 +200,8 @@ void output_add_notify(struct wl_listener *listener, void *data) { cursor_load_config(config, input->cursor, input, desktop); - struct wlr_xcursor_image *image = input->xcursor->images[0]; + struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme); + struct wlr_xcursor_image *image = xcursor->images[0]; // TODO the cursor must be set depending on which surface it is displayed // over which should happen in the compositor. if (!wlr_output_set_cursor(wlr_output, image->buffer, diff --git a/rootston/xcursor.c b/rootston/xcursor.c new file mode 100644 index 00000000..43cbfc51 --- /dev/null +++ b/rootston/xcursor.c @@ -0,0 +1,42 @@ +#include +#include "rootston/input.h" + +struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme) { + return wlr_xcursor_theme_get_cursor(theme, "left_ptr"); +} + +struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme) { + return wlr_xcursor_theme_get_cursor(theme, "grabbing"); +} + +static const char *get_resize_xcursor_name(uint32_t edges) { + if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { + if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + return "ne-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + return "nw-resize"; + } + return "n-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { + if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + return "se-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + return "sw-resize"; + } + return "s-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + return "e-resize"; + } else if (edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + return "w-resize"; + } + return "se-resize"; // fallback +} + +struct wlr_xcursor *get_resize_xcursor(struct wlr_xcursor_theme *theme, + uint32_t edges) { + return wlr_xcursor_theme_get_cursor(theme, get_resize_xcursor_name(edges)); +} + +struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme) { + return wlr_xcursor_theme_get_cursor(theme, "grabbing"); +} From 315c01ba0fc8567ca0320be2d3f28b26faebe607 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 19:21:26 +0200 Subject: [PATCH 13/14] Remove input.last_active_view --- include/rootston/input.h | 2 +- rootston/cursor.c | 1 - rootston/desktop.c | 3 --- rootston/keyboard.c | 6 ++++-- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/rootston/input.h b/include/rootston/input.h index 33750d7b..f6d75bf6 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -95,7 +95,7 @@ struct roots_input { struct wl_client *cursor_client; enum roots_cursor_mode mode; - struct roots_view *active_view, *last_active_view; + struct roots_view *active_view; int offs_x, offs_y; int view_x, view_y, view_width, view_height; float view_rotation; diff --git a/rootston/cursor.c b/rootston/cursor.c index 7d2548eb..bac8b6e7 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -172,7 +172,6 @@ void set_view_focus(struct roots_input *input, struct roots_desktop *desktop, 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 df92f0ba..a1d8a632 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -24,9 +24,6 @@ void view_destroy(struct roots_view *view) { input->active_view = NULL; input->mode = ROOTS_CURSOR_PASSTHROUGH; } - if (input->last_active_view == view) { - input->last_active_view = NULL; - } for (size_t i = 0; i < desktop->views->length; ++i) { struct roots_view *_view = desktop->views->items[i]; diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 142e9c71..c91c326b 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -29,8 +29,10 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, 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); + if (server->desktop->views->length > 0) { + struct roots_view *view = + server->desktop->views->items[server->desktop->views->length-1]; + view_close(view); } } else if (strcmp(command, "next_window") == 0) { if (server->desktop->views->length > 0) { From 2718b5718047fb2388a9d3436cc9ca4436f75768 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 20:36:25 +0200 Subject: [PATCH 14/14] Force resize for all edges in rootston --- rootston/cursor.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/rootston/cursor.c b/rootston/cursor.c index 1e44e3ae..ece115c4 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -275,17 +275,28 @@ static void do_cursor_button_press(struct roots_input *input, if (state == WLR_BUTTON_PRESSED && view && is_meta_pressed(input, device)) { set_view_focus(input, desktop, view); + uint32_t edges; switch (button) { case BTN_LEFT: view_begin_move(input, cursor, view); break; case BTN_RIGHT: - view_begin_resize(input, cursor, view, - ROOTS_CURSOR_RESIZE_EDGE_RIGHT | - ROOTS_CURSOR_RESIZE_EDGE_BOTTOM); + edges = 0; + if (sx < view->wlr_surface->current->width/2) { + edges |= ROOTS_CURSOR_RESIZE_EDGE_LEFT; + } else { + edges |= ROOTS_CURSOR_RESIZE_EDGE_RIGHT; + } + if (sy < view->wlr_surface->current->height/2) { + edges |= ROOTS_CURSOR_RESIZE_EDGE_TOP; + } else { + edges |= ROOTS_CURSOR_RESIZE_EDGE_BOTTOM; + } + view_begin_resize(input, cursor, view, edges); break; case BTN_MIDDLE: view_begin_rotate(input, cursor, view); + break; } return; }