diff options
Diffstat (limited to 'rootston')
-rw-r--r-- | rootston/config.c | 81 | ||||
-rw-r--r-- | rootston/cursor.c | 159 | ||||
-rw-r--r-- | rootston/desktop.c | 28 | ||||
-rw-r--r-- | rootston/input.c | 17 | ||||
-rw-r--r-- | rootston/keyboard.c | 52 | ||||
-rw-r--r-- | rootston/main.c | 4 | ||||
-rw-r--r-- | rootston/meson.build | 3 | ||||
-rw-r--r-- | rootston/output.c | 12 | ||||
-rw-r--r-- | rootston/wl_shell.c | 3 | ||||
-rw-r--r-- | rootston/xcursor.c | 42 | ||||
-rw-r--r-- | rootston/xdg_shell_v6.c | 18 | ||||
-rw-r--r-- | rootston/xwayland.c | 21 |
12 files changed, 375 insertions, 65 deletions
diff --git a/rootston/config.c b/rootston/config.c index c9c892f9..6f81170b 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -147,8 +147,46 @@ 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:"; static int config_ini_handler(void *user, const char *section, const char *name, const char *value) { @@ -219,9 +257,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; @@ -245,14 +283,10 @@ static int config_ini_handler(void *user, const char *section, const char *name, wlr_log(L_ERROR, "got unknown device config: %s", name); } } else if (strcmp(section, "keyboard") == 0) { - if (strcmp(name, "meta-key") == 0) { - config->keyboard.meta_key = parse_modifier(value); - if (config->keyboard.meta_key == 0) { - wlr_log(L_ERROR, "got unknown meta key: %s", name); - } - } else { - wlr_log(L_ERROR, "got unknown keyboard config: %s", name); - } + config_handle_keyboard(config, "", name, value); + } else if (strncmp(keyboard_prefix, section, strlen(keyboard_prefix)) == 0) { + const char *device_name = section + strlen(keyboard_prefix); + config_handle_keyboard(config, device_name, name, value); } else if (strcmp(section, "bindings") == 0) { add_binding_config(&config->bindings, name, value); } else { @@ -271,6 +305,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 +340,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 +372,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 +419,16 @@ 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; + wl_list_for_each(kc, &config->keyboards, link) { + if ((device != NULL && strcmp(kc->name, device->name) == 0) || + (device == NULL && strcmp(kc->name, "") == 0)) { + return kc; + } + } + + return NULL; +} diff --git a/rootston/cursor.c b/rootston/cursor.c index 2a3a7c25..27f97724 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -4,6 +4,7 @@ #include <stdint.h> #include <string.h> #include <math.h> +#include <assert.h> #ifdef __linux__ #include <linux/input-event-codes.h> #elif __FreeBSD__ @@ -12,6 +13,7 @@ #include <wayland-server.h> #include <wlr/types/wlr_cursor.h> #include <wlr/util/log.h> +#include <wlr/types/wlr_data_device.h> #include "rootston/config.h" #include "rootston/input.h" #include "rootston/desktop.h" @@ -29,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; @@ -37,6 +61,11 @@ 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 = get_move_xcursor(input->xcursor_theme); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); + } } void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor, @@ -52,6 +81,11 @@ 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 = get_resize_xcursor(input->xcursor_theme, edges); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); + } } void view_begin_rotate(struct roots_input *input, struct wlr_cursor *cursor, @@ -61,18 +95,10 @@ 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 = get_rotate_xcursor(input->xcursor_theme); + if (xcursor != NULL) { + cursor_set_xcursor_image(input, xcursor->images[0]); } } @@ -92,8 +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) { - wlr_log(L_DEBUG, "Switching to 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) { @@ -134,6 +160,13 @@ void cursor_update_position(struct roots_input *input, uint32_t time) { width += dx; } + if (width < 0) { + width = 0; + } + if (height < 0) { + height = 0; + } + // TODO we might need one configure event for this if (active_x != input->active_view->x || active_y != input->active_view->y) { @@ -170,7 +203,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) { @@ -213,8 +245,16 @@ 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) { + uint32_t meta_key = 0; + 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) { return false; } @@ -239,20 +279,31 @@ 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); + 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; } @@ -264,6 +315,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; @@ -355,6 +407,58 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) { (uint32_t)(event->time_usec / 1000), BTN_LEFT, event->state); } +static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) { + struct roots_drag_icon *drag_icon = + wl_container_of(listener, drag_icon, surface_destroy); + wl_list_remove(&drag_icon->link); + wl_list_remove(&drag_icon->surface_destroy.link); + wl_list_remove(&drag_icon->surface_commit.link); + free(drag_icon); +} + +static void handle_drag_icon_commit(struct wl_listener *listener, void *data) { + struct roots_drag_icon *drag_icon = + wl_container_of(listener, drag_icon, surface_commit); + // TODO the spec hints at rules that can determine whether the drag icon is + // mapped here, but it is not completely clear so we need to test more + // toolkits to see how we should interpret the surface state here. + drag_icon->sx += drag_icon->surface->current->sx; + drag_icon->sy += drag_icon->surface->current->sy; +} + +static void handle_pointer_grab_begin(struct wl_listener *listener, + void *data) { + struct roots_input *input = + wl_container_of(listener, input, pointer_grab_begin); + struct wlr_seat_pointer_grab *grab = data; + + if (grab->interface == &wlr_data_device_pointer_drag_interface) { + struct wlr_drag *drag = grab->data; + if (drag->icon) { + struct roots_drag_icon *iter_icon; + wl_list_for_each(iter_icon, &input->drag_icons, link) { + if (iter_icon->surface == drag->icon) { + // already in the list + return; + } + } + + struct roots_drag_icon *drag_icon = + calloc(1, sizeof(struct roots_drag_icon)); + drag_icon->surface = drag->icon; + wl_list_insert(&input->drag_icons, &drag_icon->link); + + wl_signal_add(&drag->icon->events.destroy, + &drag_icon->surface_destroy); + drag_icon->surface_destroy.notify = handle_drag_icon_destroy; + + wl_signal_add(&drag->icon->events.commit, + &drag_icon->surface_commit); + drag_icon->surface_commit.notify = handle_drag_icon_commit; + } + } +} + static void handle_pointer_grab_end(struct wl_listener *listener, void *data) { struct roots_input *input = wl_container_of(listener, input, pointer_grab_end); @@ -375,19 +479,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; } @@ -428,6 +526,11 @@ void cursor_initialize(struct roots_input *input) { wl_signal_add(&input->wl_seat->events.pointer_grab_end, &input->pointer_grab_end); input->pointer_grab_end.notify = handle_pointer_grab_end; + wl_signal_add(&input->wl_seat->events.pointer_grab_begin, &input->pointer_grab_begin); + input->pointer_grab_begin.notify = handle_pointer_grab_begin; + + wl_list_init(&input->request_set_cursor.link); + wl_signal_add(&input->wl_seat->events.request_set_cursor, &input->request_set_cursor); input->request_set_cursor.notify = handle_request_set_cursor; diff --git a/rootston/desktop.c b/rootston/desktop.c index 40d088b8..a1d8a632 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -7,11 +7,13 @@ #include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_gamma_control.h> +#include <wlr/types/wlr_server_decoration.h> #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/util/log.h> -#include "rootston/desktop.h" +#include <server-decoration-protocol.h> +#include "rootston/server.h" #include "rootston/server.h" void view_destroy(struct roots_view *view) { @@ -22,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]; @@ -107,14 +106,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) { @@ -252,6 +263,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/input.c b/rootston/input.c index 5dc7d16d..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,13 +118,15 @@ 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); cursor_load_config(config, input->cursor, input, server->desktop); + wl_list_init(&input->drag_icons); + return input; } diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 1d4699a9..a0601d05 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) { @@ -157,6 +159,28 @@ static void keyboard_modifiers_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) { @@ -174,13 +198,27 @@ void keyboard_add(struct wlr_input_device *device, struct roots_input *input) { wl_list_insert(&input->keyboards, &keyboard->link); + 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)); - 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"); + 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"); diff --git a/rootston/main.c b/rootston/main.c index b80c2efd..2a054e6c 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -20,11 +20,11 @@ int main(int argc, char **argv) { assert(server.backend = wlr_backend_autocreate(server.wl_display)); assert(server.renderer = wlr_gles2_renderer_create(server.backend)); + server.data_device_manager = + wlr_data_device_manager_create(server.wl_display); wl_display_init_shm(server.wl_display); server.desktop = desktop_create(&server, server.config); server.input = input_create(&server, server.config); - server.data_device_manager = wlr_data_device_manager_create( - server.wl_display); const char *socket = wl_display_add_socket_auto(server.wl_display); if (!socket) { diff --git a/rootston/meson.build b/rootston/meson.build index f2621450..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', ] @@ -17,5 +18,5 @@ if get_option('enable_xwayland') sources += ['xwayland.c'] endif executable( - 'rootston', sources, dependencies: wlroots + 'rootston', sources, dependencies: [wlroots, wlr_protos] ) diff --git a/rootston/output.c b/rootston/output.c index 99f70bcf..5fcd02a2 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -150,6 +150,15 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { render_view(view, desktop, wlr_output, &now); } + struct roots_drag_icon *drag_icon = NULL; + wl_list_for_each(drag_icon, &server->input->drag_icons, link) { + struct wlr_surface *icon = drag_icon->surface; + struct wlr_cursor *cursor = server->input->cursor; + double icon_x = cursor->x + drag_icon->sx; + double icon_y = cursor->y + drag_icon->sy; + render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0); + } + wlr_renderer_end(server->renderer); wlr_output_swap_buffers(wlr_output); @@ -191,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/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/xcursor.c b/rootston/xcursor.c new file mode 100644 index 00000000..43cbfc51 --- /dev/null +++ b/rootston/xcursor.c @@ -0,0 +1,42 @@ +#include <wlr/types/wlr_cursor.h> +#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"); +} diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 95b20a8b..4f284851 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -29,6 +29,21 @@ static void resize(struct roots_view *view, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XDG_SHELL_V6_VIEW); struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6; if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { + struct wlr_xdg_toplevel_v6_state *state = + &surf->toplevel_state->current; + if (width < state->min_width) { + width = state->min_width; + } else if (state->max_width > 0 && + width < state->max_width) { + width = state->max_width; + } + if (height < state->min_height) { + height = state->min_height; + } else if (state->max_height > 0 && + height < state->max_height) { + height = state->max_height; + } + wlr_xdg_toplevel_v6_set_size(surf, width, height); } } @@ -74,6 +89,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 +142,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..e1b9d227 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -22,6 +22,24 @@ static void activate(struct roots_view *view, bool active) { static void resize(struct roots_view *view, uint32_t width, uint32_t height) { assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + + struct wlr_xwayland_surface_size_hints *size_hints = + xwayland_surface->size_hints; + if (size_hints != NULL) { + if (width < (uint32_t)size_hints->min_width) { + width = size_hints->min_width; + } else if (size_hints->max_width > 0 && + width > (uint32_t)size_hints->max_width) { + width = size_hints->max_width; + } + if (height < (uint32_t)size_hints->min_height) { + height = size_hints->min_height; + } else if (size_hints->max_height > 0 && + height > (uint32_t)size_hints->max_height) { + height = size_hints->max_height; + } + } + wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, xwayland_surface->x, xwayland_surface->y, width, height); } @@ -43,6 +61,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 +120,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); } } |