From a7446792a1a0fd9fe3391f041d7bbfe9e2b11255 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 22 Oct 2017 23:19:21 -0400 Subject: Consider scale factor when rendering views --- rootston/output.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'rootston/output.c') diff --git a/rootston/output.c b/rootston/output.c index baa7b6cc..faf39e74 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -27,6 +27,8 @@ static void render_surface(struct wlr_surface *surface, if (wlr_output_layout_intersects(desktop->layout, wlr_output, lx, ly, lx + width, ly + height)) { + // TODO: accomodate for mismatched scale, which can happen, for + // example, when a view is rendered over two outputs float matrix[16]; float translate_origin[16]; @@ -217,6 +219,7 @@ void output_add_notify(struct wl_listener *listener, void *data) { if (output_config->mode.width) { set_mode(wlr_output, output_config); } + wlr_output->scale = output_config->scale; wlr_output_transform(wlr_output, output_config->transform); wlr_output_layout_add(desktop->layout, wlr_output, output_config->x, output_config->y); -- cgit v1.2.3 From 7f76f463181872f39356e5a4d6e2e34fd9a0a1bb Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 25 Oct 2017 23:48:54 -0400 Subject: Adjust rendering to compensate for disparate scale Something about my math is off, but I'm not certain what. Would appreciate a second opinion. --- rootston/output.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'rootston/output.c') diff --git a/rootston/output.c b/rootston/output.c index faf39e74..37af1e2d 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -20,29 +20,35 @@ static void render_surface(struct wlr_surface *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double lx, double ly, float rotation) { if (surface->texture->valid) { - int width = surface->current->buffer_width; - int height = surface->current->buffer_height; + float scale_factor = (float)wlr_output->scale / surface->current->scale; + int width = surface->current->buffer_width * scale_factor; + int height = surface->current->buffer_height * scale_factor; double ox = lx, oy = ly; wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); if (wlr_output_layout_intersects(desktop->layout, wlr_output, lx, ly, lx + width, ly + height)) { - // TODO: accomodate for mismatched scale, which can happen, for - // example, when a view is rendered over two outputs float matrix[16]; float translate_origin[16]; wlr_matrix_translate(&translate_origin, (int)ox + width / 2, (int)oy + height / 2, 0); + float rotate[16]; wlr_matrix_rotate(&rotate, rotation); + float translate_center[16]; wlr_matrix_translate(&translate_center, -width / 2, -height / 2, 0); + + float scale[16]; + wlr_matrix_scale(&scale, width, height, 1); + float transform[16]; wlr_matrix_mul(&translate_origin, &rotate, &transform); wlr_matrix_mul(&transform, &translate_center, &transform); - wlr_surface_get_matrix(surface, &matrix, - &wlr_output->transform_matrix, &transform); + wlr_matrix_mul(&transform, &scale, &transform); + wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix); + wlr_render_with_matrix(desktop->server->renderer, surface->texture, &matrix); -- cgit v1.2.3 From ca8cf7d48dc8de94494e23292c1687c1dad766f2 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 2 Nov 2017 23:17:39 -0400 Subject: Rethink HiDPI output layouts, fixes everything Except for subsurfaces not rendering at the right scale. But that part is (somewhat) easy. --- rootston/desktop.c | 9 ++++----- rootston/output.c | 2 ++ types/wlr_output.c | 5 ++++- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'rootston/output.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index a724a40c..f87be11e 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -167,15 +167,14 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, continue; } - int scale = view->wlr_surface->current->scale; - double view_sx = (lx - view->x) / (double)scale; - double view_sy = (ly - view->y) / (double)scale; + double view_sx = lx - view->x; + double view_sy = ly - view->y; struct wlr_box box = { .x = 0, .y = 0, - .width = view->wlr_surface->current->buffer_width * scale, - .height = view->wlr_surface->current->buffer_height * scale, + .width = view->wlr_surface->current->buffer_width, + .height = view->wlr_surface->current->buffer_height, }; if (view->rotation != 0.0) { // Coordinates relative to the center of the view diff --git a/rootston/output.c b/rootston/output.c index 37af1e2d..c21c6781 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -25,6 +25,8 @@ static void render_surface(struct wlr_surface *surface, int height = surface->current->buffer_height * scale_factor; double ox = lx, oy = ly; wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); + ox *= wlr_output->scale; + oy *= wlr_output->scale; if (wlr_output_layout_intersects(desktop->layout, wlr_output, lx, ly, lx + width, ly + height)) { diff --git a/types/wlr_output.c b/types/wlr_output.c index 44d24ae3..82e805b4 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -227,7 +227,6 @@ void wlr_output_destroy(struct wlr_output *output) { void wlr_output_effective_resolution(struct wlr_output *output, int *width, int *height) { - // TODO: Scale factor if (output->transform % 2 == 1) { *width = output->height; *height = output->width; @@ -235,6 +234,8 @@ void wlr_output_effective_resolution(struct wlr_output *output, *width = output->width; *height = output->height; } + *width /= output->scale; + *height /= output->scale; } void wlr_output_make_current(struct wlr_output *output) { @@ -450,6 +451,8 @@ void wlr_output_cursor_set_surface(struct wlr_output_cursor *cursor, } bool wlr_output_cursor_move(struct wlr_output_cursor *cursor, int x, int y) { + x *= cursor->output->scale; + y *= cursor->output->scale; cursor->x = x; cursor->y = y; -- cgit v1.2.3 From 09c60924235805d07b7915ba879685545a3442aa Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 7 Nov 2017 15:56:11 -0500 Subject: multiseat: somewhat working --- include/rootston/cursor.h | 35 +++++ include/rootston/input.h | 54 +------- include/rootston/keyboard.h | 1 + include/rootston/seat.h | 30 +++++ include/wlr/types/wlr_wl_shell.h | 4 +- include/wlr/types/wlr_xdg_shell_v6.h | 6 +- rootston/desktop.c | 36 +++--- rootston/input.c | 62 ++------- rootston/keyboard.c | 26 ++-- rootston/meson.build | 2 +- rootston/output.c | 32 ++--- rootston/roots_cursor.c | 239 +++++++++++++++++++++++++++++++++-- rootston/seat.c | 134 +++++++++++++++++++- rootston/wl_shell.c | 13 +- rootston/xdg_shell_v6.c | 14 +- rootston/xwayland.c | 32 ++--- types/wlr_wl_shell.c | 8 +- types/wlr_xdg_shell_v6.c | 12 +- 18 files changed, 521 insertions(+), 219 deletions(-) (limited to 'rootston/output.c') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index 8a8d33f2..18d5f720 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -3,10 +3,45 @@ #include "rootston/seat.h" +enum roots_cursor_mode { + ROOTS_CURSOR_PASSTHROUGH = 0, + ROOTS_CURSOR_MOVE = 1, + ROOTS_CURSOR_RESIZE = 2, + ROOTS_CURSOR_ROTATE = 3, +}; + +enum roots_cursor_resize_edge { + ROOTS_CURSOR_RESIZE_EDGE_TOP = 1, + ROOTS_CURSOR_RESIZE_EDGE_BOTTOM = 2, + ROOTS_CURSOR_RESIZE_EDGE_LEFT = 4, + ROOTS_CURSOR_RESIZE_EDGE_RIGHT = 8, +}; + +struct roots_input_event { + uint32_t serial; + struct wlr_cursor *cursor; + struct wlr_input_device *device; +}; + struct roots_cursor { struct roots_seat *seat; struct wlr_cursor *cursor; + enum roots_cursor_mode mode; + + // state from input (review if this is necessary) + struct wlr_xcursor_theme *xcursor_theme; + struct wlr_seat *wl_seat; + struct wl_client *cursor_client; + int offs_x, offs_y; + int view_x, view_y, view_width, view_height; + float view_rotation; + uint32_t resize_edges; + // Ring buffer of input events that could trigger move/resize/rotate + int input_events_idx; + struct wl_list touch_points; + struct roots_input_event input_events[16]; + struct wl_listener motion; struct wl_listener motion_absolute; struct wl_listener button; diff --git a/include/rootston/input.h b/include/rootston/input.h index 7b1358f8..7463ba3a 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -5,64 +5,15 @@ #include #include #include +#include "rootston/cursor.h" #include "rootston/config.h" #include "rootston/view.h" #include "rootston/server.h" -enum roots_cursor_mode { - ROOTS_CURSOR_PASSTHROUGH = 0, - ROOTS_CURSOR_MOVE = 1, - ROOTS_CURSOR_RESIZE = 2, - ROOTS_CURSOR_ROTATE = 3, -}; - -enum roots_cursor_resize_edge { - ROOTS_CURSOR_RESIZE_EDGE_TOP = 1, - ROOTS_CURSOR_RESIZE_EDGE_BOTTOM = 2, - ROOTS_CURSOR_RESIZE_EDGE_LEFT = 4, - ROOTS_CURSOR_RESIZE_EDGE_RIGHT = 8, -}; - -struct roots_input_event { - uint32_t serial; - struct wlr_cursor *cursor; - struct wlr_input_device *device; -}; - -struct roots_drag_icon { - struct wlr_surface *surface; - struct wl_list link; // roots_input::drag_icons - bool mapped; - - int32_t sx; - int32_t sy; - - struct wl_listener surface_destroy; - struct wl_listener surface_commit; -}; - struct roots_input { struct roots_config *config; struct roots_server *server; - // TODO: multiseat, multicursor - struct wlr_cursor *cursor; - struct wlr_xcursor_theme *xcursor_theme; - struct wlr_seat *wl_seat; - struct wl_list drag_icons; - struct wl_client *cursor_client; - - enum roots_cursor_mode mode; - struct roots_view *active_view; - int offs_x, offs_y; - int view_x, view_y, view_width, view_height; - float view_rotation; - uint32_t resize_edges; - - // Ring buffer of input events that could trigger move/resize/rotate - int input_events_idx; - struct roots_input_event input_events[16]; - struct wl_list keyboards; struct wl_list pointers; struct wl_list touch; @@ -117,4 +68,7 @@ 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); +struct roots_seat *input_seat_from_wlr_seat(struct roots_input *input, + struct wlr_seat *seat); + #endif diff --git a/include/rootston/keyboard.h b/include/rootston/keyboard.h index cb639ba1..e3caf8fb 100644 --- a/include/rootston/keyboard.h +++ b/include/rootston/keyboard.h @@ -10,6 +10,7 @@ struct roots_keyboard { struct roots_input *input; struct roots_seat *seat; struct wlr_input_device *device; + struct keyboard_config *config; struct wl_list seat_link; // XXX temporary struct wl_list link; diff --git a/include/rootston/seat.h b/include/rootston/seat.h index b7c8b477..b5593651 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -6,11 +6,26 @@ #include "rootston/input.h" #include "rootston/keyboard.h" +struct roots_drag_icon { + struct wlr_surface *surface; + struct wl_list link; // roots_seat::drag_icons + bool mapped; + + int32_t sx; + int32_t sy; + + struct wl_listener surface_destroy; + struct wl_listener surface_commit; +}; + struct roots_seat { struct roots_input *input; struct wlr_seat *seat; struct roots_cursor *cursor; struct wl_list link; + struct wl_list drag_icons; + + struct roots_view *focus; struct wl_list keyboards; struct wl_list pointers; @@ -57,4 +72,19 @@ void roots_seat_add_device(struct roots_seat *seat, void roots_seat_remove_device(struct roots_seat *seat, struct wlr_input_device *device); +void roots_seat_configure_cursor(struct roots_seat *seat); + +void roots_seat_configure_xcursor(struct roots_seat *seat); + +bool roots_seat_has_meta_pressed(struct roots_seat *seat); + +void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view); + +void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view); + +void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, + uint32_t edges); + +void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view); + #endif diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 4e814817..ab3b4b10 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -93,14 +93,14 @@ struct wlr_wl_shell_surface { struct wlr_wl_shell_surface_move_event { struct wl_client *client; struct wlr_wl_shell_surface *surface; - struct wlr_seat_handle *seat_handle; + struct wlr_seat_client *seat; uint32_t serial; }; struct wlr_wl_shell_surface_resize_event { struct wl_client *client; struct wlr_wl_shell_surface *surface; - struct wlr_seat_handle *seat_handle; + struct wlr_seat_client *seat; uint32_t serial; enum wl_shell_surface_resize edges; }; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index b0de41e2..e17393f6 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -138,14 +138,14 @@ struct wlr_xdg_surface_v6 { struct wlr_xdg_toplevel_v6_move_event { struct wl_client *client; struct wlr_xdg_surface_v6 *surface; - struct wlr_seat_handle *seat_handle; + struct wlr_seat_client *seat; uint32_t serial; }; struct wlr_xdg_toplevel_v6_resize_event { struct wl_client *client; struct wlr_xdg_surface_v6 *surface; - struct wlr_seat_handle *seat_handle; + struct wlr_seat_client *seat; uint32_t serial; uint32_t edges; }; @@ -153,7 +153,7 @@ struct wlr_xdg_toplevel_v6_resize_event { struct wlr_xdg_toplevel_v6_show_window_menu_event { struct wl_client *client; struct wlr_xdg_surface_v6 *surface; - struct wlr_seat_handle *seat_handle; + struct wlr_seat_client *seat; uint32_t serial; uint32_t x; uint32_t y; diff --git a/rootston/desktop.c b/rootston/desktop.c index 29f78ac7..e752e639 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -14,15 +14,19 @@ #include #include #include "rootston/server.h" -#include "rootston/server.h" +#include "rootston/seat.h" +// TODO replace me with a signal void view_destroy(struct roots_view *view) { struct roots_desktop *desktop = view->desktop; struct roots_input *input = desktop->server->input; - if (input->active_view == view) { - input->active_view = NULL; - input->mode = ROOTS_CURSOR_PASSTHROUGH; + struct roots_seat *seat; + wl_list_for_each(seat, &input->seats, link) { + if (seat->focus == view) { + seat->focus = NULL; + seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH; + } } for (size_t i = 0; i < desktop->views->length; ++i) { @@ -89,15 +93,9 @@ bool view_center(struct roots_view *view) { view_get_size(view, &size); struct roots_desktop *desktop = view->desktop; - struct wlr_cursor *cursor = desktop->server->input->cursor; struct wlr_output *output = - wlr_output_layout_output_at(desktop->layout, cursor->x, cursor->y); - - if (!output) { - output = wlr_output_layout_get_center_output(desktop->layout); - } - + wlr_output_layout_get_center_output(desktop->layout); if (!output) { // empty layout return false; @@ -121,19 +119,15 @@ void view_setup(struct roots_view *view) { view_center(view); struct roots_input *input = view->desktop->server->input; - set_view_focus(input, view->desktop, view); + // TODO what seat gets focus? the one with the last input event? + struct roots_seat *seat; + wl_list_for_each(seat, &input->seats, link) { + roots_seat_focus_view(seat, view); + } } 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); + // TODO replace me with a signal } struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, diff --git a/rootston/input.c b/rootston/input.c index 4a567763..8e45d6d3 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -84,43 +84,6 @@ struct roots_input *input_create(struct roots_server *server, input->config = config; input->server = server; - 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; - } - - 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->xcursor_theme); - free(input); - return NULL; - } - - if (server->desktop->xwayland != NULL) { - struct wlr_xcursor_image *xcursor_image = xcursor->images[0]; - wlr_xwayland_set_cursor(server->desktop->xwayland, - xcursor_image->buffer, xcursor_image->width, xcursor_image->width, - xcursor_image->height, xcursor_image->hotspot_x, - xcursor_image->hotspot_y); - } - - 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->xcursor_theme); - free(input); - return NULL; - } - wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD - | WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH); - - wl_list_init(&input->keyboards); - wl_list_init(&input->pointers); - wl_list_init(&input->touch); - wl_list_init(&input->tablet_tools); wl_list_init(&input->seats); input->input_add.notify = input_add_notify; @@ -128,23 +91,20 @@ struct roots_input *input_create(struct roots_server *server, input->input_remove.notify = input_remove_notify; wl_signal_add(&server->backend->events.input_remove, &input->input_remove); - input->cursor = wlr_cursor_create(); - cursor_initialize(input); - - struct wlr_xcursor_image *image = xcursor->images[0]; - wlr_cursor_set_image(input->cursor, image->buffer, image->width, - image->width, image->height, image->hotspot_x, image->hotspot_y); - - 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; } void input_destroy(struct roots_input *input) { // TODO } + +struct roots_seat *input_seat_from_wlr_seat(struct roots_input *input, + struct wlr_seat *wlr_seat) { + struct roots_seat *seat = NULL; + wl_list_for_each(seat, &input->seats, link) { + if (seat->seat == wlr_seat) { + return seat; + } + } + return seat; +} diff --git a/rootston/keyboard.c b/rootston/keyboard.c index 0865f551..ef5eb8ab 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -39,7 +39,7 @@ static void keyboard_binding_execute(struct roots_keyboard *keyboard, } else if (strcmp(command, "next_window") == 0) { if (server->desktop->views->length > 0) { struct roots_view *view = server->desktop->views->items[0]; - set_view_focus(keyboard->input, server->desktop, view); + roots_seat_focus_view(keyboard->seat, view); } } else if (strncmp(exec_prefix, command, strlen(exec_prefix)) == 0) { const char *shell_cmd = command + strlen(exec_prefix); @@ -192,13 +192,9 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, keyboard->device = device; keyboard->input = input; - // XXX temporary - 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 *config = calloc(1, sizeof(struct keyboard_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"), @@ -207,15 +203,16 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, .variant = getenv("XKB_DEFAULT_VARIANT"), .options = getenv("XKB_DEFAULT_OPTIONS"), }; - keyboard_config_merge(&config, &env_config); + keyboard_config_merge(config, &env_config); + keyboard->config = config; struct xkb_rule_names rules; memset(&rules, 0, sizeof(rules)); - rules.rules = config.rules; - rules.model = config.model; - rules.layout = config.layout; - rules.variant = config.variant; - rules.options = config.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"); @@ -231,5 +228,6 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, void roots_keyboard_destroy(struct wlr_input_device *device, struct roots_input *input) { struct roots_keyboard *keyboard = device->data; wl_list_remove(&keyboard->link); + free(keyboard->config); free(keyboard); } diff --git a/rootston/meson.build b/rootston/meson.build index baed5330..062f56fc 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -1,6 +1,6 @@ sources = [ 'config.c', - 'cursor.c', + #'cursor.c', 'roots_cursor.c', 'desktop.c', 'ini.c', diff --git a/rootston/output.c b/rootston/output.c index baa7b6cc..329c29be 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -151,15 +151,18 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { } struct roots_drag_icon *drag_icon = NULL; - wl_list_for_each(drag_icon, &server->input->drag_icons, link) { - if (!drag_icon->mapped) { - continue; + struct roots_seat *seat = NULL; + wl_list_for_each(seat, &server->input->seats, link) { + wl_list_for_each(drag_icon, &seat->drag_icons, link) { + if (!drag_icon->mapped) { + continue; + } + struct wlr_surface *icon = drag_icon->surface; + struct wlr_cursor *cursor = seat->cursor->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); } - 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); @@ -224,14 +227,11 @@ void output_add_notify(struct wl_listener *listener, void *data) { wlr_output_layout_add_auto(desktop->layout, wlr_output); } - cursor_load_config(config, input->cursor, input, desktop); - - struct wlr_xcursor *xcursor = get_default_xcursor(input->xcursor_theme); - struct wlr_xcursor_image *image = xcursor->images[0]; - wlr_cursor_set_image(input->cursor, image->buffer, image->width, - image->width, image->height, image->hotspot_x, image->hotspot_y); - - wlr_cursor_warp(input->cursor, NULL, input->cursor->x, input->cursor->y); + struct roots_seat *seat; + wl_list_for_each(seat, &input->seats, link) { + roots_seat_configure_cursor(seat); + roots_seat_configure_xcursor(seat); + } } void output_remove_notify(struct wl_listener *listener, void *data) { diff --git a/rootston/roots_cursor.c b/rootston/roots_cursor.c index 72eff996..92c0cc9e 100644 --- a/rootston/roots_cursor.c +++ b/rootston/roots_cursor.c @@ -1,4 +1,11 @@ +#define _XOPEN_SOURCE 700 #include +#include +#ifdef __linux__ +#include +#elif __FreeBSD__ +#include +#endif #include #include "rootston/cursor.h" @@ -19,47 +26,261 @@ void roots_cursor_destroy(struct roots_cursor *cursor) { // TODO } +static void cursor_set_xcursor_image(struct roots_cursor *cursor, + struct wlr_xcursor_image *image) { + wlr_cursor_set_image(cursor->cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y); +} + +static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) { + struct roots_desktop *desktop = cursor->seat->input->server->desktop; + struct roots_seat *seat = cursor->seat; + struct roots_view *view; + struct wlr_surface *surface; + double sx, sy; + switch (cursor->mode) { + case ROOTS_CURSOR_PASSTHROUGH: + view = view_at(desktop, cursor->cursor->x, cursor->cursor->y, + &surface, &sx, &sy); + bool set_compositor_cursor = !view && cursor->cursor_client; + if (view) { + struct wl_client *view_client = + wl_resource_get_client(view->wlr_surface->resource); + set_compositor_cursor = view_client != cursor->cursor_client; + } + if (set_compositor_cursor) { + struct wlr_xcursor *xcursor = get_default_xcursor(cursor->xcursor_theme); + cursor_set_xcursor_image(cursor, xcursor->images[0]); + cursor->cursor_client = NULL; + } + if (view) { + wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy); + wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy); + } else { + wlr_seat_pointer_clear_focus(seat->seat); + } + break; + case ROOTS_CURSOR_MOVE: + if (seat->focus) { + double dx = cursor->cursor->x - cursor->offs_x; + double dy = cursor->cursor->y - cursor->offs_y; + view_move(seat->focus, cursor->view_x + dx, + cursor->view_y + dy); + } + break; + case ROOTS_CURSOR_RESIZE: + if (seat->focus) { + double dx = cursor->cursor->x - cursor->offs_x; + double dy = cursor->cursor->y - cursor->offs_y; + double active_x = seat->focus->x; + double active_y = seat->focus->y; + int width = cursor->view_width; + int height = cursor->view_height; + if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { + active_y = cursor->view_y + dy; + height -= dy; + if (height < 0) { + active_y += height; + } + } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_BOTTOM) { + height += dy; + } + if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_LEFT) { + active_x = cursor->view_x + dx; + width -= dx; + if (width < 0) { + active_x += width; + } + } else if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { + width += dx; + } + + if (width < 0) { + width = 0; + } + if (height < 0) { + height = 0; + } + + if (active_x != seat->focus->x || + active_y != seat->focus->y) { + view_move_resize(seat->focus, active_x, active_y, + width, height); + } else { + view_resize(seat->focus, width, height); + } + } + break; + case ROOTS_CURSOR_ROTATE: + if (seat->focus) { + struct roots_view *view = seat->focus; + int ox = view->x + view->wlr_surface->current->width/2, + oy = view->y + view->wlr_surface->current->height/2; + int ux = cursor->offs_x - ox, + uy = cursor->offs_y - oy; + int vx = cursor->cursor->x - ox, + vy = cursor->cursor->y - oy; + float angle = atan2(vx*uy - vy*ux, vx*ux + vy*uy); + int steps = 12; + angle = round(angle/M_PI*steps) / (steps/M_PI); + view->rotation = cursor->view_rotation + angle; + } + break; + } + +} + +static void roots_cursor_press_button(struct roots_cursor *cursor, + struct wlr_input_device *device, uint32_t time, uint32_t button, + uint32_t state) { + struct roots_seat *seat = cursor->seat; + struct roots_desktop *desktop = seat->input->server->desktop; + struct wlr_surface *surface; + double sx, sy; + struct roots_view *view = view_at(desktop, + cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy); + + if (state == WLR_BUTTON_PRESSED && view && roots_seat_has_meta_pressed(seat)) { + // TODO + roots_seat_focus_view(seat, view); + + uint32_t edges; + switch (button) { + case BTN_LEFT: + // TODO + roots_seat_begin_move(seat, view); + break; + case BTN_RIGHT: + 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; + } + roots_seat_begin_resize(seat, view, edges); + break; + case BTN_MIDDLE: + roots_seat_begin_rotate(seat, view); + break; + } + return; + } + + // TODO + uint32_t serial = + wlr_seat_pointer_notify_button(seat->seat, time, button, state); + + int i; + switch (state) { + case WLR_BUTTON_RELEASED: + seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH; + roots_cursor_update_position(cursor, time); + break; + case WLR_BUTTON_PRESSED: + // TODO + i = cursor->input_events_idx; + cursor->input_events[i].serial = serial; + cursor->input_events[i].cursor = cursor->cursor; + cursor->input_events[i].device = device; + cursor->input_events_idx = (i + 1) + % (sizeof(cursor->input_events) / sizeof(cursor->input_events[0])); + roots_seat_focus_view(seat, view); + break; + } +} + void roots_cursor_handle_motion(struct roots_cursor *cursor, struct wlr_event_pointer_motion *event) { - wlr_log(L_DEBUG, "TODO: cursor handle motion"); + wlr_cursor_move(cursor->cursor, event->device, + event->delta_x, event->delta_y); + roots_cursor_update_position(cursor, event->time_msec); } void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor, struct wlr_event_pointer_motion_absolute *event) { - wlr_log(L_DEBUG, "TODO: cursor handle motion absolute"); + wlr_cursor_warp_absolute(cursor->cursor, event->device, + event->x_mm / event->width_mm, event->y_mm / event->height_mm); + roots_cursor_update_position(cursor, event->time_msec); } void roots_cursor_handle_button(struct roots_cursor *cursor, struct wlr_event_pointer_button *event) { - wlr_log(L_DEBUG, "TODO: cursor handle button"); + roots_cursor_press_button(cursor, event->device, event->time_msec, + event->button, event->state); } void roots_cursor_handle_axis(struct roots_cursor *cursor, struct wlr_event_pointer_axis *event) { - wlr_log(L_DEBUG, "TODO: cursor handle axis"); + wlr_seat_pointer_notify_axis(cursor->seat->seat, event->time_msec, + event->orientation, event->delta); } void roots_cursor_handle_touch_down(struct roots_cursor *cursor, struct wlr_event_touch_down *event) { - wlr_log(L_DEBUG, "TODO: cursor handle touch down"); + struct roots_touch_point *point = + calloc(1, sizeof(struct roots_touch_point)); + if (!point) { + wlr_log(L_ERROR, "could not allocate memory for touch point"); + return; + } + + point->device = event->device->data; + point->slot = event->slot; + point->x = event->x_mm / event->width_mm; + point->y = event->y_mm / event->height_mm; + wlr_cursor_warp_absolute(cursor->cursor, event->device, point->x, point->y); + roots_cursor_update_position(cursor, event->time_msec); + wl_list_insert(&cursor->touch_points, &point->link); + roots_cursor_press_button(cursor, event->device, + event->time_msec, BTN_LEFT, 1); } void roots_cursor_handle_touch_up(struct roots_cursor *cursor, struct wlr_event_touch_up *event) { - wlr_log(L_DEBUG, "TODO: cursor handle touch up"); + struct roots_touch_point *point; + wl_list_for_each(point, &cursor->touch_points, link) { + if (point->slot == event->slot) { + wl_list_remove(&point->link); + free(point); + break; + } + } + roots_cursor_press_button(cursor, event->device, + event->time_msec, BTN_LEFT, 0); } void roots_cursor_handle_touch_motion(struct roots_cursor *cursor, struct wlr_event_touch_motion *event) { - wlr_log(L_DEBUG, "TODO: cursor handle touch motion"); + struct roots_touch_point *point; + wl_list_for_each(point, &cursor->touch_points, link) { + if (point->slot == event->slot) { + point->x = event->x_mm / event->width_mm; + point->y = event->y_mm / event->height_mm; + wlr_cursor_warp_absolute(cursor->cursor, event->device, + point->x, point->y); + roots_cursor_update_position(cursor, event->time_msec); + break; + } + } } void roots_cursor_handle_tool_axis(struct roots_cursor *cursor, struct wlr_event_tablet_tool_axis *event) { - wlr_log(L_DEBUG, "TODO: cursor handle tool axis"); + if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && + (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { + wlr_cursor_warp_absolute(cursor->cursor, event->device, + event->x_mm / event->width_mm, event->y_mm / event->height_mm); + roots_cursor_update_position(cursor, event->time_msec); + } } void roots_cursor_handle_tool_tip(struct roots_cursor *cursor, struct wlr_event_tablet_tool_tip *event) { - wlr_log(L_DEBUG, "TODO: cursor handle tool tip"); + roots_cursor_press_button(cursor, event->device, + event->time_msec, BTN_LEFT, event->state); } diff --git a/rootston/seat.c b/rootston/seat.c index 957843ec..ec7709fa 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -1,6 +1,7 @@ #include #include #include +#include #include @@ -110,7 +111,7 @@ static void seat_set_device_output_mappings(struct roots_seat *seat, } } -static void roots_seat_configure_cursor(struct roots_seat *seat) { +void roots_seat_configure_cursor(struct roots_seat *seat) { struct roots_config *config = seat->input->config; struct roots_desktop *desktop = seat->input->server->desktop; struct wlr_cursor *cursor = seat->cursor->cursor; @@ -156,10 +157,44 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { if (!seat->cursor) { return; } + seat->cursor->seat = seat; struct wlr_cursor *wlr_cursor = seat->cursor->cursor; struct roots_desktop *desktop = seat->input->server->desktop; wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout); + seat->cursor->xcursor_theme = wlr_xcursor_theme_load("default", 16); + if (seat->cursor->xcursor_theme == NULL) { + wlr_log(L_ERROR, "Cannot load xcursor theme"); + roots_cursor_destroy(seat->cursor); + seat->cursor = NULL; + return; + } + + struct wlr_xcursor *xcursor = get_default_xcursor(seat->cursor->xcursor_theme); + if (xcursor == NULL) { + wlr_log(L_ERROR, "Cannot load xcursor from theme"); + wlr_xcursor_theme_destroy(seat->cursor->xcursor_theme); + roots_cursor_destroy(seat->cursor); + seat->cursor = NULL; + return; + } + + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_cursor_set_image(seat->cursor->cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y); + + // XXX: xwayland will always have the theme of the last created seat + if (seat->input->server->desktop->xwayland != NULL) { + wlr_xwayland_set_cursor(seat->input->server->desktop->xwayland, + image->buffer, image->width, image->width, + image->height, image->hotspot_x, + image->hotspot_y); + } + + wl_list_init(&seat->cursor->touch_points); + + roots_seat_configure_cursor(seat); + // add input signals wl_signal_add(&wlr_cursor->events.motion, &seat->cursor->motion); seat->cursor->motion.notify = handle_cursor_motion; @@ -196,6 +231,12 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { return NULL; } + wl_list_init(&seat->keyboards); + wl_list_init(&seat->pointers); + wl_list_init(&seat->touch); + wl_list_init(&seat->tablet_tools); + wl_list_init(&seat->drag_icons); + seat->input = input; roots_seat_init_cursor(seat); @@ -218,11 +259,6 @@ struct roots_seat *roots_seat_create(struct roots_input *input, char *name) { wl_list_insert(&input->seats, &seat->link); - wl_list_init(&seat->keyboards); - wl_list_init(&seat->pointers); - wl_list_init(&seat->touch); - wl_list_init(&seat->tablet_tools); - return seat; } @@ -231,6 +267,7 @@ void roots_seat_destroy(struct roots_seat *seat) { } static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) { + assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); struct roots_keyboard *keyboard = roots_keyboard_create(device, seat->input); keyboard->seat = seat; @@ -319,3 +356,88 @@ void roots_seat_remove_device(struct roots_seat *seat, struct wlr_input_device *device) { // TODO } + +void roots_seat_configure_xcursor(struct roots_seat *seat) { + struct wlr_xcursor *xcursor = get_default_xcursor(seat->cursor->xcursor_theme); + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_cursor_set_image(seat->cursor->cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y); + + wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, + seat->cursor->cursor->y); +} + +bool roots_seat_has_meta_pressed(struct roots_seat *seat) { + struct roots_keyboard *keyboard; + wl_list_for_each(keyboard, &seat->keyboards, seat_link) { + if (!keyboard->config->meta_key) { + continue; + } + + uint32_t modifiers = + wlr_keyboard_get_modifiers(keyboard->device->keyboard); + if ((modifiers ^ keyboard->config->meta_key) == 0) { + return true; + } + } + + return false; +} + +void roots_seat_focus_view(struct roots_seat *seat, struct roots_view *view) { + struct roots_desktop *desktop = seat->input->server->desktop; + if (seat->focus == view) { + return; + } + seat->focus = view; + seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH; + if (!view) { + return; + } + + if (view->type == ROOTS_XWAYLAND_VIEW && + view->xwayland_surface->override_redirect) { + return; + } + + size_t index = 0; + for (size_t i = 0; i < desktop->views->length; ++i) { + struct roots_view *_view = desktop->views->items[i]; + if (_view != view) { + view_activate(_view, false); + } else { + index = i; + } + } + view_activate(view, true); + // TODO: list_swap + wlr_list_del(desktop->views, index); + wlr_list_add(desktop->views, view); + wlr_seat_keyboard_notify_enter(seat->seat, view->wlr_surface); +} + +void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { + struct roots_cursor *cursor = seat->cursor; + cursor->mode = ROOTS_CURSOR_MOVE; + cursor->offs_x = cursor->cursor->x; + cursor->offs_y = cursor->cursor->y; + cursor->view_x = view->x; + cursor->view_y = view->y; + wlr_seat_pointer_clear_focus(seat->seat); + + struct wlr_xcursor *xcursor = get_move_xcursor(seat->cursor->xcursor_theme); + if (xcursor != NULL) { + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_cursor_set_image(cursor->cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y); + } +} + +void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, + uint32_t edges) { + // TODO +} + +void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { + // TODO +} diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index e38eb697..81b9e640 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -29,11 +29,11 @@ static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct roots_input *input = view->desktop->server->input; struct wlr_wl_shell_surface_move_event *e = data; - const struct roots_input_event *event = get_input_event(input, e->serial); - if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); + if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { return; } - view_begin_move(input, event->cursor, view); + roots_seat_begin_move(seat, view); } static void handle_request_resize(struct wl_listener *listener, void *data) { @@ -42,11 +42,12 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { struct roots_view *view = roots_surface->view; struct roots_input *input = view->desktop->server->input; struct wlr_wl_shell_surface_resize_event *e = data; - const struct roots_input_event *event = get_input_event(input, e->serial); - if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); + // TODO verify input event + if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { return; } - view_begin_resize(input, event->cursor, view, e->edges); + roots_seat_begin_resize(seat, view, e->edges); } static void handle_surface_commit(struct wl_listener *listener, void *data) { diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index ca33c582..4a694349 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -98,11 +98,12 @@ static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_view *view = roots_xdg_surface->view; struct roots_input *input = view->desktop->server->input; struct wlr_xdg_toplevel_v6_move_event *e = data; - const struct roots_input_event *event = get_input_event(input, e->serial); - if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); + // TODO verify event serial + if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { return; } - view_begin_move(input, event->cursor, view); + roots_seat_begin_move(seat, view); } static void handle_request_resize(struct wl_listener *listener, void *data) { @@ -111,11 +112,12 @@ static void handle_request_resize(struct wl_listener *listener, void *data) { struct roots_view *view = roots_xdg_surface->view; struct roots_input *input = view->desktop->server->input; struct wlr_xdg_toplevel_v6_resize_event *e = data; - const struct roots_input_event *event = get_input_event(input, e->serial); - if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + // TODO verify event serial + struct roots_seat *seat = input_seat_from_wlr_seat(input, e->seat->seat); + if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { return; } - view_begin_resize(input, event->cursor, view, e->edges); + roots_seat_begin_resize(seat, view, e->edges); } static void handle_commit(struct wl_listener *listener, void *data) { diff --git a/rootston/xwayland.c b/rootston/xwayland.c index e3fc1c84..b53b98a9 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -114,22 +114,8 @@ static void handle_request_configure(struct wl_listener *listener, void *data) { // seat based on seat pointer focus, but interactive moving and resizing is not // yet seat aware. Even then, we can only guess because X11 events don't give us // enough wayland info to know for sure. -static struct wlr_cursor *guess_cursor_for_view(struct roots_view *view) { - struct roots_input *input = view->desktop->server->input; - size_t len = sizeof(input->input_events) / sizeof(*input->input_events); - for (size_t i = 0; i < len; i++) { - struct wlr_cursor *cursor = input->input_events[i].cursor; - if (cursor) { - int width = view->xwayland_surface->surface->current->width; - int height = view->xwayland_surface->surface->current->height; - if (cursor->x > view->x && cursor->y > view->y && - cursor->x < view->x + width && - cursor->y < view->y + height) { - return cursor; - } - } - } - +static struct roots_seat *guess_seat_for_view(struct roots_view *view) { + // TODO return NULL; } @@ -137,28 +123,26 @@ static void handle_request_move(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, request_move); struct roots_view *view = roots_surface->view; - struct roots_input *input = view->desktop->server->input; - struct wlr_cursor *cursor = guess_cursor_for_view(view); + struct roots_seat *seat = guess_seat_for_view(view); - if (!cursor || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { return; } - view_begin_move(input, cursor, view); + roots_seat_begin_move(seat, view); } static void handle_request_resize(struct wl_listener *listener, void *data) { struct roots_xwayland_surface *roots_surface = wl_container_of(listener, roots_surface, request_resize); struct roots_view *view = roots_surface->view; - struct roots_input *input = view->desktop->server->input; - struct wlr_cursor *cursor = guess_cursor_for_view(view); + struct roots_seat *seat = guess_seat_for_view(view); struct wlr_xwayland_resize_event *e = data; - if (!cursor || input->mode != ROOTS_CURSOR_PASSTHROUGH) { + if (!seat || seat->cursor->mode != ROOTS_CURSOR_PASSTHROUGH) { return; } - view_begin_resize(input, cursor, view, e->edges); + roots_seat_begin_resize(seat, view, e->edges); } static void handle_map_notify(struct wl_listener *listener, void *data) { diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index fe61075e..ce32d186 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -110,7 +110,7 @@ static void shell_surface_protocol_move(struct wl_client *client, uint32_t serial) { wlr_log(L_DEBUG, "got shell surface move"); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); - struct wlr_seat_handle *seat_handle = + struct wlr_seat_client *seat = wl_resource_get_user_data(seat_resource); struct wlr_wl_shell_surface_move_event *event = @@ -121,7 +121,7 @@ static void shell_surface_protocol_move(struct wl_client *client, } event->client = client; event->surface = surface; - event->seat_handle = seat_handle; + event->seat = seat; event->serial = serial; wl_signal_emit(&surface->events.request_move, event); @@ -177,7 +177,7 @@ static void shell_surface_protocol_resize(struct wl_client *client, uint32_t serial, enum wl_shell_surface_resize edges) { wlr_log(L_DEBUG, "got shell surface resize"); struct wlr_wl_shell_surface *surface = wl_resource_get_user_data(resource); - struct wlr_seat_handle *seat_handle = + struct wlr_seat_client *seat = wl_resource_get_user_data(seat_resource); struct wlr_wl_shell_surface_resize_event *event = @@ -188,7 +188,7 @@ static void shell_surface_protocol_resize(struct wl_client *client, } event->client = client; event->surface = surface; - event->seat_handle = seat_handle; + event->seat = seat; event->serial = serial; event->edges = edges; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index fc45bc17..0c41b66f 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -557,7 +557,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); - struct wlr_seat_handle *seat_handle = + struct wlr_seat_client *seat = wl_resource_get_user_data(seat_resource); if (!surface->configured) { @@ -576,7 +576,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, event->client = client; event->surface = surface; - event->seat_handle = seat_handle; + event->seat = seat; event->serial = serial; event->x = x; event->y = y; @@ -590,7 +590,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); - struct wlr_seat_handle *seat_handle = + struct wlr_seat_client *seat = wl_resource_get_user_data(seat_resource); if (!surface->configured) { @@ -609,7 +609,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, event->client = client; event->surface = surface; - event->seat_handle = seat_handle; + event->seat = seat; event->serial = serial; wl_signal_emit(&surface->events.request_move, event); @@ -621,7 +621,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); - struct wlr_seat_handle *seat_handle = + struct wlr_seat_client *seat = wl_resource_get_user_data(seat_resource); if (!surface->configured) { @@ -640,7 +640,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, event->client = client; event->surface = surface; - event->seat_handle = seat_handle; + event->seat = seat; event->serial = serial; event->edges = edges; -- cgit v1.2.3 From 1db3b5512821b1d6f936897f598e0f4d12233e8e Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 11 Nov 2017 10:59:04 -0500 Subject: rootston: prefix config structs and functions --- include/rootston/config.h | 18 +++++++++--------- include/rootston/keyboard.h | 2 +- rootston/config.c | 42 ++++++++++++++++++++++-------------------- rootston/input.c | 3 ++- rootston/keyboard.c | 15 ++++++++------- rootston/main.c | 2 +- rootston/output.c | 6 ++++-- rootston/seat.c | 8 ++++---- 8 files changed, 51 insertions(+), 45 deletions(-) (limited to 'rootston/output.c') diff --git a/include/rootston/config.h b/include/rootston/config.h index d2a25b5b..71ee61c7 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -3,7 +3,7 @@ #include #include -struct output_config { +struct roots_output_config { char *name; enum wl_output_transform transform; int x, y; @@ -15,7 +15,7 @@ struct output_config { } mode; }; -struct device_config { +struct roots_device_config { char *name; char *mapped_output; struct wlr_box *mapped_box; @@ -23,7 +23,7 @@ struct device_config { struct wl_list link; }; -struct binding_config { +struct roots_binding_config { uint32_t modifiers; xkb_keysym_t *keysyms; size_t keysyms_len; @@ -31,7 +31,7 @@ struct binding_config { struct wl_list link; }; -struct keyboard_config { +struct roots_keyboard_config { char *name; uint32_t meta_key; char *rules; @@ -63,7 +63,7 @@ struct roots_config { * arguments can specify the location of the config file. If it is not * specified, the default location will be used. */ -struct roots_config *parse_args(int argc, char *argv[]); +struct roots_config *roots_config_create_from_args(int argc, char *argv[]); /** * Destroy the config and free its resources. @@ -74,21 +74,21 @@ void roots_config_destroy(struct roots_config *config); * Get configuration for the output. If the output is not configured, returns * NULL. */ -struct output_config *config_get_output(struct roots_config *config, +struct roots_output_config *roots_config_get_output(struct roots_config *config, 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 roots_device_config *roots_config_get_device(struct roots_config *config, struct wlr_input_device *device); /** * Get configuration for the keyboard. If the keyboard is not configured, * 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); +struct roots_keyboard_config *roots_config_get_keyboard( + struct roots_config *config, struct wlr_input_device *device); #endif diff --git a/include/rootston/keyboard.h b/include/rootston/keyboard.h index 51977f08..15e7c9c4 100644 --- a/include/rootston/keyboard.h +++ b/include/rootston/keyboard.h @@ -10,7 +10,7 @@ struct roots_keyboard { struct roots_input *input; struct roots_seat *seat; struct wlr_input_device *device; - struct keyboard_config *config; + struct roots_keyboard_config *config; struct wl_list link; struct wl_listener keyboard_key; diff --git a/rootston/config.c b/rootston/config.c index 73bb6eb0..9530ba37 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -115,7 +115,8 @@ static uint32_t parse_modifier(const char *symname) { void add_binding_config(struct wl_list *bindings, const char* combination, const char* command) { - struct binding_config *bc = calloc(1, sizeof(struct binding_config)); + struct roots_binding_config *bc = + calloc(1, sizeof(struct roots_binding_config)); xkb_keysym_t keysyms[ROOTS_KEYBOARD_PRESSED_KEYSYMS_CAP]; char *symnames = strdup(combination); @@ -151,7 +152,7 @@ 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; + struct roots_keyboard_config *kc; bool found = false; wl_list_for_each(kc, &config->keyboards, link) { if (strcmp(kc->name, device_name) == 0) { @@ -161,7 +162,7 @@ static void config_handle_keyboard(struct roots_config *config, } if (!found) { - kc = calloc(1, sizeof(struct keyboard_config)); + kc = calloc(1, sizeof(struct roots_keyboard_config)); kc->name = strdup(device_name); wl_list_insert(&config->keyboards, &kc->link); } @@ -207,7 +208,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, } } else if (strncmp(output_prefix, section, strlen(output_prefix)) == 0) { const char *output_name = section + strlen(output_prefix); - struct output_config *oc; + struct roots_output_config *oc; bool found = false; wl_list_for_each(oc, &config->outputs, link) { @@ -218,7 +219,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, } if (!found) { - oc = calloc(1, sizeof(struct output_config)); + oc = calloc(1, sizeof(struct roots_output_config)); oc->name = strdup(output_name); oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; oc->scale = 1; @@ -281,7 +282,7 @@ 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; + struct roots_device_config *dc; bool found = false; wl_list_for_each(dc, &config->devices, link) { if (strcmp(dc->name, device_name) == 0) { @@ -291,7 +292,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, } if (!found) { - dc = calloc(1, sizeof(struct device_config)); + dc = calloc(1, sizeof(struct roots_device_config)); dc->name = strdup(device_name); dc->seat = strdup("seat0"); wl_list_insert(&config->devices, &dc->link); @@ -323,7 +324,7 @@ static int config_ini_handler(void *user, const char *section, const char *name, return 1; } -struct roots_config *parse_args(int argc, char *argv[]) { +struct roots_config *roots_config_create_from_args(int argc, char *argv[]) { struct roots_config *config = calloc(1, sizeof(struct roots_config)); if (config == NULL) { return NULL; @@ -370,7 +371,8 @@ struct roots_config *parse_args(int argc, char *argv[]) { 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)); + struct roots_keyboard_config *kc = + calloc(1, sizeof(struct roots_keyboard_config)); kc->meta_key = WLR_MODIFIER_LOGO; kc->name = strdup(""); wl_list_insert(&config->keyboards, &kc->link); @@ -386,13 +388,13 @@ struct roots_config *parse_args(int argc, char *argv[]) { } void roots_config_destroy(struct roots_config *config) { - struct output_config *oc, *otmp = NULL; + struct roots_output_config *oc, *otmp = NULL; wl_list_for_each_safe(oc, otmp, &config->outputs, link) { free(oc->name); free(oc); } - struct device_config *dc, *dtmp = NULL; + struct roots_device_config *dc, *dtmp = NULL; wl_list_for_each_safe(dc, dtmp, &config->devices, link) { free(dc->name); free(dc->seat); @@ -401,7 +403,7 @@ void roots_config_destroy(struct roots_config *config) { free(dc); } - struct keyboard_config *kc, *ktmp = NULL; + struct roots_keyboard_config *kc, *ktmp = NULL; wl_list_for_each_safe(kc, ktmp, &config->bindings, link) { free(kc->name); free(kc->rules); @@ -412,7 +414,7 @@ void roots_config_destroy(struct roots_config *config) { free(kc); } - struct binding_config *bc, *btmp = NULL; + struct roots_binding_config *bc, *btmp = NULL; wl_list_for_each_safe(bc, btmp, &config->bindings, link) { free(bc->keysyms); free(bc->command); @@ -425,9 +427,9 @@ void roots_config_destroy(struct roots_config *config) { free(config); } -struct output_config *config_get_output(struct roots_config *config, +struct roots_output_config *roots_config_get_output(struct roots_config *config, struct wlr_output *output) { - struct output_config *o_config; + struct roots_output_config *o_config; wl_list_for_each(o_config, &config->outputs, link) { if (strcmp(o_config->name, output->name) == 0) { return o_config; @@ -437,9 +439,9 @@ struct output_config *config_get_output(struct roots_config *config, return NULL; } -struct device_config *config_get_device(struct roots_config *config, +struct roots_device_config *roots_config_get_device(struct roots_config *config, struct wlr_input_device *device) { - struct device_config *d_config; + struct roots_device_config *d_config; wl_list_for_each(d_config, &config->devices, link) { if (strcmp(d_config->name, device->name) == 0) { return d_config; @@ -449,9 +451,9 @@ 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 roots_keyboard_config *roots_config_get_keyboard( + struct roots_config *config, struct wlr_input_device *device) { + struct roots_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)) { diff --git a/rootston/input.c b/rootston/input.c index e96565e0..35a5af97 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -44,7 +44,8 @@ static void input_add_notify(struct wl_listener *listener, void *data) { struct roots_input *input = wl_container_of(listener, input, input_add); char *seat_name = "seat0"; - struct device_config *dc = config_get_device(input->config, device); + struct roots_device_config *dc = + roots_config_get_device(input->config, device); if (dc) { seat_name = dc->seat; } diff --git a/rootston/keyboard.c b/rootston/keyboard.c index bb748550..c118e55c 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -92,7 +92,7 @@ static bool keyboard_keysym_press(struct roots_keyboard *keyboard, uint32_t modifiers = wlr_keyboard_get_modifiers(keyboard->device->keyboard); struct wl_list *bindings = &keyboard->input->server->config->bindings; - struct binding_config *bc; + struct roots_binding_config *bc; wl_list_for_each(bc, bindings, link) { if (modifiers ^ bc->modifiers) { continue; @@ -210,8 +210,8 @@ void roots_keyboard_handle_modifiers(struct roots_keyboard *r_keyboard) { wlr_seat_keyboard_notify_modifiers(seat); } -static void keyboard_config_merge(struct keyboard_config *config, - struct keyboard_config *fallback) { +static void keyboard_config_merge(struct roots_keyboard_config *config, + struct roots_keyboard_config *fallback) { if (fallback == NULL) { return; } @@ -248,15 +248,16 @@ struct roots_keyboard *roots_keyboard_create(struct wlr_input_device *device, keyboard->device = device; keyboard->input = input; - struct keyboard_config *config = calloc(1, sizeof(struct keyboard_config)); + struct roots_keyboard_config *config = + calloc(1, sizeof(struct roots_keyboard_config)); if (config == NULL) { free(keyboard); return NULL; } - keyboard_config_merge(config, config_get_keyboard(input->config, device)); - keyboard_config_merge(config, config_get_keyboard(input->config, NULL)); + keyboard_config_merge(config, roots_config_get_keyboard(input->config, device)); + keyboard_config_merge(config, roots_config_get_keyboard(input->config, NULL)); - struct keyboard_config env_config = { + struct roots_keyboard_config env_config = { .rules = getenv("XKB_DEFAULT_RULES"), .model = getenv("XKB_DEFAULT_MODEL"), .layout = getenv("XKB_DEFAULT_LAYOUT"), diff --git a/rootston/main.c b/rootston/main.c index 2a054e6c..d55bc682 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -13,7 +13,7 @@ struct roots_server server = { 0 }; int main(int argc, char **argv) { - assert(server.config = parse_args(argc, argv)); + assert(server.config = roots_config_create_from_args(argc, argv)); assert(server.wl_display = wl_display_create()); assert(server.wl_event_loop = wl_display_get_event_loop(server.wl_display)); diff --git a/rootston/output.c b/rootston/output.c index f192cb48..d853c45f 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -181,7 +181,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { output->last_frame = desktop->last_frame = now; } -static void set_mode(struct wlr_output *output, struct output_config *oc) { +static void set_mode(struct wlr_output *output, + struct roots_output_config *oc) { struct wlr_output_mode *mode, *best = NULL; int mhz = (int)(oc->mode.refresh_rate * 1000); wl_list_for_each(mode, &output->modes, link) { @@ -225,7 +226,8 @@ void output_add_notify(struct wl_listener *listener, void *data) { wl_signal_add(&wlr_output->events.frame, &output->frame); wl_list_insert(&desktop->outputs, &output->link); - struct output_config *output_config = config_get_output(config, wlr_output); + struct roots_output_config *output_config = + roots_config_get_output(config, wlr_output); if (output_config) { if (output_config->mode.width) { set_mode(wlr_output, output_config); diff --git a/rootston/seat.c b/rootston/seat.c index 3530fb75..4602aad5 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -117,8 +117,8 @@ static void seat_reset_device_mappings(struct roots_seat *seat, struct wlr_input struct roots_config *config = seat->input->config; wlr_cursor_map_input_to_output(cursor, device, NULL); - struct device_config *dconfig; - if ((dconfig = config_get_device(config, device))) { + struct roots_device_config *dconfig; + if ((dconfig = roots_config_get_device(config, device))) { wlr_cursor_map_input_to_region(cursor, device, dconfig->mapped_box); } } @@ -127,8 +127,8 @@ static void seat_set_device_output_mappings(struct roots_seat *seat, struct wlr_input_device *device, struct wlr_output *output) { struct wlr_cursor *cursor = seat->cursor->cursor; struct roots_config *config = seat->input->config; - struct device_config *dconfig; - dconfig = config_get_device(config, device); + struct roots_device_config *dconfig; + dconfig = roots_config_get_device(config, device); if (dconfig && dconfig->mapped_output && strcmp(dconfig->mapped_output, output->name) == 0) { wlr_cursor_map_input_to_output(cursor, device, output); -- cgit v1.2.3 From aaf069188319f42bc214f4317c37d533aea64518 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 11 Nov 2017 18:42:14 +0100 Subject: rootston: add roots_xcursor_theme roots_xcursor_theme loads multiple wlr_xcursor_theme at different scales. --- include/rootston/cursor.h | 1 - include/rootston/desktop.h | 2 + include/rootston/xcursor.h | 39 ++++++++++++++-- rootston/cursor.c | 10 +--- rootston/desktop.c | 14 ++++++ rootston/output.c | 6 +++ rootston/seat.c | 61 ++++-------------------- rootston/xcursor.c | 114 ++++++++++++++++++++++++++++++++++++++++----- 8 files changed, 170 insertions(+), 77 deletions(-) (limited to 'rootston/output.c') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index c0dbc010..fc71e31d 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -30,7 +30,6 @@ struct roots_cursor { enum roots_cursor_mode mode; // state from input (review if this is necessary) - struct wlr_xcursor_theme *xcursor_theme; struct wlr_seat *wl_seat; struct wl_client *cursor_client; int offs_x, offs_y; diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 376412fb..b12fff70 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -12,6 +12,7 @@ #include #include "rootston/view.h" #include "rootston/config.h" +#include "rootston/xcursor.h" struct roots_output { struct roots_desktop *desktop; @@ -29,6 +30,7 @@ struct roots_desktop { struct roots_server *server; struct roots_config *config; + struct roots_xcursor_theme *xcursor_theme; struct wlr_output_layout *layout; diff --git a/include/rootston/xcursor.h b/include/rootston/xcursor.h index c96e50ef..45fac481 100644 --- a/include/rootston/xcursor.h +++ b/include/rootston/xcursor.h @@ -1,15 +1,44 @@ #ifndef _ROOTSTON_XCURSOR_H #define _ROOTSTON_XCURSOR_H +#include #include +#include +#include -struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme); +#define ROOTS_XCURSOR_SIZE 16 -struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme); +struct roots_xcursor_scaled_theme { + uint32_t scale; + struct wlr_xcursor_theme *theme; + struct wl_list link; +}; -struct wlr_xcursor *get_resize_xcursor(struct wlr_xcursor_theme *theme, - uint32_t edges); +struct roots_xcursor_theme { + char *name; + struct wl_list scaled_themes; // roots_xcursor_scaled_theme::link +}; -struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme); +struct roots_xcursor_theme *roots_xcursor_theme_create(const char *name); + +void roots_xcursor_theme_destroy(struct roots_xcursor_theme *theme); + +int roots_xcursor_theme_load(struct roots_xcursor_theme *theme, + uint32_t scale); + +void roots_xcursor_theme_set_default(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor); + +void roots_xcursor_theme_set_move(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor); + +void roots_xcursor_theme_set_resize(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor, uint32_t edges); + +void roots_xcursor_theme_set_rotate(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor); + +void roots_xcursor_theme_xwayland_set_default(struct roots_xcursor_theme *theme, + struct wlr_xwayland *xwayland); #endif diff --git a/rootston/cursor.c b/rootston/cursor.c index c3982e0e..46f4caea 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -27,12 +27,6 @@ void roots_cursor_destroy(struct roots_cursor *cursor) { // TODO } -static void cursor_set_xcursor_image(struct roots_cursor *cursor, - struct wlr_xcursor_image *image) { - wlr_cursor_set_image(cursor->cursor, image->buffer, image->width, - image->width, image->height, image->hotspot_x, image->hotspot_y, 0); -} - static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t time) { struct roots_desktop *desktop = cursor->seat->input->server->desktop; struct roots_seat *seat = cursor->seat; @@ -50,8 +44,8 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t set_compositor_cursor = view_client != cursor->cursor_client; } if (set_compositor_cursor) { - struct wlr_xcursor *xcursor = get_default_xcursor(cursor->xcursor_theme); - cursor_set_xcursor_image(cursor, xcursor->images[0]); + roots_xcursor_theme_set_default(desktop->xcursor_theme, + cursor->cursor); cursor->cursor_client = NULL; } if (view) { diff --git a/rootston/desktop.c b/rootston/desktop.c index 448171ec..e20fceab 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -323,6 +323,14 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->server = server; desktop->config = config; + + desktop->xcursor_theme = roots_xcursor_theme_create("default"); + if (desktop->xcursor_theme == NULL) { + wlr_list_free(desktop->views); + free(desktop); + return NULL; + } + desktop->layout = wlr_output_layout_create(); desktop->compositor = wlr_compositor_create(server->wl_display, server->renderer); @@ -344,6 +352,12 @@ struct roots_desktop *desktop_create(struct roots_server *server, wl_signal_add(&desktop->xwayland->events.new_surface, &desktop->xwayland_surface); desktop->xwayland_surface.notify = handle_xwayland_surface; + + if (roots_xcursor_theme_load(desktop->xcursor_theme, 1)) { + wlr_log(L_ERROR, "Cannot load xwayland xcursor theme"); + } + roots_xcursor_theme_xwayland_set_default(desktop->xcursor_theme, + desktop->xwayland); } #endif diff --git a/rootston/output.c b/rootston/output.c index d853c45f..943e14c0 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -11,6 +11,7 @@ #include "rootston/server.h" #include "rootston/desktop.h" #include "rootston/config.h" +#include "rootston/xcursor.h" static inline int64_t timespec_to_msec(const struct timespec *a) { return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; @@ -240,6 +241,11 @@ void output_add_notify(struct wl_listener *listener, void *data) { wlr_output_layout_add_auto(desktop->layout, wlr_output); } + if (roots_xcursor_theme_load(desktop->xcursor_theme, wlr_output->scale)) { + wlr_log(L_ERROR, "Cannot load xcursor theme with scale %d", + wlr_output->scale); + } + struct roots_seat *seat; wl_list_for_each(seat, &input->seats, link) { roots_seat_configure_cursor(seat); diff --git a/rootston/seat.c b/rootston/seat.c index 280443ac..376da67f 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -176,12 +176,6 @@ void roots_seat_configure_cursor(struct roots_seat *seat) { } } -static void seat_set_xcursor_image(struct roots_seat *seat, struct - wlr_xcursor_image *image) { - wlr_cursor_set_image(seat->cursor->cursor, image->buffer, image->width, - image->width, image->height, image->hotspot_x, image->hotspot_y, 0); -} - static void roots_seat_init_cursor(struct roots_seat *seat) { seat->cursor = roots_cursor_create(seat); if (!seat->cursor) { @@ -192,33 +186,7 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { struct roots_desktop *desktop = seat->input->server->desktop; wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout); - seat->cursor->xcursor_theme = wlr_xcursor_theme_load("default", 16); - if (seat->cursor->xcursor_theme == NULL) { - wlr_log(L_ERROR, "Cannot load xcursor theme"); - roots_cursor_destroy(seat->cursor); - seat->cursor = NULL; - return; - } - - struct wlr_xcursor *xcursor = get_default_xcursor(seat->cursor->xcursor_theme); - if (xcursor == NULL) { - wlr_log(L_ERROR, "Cannot load xcursor from theme"); - wlr_xcursor_theme_destroy(seat->cursor->xcursor_theme); - roots_cursor_destroy(seat->cursor); - seat->cursor = NULL; - return; - } - - struct wlr_xcursor_image *image = xcursor->images[0]; - seat_set_xcursor_image(seat, image); - - // XXX: xwayland will always have the theme of the last created seat - if (seat->input->server->desktop->xwayland != NULL) { - wlr_xwayland_set_cursor(seat->input->server->desktop->xwayland, - image->buffer, image->width, image->width, - image->height, image->hotspot_x, - image->hotspot_y); - } + roots_xcursor_theme_set_default(desktop->xcursor_theme, wlr_cursor); wl_list_init(&seat->cursor->touch_points); @@ -476,11 +444,8 @@ void roots_seat_remove_device(struct roots_seat *seat, } void roots_seat_configure_xcursor(struct roots_seat *seat) { - struct wlr_xcursor *xcursor = - get_default_xcursor(seat->cursor->xcursor_theme); - struct wlr_xcursor_image *image = xcursor->images[0]; - seat_set_xcursor_image(seat, image); - + roots_xcursor_theme_set_default(seat->input->server->desktop->xcursor_theme, + seat->cursor->cursor); wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, seat->cursor->cursor->y); } @@ -557,11 +522,8 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - struct wlr_xcursor *xcursor = get_move_xcursor(seat->cursor->xcursor_theme); - if (xcursor != NULL) { - struct wlr_xcursor_image *image = xcursor->images[0]; - seat_set_xcursor_image(seat, image); - } + roots_xcursor_theme_set_move(seat->input->server->desktop->xcursor_theme, + seat->cursor->cursor); } void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, @@ -587,11 +549,8 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - struct wlr_xcursor *xcursor = get_resize_xcursor(cursor->xcursor_theme, edges); - if (xcursor != NULL) { - seat_set_xcursor_image(seat, xcursor->images[0]); - } - + roots_xcursor_theme_set_resize(seat->input->server->desktop->xcursor_theme, + seat->cursor->cursor, edges); } void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { @@ -603,8 +562,6 @@ void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - struct wlr_xcursor *xcursor = get_rotate_xcursor(cursor->xcursor_theme); - if (xcursor != NULL) { - seat_set_xcursor_image(seat, xcursor->images[0]); - } + roots_xcursor_theme_set_rotate(seat->input->server->desktop->xcursor_theme, + seat->cursor->cursor); } diff --git a/rootston/xcursor.c b/rootston/xcursor.c index 8697cdc3..6aa74bc4 100644 --- a/rootston/xcursor.c +++ b/rootston/xcursor.c @@ -1,6 +1,85 @@ -#include +#define _POSIX_C_SOURCE 200809L +#include +#include +#include "rootston/xcursor.h" #include "rootston/input.h" +struct roots_xcursor_theme *roots_xcursor_theme_create(const char *name) { + struct roots_xcursor_theme *theme = + calloc(1, sizeof(struct roots_xcursor_theme)); + if (theme == NULL) { + return NULL; + } + theme->name = strdup(name); + wl_list_init(&theme->scaled_themes); + return theme; +} + +void roots_xcursor_theme_destroy(struct roots_xcursor_theme *theme) { + if (theme == NULL) { + return; + } + struct roots_xcursor_scaled_theme *scaled_theme, *tmp; + wl_list_for_each_safe(scaled_theme, tmp, &theme->scaled_themes, link) { + wl_list_remove(&scaled_theme->link); + wlr_xcursor_theme_destroy(scaled_theme->theme); + free(scaled_theme); + } + free(theme->name); + free(theme); +} + +int roots_xcursor_theme_load(struct roots_xcursor_theme *theme, + uint32_t scale) { + struct roots_xcursor_scaled_theme *scaled_theme; + wl_list_for_each(scaled_theme, &theme->scaled_themes, link) { + if (scaled_theme->scale == scale) { + return 0; + } + } + + scaled_theme = calloc(1, sizeof(struct roots_xcursor_scaled_theme)); + if (scaled_theme == NULL) { + return 1; + } + scaled_theme->scale = scale; + scaled_theme->theme = wlr_xcursor_theme_load(NULL, + ROOTS_XCURSOR_SIZE * scale); + if (scaled_theme->theme == NULL) { + free(scaled_theme); + return 1; + } + wl_list_insert(&theme->scaled_themes, &scaled_theme->link); + return 0; +} + +static void roots_xcursor_theme_set(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor, const char *name) { + struct roots_xcursor_scaled_theme *scaled_theme; + wl_list_for_each(scaled_theme, &theme->scaled_themes, link) { + struct wlr_xcursor *xcursor = + wlr_xcursor_theme_get_cursor(scaled_theme->theme, name); + if (xcursor == NULL) { + continue; + } + + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_cursor_set_image(cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y, + scaled_theme->scale); + } +} + +void roots_xcursor_theme_set_default(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor) { + roots_xcursor_theme_set(theme, cursor, "left_ptr"); +} + +void roots_xcursor_theme_set_move(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor) { + roots_xcursor_theme_set(theme, cursor, "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) { @@ -24,19 +103,32 @@ static const char *get_resize_xcursor_name(uint32_t edges) { return "se-resize"; // fallback } -struct wlr_xcursor *get_default_xcursor(struct wlr_xcursor_theme *theme) { - return wlr_xcursor_theme_get_cursor(theme, "left_ptr"); +void roots_xcursor_theme_set_resize(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor, uint32_t edges) { + roots_xcursor_theme_set(theme, cursor, get_resize_xcursor_name(edges)); } -struct wlr_xcursor *get_move_xcursor(struct wlr_xcursor_theme *theme) { - return wlr_xcursor_theme_get_cursor(theme, "grabbing"); +void roots_xcursor_theme_set_rotate(struct roots_xcursor_theme *theme, + struct wlr_cursor *cursor) { + roots_xcursor_theme_set(theme, cursor, "grabbing"); } -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)); -} +void roots_xcursor_theme_xwayland_set_default(struct roots_xcursor_theme *theme, + struct wlr_xwayland *xwayland) { + struct roots_xcursor_scaled_theme *scaled_theme; + wl_list_for_each(scaled_theme, &theme->scaled_themes, link) { + if (scaled_theme->scale == 1) { + struct wlr_xcursor *xcursor = + wlr_xcursor_theme_get_cursor(scaled_theme->theme, "left_ptr"); + if (xcursor == NULL) { + continue; + } -struct wlr_xcursor *get_rotate_xcursor(struct wlr_xcursor_theme *theme) { - return wlr_xcursor_theme_get_cursor(theme, "grabbing"); + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_xwayland_set_cursor(xwayland, image->buffer, image->width, + image->width, image->height, image->hotspot_x, + image->hotspot_y); + break; + } + } } -- cgit v1.2.3 From 09279b90a63c5fdb2e28a61f2dfc936285126177 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 11 Nov 2017 19:09:34 +0100 Subject: Add wlr_output.serial --- backend/drm/util.c | 9 ++++++++- include/wlr/types/wlr_output.h | 1 + rootston/output.c | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'rootston/output.c') diff --git a/backend/drm/util.c b/backend/drm/util.c index 656c070a..c27d7b67 100644 --- a/backend/drm/util.c +++ b/backend/drm/util.c @@ -106,8 +106,15 @@ void parse_edid(struct wlr_output *restrict output, size_t len, const uint8_t *d if (nl) { *nl = '\0'; } + } else if (flag == 0 && data[i + 3] == 0xFF) { + sprintf(output->serial, "%.13s", &data[i + 5]); - break; + // Monitor serial numbers are terminated by newline if they're too + // short + char *nl = strchr(output->serial, '\n'); + if (nl) { + *nl = '\0'; + } } } } diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index df123639..cf000019 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -43,6 +43,7 @@ struct wlr_output { char name[16]; char make[48]; char model[16]; + char serial[16]; uint32_t scale; int32_t width, height; int32_t phys_width, phys_height; // mm diff --git a/rootston/output.c b/rootston/output.c index d853c45f..a929e6be 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -210,8 +210,9 @@ void output_add_notify(struct wl_listener *listener, void *data) { struct roots_config *config = desktop->config; wlr_log(L_DEBUG, "Output '%s' added", wlr_output->name); - wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make, - wlr_output->model, wlr_output->phys_width, wlr_output->phys_height); + wlr_log(L_DEBUG, "%s %s %s %"PRId32"mm x %"PRId32"mm", wlr_output->make, + wlr_output->model, wlr_output->serial, wlr_output->phys_width, + wlr_output->phys_height); if (wl_list_length(&wlr_output->modes) > 0) { struct wlr_output_mode *mode = NULL; mode = wl_container_of((&wlr_output->modes)->prev, mode, link); -- cgit v1.2.3 From 2dccb11741abd99fd71d4ccaba1ad42362d8f204 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 11 Nov 2017 23:53:45 +0100 Subject: rootston: keep one xcursor_theme per seat --- include/rootston/cursor.h | 1 + rootston/cursor.c | 2 +- rootston/output.c | 11 ++++++----- rootston/seat.c | 12 +++++++----- 4 files changed, 15 insertions(+), 11 deletions(-) (limited to 'rootston/output.c') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index fc71e31d..575c9d0e 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -30,6 +30,7 @@ struct roots_cursor { enum roots_cursor_mode mode; // state from input (review if this is necessary) + struct roots_xcursor_theme *xcursor_theme; struct wlr_seat *wl_seat; struct wl_client *cursor_client; int offs_x, offs_y; diff --git a/rootston/cursor.c b/rootston/cursor.c index 46f4caea..0795cea6 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -44,7 +44,7 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t set_compositor_cursor = view_client != cursor->cursor_client; } if (set_compositor_cursor) { - roots_xcursor_theme_set_default(desktop->xcursor_theme, + roots_xcursor_theme_set_default(cursor->xcursor_theme, cursor->cursor); cursor->cursor_client = NULL; } diff --git a/rootston/output.c b/rootston/output.c index 943e14c0..b35e56cd 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -241,13 +241,14 @@ void output_add_notify(struct wl_listener *listener, void *data) { wlr_output_layout_add_auto(desktop->layout, wlr_output); } - if (roots_xcursor_theme_load(desktop->xcursor_theme, wlr_output->scale)) { - wlr_log(L_ERROR, "Cannot load xcursor theme with scale %d", - wlr_output->scale); - } - struct roots_seat *seat; wl_list_for_each(seat, &input->seats, link) { + if (roots_xcursor_theme_load(seat->cursor->xcursor_theme, + wlr_output->scale)) { + wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' " + "with scale %d", wlr_output->name, wlr_output->scale); + } + roots_seat_configure_cursor(seat); roots_seat_configure_xcursor(seat); } diff --git a/rootston/seat.c b/rootston/seat.c index 376da67f..ec4e9800 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -186,7 +186,9 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { struct roots_desktop *desktop = seat->input->server->desktop; wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout); - roots_xcursor_theme_set_default(desktop->xcursor_theme, wlr_cursor); + // TODO: be able to configure per-seat cursor themes + seat->cursor->xcursor_theme = desktop->xcursor_theme; + roots_xcursor_theme_set_default(seat->cursor->xcursor_theme, wlr_cursor); wl_list_init(&seat->cursor->touch_points); @@ -444,7 +446,7 @@ void roots_seat_remove_device(struct roots_seat *seat, } void roots_seat_configure_xcursor(struct roots_seat *seat) { - roots_xcursor_theme_set_default(seat->input->server->desktop->xcursor_theme, + roots_xcursor_theme_set_default(seat->cursor->xcursor_theme, seat->cursor->cursor); wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, seat->cursor->cursor->y); @@ -522,7 +524,7 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - roots_xcursor_theme_set_move(seat->input->server->desktop->xcursor_theme, + roots_xcursor_theme_set_move(seat->cursor->xcursor_theme, seat->cursor->cursor); } @@ -549,7 +551,7 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - roots_xcursor_theme_set_resize(seat->input->server->desktop->xcursor_theme, + roots_xcursor_theme_set_resize(seat->cursor->xcursor_theme, seat->cursor->cursor, edges); } @@ -562,6 +564,6 @@ void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - roots_xcursor_theme_set_rotate(seat->input->server->desktop->xcursor_theme, + roots_xcursor_theme_set_rotate(seat->cursor->xcursor_theme, seat->cursor->cursor); } -- cgit v1.2.3 From 8605243459629f566ed5109ffd896fd57b329ceb Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 12 Nov 2017 11:10:56 +0100 Subject: Introduce wlr_xcursor_manager --- include/rootston/cursor.h | 2 +- include/rootston/desktop.h | 2 +- include/rootston/xcursor.h | 40 ++---------- include/wlr/types/wlr_cursor.h | 1 - include/wlr/types/wlr_xcursor_manager.h | 53 ++++++++++++++++ include/wlr/xcursor.h | 2 +- rootston/cursor.c | 5 +- rootston/desktop.c | 21 +++++-- rootston/output.c | 4 +- rootston/seat.c | 22 ++++--- rootston/xcursor.c | 108 +------------------------------- types/meson.build | 3 +- types/wlr_xcursor_manager.c | 84 +++++++++++++++++++++++++ 13 files changed, 180 insertions(+), 167 deletions(-) create mode 100644 include/wlr/types/wlr_xcursor_manager.h create mode 100644 types/wlr_xcursor_manager.c (limited to 'rootston/output.c') diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index 575c9d0e..f49b6439 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -30,7 +30,7 @@ struct roots_cursor { enum roots_cursor_mode mode; // state from input (review if this is necessary) - struct roots_xcursor_theme *xcursor_theme; + struct wlr_xcursor_manager *xcursor_manager; struct wlr_seat *wl_seat; struct wl_client *cursor_client; int offs_x, offs_y; diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index b12fff70..7371284f 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -30,9 +30,9 @@ struct roots_desktop { struct roots_server *server; struct roots_config *config; - struct roots_xcursor_theme *xcursor_theme; struct wlr_output_layout *layout; + struct wlr_xcursor_manager *xcursor_manager; struct wlr_compositor *compositor; struct wlr_wl_shell *wl_shell; diff --git a/include/rootston/xcursor.h b/include/rootston/xcursor.h index 45fac481..bc00f79c 100644 --- a/include/rootston/xcursor.h +++ b/include/rootston/xcursor.h @@ -1,44 +1,14 @@ #ifndef _ROOTSTON_XCURSOR_H #define _ROOTSTON_XCURSOR_H -#include -#include -#include -#include +#include #define ROOTS_XCURSOR_SIZE 16 -struct roots_xcursor_scaled_theme { - uint32_t scale; - struct wlr_xcursor_theme *theme; - struct wl_list link; -}; +#define ROOTS_XCURSOR_DEFAULT "left_ptr" +#define ROOTS_XCURSOR_MOVE "grabbing" +#define ROOTS_XCURSOR_ROTATE "grabbing" -struct roots_xcursor_theme { - char *name; - struct wl_list scaled_themes; // roots_xcursor_scaled_theme::link -}; - -struct roots_xcursor_theme *roots_xcursor_theme_create(const char *name); - -void roots_xcursor_theme_destroy(struct roots_xcursor_theme *theme); - -int roots_xcursor_theme_load(struct roots_xcursor_theme *theme, - uint32_t scale); - -void roots_xcursor_theme_set_default(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor); - -void roots_xcursor_theme_set_move(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor); - -void roots_xcursor_theme_set_resize(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor, uint32_t edges); - -void roots_xcursor_theme_set_rotate(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor); - -void roots_xcursor_theme_xwayland_set_default(struct roots_xcursor_theme *theme, - struct wlr_xwayland *xwayland); +const char *roots_xcursor_get_resize_name(uint32_t edges); #endif diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index 3df74d28..0db32eb2 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -6,7 +6,6 @@ #include #include #include -#include struct wlr_cursor_state; diff --git a/include/wlr/types/wlr_xcursor_manager.h b/include/wlr/types/wlr_xcursor_manager.h new file mode 100644 index 00000000..c78a6e8d --- /dev/null +++ b/include/wlr/types/wlr_xcursor_manager.h @@ -0,0 +1,53 @@ +#ifndef WLR_TYPES_WLR_XCURSOR_MANAGER_H +#define WLR_TYPES_WLR_XCURSOR_MANAGER_H + +#include +#include +#include + +/** + * A scaled XCursor theme. + */ +struct wlr_xcursor_manager_theme { + uint32_t scale; + struct wlr_xcursor_theme *theme; + struct wl_list link; +}; + +/** + * Manage multiple XCursor themes with different scales and set `wlr_cursor` + * images. + * + * This manager can be used to display cursor images on multiple outputs having + * different scale factors. + */ +struct wlr_xcursor_manager { + char *name; + uint32_t size; + struct wl_list scaled_themes; // wlr_xcursor_manager_theme::link +}; + +/** + * Create a new XCursor manager. After initialization, scaled themes need to be + * loaded with `wlr_xcursor_manager_load`. `size` is the unscaled cursor theme + * size. + */ +struct wlr_xcursor_manager *wlr_xcursor_manager_create(const char *name, + uint32_t size); + +void wlr_xcursor_manager_destroy(struct wlr_xcursor_manager *manager); + +int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager, + uint32_t scale); + +struct wlr_xcursor *wlr_xcursor_manager_get_xcursor( + struct wlr_xcursor_manager *manager, const char *name, uint32_t scale); + +/** + * Set a `wlr_cursor` image. The manager uses all currently loaded scaled + * themes. + */ +void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, + const char *name, struct wlr_cursor *cursor); + +#endif diff --git a/include/wlr/xcursor.h b/include/wlr/xcursor.h index c12d5405..b6362b06 100644 --- a/include/wlr/xcursor.h +++ b/include/wlr/xcursor.h @@ -61,7 +61,7 @@ struct wlr_xcursor_theme *wlr_xcursor_theme_load(const char *name, int size); void wlr_xcursor_theme_destroy(struct wlr_xcursor_theme *theme); struct wlr_xcursor *wlr_xcursor_theme_get_cursor( - struct wlr_xcursor_theme *theme, const char *name); + struct wlr_xcursor_theme *theme, const char *name); int wlr_xcursor_frame(struct wlr_xcursor *cursor, uint32_t time); diff --git a/rootston/cursor.c b/rootston/cursor.c index 0795cea6..ecd5e9a0 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -6,6 +6,7 @@ #elif __FreeBSD__ #include #endif +#include #include #include "rootston/xcursor.h" #include "rootston/cursor.h" @@ -44,8 +45,8 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t set_compositor_cursor = view_client != cursor->cursor_client; } if (set_compositor_cursor) { - roots_xcursor_theme_set_default(cursor->xcursor_theme, - cursor->cursor); + wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, + ROOTS_XCURSOR_DEFAULT, cursor->cursor); cursor->cursor_client = NULL; } if (view) { diff --git a/rootston/desktop.c b/rootston/desktop.c index e20fceab..bb030e74 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -324,8 +325,10 @@ struct roots_desktop *desktop_create(struct roots_server *server, desktop->server = server; desktop->config = config; - desktop->xcursor_theme = roots_xcursor_theme_create("default"); - if (desktop->xcursor_theme == NULL) { + desktop->xcursor_manager = wlr_xcursor_manager_create(NULL, + ROOTS_XCURSOR_SIZE); + if (desktop->xcursor_manager == NULL) { + wlr_log(L_ERROR, "Cannot create XCursor manager"); wlr_list_free(desktop->views); free(desktop); return NULL; @@ -353,11 +356,17 @@ struct roots_desktop *desktop_create(struct roots_server *server, &desktop->xwayland_surface); desktop->xwayland_surface.notify = handle_xwayland_surface; - if (roots_xcursor_theme_load(desktop->xcursor_theme, 1)) { - wlr_log(L_ERROR, "Cannot load xwayland xcursor theme"); + if (wlr_xcursor_manager_load(desktop->xcursor_manager, 1)) { + wlr_log(L_ERROR, "Cannot load XWayland XCursor theme"); + } + struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor( + desktop->xcursor_manager, ROOTS_XCURSOR_DEFAULT, 1); + if (xcursor != NULL) { + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_xwayland_set_cursor(desktop->xwayland, image->buffer, + image->width, image->width, image->height, image->hotspot_x, + image->hotspot_y); } - roots_xcursor_theme_xwayland_set_default(desktop->xcursor_theme, - desktop->xwayland); } #endif diff --git a/rootston/output.c b/rootston/output.c index b35e56cd..cd288195 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -5,13 +5,13 @@ #include #include #include +#include #include #include #include #include "rootston/server.h" #include "rootston/desktop.h" #include "rootston/config.h" -#include "rootston/xcursor.h" static inline int64_t timespec_to_msec(const struct timespec *a) { return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; @@ -243,7 +243,7 @@ void output_add_notify(struct wl_listener *listener, void *data) { struct roots_seat *seat; wl_list_for_each(seat, &input->seats, link) { - if (roots_xcursor_theme_load(seat->cursor->xcursor_theme, + if (wlr_xcursor_manager_load(seat->cursor->xcursor_manager, wlr_output->scale)) { wlr_log(L_ERROR, "Cannot load xcursor theme for output '%s' " "with scale %d", wlr_output->name, wlr_output->scale); diff --git a/rootston/seat.c b/rootston/seat.c index ec4e9800..8a838efe 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -3,6 +3,7 @@ #include #include +#include #include #include "rootston/xcursor.h" @@ -187,8 +188,9 @@ static void roots_seat_init_cursor(struct roots_seat *seat) { wlr_cursor_attach_output_layout(wlr_cursor, desktop->layout); // TODO: be able to configure per-seat cursor themes - seat->cursor->xcursor_theme = desktop->xcursor_theme; - roots_xcursor_theme_set_default(seat->cursor->xcursor_theme, wlr_cursor); + seat->cursor->xcursor_manager = desktop->xcursor_manager; + wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, + ROOTS_XCURSOR_DEFAULT, wlr_cursor); wl_list_init(&seat->cursor->touch_points); @@ -446,8 +448,8 @@ void roots_seat_remove_device(struct roots_seat *seat, } void roots_seat_configure_xcursor(struct roots_seat *seat) { - roots_xcursor_theme_set_default(seat->cursor->xcursor_theme, - seat->cursor->cursor); + wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, + ROOTS_XCURSOR_DEFAULT, seat->cursor->cursor); wlr_cursor_warp(seat->cursor->cursor, NULL, seat->cursor->cursor->x, seat->cursor->cursor->y); } @@ -524,8 +526,8 @@ void roots_seat_begin_move(struct roots_seat *seat, struct roots_view *view) { view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - roots_xcursor_theme_set_move(seat->cursor->xcursor_theme, - seat->cursor->cursor); + wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, + ROOTS_XCURSOR_MOVE, seat->cursor->cursor); } void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, @@ -551,8 +553,8 @@ void roots_seat_begin_resize(struct roots_seat *seat, struct roots_view *view, view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - roots_xcursor_theme_set_resize(seat->cursor->xcursor_theme, - seat->cursor->cursor, edges); + wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, + roots_xcursor_get_resize_name(edges), seat->cursor->cursor); } void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { @@ -564,6 +566,6 @@ void roots_seat_begin_rotate(struct roots_seat *seat, struct roots_view *view) { view_maximize(view, false); wlr_seat_pointer_clear_focus(seat->seat); - roots_xcursor_theme_set_rotate(seat->cursor->xcursor_theme, - seat->cursor->cursor); + wlr_xcursor_manager_set_cursor_image(seat->cursor->xcursor_manager, + ROOTS_XCURSOR_ROTATE, seat->cursor->cursor); } diff --git a/rootston/xcursor.c b/rootston/xcursor.c index 6aa74bc4..74e732c9 100644 --- a/rootston/xcursor.c +++ b/rootston/xcursor.c @@ -4,83 +4,7 @@ #include "rootston/xcursor.h" #include "rootston/input.h" -struct roots_xcursor_theme *roots_xcursor_theme_create(const char *name) { - struct roots_xcursor_theme *theme = - calloc(1, sizeof(struct roots_xcursor_theme)); - if (theme == NULL) { - return NULL; - } - theme->name = strdup(name); - wl_list_init(&theme->scaled_themes); - return theme; -} - -void roots_xcursor_theme_destroy(struct roots_xcursor_theme *theme) { - if (theme == NULL) { - return; - } - struct roots_xcursor_scaled_theme *scaled_theme, *tmp; - wl_list_for_each_safe(scaled_theme, tmp, &theme->scaled_themes, link) { - wl_list_remove(&scaled_theme->link); - wlr_xcursor_theme_destroy(scaled_theme->theme); - free(scaled_theme); - } - free(theme->name); - free(theme); -} - -int roots_xcursor_theme_load(struct roots_xcursor_theme *theme, - uint32_t scale) { - struct roots_xcursor_scaled_theme *scaled_theme; - wl_list_for_each(scaled_theme, &theme->scaled_themes, link) { - if (scaled_theme->scale == scale) { - return 0; - } - } - - scaled_theme = calloc(1, sizeof(struct roots_xcursor_scaled_theme)); - if (scaled_theme == NULL) { - return 1; - } - scaled_theme->scale = scale; - scaled_theme->theme = wlr_xcursor_theme_load(NULL, - ROOTS_XCURSOR_SIZE * scale); - if (scaled_theme->theme == NULL) { - free(scaled_theme); - return 1; - } - wl_list_insert(&theme->scaled_themes, &scaled_theme->link); - return 0; -} - -static void roots_xcursor_theme_set(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor, const char *name) { - struct roots_xcursor_scaled_theme *scaled_theme; - wl_list_for_each(scaled_theme, &theme->scaled_themes, link) { - struct wlr_xcursor *xcursor = - wlr_xcursor_theme_get_cursor(scaled_theme->theme, name); - if (xcursor == NULL) { - continue; - } - - struct wlr_xcursor_image *image = xcursor->images[0]; - wlr_cursor_set_image(cursor, image->buffer, image->width, - image->width, image->height, image->hotspot_x, image->hotspot_y, - scaled_theme->scale); - } -} - -void roots_xcursor_theme_set_default(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor) { - roots_xcursor_theme_set(theme, cursor, "left_ptr"); -} - -void roots_xcursor_theme_set_move(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor) { - roots_xcursor_theme_set(theme, cursor, "grabbing"); -} - -static const char *get_resize_xcursor_name(uint32_t edges) { +const char *roots_xcursor_get_resize_name(uint32_t edges) { if (edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) { if (edges & ROOTS_CURSOR_RESIZE_EDGE_RIGHT) { return "ne-resize"; @@ -102,33 +26,3 @@ static const char *get_resize_xcursor_name(uint32_t edges) { } return "se-resize"; // fallback } - -void roots_xcursor_theme_set_resize(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor, uint32_t edges) { - roots_xcursor_theme_set(theme, cursor, get_resize_xcursor_name(edges)); -} - -void roots_xcursor_theme_set_rotate(struct roots_xcursor_theme *theme, - struct wlr_cursor *cursor) { - roots_xcursor_theme_set(theme, cursor, "grabbing"); -} - -void roots_xcursor_theme_xwayland_set_default(struct roots_xcursor_theme *theme, - struct wlr_xwayland *xwayland) { - struct roots_xcursor_scaled_theme *scaled_theme; - wl_list_for_each(scaled_theme, &theme->scaled_themes, link) { - if (scaled_theme->scale == 1) { - struct wlr_xcursor *xcursor = - wlr_xcursor_theme_get_cursor(scaled_theme->theme, "left_ptr"); - if (xcursor == NULL) { - continue; - } - - struct wlr_xcursor_image *image = xcursor->images[0]; - wlr_xwayland_set_cursor(xwayland, image->buffer, image->width, - image->width, image->height, image->hotspot_x, - image->hotspot_y); - break; - } - } -} diff --git a/types/meson.build b/types/meson.build index 2603ecfd..4669165a 100644 --- a/types/meson.build +++ b/types/meson.build @@ -20,8 +20,9 @@ lib_wlr_types = static_library( 'wlr_tablet_pad.c', 'wlr_tablet_tool.c', 'wlr_touch.c', - 'wlr_xdg_shell_v6.c', 'wlr_wl_shell.c', + 'wlr_xcursor_manager.c', + 'wlr_xdg_shell_v6.c', ), include_directories: wlr_inc, dependencies: [wayland_server, pixman, wlr_protos], diff --git a/types/wlr_xcursor_manager.c b/types/wlr_xcursor_manager.c new file mode 100644 index 00000000..6c12d04b --- /dev/null +++ b/types/wlr_xcursor_manager.c @@ -0,0 +1,84 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include +#include + +struct wlr_xcursor_manager *wlr_xcursor_manager_create(const char *name, + uint32_t size) { + struct wlr_xcursor_manager *manager = + calloc(1, sizeof(struct wlr_xcursor_manager)); + if (manager == NULL) { + return NULL; + } + if (name != NULL) { + manager->name = strdup(name); + } + manager->size = size; + wl_list_init(&manager->scaled_themes); + return manager; +} + +void wlr_xcursor_manager_destroy(struct wlr_xcursor_manager *manager) { + if (manager == NULL) { + return; + } + struct wlr_xcursor_manager_theme *theme, *tmp; + wl_list_for_each_safe(theme, tmp, &manager->scaled_themes, link) { + wl_list_remove(&theme->link); + wlr_xcursor_theme_destroy(theme->theme); + free(theme); + } + free(manager->name); + free(manager); +} + +int wlr_xcursor_manager_load(struct wlr_xcursor_manager *manager, + uint32_t scale) { + struct wlr_xcursor_manager_theme *theme; + wl_list_for_each(theme, &manager->scaled_themes, link) { + if (theme->scale == scale) { + return 0; + } + } + + theme = calloc(1, sizeof(struct wlr_xcursor_manager_theme)); + if (theme == NULL) { + return 1; + } + theme->scale = scale; + theme->theme = wlr_xcursor_theme_load(NULL, manager->size * scale); + if (theme->theme == NULL) { + free(theme); + return 1; + } + wl_list_insert(&manager->scaled_themes, &theme->link); + return 0; +} + +struct wlr_xcursor *wlr_xcursor_manager_get_xcursor( + struct wlr_xcursor_manager *manager, const char *name, uint32_t scale) { + struct wlr_xcursor_manager_theme *theme; + wl_list_for_each(theme, &manager->scaled_themes, link) { + if (theme->scale == scale) { + return wlr_xcursor_theme_get_cursor(theme->theme, name); + } + } + return NULL; +} + +void wlr_xcursor_manager_set_cursor_image(struct wlr_xcursor_manager *manager, + const char *name, struct wlr_cursor *cursor) { + struct wlr_xcursor_manager_theme *theme; + wl_list_for_each(theme, &manager->scaled_themes, link) { + struct wlr_xcursor *xcursor = + wlr_xcursor_theme_get_cursor(theme->theme, name); + if (xcursor == NULL) { + continue; + } + + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_cursor_set_image(cursor, image->buffer, image->width, + image->width, image->height, image->hotspot_x, image->hotspot_y, + theme->scale); + } +} -- cgit v1.2.3 From 454bea678b6c253ac102522f7af1ffd75de92de1 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 12 Nov 2017 12:54:45 +0100 Subject: Fix rendering of rotated views on HiDPI outputs --- rootston/desktop.c | 2 -- rootston/output.c | 43 ++++++++++++++++++++++++------------------- 2 files changed, 24 insertions(+), 21 deletions(-) (limited to 'rootston/output.c') diff --git a/rootston/desktop.c b/rootston/desktop.c index dcf36ecf..4d744597 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -247,7 +247,6 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, } if (view->type == ROOTS_XDG_SHELL_V6_VIEW) { - // TODO: test if this works with rotated views double popup_sx, popup_sy; struct wlr_xdg_surface_v6 *popup = wlr_xdg_surface_v6_popup_at(view->xdg_surface_v6, @@ -262,7 +261,6 @@ struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly, } if (view->type == ROOTS_WL_SHELL_VIEW) { - // TODO: test if this works with rotated views double popup_sx, popup_sy; struct wlr_wl_shell_surface *popup = wlr_wl_shell_surface_popup_at(view->wl_shell_surface, diff --git a/rootston/output.c b/rootston/output.c index a929e6be..4b7a4b00 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -20,30 +20,33 @@ static void render_surface(struct wlr_surface *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double lx, double ly, float rotation) { if (surface->texture->valid) { - float scale_factor = (float)wlr_output->scale / surface->current->scale; - int width = surface->current->buffer_width * scale_factor; - int height = surface->current->buffer_height * scale_factor; + double surface_scale = surface->current->scale; + double width = (double)surface->current->buffer_width / surface_scale; + double height = (double)surface->current->buffer_height / surface_scale; + int render_width = width * wlr_output->scale; + int render_height = height * wlr_output->scale; double ox = lx, oy = ly; wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy); ox *= wlr_output->scale; oy *= wlr_output->scale; if (wlr_output_layout_intersects(desktop->layout, wlr_output, - lx, ly, lx + width, ly + height)) { + lx, ly, lx + render_width, ly + render_height)) { float matrix[16]; float translate_origin[16]; wlr_matrix_translate(&translate_origin, - (int)ox + width / 2, (int)oy + height / 2, 0); + (int)ox + render_width / 2, (int)oy + render_height / 2, 0); float rotate[16]; wlr_matrix_rotate(&rotate, rotation); float translate_center[16]; - wlr_matrix_translate(&translate_center, -width / 2, -height / 2, 0); + wlr_matrix_translate(&translate_center, -render_width / 2, + -render_height / 2, 0); float scale[16]; - wlr_matrix_scale(&scale, width, height, 1); + wlr_matrix_scale(&scale, render_width, render_height, 1); float transform[16]; wlr_matrix_mul(&translate_origin, &rotate, &transform); @@ -51,12 +54,12 @@ static void render_surface(struct wlr_surface *surface, wlr_matrix_mul(&transform, &scale, &transform); wlr_matrix_mul(&wlr_output->transform_matrix, &transform, &matrix); - wlr_render_with_matrix(desktop->server->renderer, - surface->texture, &matrix); + wlr_render_with_matrix(desktop->server->renderer, surface->texture, + &matrix); struct wlr_frame_callback *cb, *cnext; wl_list_for_each_safe(cb, cnext, - &surface->current->frame_callback_list, link) { + &surface->current->frame_callback_list, link) { wl_callback_send_done(cb->resource, timespec_to_msec(when)); wl_resource_destroy(cb->resource); } @@ -64,19 +67,20 @@ static void render_surface(struct wlr_surface *surface, struct wlr_subsurface *subsurface; wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { - double sx = subsurface->surface->current->subsurface_position.x, - sy = subsurface->surface->current->subsurface_position.y; - double sw = subsurface->surface->current->buffer_width, - sh = subsurface->surface->current->buffer_height; + struct wlr_surface_state *state = subsurface->surface->current; + double sx = state->subsurface_position.x; + double sy = state->subsurface_position.y; + double sw = state->buffer_width / state->scale; + double sh = state->buffer_height / state->scale; if (rotation != 0.0) { // Coordinates relative to the center of the subsurface - double ox = sx - (double)width/2 + sw/2, - oy = sy - (double)height/2 + sh/2; + double ox = sx - width/2 + sw/2, + oy = sy - height/2 + sh/2; // Rotated coordinates double rx = cos(-rotation)*ox - sin(-rotation)*oy, ry = cos(-rotation)*oy + sin(-rotation)*ox; - sx = rx + (double)width/2 - sw/2; - sy = ry + (double)height/2 - sh/2; + sx = rx + width/2 - sw/2; + sy = ry + height/2 - sh/2; } render_surface(subsurface->surface, desktop, wlr_output, when, @@ -103,7 +107,8 @@ static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, popup->popup_state->geometry.y - popup->geometry->y; render_surface(popup->surface, desktop, wlr_output, when, popup_x, popup_y, rotation); - render_xdg_v6_popups(popup, desktop, wlr_output, when, popup_x, popup_y, rotation); + render_xdg_v6_popups(popup, desktop, wlr_output, when, popup_x, popup_y, + rotation); } } -- cgit v1.2.3 From 94b20da3cecbcfbf36797bc781308eeb18542a75 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 14 Nov 2017 10:20:20 +0100 Subject: Fix popups position for rotated views --- rootston/output.c | 91 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 27 deletions(-) (limited to 'rootston/output.c') diff --git a/rootston/output.c b/rootston/output.c index 145016b3..294047d7 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -17,13 +17,40 @@ static inline int64_t timespec_to_msec(const struct timespec *a) { return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; } +/** + * Computes the surface size homogeneous to the global compositor coordinates. + */ +static void get_surface_size(struct wlr_surface *surface, double *width, + double *height) { + double surface_scale = surface->current->scale; + *width = (double)surface->current->buffer_width / surface_scale; + *height = (double)surface->current->buffer_height / surface_scale; +} + +/** + * Rotate a child's position relative to a parent. The parent size is (pw, ph), + * the child position is (*sx, *sy) and its size is (sw, sh). + */ +static void rotate_child_position(double *sx, double *sy, double sw, double sh, + double pw, double ph, float rotation) { + if (rotation != 0.0) { + // Coordinates relative to the center of the subsurface + double ox = *sx - pw/2 + sw/2, + oy = *sy - ph/2 + sh/2; + // Rotated coordinates + double rx = cos(-rotation)*ox - sin(-rotation)*oy, + ry = cos(-rotation)*oy + sin(-rotation)*ox; + *sx = rx + pw/2 - sw/2; + *sy = ry + ph/2 - sh/2; + } +} + static void render_surface(struct wlr_surface *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double lx, double ly, float rotation) { if (surface->texture->valid) { - double surface_scale = surface->current->scale; - double width = (double)surface->current->buffer_width / surface_scale; - double height = (double)surface->current->buffer_height / surface_scale; + double width, height; + get_surface_size(surface, &width, &height); int render_width = width * wlr_output->scale; int render_height = height * wlr_output->scale; double ox = lx, oy = ly; @@ -73,16 +100,7 @@ static void render_surface(struct wlr_surface *surface, double sy = state->subsurface_position.y; double sw = state->buffer_width / state->scale; double sh = state->buffer_height / state->scale; - if (rotation != 0.0) { - // Coordinates relative to the center of the subsurface - double ox = sx - width/2 + sw/2, - oy = sy - height/2 + sh/2; - // Rotated coordinates - double rx = cos(-rotation)*ox - sin(-rotation)*oy, - ry = cos(-rotation)*oy + sin(-rotation)*ox; - sx = rx + width/2 - sw/2; - sy = ry + height/2 - sh/2; - } + rotate_child_position(&sx, &sy, sw, sh, width, height, rotation); render_surface(subsurface->surface, desktop, wlr_output, when, lx + sx, @@ -95,36 +113,55 @@ static void render_surface(struct wlr_surface *surface, static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double base_x, double base_y, float rotation) { - // TODO: make sure this works with view rotation + double width, height; + get_surface_size(surface->surface, &width, &height); + struct wlr_xdg_surface_v6 *popup; wl_list_for_each(popup, &surface->popups, popup_link) { if (!popup->configured) { continue; } - double popup_x = base_x + surface->geometry->x + - popup->popup_state->geometry.x - popup->geometry->x; - double popup_y = base_y + surface->geometry->y + - popup->popup_state->geometry.y - popup->geometry->y; - render_surface(popup->surface, desktop, wlr_output, when, popup_x, - popup_y, rotation); - render_xdg_v6_popups(popup, desktop, wlr_output, when, popup_x, popup_y, + double sw, sh; + get_surface_size(popup->surface, &sw, &sh); + + double popup_x = surface->geometry->x + popup->popup_state->geometry.x - + popup->geometry->x; + double popup_y = surface->geometry->y + popup->popup_state->geometry.y - + popup->geometry->y; + rotate_child_position(&popup_x, &popup_y, sw, sh, width, height, rotation); + + render_surface(popup->surface, desktop, wlr_output, when, + base_x + popup_x, base_y + popup_y, rotation); + render_xdg_v6_popups(popup, desktop, wlr_output, when, base_x + popup_x, + base_y + popup_y, rotation); } } -static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, struct roots_desktop *desktop, - struct wlr_output *wlr_output, struct timespec *when, double lx, - double ly, float rotation, bool is_child) { +static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, + struct roots_desktop *desktop, struct wlr_output *wlr_output, + struct timespec *when, double lx, double ly, float rotation, + bool is_child) { if (is_child || surface->state != WLR_WL_SHELL_SURFACE_STATE_POPUP) { render_surface(surface->surface, desktop, wlr_output, when, lx, ly, rotation); + + double width, height; + get_surface_size(surface->surface, &width, &height); + struct wlr_wl_shell_surface *popup; wl_list_for_each(popup, &surface->popups, popup_link) { + double sw, sh; + get_surface_size(popup->surface, &sw, &sh); + + double popup_x = popup->transient_state->x; + double popup_y = popup->transient_state->y; + rotate_child_position(&popup_x, &popup_y, sw, sh, width, height, + rotation); + render_wl_shell_surface(popup, desktop, wlr_output, when, - lx + popup->transient_state->x, - ly + popup->transient_state->y, - rotation, true); + lx + popup_x, ly + popup_y, rotation, true); } } } -- cgit v1.2.3 From 2f44140f4afdab3231d215b913393e3d6a5e36d9 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 14 Nov 2017 15:33:29 +0100 Subject: Don't use buffer size --- rootston/output.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'rootston/output.c') diff --git a/rootston/output.c b/rootston/output.c index 294047d7..2a39510b 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -17,16 +17,6 @@ static inline int64_t timespec_to_msec(const struct timespec *a) { return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; } -/** - * Computes the surface size homogeneous to the global compositor coordinates. - */ -static void get_surface_size(struct wlr_surface *surface, double *width, - double *height) { - double surface_scale = surface->current->scale; - *width = (double)surface->current->buffer_width / surface_scale; - *height = (double)surface->current->buffer_height / surface_scale; -} - /** * Rotate a child's position relative to a parent. The parent size is (pw, ph), * the child position is (*sx, *sy) and its size is (sw, sh). @@ -49,8 +39,9 @@ static void render_surface(struct wlr_surface *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double lx, double ly, float rotation) { if (surface->texture->valid) { - double width, height; - get_surface_size(surface, &width, &height); + double surface_scale = surface->current->scale; + double width = (double)surface->current->buffer_width / surface_scale; + double height = (double)surface->current->buffer_height / surface_scale; int render_width = width * wlr_output->scale; int render_height = height * wlr_output->scale; double ox = lx, oy = ly; @@ -113,8 +104,8 @@ static void render_surface(struct wlr_surface *surface, static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double base_x, double base_y, float rotation) { - double width, height; - get_surface_size(surface->surface, &width, &height); + double width = surface->surface->current->width; + double height = surface->surface->current->height; struct wlr_xdg_surface_v6 *popup; wl_list_for_each(popup, &surface->popups, popup_link) { @@ -122,15 +113,15 @@ static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, continue; } - double sw, sh; - get_surface_size(popup->surface, &sw, &sh); + double popup_width = popup->surface->current->width; + double popup_height = popup->surface->current->height; double popup_x = surface->geometry->x + popup->popup_state->geometry.x - popup->geometry->x; double popup_y = surface->geometry->y + popup->popup_state->geometry.y - popup->geometry->y; - rotate_child_position(&popup_x, &popup_y, sw, sh, width, height, - rotation); + rotate_child_position(&popup_x, &popup_y, popup_width, popup_height, + width, height, rotation); render_surface(popup->surface, desktop, wlr_output, when, base_x + popup_x, base_y + popup_y, rotation); @@ -147,18 +138,18 @@ static void render_wl_shell_surface(struct wlr_wl_shell_surface *surface, render_surface(surface->surface, desktop, wlr_output, when, lx, ly, rotation); - double width, height; - get_surface_size(surface->surface, &width, &height); + double width = surface->surface->current->width; + double height = surface->surface->current->height; struct wlr_wl_shell_surface *popup; wl_list_for_each(popup, &surface->popups, popup_link) { - double sw, sh; - get_surface_size(popup->surface, &sw, &sh); + double popup_width = popup->surface->current->width; + double popup_height = popup->surface->current->height; double popup_x = popup->transient_state->x; double popup_y = popup->transient_state->y; - rotate_child_position(&popup_x, &popup_y, sw, sh, width, height, - rotation); + rotate_child_position(&popup_x, &popup_y, popup_width, popup_height, + width, height, rotation); render_wl_shell_surface(popup, desktop, wlr_output, when, lx + popup_x, ly + popup_y, rotation, true); -- cgit v1.2.3 From bb973ff27d5b735d2eb8ec620d7ea74e43eab301 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 14 Nov 2017 21:18:34 +0100 Subject: Remove remaining buffer_{width,height} usage --- rootston/output.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'rootston/output.c') diff --git a/rootston/output.c b/rootston/output.c index 2a39510b..cfab3756 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -39,9 +39,8 @@ static void render_surface(struct wlr_surface *surface, struct roots_desktop *desktop, struct wlr_output *wlr_output, struct timespec *when, double lx, double ly, float rotation) { if (surface->texture->valid) { - double surface_scale = surface->current->scale; - double width = (double)surface->current->buffer_width / surface_scale; - double height = (double)surface->current->buffer_height / surface_scale; + int width = surface->current->width; + int height = surface->current->height; int render_width = width * wlr_output->scale; int render_height = height * wlr_output->scale; double ox = lx, oy = ly; -- cgit v1.2.3 From 3f6cf517b9b8d5efa0c6001db5ed0871e5d8d2b4 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 15 Nov 2017 14:03:13 +0100 Subject: Add wlr_xdg_surface_v6_popup_get_position --- include/wlr/types/wlr_xdg_shell_v6.h | 6 ++++++ rootston/output.c | 14 ++++++-------- types/wlr_xdg_shell_v6.c | 10 ++++++++++ 3 files changed, 22 insertions(+), 8 deletions(-) (limited to 'rootston/output.c') diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 07911ffa..e3982003 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -209,6 +209,12 @@ void wlr_xdg_toplevel_v6_set_resizing(struct wlr_xdg_surface_v6 *surface, */ void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface); +/** + * Compute the popup position in surface-local coordinates. + */ +void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, + double *popup_sx, double *popup_sy); + /** * Find a popup within this surface at the surface-local coordinates. Returns * the popup and coordinates in the topmost surface coordinate system or NULL if diff --git a/rootston/output.c b/rootston/output.c index cfab3756..28312c2c 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -115,17 +115,15 @@ static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, double popup_width = popup->surface->current->width; double popup_height = popup->surface->current->height; - double popup_x = surface->geometry->x + popup->popup_state->geometry.x - - popup->geometry->x; - double popup_y = surface->geometry->y + popup->popup_state->geometry.y - - popup->geometry->y; - rotate_child_position(&popup_x, &popup_y, popup_width, popup_height, + double popup_sx, popup_sy; + wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy); + rotate_child_position(&popup_sx, &popup_sy, popup_width, popup_height, width, height, rotation); render_surface(popup->surface, desktop, wlr_output, when, - base_x + popup_x, base_y + popup_y, rotation); - render_xdg_v6_popups(popup, desktop, wlr_output, when, base_x + popup_x, - base_y + popup_y, rotation); + base_x + popup_sx, base_y + popup_sy, rotation); + render_xdg_v6_popups(popup, desktop, wlr_output, when, + base_x + popup_sx, base_y + popup_sy, rotation); } } diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 05ca2b76..429baa70 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -1350,6 +1350,16 @@ void wlr_xdg_toplevel_v6_send_close(struct wlr_xdg_surface_v6 *surface) { zxdg_toplevel_v6_send_close(surface->toplevel_state->resource); } +void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface, + double *popup_sx, double *popup_sy) { + assert(surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP); + struct wlr_xdg_surface_v6 *parent = surface->popup_state->parent; + *popup_sx = parent->geometry->x + surface->popup_state->geometry.x - + surface->geometry->x; + *popup_sy = parent->geometry->y + surface->popup_state->geometry.y - + surface->geometry->y; +} + struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at( struct wlr_xdg_surface_v6 *surface, double sx, double sy, double *popup_sx, double *popup_sy) { -- cgit v1.2.3