diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-05-16 21:54:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 21:54:16 -0400 |
commit | c2c5a3f5f6bdc061acae4e0583c4fd85c7ed21ac (patch) | |
tree | 02f3205870487dbedb981a1770a6ec77c8894c15 /sway/tree | |
parent | fe24f58297b4fb7bad94a5bad1593f12a764356c (diff) | |
parent | f0212d66eee61517ab1bb0f8bb68784d50e14c9a (diff) |
Merge pull request #1982 from RyanDwyer/show-marks
Implement show_marks
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/container.c | 14 | ||||
-rw-r--r-- | sway/tree/view.c | 94 |
2 files changed, 101 insertions, 7 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c index a17b20f7..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); @@ -592,6 +591,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 833345c5..648c1655 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -43,6 +43,11 @@ void view_destroy(struct sway_view *view) { } list_free(view->marks); + 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) { @@ -746,6 +751,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 +775,91 @@ 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); + *texture = NULL; + } + if (!view->marks->length) { + return; + } + + size_t len = 0; + for (int i = 0; i < view->marks->length; ++i) { + char *mark = view->marks->items[i]; + if (mark[0] != '_') { + len += strlen(mark) + 2; + } + } + 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] != '_') { + 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); +} |