From d43500831a78580f59525144a0c9b034d4d399d0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 1 Jul 2018 09:46:02 -0400 Subject: [PATCH 1/6] Updates per wlroots#1076 --- sway/desktop/output.c | 18 +++++++++--------- sway/desktop/transaction.c | 4 ++-- sway/desktop/xdg_shell.c | 4 ++-- sway/desktop/xdg_shell_v6.c | 4 ++-- sway/desktop/xwayland.c | 2 +- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 1e7494b3..a86c1646 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -81,8 +81,8 @@ static bool get_surface_box(struct root_geometry *geo, return false; } - int sw = surface->current->width; - int sh = surface->current->height; + int sw = surface->current.width; + int sh = surface->current.height; double _sx = sx, _sy = sy; rotate_child_position(&_sx, &_sy, sw, sh, geo->width, geo->height, @@ -115,8 +115,8 @@ static void surface_for_each_surface(struct wlr_surface *surface, wlr_surface_iterator_func_t iterator, void *user_data) { geo->x = ox; geo->y = oy; - geo->width = surface->current->width; - geo->height = surface->current->height; + geo->width = surface->current.width; + geo->height = surface->current.height; geo->rotation = 0; wlr_surface_for_each_surface(surface, iterator, user_data); @@ -258,7 +258,7 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy, float matrix[9]; enum wl_output_transform transform = - wlr_output_transform_invert(surface->current->transform); + wlr_output_transform_invert(surface->current.transform); wlr_matrix_project_box(matrix, &box, transform, rotation, wlr_output->transform_matrix); @@ -1163,16 +1163,16 @@ static void damage_surface_iterator(struct wlr_surface *surface, int sx, int sy, int center_x = box.x + box.width/2; int center_y = box.y + box.height/2; - if (pixman_region32_not_empty(&surface->current->surface_damage)) { + if (pixman_region32_not_empty(&surface->current.surface_damage)) { pixman_region32_t damage; pixman_region32_init(&damage); - pixman_region32_copy(&damage, &surface->current->surface_damage); + pixman_region32_copy(&damage, &surface->current.surface_damage); wlr_region_scale(&damage, &damage, output->wlr_output->scale); - if (ceil(output->wlr_output->scale) > surface->current->scale) { + if (ceil(output->wlr_output->scale) > surface->current.scale) { // When scaling up a surface, it'll become blurry so we need to // expand the damage region wlr_region_expand(&damage, &damage, - ceil(output->wlr_output->scale) - surface->current->scale); + ceil(output->wlr_output->scale) - surface->current.scale); } pixman_region32_translate(&damage, box.x, box.y); wlr_region_rotated_bounds(&damage, &damage, rotation, diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index b4d796cb..179af617 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -73,8 +73,8 @@ static void save_view_buffer(struct sway_view *view, } if (view->surface && wlr_surface_has_buffer(view->surface)) { instruction->saved_buffer = wlr_buffer_ref(view->surface->buffer); - instruction->saved_buffer_width = view->surface->current->width; - instruction->saved_buffer_height = view->surface->current->height; + instruction->saved_buffer_width = view->surface->current.width; + instruction->saved_buffer_height = view->surface->current.height; } } diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 2b634749..ac35a8d1 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -251,8 +251,8 @@ static void handle_map(struct wl_listener *listener, void *data) { view->natural_width = view->wlr_xdg_surface->geometry.width; view->natural_height = view->wlr_xdg_surface->geometry.height; if (!view->natural_width && !view->natural_height) { - view->natural_width = view->wlr_xdg_surface->surface->current->width; - view->natural_height = view->wlr_xdg_surface->surface->current->height; + view->natural_width = view->wlr_xdg_surface->surface->current.width; + view->natural_height = view->wlr_xdg_surface->surface->current.height; } view_map(view, view->wlr_xdg_surface->surface); diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 2f0730e4..56bbb244 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -246,8 +246,8 @@ static void handle_map(struct wl_listener *listener, void *data) { view->natural_width = view->wlr_xdg_surface_v6->geometry.width; view->natural_height = view->wlr_xdg_surface_v6->geometry.height; if (!view->natural_width && !view->natural_height) { - view->natural_width = view->wlr_xdg_surface_v6->surface->current->width; - view->natural_height = view->wlr_xdg_surface_v6->surface->current->height; + view->natural_width = view->wlr_xdg_surface_v6->surface->current.width; + view->natural_height = view->wlr_xdg_surface_v6->surface->current.height; } view_map(view, view->wlr_xdg_surface_v6->surface); diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 71803262..0669a485 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -278,7 +278,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { wl_container_of(listener, xwayland_view, commit); struct sway_view *view = &xwayland_view->view; struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - struct wlr_surface_state *surface_state = xsurface->surface->current; + struct wlr_surface_state *surface_state = &xsurface->surface->current; if (view->swayc->instructions->length) { transaction_notify_view_ready_by_size(view, From 51b215ad5c0cadc4f1c10f407d1a2c375b46a769 Mon Sep 17 00:00:00 2001 From: emersion Date: Sun, 1 Jul 2018 14:55:14 +0100 Subject: [PATCH 2/6] Use wlr_surface.buffer_damage --- sway/desktop/output.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index a86c1646..1211cc07 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -1163,11 +1163,17 @@ static void damage_surface_iterator(struct wlr_surface *surface, int sx, int sy, int center_x = box.x + box.width/2; int center_y = box.y + box.height/2; - if (pixman_region32_not_empty(&surface->current.surface_damage)) { + if (pixman_region32_not_empty(&surface->buffer_damage)) { + enum wl_output_transform transform = + wlr_output_transform_invert(surface->current.transform); + pixman_region32_t damage; pixman_region32_init(&damage); - pixman_region32_copy(&damage, &surface->current.surface_damage); - wlr_region_scale(&damage, &damage, output->wlr_output->scale); + pixman_region32_copy(&damage, &surface->buffer_damage); + wlr_region_transform(&damage, &damage, transform, + surface->current.buffer_width, surface->current.buffer_height); + wlr_region_scale(&damage, &damage, + output->wlr_output->scale / (float)surface->current.scale); if (ceil(output->wlr_output->scale) > surface->current.scale) { // When scaling up a surface, it'll become blurry so we need to // expand the damage region From ab5c8c31a07a0b9842620a0777e3009cc53213df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Pla=C3=A7ais?= Date: Thu, 5 Jul 2018 14:27:49 +0200 Subject: [PATCH 3/6] Escape underscore in sway-input(5) man page to avoid invalid colors --- sway/sway-input.5.scd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index c07460b1..cf7a6385 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd @@ -67,8 +67,8 @@ For more information on these xkb configuration options, see Enables or disables disable-while-typing for the specified input device. *input* events enabled|disabled|disabled\_on\_external\_mouse - Enables or disables send_events for specified input device. (Disabling - send_events disables the input device) + Enables or disables send\_events for specified input device. (Disabling + send\_events disables the input device) *input* left\_handed enabled|disabled Enables or disables left handed mode for specified input device. From 78c08fb0a281cbe74c56f0a2ea4b9370b9372661 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 5 Jul 2018 18:12:14 -0400 Subject: [PATCH 4/6] Implement mode --pango_markup --- include/sway/config.h | 1 + include/sway/ipc-server.h | 2 +- sway/commands/mode.c | 19 ++++++++++++++++--- sway/ipc-server.c | 4 +++- sway/sway.5.scd | 4 +++- swaybar/render.c | 5 +++-- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index e75b0664..ac668c24 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -50,6 +50,7 @@ struct sway_mode { char *name; list_t *keysym_bindings; list_t *keycode_bindings; + bool pango; }; struct input_config_mapped_from_region { diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h index 026b5554..6469f097 100644 --- a/include/sway/ipc-server.h +++ b/include/sway/ipc-server.h @@ -15,6 +15,6 @@ void ipc_event_workspace(struct sway_container *old, struct sway_container *new, const char *change); void ipc_event_window(struct sway_container *window, const char *change); void ipc_event_barconfig_update(struct bar_config *bar); -void ipc_event_mode(const char *mode); +void ipc_event_mode(const char *mode, bool pango); #endif diff --git a/sway/commands/mode.c b/sway/commands/mode.c index 00331ccc..d2c14468 100644 --- a/sway/commands/mode.c +++ b/sway/commands/mode.c @@ -26,7 +26,17 @@ struct cmd_results *cmd_mode(int argc, char **argv) { "mode", "Can only be used in config file."); } - const char *mode_name = argv[0]; + bool pango = strcmp(*argv, "--pango_markup") == 0; + if (pango) { + argc--; argv++; + if (argc == 0) { + return cmd_results_new(CMD_FAILURE, "mode", + "Mode name is missing"); + } + } + + char *mode_name = *argv; + strip_quotes(mode_name); struct sway_mode *mode = NULL; // Find mode for (int i = 0; i < config->modes->length; ++i) { @@ -46,6 +56,7 @@ struct cmd_results *cmd_mode(int argc, char **argv) { mode->name = strdup(mode_name); mode->keysym_bindings = create_list(); mode->keycode_bindings = create_list(); + mode->pango = pango; list_add(config->modes, mode); } if (!mode) { @@ -54,13 +65,15 @@ struct cmd_results *cmd_mode(int argc, char **argv) { return error; } if ((config->reading && argc > 1) || (!config->reading && argc == 1)) { - wlr_log(L_DEBUG, "Switching to mode `%s'",mode->name); + wlr_log(L_DEBUG, "Switching to mode `%s' (pango=%d)", + mode->name, mode->pango); } // Set current mode config->current_mode = mode; if (argc == 1) { // trigger IPC mode event - ipc_event_mode(config->current_mode->name); + ipc_event_mode(config->current_mode->name, + config->current_mode->pango); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/ipc-server.c b/sway/ipc-server.c index abc2d7cb..8cfd9f26 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -332,13 +332,15 @@ void ipc_event_barconfig_update(struct bar_config *bar) { json_object_put(json); } -void ipc_event_mode(const char *mode) { +void ipc_event_mode(const char *mode, bool pango) { if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { return; } wlr_log(L_DEBUG, "Sending mode::%s event", mode); json_object *obj = json_object_new_object(); json_object_object_add(obj, "change", json_object_new_string(mode)); + json_object_object_add(obj, "pango_markup", + json_object_new_boolean(pango)); const char *json_string = json_object_to_json_string(obj); ipc_send_event(json_string, IPC_EVENT_MODE); diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 5ce6bf06..7c553d3f 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -413,10 +413,12 @@ The default colors are: *mode* Switches to the specified mode. The default mode _default_. -*mode* *{* *}* +*mode* [--pango\_markup] *{* *}* _commands..._ after *{* will be added to the specified mode. A newline is required between *{* and the first command, and *}* must be alone on a line. Only *bindsym* and *bindcode* commands are permitted in mode blocks. + If _--pango\_markup_ is given, then _mode_ will be interpreted as pango + markup. *mouse\_warping* output|none If _output_ is specified, the mouse will be moved to new outputs as you diff --git a/swaybar/render.c b/swaybar/render.c index 327a6f5f..efd3fdeb 100644 --- a/swaybar/render.c +++ b/swaybar/render.c @@ -298,7 +298,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, int text_width, text_height; get_text_size(cairo, config->font, &text_width, &text_height, - output->scale, config->pango_markup, "%s", mode); + output->scale, config->mode_pango_markup, + "%s", mode); int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale; int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale; @@ -329,7 +330,7 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo, double text_y = height / 2.0 - text_height / 2.0; cairo_set_source_u32(cairo, config->colors.binding_mode.text); cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y)); - pango_printf(cairo, config->font, output->scale, config->pango_markup, + pango_printf(cairo, config->font, output->scale, config->mode_pango_markup, "%s", mode); return surface_height; } From c833ae64bc1d1561cc71e68dcd2d2bd909aac538 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 5 Jul 2018 23:01:35 -0400 Subject: [PATCH 5/6] Fix pointer button events for layer surfaces --- sway/input/cursor.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 944e35aa..a2f11557 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -255,14 +255,12 @@ void dispatch_cursor_button(struct sway_cursor *cursor, wlr_layer_surface_from_wlr_surface(surface); if (layer->current.keyboard_interactive) { seat_set_focus_layer(cursor->seat, layer); - return; } - } - // Avoid moving keyboard focus from a surface that accepts it to one - // that does not unless the change would move us to a new workspace. - // - // This prevents, for example, losing focus when clicking on swaybar. - if (surface && cont && cont->type != C_VIEW) { + } else if (surface && cont && cont->type != C_VIEW) { + // Avoid moving keyboard focus from a surface that accepts it to one + // that does not unless the change would move us to a new workspace. + // + // This prevents, for example, losing focus when clicking on swaybar. struct sway_container *new_ws = cont; if (new_ws && new_ws->type != C_WORKSPACE) { new_ws = container_parent(new_ws, C_WORKSPACE); From f63b209d51bab84aacb001adfd443c7f4c9a8cfe Mon Sep 17 00:00:00 2001 From: Ian Fan Date: Fri, 6 Jul 2018 14:13:45 +0100 Subject: [PATCH 6/6] Attach destroy handler earlier This prevents it from being bypassed when the device has no seat configuration --- sway/input/input-manager.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 29b47a7b..98f7d7cf 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c @@ -224,6 +224,9 @@ static void handle_new_input(struct wl_listener *listener, void *data) { input_manager_libinput_config_pointer(input_device); } + wl_signal_add(&device->events.destroy, &input_device->device_destroy); + input_device->device_destroy.notify = handle_device_destroy; + struct sway_seat *seat = NULL; if (!input_has_seat_configuration(input)) { wlr_log(L_DEBUG, "no seat configuration, using default seat"); @@ -260,9 +263,6 @@ static void handle_new_input(struct wl_listener *listener, void *data) { "device '%s' is not configured on any seats", input_device->identifier); } - - wl_signal_add(&device->events.destroy, &input_device->device_destroy); - input_device->device_destroy.notify = handle_device_destroy; } static void handle_inhibit_activate(struct wl_listener *listener, void *data) {