mirror of
https://github.com/swaywm/sway.git
synced 2026-04-26 06:46:26 -04:00
Draw icon and window title only if enough space
Signed-off-by: Felix Weilbach <felix.weilbach@t-online.de>
This commit is contained in:
parent
bb9a97ace5
commit
93b60f799b
1 changed files with 13 additions and 3 deletions
|
|
@ -124,7 +124,13 @@ static uint32_t render_status_line_text(struct render_context *ctx, double *x) {
|
||||||
return output->height;
|
return output->height;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t render_focused_window_title(struct render_context *ctx, double *x, double max_width) {
|
static uint32_t render_focused_window_title(struct render_context *ctx,
|
||||||
|
double *x,
|
||||||
|
double max_width) {
|
||||||
|
if (*x >= max_width) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct swaybar_output *output = ctx->output;
|
struct swaybar_output *output = ctx->output;
|
||||||
const char *text = output->bar->focused_window ? output->bar->focused_window->name : "";
|
const char *text = output->bar->focused_window ? output->bar->focused_window->name : "";
|
||||||
if (!text) {
|
if (!text) {
|
||||||
|
|
@ -735,7 +741,8 @@ static uint32_t render_workspace_button(struct render_context *ctx,
|
||||||
|
|
||||||
uint32_t render_focused_window_icon(cairo_t *cairo,
|
uint32_t render_focused_window_icon(cairo_t *cairo,
|
||||||
struct swaybar_output *output,
|
struct swaybar_output *output,
|
||||||
double *x) {
|
double *x,
|
||||||
|
double max_width) {
|
||||||
assert(output);
|
assert(output);
|
||||||
assert(output->bar);
|
assert(output->bar);
|
||||||
|
|
||||||
|
|
@ -782,6 +789,9 @@ uint32_t render_focused_window_icon(cairo_t *cairo,
|
||||||
icon = cairo_image_surface_scale(icon, icon_size, icon_size);
|
icon = cairo_image_surface_scale(icon, icon_size, icon_size);
|
||||||
|
|
||||||
int padded_size = icon_size + padding;
|
int padded_size = icon_size + padding;
|
||||||
|
if (*x + padded_size >= max_width) {
|
||||||
|
return output->height;
|
||||||
|
}
|
||||||
int y = floor((height - padded_size) / 2.0);
|
int y = floor((height - padded_size) / 2.0);
|
||||||
|
|
||||||
cairo_operator_t op = cairo_get_operator(cairo);
|
cairo_operator_t op = cairo_get_operator(cairo);
|
||||||
|
|
@ -850,7 +860,7 @@ static uint32_t render_to_cairo(struct render_context *ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bar->workspace_window_title_sync && output->focused) {
|
if (bar->workspace_window_title_sync && output->focused) {
|
||||||
uint32_t h = render_focused_window_icon(cairo, output, &x);
|
uint32_t h = render_focused_window_icon(cairo, output, &x, old_x);
|
||||||
max_height = h > max_height ? h : max_height;
|
max_height = h > max_height ? h : max_height;
|
||||||
old_x -= x;
|
old_x -= x;
|
||||||
h = render_focused_window_title(ctx, &x, old_x);
|
h = render_focused_window_title(ctx, &x, old_x);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue