aboutsummaryrefslogtreecommitdiff
path: root/sway/tree/container.c
diff options
context:
space:
mode:
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 @@
#include <wayland-server.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_wl_shell.h>
+#include "cairo.h"
+#include "pango.h"
#include "sway/config.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
@@ -120,6 +122,13 @@ 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);
+ }
list_free(cont->children);
cont->children = NULL;
free(cont);
@@ -546,3 +555,59 @@ void container_damage_whole(struct sway_container *con) {
}
output_damage_whole_container(output->sway_output, con);
}
+
+static void update_title_texture(struct sway_container *con,
+ struct wlr_texture **texture, struct border_colors *class) {
+ if (!sway_assert(con->type == C_CONTAINER || con->type == C_VIEW,
+ "Unexpected type %s", container_type_to_str(con->type))) {
+ return;
+ }
+ if (!con->width) {
+ return;
+ }
+ struct sway_container *output = container_parent(con, C_OUTPUT);
+ if (!output) {
+ return;
+ }
+ if (*texture) {
+ wlr_texture_destroy(*texture);
+ }
+ if (!con->name) {
+ return;
+ }
+
+ int width = con->width * output->sway_output->wlr_output->scale;
+ int height = config->font_height * output->sway_output->wlr_output->scale;
+
+ cairo_surface_t *surface = cairo_image_surface_create(
+ CAIRO_FORMAT_ARGB32, width, height);
+ cairo_t *cairo = cairo_create(surface);
+ PangoContext *pango = pango_cairo_create_context(cairo);
+ cairo_set_source_u32(cairo, class->text);
+ cairo_move_to(cairo, 0, 0);
+
+ pango_printf(cairo, config->font, output->sway_output->wlr_output->scale,
+ false, "%s", con->name);
+
+ 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);
+}
+
+void container_update_title_textures(struct sway_container *container) {
+ update_title_texture(container, &container->title_focused,
+ &config->border_colors.focused);
+ update_title_texture(container, &container->title_focused_inactive,
+ &config->border_colors.focused_inactive);
+ update_title_texture(container, &container->title_unfocused,
+ &config->border_colors.unfocused);
+ update_title_texture(container, &container->title_urgent,
+ &config->border_colors.urgent);
+}