mirror of
https://github.com/swaywm/sway.git
synced 2025-11-17 06:59:48 -05:00
Render titles
This commit is contained in:
parent
f3d0885524
commit
b667298a0a
11 changed files with 155 additions and 19 deletions
|
|
@ -203,6 +203,7 @@ void arrange_children_of(struct sway_container *parent) {
|
|||
} else {
|
||||
arrange_children_of(child);
|
||||
}
|
||||
container_update_title_textures(child);
|
||||
}
|
||||
container_damage_whole(parent);
|
||||
update_debug_tree();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,11 +103,12 @@ void view_autoconfigure(struct sway_view *view) {
|
|||
height = view->swayc->height - view->border_thickness * 2;
|
||||
break;
|
||||
case B_NORMAL:
|
||||
// TODO: Size the title bar by checking the font
|
||||
// Height is: border + title height + border + view height + border
|
||||
x = view->swayc->x + view->border_thickness;
|
||||
y = view->swayc->y + 20;
|
||||
y = view->swayc->y + config->font_height + view->border_thickness * 2;
|
||||
width = view->swayc->width - view->border_thickness * 2;
|
||||
height = view->swayc->height - view->border_thickness - 20;
|
||||
height = view->swayc->height - config->font_height
|
||||
- view->border_thickness * 3;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue