From 7c85709de19e2cb03209b414ce91039d363972ff Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 25 Oct 2017 20:34:40 +0200 Subject: Focus last view on close in rootston --- include/rootston/view.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/rootston') 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 -- cgit v1.2.3 From 4e5d23daa9b4d70bf8b614d5375ee1ccdab6771f Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 19:59:32 +0200 Subject: 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(-) (limited to 'include/rootston') 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 -- cgit v1.2.3 From c0c4816b132649d1ffc5435720578286d83a19ef Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 26 Oct 2017 22:38:03 +0200 Subject: 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(-) (limited to 'include/rootston') 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"); -- cgit v1.2.3 From a43acae0005ec4d635f1477376fad2ff5d12d611 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 00:02:30 +0200 Subject: 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(-) (limited to 'include/rootston') 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); } -- cgit v1.2.3 From ec5beeb8b8eec615f74f640f84e8fa8e451ba3bb Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 19:09:38 +0200 Subject: 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 (limited to 'include/rootston') 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"); +} -- cgit v1.2.3 From 315c01ba0fc8567ca0320be2d3f28b26faebe607 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 27 Oct 2017 19:21:26 +0200 Subject: 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(-) (limited to 'include/rootston') 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) { -- cgit v1.2.3