From 0e2cc0af3049c6d1b91bda3081238e2e723e81b7 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 15 May 2018 13:14:18 +1000 Subject: [PATCH 1/7] Implement show_marks --- include/sway/tree/view.h | 7 ++++ sway/commands.c | 1 + sway/commands/mark.c | 1 + sway/commands/show_marks.c | 43 +++++++++++++++++++++ sway/commands/unmark.c | 2 + sway/desktop/output.c | 27 ++++++++++++- sway/meson.build | 1 + sway/tree/view.c | 78 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 sway/commands/show_marks.c diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 7ed4d3df..951912d0 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -63,6 +63,11 @@ struct sway_view { list_t *executed_criteria; // struct criteria * list_t *marks; // char * + struct wlr_texture *marks_focused; + struct wlr_texture *marks_focused_inactive; + struct wlr_texture *marks_unfocused; + struct wlr_texture *marks_urgent; + union { struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; struct wlr_xdg_surface *wlr_xdg_surface; @@ -267,4 +272,6 @@ void view_clear_marks(struct sway_view *view); bool view_has_mark(struct sway_view *view, char *mark); +void view_update_marks_textures(struct sway_view *view); + #endif diff --git a/sway/commands.c b/sway/commands.c index 9b6d6459..6cba0a1c 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -116,6 +116,7 @@ static struct cmd_handler handlers[] = { { "mouse_warping", cmd_mouse_warping }, { "output", cmd_output }, { "seat", cmd_seat }, + { "show_marks", cmd_show_marks }, { "workspace", cmd_workspace }, { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }, }; diff --git a/sway/commands/mark.c b/sway/commands/mark.c index b131f2f3..5a897e69 100644 --- a/sway/commands/mark.c +++ b/sway/commands/mark.c @@ -62,6 +62,7 @@ struct cmd_results *cmd_mark(int argc, char **argv) { } free(mark); + view_update_marks_textures(view); view_execute_criteria(view); return cmd_results_new(CMD_SUCCESS, NULL, NULL); diff --git a/sway/commands/show_marks.c b/sway/commands/show_marks.c new file mode 100644 index 00000000..c7fdc538 --- /dev/null +++ b/sway/commands/show_marks.c @@ -0,0 +1,43 @@ +#define _POSIX_C_SOURCE 200809L +#include +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/tree/view.h" +#include "sway/output.h" +#include "list.h" +#include "log.h" +#include "stringop.h" + +static void rebuild_marks_iterator(struct sway_container *con, void *data) { + if (con->type == C_VIEW) { + view_update_marks_textures(con->sway_view); + } +} + +struct cmd_results *cmd_show_marks(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "show_marks", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (strcmp(*argv, "yes") == 0) { + config->show_marks = true; + } else if (strcmp(*argv, "no") == 0) { + config->show_marks = false; + } else { + return cmd_results_new(CMD_INVALID, "show_marks", + "Expected 'show_marks '"); + } + + if (config->show_marks) { + container_for_each_descendant_dfs(&root_container, + rebuild_marks_iterator, NULL); + } + + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *con = root_container.children->items[i]; + output_damage_whole(con->sway_output); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/commands/unmark.c b/sway/commands/unmark.c index ea2a5709..1ce2c56b 100644 --- a/sway/commands/unmark.c +++ b/sway/commands/unmark.c @@ -10,6 +10,7 @@ static void remove_all_marks_iterator(struct sway_container *con, void *data) { if (con->type == C_VIEW) { view_clear_marks(con->sway_view); + view_update_marks_textures(con->sway_view); } } @@ -45,6 +46,7 @@ struct cmd_results *cmd_unmark(int argc, char **argv) { } else if (view && !mark) { // Clear all marks from the given view view_clear_marks(view); + view_update_marks_textures(view); } else if (!view && mark) { // Remove mark from whichever view has it view_find_and_unmark(mark); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index b12130d9..57d71d5e 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -317,7 +317,7 @@ damage_finish: static void render_container_simple_border_normal(struct sway_output *output, pixman_region32_t *output_damage, struct sway_container *con, struct border_colors *colors, - struct wlr_texture *title_texture) { + struct wlr_texture *title_texture, struct wlr_texture *marks_texture) { struct wlr_box box; float color[4]; @@ -413,6 +413,25 @@ static void render_container_simple_border_normal(struct sway_output *output, render_texture(output->wlr_output, output_damage, title_texture, &texture_box, matrix, 1.0); } + + // Marks + if (config->show_marks && marks_texture) { + float output_scale = output->wlr_output->scale; + struct wlr_box texture_box; + wlr_texture_get_size(marks_texture, + &texture_box.width, &texture_box.height); + texture_box.x = (box.x + box.width) * output_scale - texture_box.width; + texture_box.y = (box.y + box.height) + * output_scale - texture_box.height; + + float matrix[9]; + wlr_matrix_project_box(matrix, &texture_box, + WL_OUTPUT_TRANSFORM_NORMAL, + 0.0, output->wlr_output->transform_matrix); + + render_texture(output->wlr_output, output_damage, marks_texture, + &texture_box, matrix, 1.0); + } } /** @@ -501,20 +520,24 @@ static void render_container_simple(struct sway_output *output, if (child->sway_view->border != B_NONE) { struct border_colors *colors; struct wlr_texture *title_texture; + struct wlr_texture *marks_texture; if (focus == child || parent_focused) { colors = &config->border_colors.focused; title_texture = child->title_focused; + marks_texture = child->sway_view->marks_focused; } else if (seat_get_focus_inactive(seat, con) == child) { colors = &config->border_colors.focused_inactive; title_texture = child->title_focused_inactive; + marks_texture = child->sway_view->marks_focused_inactive; } else { colors = &config->border_colors.unfocused; title_texture = child->title_unfocused; + marks_texture = child->sway_view->marks_unfocused; } if (child->sway_view->border == B_NORMAL) { render_container_simple_border_normal(output, damage, - child, colors, title_texture); + child, colors, title_texture, marks_texture); } else { render_container_simple_border_pixel(output, damage, child, colors); diff --git a/sway/meson.build b/sway/meson.build index ed14b51a..72347d51 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -60,6 +60,7 @@ sway_sources = files( 'commands/seat/cursor.c', 'commands/seat/fallback.c', 'commands/set.c', + 'commands/show_marks.c', 'commands/split.c', 'commands/swaybg_command.c', 'commands/title_format.c', diff --git a/sway/tree/view.c b/sway/tree/view.c index 833345c5..e26159d2 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -746,6 +746,7 @@ bool view_find_and_unmark(char *mark) { if (strcmp(view_mark, mark) == 0) { free(view_mark); list_del(view->marks, i); + view_update_marks_textures(view); return true; } } @@ -769,3 +770,80 @@ bool view_has_mark(struct sway_view *view, char *mark) { } return false; } + +static void update_marks_texture(struct sway_view *view, + struct wlr_texture **texture, struct border_colors *class) { + struct sway_container *output = container_parent(view->swayc, C_OUTPUT); + if (!output) { + return; + } + if (*texture) { + wlr_texture_destroy(*texture); + } + if (!view->marks->length) { + return; + } + + size_t len = 0; + for (int i = 0; i < view->marks->length; ++i) { + len += strlen((char *)view->marks->items[i]) + 2; + } + char *buffer = calloc(len + 1, 1); + char *part = malloc(len + 1); + + for (int i = 0; i < view->marks->length; ++i) { + char *mark = view->marks->items[i]; + sprintf(part, "[%s]", mark); + strcat(buffer, part); + } + free(part); + + double scale = output->sway_output->wlr_output->scale; + int width = 0; + int height = config->font_height * scale; + + cairo_t *c = cairo_create(NULL); + get_text_size(c, config->font, &width, NULL, scale, false, "%s", buffer); + cairo_destroy(c); + + cairo_surface_t *surface = cairo_image_surface_create( + CAIRO_FORMAT_ARGB32, width, height); + cairo_t *cairo = cairo_create(surface); + cairo_set_source_rgba(cairo, class->background[0], class->background[1], + class->background[2], class->background[3]); + cairo_paint(cairo); + PangoContext *pango = pango_cairo_create_context(cairo); + cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); + cairo_set_source_rgba(cairo, class->text[0], class->text[1], + class->text[2], class->text[3]); + cairo_move_to(cairo, 0, 0); + + pango_printf(cairo, config->font, scale, false, "%s", buffer); + + cairo_surface_flush(surface); + unsigned char *data = cairo_image_surface_get_data(surface); + int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width); + struct wlr_renderer *renderer = wlr_backend_get_renderer( + output->sway_output->wlr_output->backend); + *texture = wlr_texture_from_pixels( + renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data); + cairo_surface_destroy(surface); + g_object_unref(pango); + cairo_destroy(cairo); + free(buffer); +} + +void view_update_marks_textures(struct sway_view *view) { + if (!config->show_marks) { + return; + } + update_marks_texture(view, &view->marks_focused, + &config->border_colors.focused); + update_marks_texture(view, &view->marks_focused_inactive, + &config->border_colors.focused_inactive); + update_marks_texture(view, &view->marks_unfocused, + &config->border_colors.unfocused); + update_marks_texture(view, &view->marks_urgent, + &config->border_colors.urgent); + container_damage_whole(view->swayc); +} From 5384fdcbc64c90be01dcfe4067dd9a2a9328f053 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 15 May 2018 14:35:25 +1000 Subject: [PATCH 2/7] Don't show marks which start with an underscore --- sway/tree/view.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sway/tree/view.c b/sway/tree/view.c index e26159d2..8db5c9d5 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -786,15 +786,20 @@ static void update_marks_texture(struct sway_view *view, size_t len = 0; for (int i = 0; i < view->marks->length; ++i) { - len += strlen((char *)view->marks->items[i]) + 2; + char *mark = view->marks->items[i]; + if (mark[0] != '_') { + len += strlen(mark) + 2; + } } char *buffer = calloc(len + 1, 1); char *part = malloc(len + 1); for (int i = 0; i < view->marks->length; ++i) { char *mark = view->marks->items[i]; - sprintf(part, "[%s]", mark); - strcat(buffer, part); + if (mark[0] != '_') { + sprintf(part, "[%s]", mark); + strcat(buffer, part); + } } free(part); From b351d0a64a9d545cdfe1fe1821858cbda1f5fa4e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 15 May 2018 14:35:54 +1000 Subject: [PATCH 3/7] Set textures to null when destroying --- sway/tree/container.c | 1 + sway/tree/view.c | 1 + 2 files changed, 2 insertions(+) diff --git a/sway/tree/container.c b/sway/tree/container.c index a17b20f7..47ba88a9 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -592,6 +592,7 @@ static void update_title_texture(struct sway_container *con, } if (*texture) { wlr_texture_destroy(*texture); + *texture = NULL; } if (!con->formatted_title) { return; diff --git a/sway/tree/view.c b/sway/tree/view.c index 8db5c9d5..aaca8753 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -779,6 +779,7 @@ static void update_marks_texture(struct sway_view *view, } if (*texture) { wlr_texture_destroy(*texture); + *texture = NULL; } if (!view->marks->length) { return; From 69ac7f73e74a8c6c40991ef8ad3e90c6a35f7fa7 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 15 May 2018 14:48:19 +1000 Subject: [PATCH 4/7] Destroy marks textures when view destroyed --- sway/tree/view.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sway/tree/view.c b/sway/tree/view.c index aaca8753..c0984ca4 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -43,6 +43,14 @@ void view_destroy(struct sway_view *view) { } list_free(view->marks); + if (view->marks_focused) { + // If one is set then all of these are set + wlr_texture_destroy(view->marks_focused); + wlr_texture_destroy(view->marks_focused_inactive); + wlr_texture_destroy(view->marks_unfocused); + wlr_texture_destroy(view->marks_urgent); + } + container_destroy(view->swayc); if (view->impl->destroy) { From b1645fb352748398783981ecccad0f42e285b6bf Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 15 May 2018 15:11:28 +1000 Subject: [PATCH 5/7] Update show_marks documentation --- sway/sway.5.scd | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sway/sway.5.scd b/sway/sway.5.scd index 2ebdb8ed..ff138562 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd @@ -174,7 +174,7 @@ runtime. Assigns views matching _criteria_ (see *CRITERIA* for details) to _workspace_. The → (U+2192) is optional and cosmetic. This command is equivalent to: - + for\_window move container to workspace *bindsym* @@ -238,7 +238,7 @@ The default colors are: [- *class* :[ _border_ :[ _background_ -:[ _text_ +:[ _text_ :[ _indicator_ :[ _child\_border_ |[ *background* @@ -451,10 +451,10 @@ You can get a list of output names with *swaymsg -t get\_outputs*. You may also match any output by using the output name "\*". Be sure to add this output config after the others, or it will be matched instead of the others. -*show\_marks* on|off - If *show\_marks* is on, marks will be displayed in the window borders. - Any mark that starts with an underscore will not be drawn even if the - option is on. The default is _on_. +*show\_marks* yes|no + If *show\_marks* is yes, marks will be displayed in the window borders. + Any mark that starts with an underscore will not be drawn even if + *show\_marks* is yes. The default is _yes_. *opacity* Set the opacity of the window between 0 (completely transparent) and 1 From ebb0d051db2f73fd13a4e844a51e70f09703372a Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 15 May 2018 23:29:54 +1000 Subject: [PATCH 6/7] Fix many border opacity issues --- sway/desktop/output.c | 159 ++++++++++++++++++++++++++---------------- sway/tree/container.c | 13 ++-- sway/tree/view.c | 16 +++-- 3 files changed, 115 insertions(+), 73 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 57d71d5e..3f680b36 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -287,7 +287,6 @@ static void render_rect(struct wlr_output *wlr_output, wlr_backend_get_renderer(wlr_output->backend); struct wlr_box box = *_box; - scale_box(&box, wlr_output->scale); pixman_region32_t damage; pixman_region32_init(&damage); @@ -313,6 +312,9 @@ damage_finish: /** * Render decorations for a view with "border normal". + * + * Care must be taken not to render over the same pixel multiple times, + * otherwise the colors will be incorrect when using opacity. */ static void render_container_simple_border_normal(struct sway_output *output, pixman_region32_t *output_damage, @@ -320,19 +322,23 @@ static void render_container_simple_border_normal(struct sway_output *output, struct wlr_texture *title_texture, struct wlr_texture *marks_texture) { struct wlr_box box; float color[4]; + struct sway_view *view = con->sway_view; + float output_scale = output->wlr_output->scale; - if (con->sway_view->border_left) { + if (view->border_left) { // Child border - left edge memcpy(&color, colors->child_border, sizeof(float) * 4); color[3] *= con->alpha; box.x = con->x; box.y = con->y + 1; - box.width = con->sway_view->border_thickness; - box.height = con->height - 1; + box.width = view->border_thickness; + box.height = con->height - 1 + - view->border_thickness * view->border_bottom; + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } - if (con->sway_view->border_right) { + if (view->border_right) { // Child border - right edge if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { @@ -341,14 +347,16 @@ static void render_container_simple_border_normal(struct sway_output *output, memcpy(&color, colors->child_border, sizeof(float) * 4); } color[3] *= con->alpha; - box.x = con->x + con->width - con->sway_view->border_thickness; + box.x = con->x + con->width - view->border_thickness; box.y = con->y + 1; - box.width = con->sway_view->border_thickness; - box.height = con->height - 1; + box.width = view->border_thickness; + box.height = con->height - 1 + - view->border_thickness * view->border_bottom; + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } - if (con->sway_view->border_bottom) { + if (view->border_bottom) { // Child border - bottom edge if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { @@ -358,9 +366,10 @@ static void render_container_simple_border_normal(struct sway_output *output, } color[3] *= con->alpha; box.x = con->x; - box.y = con->y + con->height - con->sway_view->border_thickness; + box.y = con->y + con->height - view->border_thickness; box.width = con->width; - box.height = con->sway_view->border_thickness; + box.height = view->border_thickness; + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } @@ -371,90 +380,118 @@ static void render_container_simple_border_normal(struct sway_output *output, box.y = con->y; box.width = con->width; box.height = 1; + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); // Single pixel bar below title memcpy(&color, colors->border, sizeof(float) * 4); color[3] *= con->alpha; - box.x = con->x + con->sway_view->border_thickness; - box.y = con->sway_view->y - 1; - box.width = con->width - con->sway_view->border_thickness * 2; + box.x = con->x + view->border_thickness; + box.y = view->y - 1; + box.width = con->width - view->border_thickness * 2; box.height = 1; + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); - // Title background - memcpy(&color, colors->background, sizeof(float) * 4); - color[3] *= con->alpha; - box.x = con->x - + con->sway_view->border_thickness * con->sway_view->border_left; - box.y = con->y + 1; - box.width = con->width - - con->sway_view->border_thickness * con->sway_view->border_left - - con->sway_view->border_thickness * con->sway_view->border_right; - box.height = con->sway_view->y - con->y - 2; - render_rect(output->wlr_output, output_damage, &box, color); + // Setting these makes marks and title easier + size_t inner_x = con->x + view->border_thickness * view->border_left; + size_t inner_width = con->width - view->border_thickness * view->border_left + - view->border_thickness * view->border_right; - // Title text - if (title_texture) { - float output_scale = output->wlr_output->scale; - struct wlr_box texture_box = { - .x = box.x * output_scale, - .y = box.y * output_scale, - }; - wlr_texture_get_size(title_texture, + // Marks + size_t marks_width = 0; + if (config->show_marks && marks_texture) { + struct wlr_box texture_box; + wlr_texture_get_size(marks_texture, &texture_box.width, &texture_box.height); + texture_box.x = (inner_x + inner_width) * output_scale - texture_box.width; + texture_box.y = (con->y + view->border_thickness) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, 0.0, output->wlr_output->transform_matrix); - texture_box.width = box.width * output_scale; - render_texture(output->wlr_output, output_damage, title_texture, - &texture_box, matrix, 1.0); + render_texture(output->wlr_output, output_damage, marks_texture, + &texture_box, matrix, con->alpha); + marks_width = texture_box.width; } - // Marks - if (config->show_marks && marks_texture) { - float output_scale = output->wlr_output->scale; + // Title text + size_t title_width = 0; + if (title_texture) { struct wlr_box texture_box; - wlr_texture_get_size(marks_texture, + wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); - texture_box.x = (box.x + box.width) * output_scale - texture_box.width; - texture_box.y = (box.y + box.height) - * output_scale - texture_box.height; + texture_box.x = inner_x * output_scale; + texture_box.y = (con->y + view->border_thickness) * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, WL_OUTPUT_TRANSFORM_NORMAL, 0.0, output->wlr_output->transform_matrix); - render_texture(output->wlr_output, output_damage, marks_texture, - &texture_box, matrix, 1.0); + if (inner_width * output_scale - marks_width < texture_box.width) { + texture_box.width = inner_width * output_scale - marks_width; + } + render_texture(output->wlr_output, output_damage, title_texture, + &texture_box, matrix, con->alpha); + title_width = texture_box.width; + } + + // Title background - above the text + memcpy(&color, colors->background, sizeof(float) * 4); + color[3] *= con->alpha; + box.x = inner_x; + box.y = con->y + 1; + box.width = inner_width; + box.height = view->border_thickness - 1; + scale_box(&box, output_scale); + render_rect(output->wlr_output, output_damage, &box, color); + + // Title background - below the text + box.y = (con->y + view->border_thickness + config->font_height) + * output_scale; + render_rect(output->wlr_output, output_damage, &box, color); + + // Title background - filler between title and marks + box.width = inner_width * output_scale - title_width - marks_width; + if (box.width > 0) { + box.x = inner_x * output_scale + title_width; + box.y = (con->y + view->border_thickness) * output_scale; + box.height = config->font_height * output_scale; + render_rect(output->wlr_output, output_damage, &box, color); } } /** * Render decorations for a view with "border pixel". + * + * Care must be taken not to render over the same pixel multiple times, + * otherwise the colors will be incorrect when using opacity. */ static void render_container_simple_border_pixel(struct sway_output *output, pixman_region32_t *output_damage, struct sway_container *con, struct border_colors *colors) { struct wlr_box box; float color[4]; + struct sway_view *view = con->sway_view; + float output_scale = output->wlr_output->scale; - if (con->sway_view->border_left) { + if (view->border_left) { // Child border - left edge memcpy(&color, colors->child_border, sizeof(float) * 4); color[3] *= con->alpha; box.x = con->x; - box.y = con->y; - box.width = con->sway_view->border_thickness; - box.height = con->height; + box.y = con->y + view->border_thickness * view->border_top; + box.width = view->border_thickness; + box.height = con->height - view->border_thickness + * (view->border_top + view->border_bottom); + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } - if (con->sway_view->border_right) { + if (view->border_right) { // Child border - right edge if (con->parent->children->length == 1 && con->parent->layout == L_HORIZ) { @@ -463,25 +500,28 @@ static void render_container_simple_border_pixel(struct sway_output *output, memcpy(&color, colors->child_border, sizeof(float) * 4); } color[3] *= con->alpha; - box.x = con->x + con->width - con->sway_view->border_thickness; - box.y = con->y; - box.width = con->sway_view->border_thickness; - box.height = con->height; + box.x = con->x + con->width - view->border_thickness; + box.y = con->y + view->border_thickness * view->border_top; + box.width = view->border_thickness; + box.height = con->height - view->border_thickness + * (view->border_top + view->border_bottom); + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } - if (con->sway_view->border_top) { + if (view->border_top) { // Child border - top edge memcpy(&color, colors->child_border, sizeof(float) * 4); color[3] *= con->alpha; box.x = con->x; box.y = con->y; box.width = con->width; - box.height = con->sway_view->border_thickness; + box.height = view->border_thickness; + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } - if (con->sway_view->border_bottom) { + if (view->border_bottom) { // Child border - bottom edge if (con->parent->children->length == 1 && con->parent->layout == L_VERT) { @@ -491,9 +531,10 @@ static void render_container_simple_border_pixel(struct sway_output *output, } color[3] *= con->alpha; box.x = con->x; - box.y = con->y + con->height - con->sway_view->border_thickness; + box.y = con->y + con->height - view->border_thickness; box.width = con->width; - box.height = con->sway_view->border_thickness; + box.height = view->border_thickness; + scale_box(&box, output_scale); render_rect(output->wlr_output, output_damage, &box, color); } } diff --git a/sway/tree/container.c b/sway/tree/container.c index 47ba88a9..e47338e7 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -123,13 +123,12 @@ static void _container_destroy(struct sway_container *cont) { if (cont->name) { free(cont->name); } - if (cont->title_focused) { - // If one is set then all of these are set - wlr_texture_destroy(cont->title_focused); - wlr_texture_destroy(cont->title_focused_inactive); - wlr_texture_destroy(cont->title_unfocused); - wlr_texture_destroy(cont->title_urgent); - } + + wlr_texture_destroy(cont->title_focused); + wlr_texture_destroy(cont->title_focused_inactive); + wlr_texture_destroy(cont->title_unfocused); + wlr_texture_destroy(cont->title_urgent); + list_free(cont->children); cont->children = NULL; free(cont); diff --git a/sway/tree/view.c b/sway/tree/view.c index c0984ca4..648c1655 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -43,13 +43,10 @@ void view_destroy(struct sway_view *view) { } list_free(view->marks); - if (view->marks_focused) { - // If one is set then all of these are set - wlr_texture_destroy(view->marks_focused); - wlr_texture_destroy(view->marks_focused_inactive); - wlr_texture_destroy(view->marks_unfocused); - wlr_texture_destroy(view->marks_urgent); - } + wlr_texture_destroy(view->marks_focused); + wlr_texture_destroy(view->marks_focused_inactive); + wlr_texture_destroy(view->marks_unfocused); + wlr_texture_destroy(view->marks_urgent); container_destroy(view->swayc); @@ -803,6 +800,11 @@ static void update_marks_texture(struct sway_view *view, char *buffer = calloc(len + 1, 1); char *part = malloc(len + 1); + if (!sway_assert(buffer && part, "Unable to allocate memory")) { + free(buffer); + return; + } + for (int i = 0; i < view->marks->length; ++i) { char *mark = view->marks->items[i]; if (mark[0] != '_') { From f0212d66eee61517ab1bb0f8bb68784d50e14c9a Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 16 May 2018 20:47:03 +1000 Subject: [PATCH 7/7] Update marks textures on output scale event --- sway/desktop/output.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 3f680b36..94562052 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -962,10 +962,15 @@ static void handle_transform(struct wl_listener *listener, void *data) { arrange_output(output->swayc); } +static void handle_scale_iterator(struct sway_container *view, void *data) { + view_update_marks_textures(view->sway_view); +} + static void handle_scale(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, scale); arrange_layers(output); arrange_output(output->swayc); + container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL); } void handle_new_output(struct wl_listener *listener, void *data) {