aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/container.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-02 23:07:52 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-03 15:12:00 +1000
commitb667298a0a1efead7949715a31ec86fe3b8b1cda (patch)
treebc658e3019d741f1f245350003b156d05cc354a2 /sway/tree/container.c
parentMerge pull request #1893 from swaywm/touch (diff)
downloadsway-b667298a0a1efead7949715a31ec86fe3b8b1cda.tar.gz
sway-b667298a0a1efead7949715a31ec86fe3b8b1cda.tar.zst
sway-b667298a0a1efead7949715a31ec86fe3b8b1cda.zip
Render titles
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 6ac59547..b33985af 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -7,6 +7,8 @@
7#include <wayland-server.h> 7#include <wayland-server.h>
8#include <wlr/types/wlr_output_layout.h> 8#include <wlr/types/wlr_output_layout.h>
9#include <wlr/types/wlr_wl_shell.h> 9#include <wlr/types/wlr_wl_shell.h>
10#include "cairo.h"
11#include "pango.h"
10#include "sway/config.h" 12#include "sway/config.h"
11#include "sway/input/input-manager.h" 13#include "sway/input/input-manager.h"
12#include "sway/input/seat.h" 14#include "sway/input/seat.h"
@@ -120,6 +122,13 @@ static void _container_destroy(struct sway_container *cont) {
120 if (cont->name) { 122 if (cont->name) {
121 free(cont->name); 123 free(cont->name);
122 } 124 }
125 if (cont->title_focused) {
126 // If one is set then all of these are set
127 wlr_texture_destroy(cont->title_focused);
128 wlr_texture_destroy(cont->title_focused_inactive);
129 wlr_texture_destroy(cont->title_unfocused);
130 wlr_texture_destroy(cont->title_urgent);
131 }
123 list_free(cont->children); 132 list_free(cont->children);
124 cont->children = NULL; 133 cont->children = NULL;
125 free(cont); 134 free(cont);
@@ -546,3 +555,59 @@ void container_damage_whole(struct sway_container *con) {
546 } 555 }
547 output_damage_whole_container(output->sway_output, con); 556 output_damage_whole_container(output->sway_output, con);
548} 557}
558
559static void update_title_texture(struct sway_container *con,
560 struct wlr_texture **texture, struct border_colors *class) {
561 if (!sway_assert(con->type == C_CONTAINER || con->type == C_VIEW,
562 "Unexpected type %s", container_type_to_str(con->type))) {
563 return;
564 }
565 if (!con->width) {
566 return;
567 }
568 struct sway_container *output = container_parent(con, C_OUTPUT);
569 if (!output) {
570 return;
571 }
572 if (*texture) {
573 wlr_texture_destroy(*texture);
574 }
575 if (!con->name) {
576 return;
577 }
578
579 int width = con->width * output->sway_output->wlr_output->scale;
580 int height = config->font_height * output->sway_output->wlr_output->scale;
581
582 cairo_surface_t *surface = cairo_image_surface_create(
583 CAIRO_FORMAT_ARGB32, width, height);
584 cairo_t *cairo = cairo_create(surface);
585 PangoContext *pango = pango_cairo_create_context(cairo);
586 cairo_set_source_u32(cairo, class->text);
587 cairo_move_to(cairo, 0, 0);
588
589 pango_printf(cairo, config->font, output->sway_output->wlr_output->scale,
590 false, "%s", con->name);
591
592 cairo_surface_flush(surface);
593 unsigned char *data = cairo_image_surface_get_data(surface);
594 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
595 struct wlr_renderer *renderer = wlr_backend_get_renderer(
596 output->sway_output->wlr_output->backend);
597 *texture = wlr_texture_from_pixels(
598 renderer, WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
599 cairo_surface_destroy(surface);
600 g_object_unref(pango);
601 cairo_destroy(cairo);
602}
603
604void container_update_title_textures(struct sway_container *container) {
605 update_title_texture(container, &container->title_focused,
606 &config->border_colors.focused);
607 update_title_texture(container, &container->title_focused_inactive,
608 &config->border_colors.focused_inactive);
609 update_title_texture(container, &container->title_unfocused,
610 &config->border_colors.unfocused);
611 update_title_texture(container, &container->title_urgent,
612 &config->border_colors.urgent);
613}