|
|
@ -14,55 +14,72 @@
|
|
|
|
#include "swaybar/status_line.h"
|
|
|
|
#include "swaybar/status_line.h"
|
|
|
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
|
|
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
|
|
|
|
|
|
|
|
|
|
|
static const int ws_horizontal_padding = 5;
|
|
|
|
static const int WS_HORIZONTAL_PADDING = 5;
|
|
|
|
static const double ws_vertical_padding = 1.5;
|
|
|
|
static const double WS_VERTICAL_PADDING = 1.5;
|
|
|
|
static const double border_width = 1;
|
|
|
|
static const double BORDER_WIDTH = 1;
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t render_status_line_error(cairo_t *cairo,
|
|
|
|
static uint32_t render_status_line_error(cairo_t *cairo,
|
|
|
|
struct swaybar_config *config, const char *error,
|
|
|
|
struct swaybar_output *output, struct swaybar_config *config,
|
|
|
|
double *x, uint32_t width, uint32_t height) {
|
|
|
|
const char *error, double *x, uint32_t surface_height) {
|
|
|
|
if (!error) {
|
|
|
|
if (!error) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t height = surface_height * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
cairo_set_source_u32(cairo, 0xFF0000FF);
|
|
|
|
cairo_set_source_u32(cairo, 0xFF0000FF);
|
|
|
|
static const int margin = 3;
|
|
|
|
|
|
|
|
|
|
|
|
int margin = 3 * output->scale;
|
|
|
|
|
|
|
|
int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
int text_width, text_height;
|
|
|
|
int text_width, text_height;
|
|
|
|
get_text_size(cairo, config->font,
|
|
|
|
get_text_size(cairo, config->font,
|
|
|
|
&text_width, &text_height, 1, false, "%s", error);
|
|
|
|
&text_width, &text_height, output->scale, false, "%s", error);
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
|
|
|
if (height < ideal_height) {
|
|
|
|
if (height < ideal_height) {
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*x -= text_width + margin;
|
|
|
|
*x -= text_width + margin;
|
|
|
|
|
|
|
|
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
cairo_move_to(cairo, *x, (int)floor(text_y));
|
|
|
|
cairo_move_to(cairo, *x, (int)floor(text_y));
|
|
|
|
pango_printf(cairo, config->font, 1, false, "%s", error);
|
|
|
|
pango_printf(cairo, config->font, output->scale, false, "%s", error);
|
|
|
|
*x -= margin;
|
|
|
|
*x -= margin;
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t render_status_line_text(cairo_t *cairo,
|
|
|
|
static uint32_t render_status_line_text(cairo_t *cairo,
|
|
|
|
struct swaybar_config *config, const char *text,
|
|
|
|
struct swaybar_output *output, struct swaybar_config *config,
|
|
|
|
bool focused, double *x, uint32_t width, uint32_t height) {
|
|
|
|
const char *text, bool focused, double *x, uint32_t surface_height) {
|
|
|
|
if (!text) {
|
|
|
|
if (!text) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t height = surface_height * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
cairo_set_source_u32(cairo, focused ?
|
|
|
|
cairo_set_source_u32(cairo, focused ?
|
|
|
|
config->colors.focused_statusline : config->colors.statusline);
|
|
|
|
config->colors.focused_statusline : config->colors.statusline);
|
|
|
|
static const int margin = 3;
|
|
|
|
|
|
|
|
int text_width, text_height;
|
|
|
|
int text_width, text_height;
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
1, config->pango_markup, "%s", text);
|
|
|
|
output->scale, config->pango_markup, "%s", text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
|
|
|
|
|
|
|
|
int margin = 3 * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
|
|
|
if (height < ideal_height) {
|
|
|
|
if (height < ideal_height) {
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*x -= text_width + margin;
|
|
|
|
*x -= text_width + margin;
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
cairo_move_to(cairo, *x, (int)floor(text_y));
|
|
|
|
cairo_move_to(cairo, *x, (int)floor(text_y));
|
|
|
|
pango_printf(cairo, config->font, 1, config->pango_markup, "%s", text);
|
|
|
|
pango_printf(cairo, config->font, output->scale,
|
|
|
|
|
|
|
|
config->pango_markup, "%s", text);
|
|
|
|
*x -= margin;
|
|
|
|
*x -= margin;
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void render_sharp_line(cairo_t *cairo, uint32_t color,
|
|
|
|
static void render_sharp_line(cairo_t *cairo, uint32_t color,
|
|
|
@ -99,23 +116,29 @@ static void block_hotspot_callback(struct swaybar_output *output,
|
|
|
|
static uint32_t render_status_block(cairo_t *cairo,
|
|
|
|
static uint32_t render_status_block(cairo_t *cairo,
|
|
|
|
struct swaybar_config *config, struct swaybar_output *output,
|
|
|
|
struct swaybar_config *config, struct swaybar_output *output,
|
|
|
|
struct i3bar_block *block, double *x,
|
|
|
|
struct i3bar_block *block, double *x,
|
|
|
|
uint32_t height, bool focused, bool edge) {
|
|
|
|
uint32_t surface_height, bool focused, bool edge) {
|
|
|
|
static const int margin = 3;
|
|
|
|
|
|
|
|
if (!block->full_text || !*block->full_text) {
|
|
|
|
if (!block->full_text || !*block->full_text) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t height = surface_height * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
int text_width, text_height;
|
|
|
|
int text_width, text_height;
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
1, block->markup, "%s", block->full_text);
|
|
|
|
output->scale, block->markup, "%s", block->full_text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int margin = 3 * output->scale;
|
|
|
|
|
|
|
|
int ws_vertical_padding = WS_VERTICAL_PADDING * 2;
|
|
|
|
|
|
|
|
|
|
|
|
int width = text_width;
|
|
|
|
int width = text_width;
|
|
|
|
if (width < block->min_width) {
|
|
|
|
if (width < block->min_width) {
|
|
|
|
width = block->min_width;
|
|
|
|
width = block->min_width;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
double block_width = width;
|
|
|
|
double block_width = width;
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2;
|
|
|
|
if (height < ideal_height) {
|
|
|
|
if (height < ideal_height) {
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
*x -= width;
|
|
|
|
*x -= width;
|
|
|
@ -133,10 +156,10 @@ static uint32_t render_status_block(cairo_t *cairo,
|
|
|
|
if (config->sep_symbol) {
|
|
|
|
if (config->sep_symbol) {
|
|
|
|
int _height;
|
|
|
|
int _height;
|
|
|
|
get_text_size(cairo, config->font, &sep_width, &_height,
|
|
|
|
get_text_size(cairo, config->font, &sep_width, &_height,
|
|
|
|
1, false, "%s", config->sep_symbol);
|
|
|
|
output->scale, false, "%s", config->sep_symbol);
|
|
|
|
uint32_t _ideal_height = _height + ws_vertical_padding * 2;
|
|
|
|
uint32_t _ideal_height = _height + ws_vertical_padding * 2;
|
|
|
|
if (height < _ideal_height) {
|
|
|
|
if ((uint32_t)_height < _ideal_height / output->scale) {
|
|
|
|
return _height;
|
|
|
|
return _height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sep_width > block->separator_block_width) {
|
|
|
|
if (sep_width > block->separator_block_width) {
|
|
|
|
block->separator_block_width = sep_width + margin * 2;
|
|
|
|
block->separator_block_width = sep_width + margin * 2;
|
|
|
@ -160,22 +183,26 @@ static uint32_t render_status_block(cairo_t *cairo,
|
|
|
|
double pos = *x;
|
|
|
|
double pos = *x;
|
|
|
|
if (block->background) {
|
|
|
|
if (block->background) {
|
|
|
|
cairo_set_source_u32(cairo, block->background);
|
|
|
|
cairo_set_source_u32(cairo, block->background);
|
|
|
|
cairo_rectangle(cairo, pos - 0.5, 1, block_width, height);
|
|
|
|
cairo_rectangle(cairo, pos - 0.5 * output->scale,
|
|
|
|
|
|
|
|
output->scale, block_width, height);
|
|
|
|
cairo_fill(cairo);
|
|
|
|
cairo_fill(cairo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (block->border && block->border_top > 0) {
|
|
|
|
if (block->border && block->border_top > 0) {
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
pos - 0.5, 1, block_width, block->border_top);
|
|
|
|
pos - 0.5 * output->scale, output->scale,
|
|
|
|
|
|
|
|
block_width, block->border_top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (block->border && block->border_bottom > 0) {
|
|
|
|
if (block->border && block->border_bottom > 0) {
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
pos - 0.5, height - 1 - block->border_bottom,
|
|
|
|
pos - 0.5 * output->scale,
|
|
|
|
|
|
|
|
height - output->scale - block->border_bottom,
|
|
|
|
block_width, block->border_bottom);
|
|
|
|
block_width, block->border_bottom);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (block->border != 0 && block->border_left > 0) {
|
|
|
|
if (block->border != 0 && block->border_left > 0) {
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
pos - 0.5, 1, block->border_left, height);
|
|
|
|
pos - 0.5 * output->scale, output->scale,
|
|
|
|
|
|
|
|
block->border_left, height);
|
|
|
|
pos += block->border_left + margin;
|
|
|
|
pos += block->border_left + margin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -190,13 +217,15 @@ static uint32_t render_status_block(cairo_t *cairo,
|
|
|
|
cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0);
|
|
|
|
cairo_move_to(cairo, offset, height / 2.0 - text_height / 2.0);
|
|
|
|
uint32_t color = block->color ? *block->color : config->colors.statusline;
|
|
|
|
uint32_t color = block->color ? *block->color : config->colors.statusline;
|
|
|
|
cairo_set_source_u32(cairo, color);
|
|
|
|
cairo_set_source_u32(cairo, color);
|
|
|
|
pango_printf(cairo, config->font, 1, block->markup, "%s", block->full_text);
|
|
|
|
pango_printf(cairo, config->font, output->scale,
|
|
|
|
|
|
|
|
block->markup, "%s", block->full_text);
|
|
|
|
pos += width;
|
|
|
|
pos += width;
|
|
|
|
|
|
|
|
|
|
|
|
if (block->border && block->border_right > 0) {
|
|
|
|
if (block->border && block->border_right > 0) {
|
|
|
|
pos += margin;
|
|
|
|
pos += margin;
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
render_sharp_line(cairo, block->border,
|
|
|
|
pos - 0.5, 1, block->border_right, height);
|
|
|
|
pos - 0.5 * output->scale, output->scale,
|
|
|
|
|
|
|
|
block->border_right, height);
|
|
|
|
pos += block->border_right;
|
|
|
|
pos += block->border_right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -209,7 +238,7 @@ static uint32_t render_status_block(cairo_t *cairo,
|
|
|
|
if (config->sep_symbol) {
|
|
|
|
if (config->sep_symbol) {
|
|
|
|
offset = pos + (block->separator_block_width - sep_width) / 2;
|
|
|
|
offset = pos + (block->separator_block_width - sep_width) / 2;
|
|
|
|
cairo_move_to(cairo, offset, margin);
|
|
|
|
cairo_move_to(cairo, offset, margin);
|
|
|
|
pango_printf(cairo, config->font, 1, false,
|
|
|
|
pango_printf(cairo, config->font, output->scale, false,
|
|
|
|
"%s", config->sep_symbol);
|
|
|
|
"%s", config->sep_symbol);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
cairo_set_line_width(cairo, 1);
|
|
|
|
cairo_set_line_width(cairo, 1);
|
|
|
@ -220,19 +249,19 @@ static uint32_t render_status_block(cairo_t *cairo,
|
|
|
|
cairo_stroke(cairo);
|
|
|
|
cairo_stroke(cairo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
|
|
|
static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
|
|
|
struct swaybar_config *config, struct swaybar_output *output,
|
|
|
|
struct swaybar_config *config, struct swaybar_output *output,
|
|
|
|
struct status_line *status, bool focused,
|
|
|
|
struct status_line *status, bool focused,
|
|
|
|
double *x, uint32_t width, uint32_t height) {
|
|
|
|
double *x, uint32_t surface_height) {
|
|
|
|
uint32_t max_height = 0;
|
|
|
|
uint32_t max_height = 0;
|
|
|
|
bool edge = true;
|
|
|
|
bool edge = true;
|
|
|
|
struct i3bar_block *block;
|
|
|
|
struct i3bar_block *block;
|
|
|
|
wl_list_for_each(block, &status->blocks, link) {
|
|
|
|
wl_list_for_each(block, &status->blocks, link) {
|
|
|
|
uint32_t h = render_status_block(cairo, config, output,
|
|
|
|
uint32_t h = render_status_block(cairo, config, output,
|
|
|
|
block, x, height, focused, edge);
|
|
|
|
block, x, surface_height, focused, edge);
|
|
|
|
max_height = h > max_height ? h : max_height;
|
|
|
|
max_height = h > max_height ? h : max_height;
|
|
|
|
edge = false;
|
|
|
|
edge = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -242,17 +271,17 @@ static uint32_t render_status_line_i3bar(cairo_t *cairo,
|
|
|
|
static uint32_t render_status_line(cairo_t *cairo,
|
|
|
|
static uint32_t render_status_line(cairo_t *cairo,
|
|
|
|
struct swaybar_config *config, struct swaybar_output *output,
|
|
|
|
struct swaybar_config *config, struct swaybar_output *output,
|
|
|
|
struct status_line *status, bool focused,
|
|
|
|
struct status_line *status, bool focused,
|
|
|
|
double *x, uint32_t width, uint32_t height) {
|
|
|
|
double *x, uint32_t surface_height) {
|
|
|
|
switch (status->protocol) {
|
|
|
|
switch (status->protocol) {
|
|
|
|
case PROTOCOL_ERROR:
|
|
|
|
case PROTOCOL_ERROR:
|
|
|
|
return render_status_line_error(cairo,
|
|
|
|
return render_status_line_error(cairo, output, config,
|
|
|
|
config, status->text, x, width, height);
|
|
|
|
status->text, x, surface_height);
|
|
|
|
case PROTOCOL_TEXT:
|
|
|
|
case PROTOCOL_TEXT:
|
|
|
|
return render_status_line_text(cairo,
|
|
|
|
return render_status_line_text(cairo, output, config,
|
|
|
|
config, status->text, focused, x, width, height);
|
|
|
|
status->text, focused, x, surface_height);
|
|
|
|
case PROTOCOL_I3BAR:
|
|
|
|
case PROTOCOL_I3BAR:
|
|
|
|
return render_status_line_i3bar(cairo, config, output, status,
|
|
|
|
return render_status_line_i3bar(cairo, config, output,
|
|
|
|
focused, x, width, height);
|
|
|
|
status, focused, x, surface_height);
|
|
|
|
case PROTOCOL_UNDEF:
|
|
|
|
case PROTOCOL_UNDEF:
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -260,15 +289,23 @@ static uint32_t render_status_line(cairo_t *cairo,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t render_binding_mode_indicator(cairo_t *cairo,
|
|
|
|
static uint32_t render_binding_mode_indicator(cairo_t *cairo,
|
|
|
|
struct swaybar_config *config, const char *mode, double x,
|
|
|
|
struct swaybar_output *output, struct swaybar_config *config,
|
|
|
|
uint32_t height) {
|
|
|
|
const char *mode, double x, uint32_t surface_height) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t height = surface_height * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
int text_width, text_height;
|
|
|
|
int text_width, text_height;
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
1, true, "%s", mode);
|
|
|
|
output->scale, true, "%s", mode);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
|
|
|
|
|
|
|
|
int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale;
|
|
|
|
|
|
|
|
int border_width = BORDER_WIDTH * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2
|
|
|
|
uint32_t ideal_height = text_height + ws_vertical_padding * 2
|
|
|
|
+ border_width * 2;
|
|
|
|
+ border_width * 2;
|
|
|
|
if (height < ideal_height) {
|
|
|
|
if (height < ideal_height) {
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
|
|
|
|
uint32_t width = text_width + ws_horizontal_padding * 2 + border_width * 2;
|
|
|
|
|
|
|
|
|
|
|
@ -289,8 +326,8 @@ static uint32_t render_binding_mode_indicator(cairo_t *cairo,
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
cairo_set_source_u32(cairo, config->colors.binding_mode.text);
|
|
|
|
cairo_set_source_u32(cairo, config->colors.binding_mode.text);
|
|
|
|
cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
|
|
|
|
cairo_move_to(cairo, x + width / 2 - text_width / 2, (int)floor(text_y));
|
|
|
|
pango_printf(cairo, config->font, 1, true, "%s", mode);
|
|
|
|
pango_printf(cairo, config->font, output->scale, true, "%s", mode);
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *strip_workspace_number(const char *ws_name) {
|
|
|
|
static const char *strip_workspace_number(const char *ws_name) {
|
|
|
@ -313,7 +350,7 @@ static void workspace_hotspot_callback(struct swaybar_output *output,
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t render_workspace_button(cairo_t *cairo,
|
|
|
|
static uint32_t render_workspace_button(cairo_t *cairo,
|
|
|
|
struct swaybar_output *output, struct swaybar_config *config,
|
|
|
|
struct swaybar_output *output, struct swaybar_config *config,
|
|
|
|
struct swaybar_workspace *ws, double *x, uint32_t height) {
|
|
|
|
struct swaybar_workspace *ws, double *x, uint32_t surface_height) {
|
|
|
|
const char *name = ws->name;
|
|
|
|
const char *name = ws->name;
|
|
|
|
if (config->strip_workspace_numbers) {
|
|
|
|
if (config->strip_workspace_numbers) {
|
|
|
|
name = strip_workspace_number(ws->name);
|
|
|
|
name = strip_workspace_number(ws->name);
|
|
|
@ -330,14 +367,22 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
|
|
|
box_colors = config->colors.inactive_workspace;
|
|
|
|
box_colors = config->colors.inactive_workspace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t height = surface_height * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
int text_width, text_height;
|
|
|
|
int text_width, text_height;
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
get_text_size(cairo, config->font, &text_width, &text_height,
|
|
|
|
1, true, "%s", name);
|
|
|
|
output->scale, true, "%s", name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ws_vertical_padding = WS_VERTICAL_PADDING * output->scale;
|
|
|
|
|
|
|
|
int ws_horizontal_padding = WS_HORIZONTAL_PADDING * output->scale;
|
|
|
|
|
|
|
|
int border_width = BORDER_WIDTH * output->scale;
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t ideal_height = ws_vertical_padding * 2 + text_height
|
|
|
|
uint32_t ideal_height = ws_vertical_padding * 2 + text_height
|
|
|
|
+ border_width * 2;
|
|
|
|
+ border_width * 2;
|
|
|
|
if (height < ideal_height) {
|
|
|
|
if (height < ideal_height) {
|
|
|
|
return ideal_height;
|
|
|
|
return ideal_height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2;
|
|
|
|
uint32_t width = ws_horizontal_padding * 2 + text_width + border_width * 2;
|
|
|
|
|
|
|
|
|
|
|
|
cairo_set_source_u32(cairo, box_colors.background);
|
|
|
|
cairo_set_source_u32(cairo, box_colors.background);
|
|
|
@ -357,7 +402,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
double text_y = height / 2.0 - text_height / 2.0;
|
|
|
|
cairo_set_source_u32(cairo, box_colors.text);
|
|
|
|
cairo_set_source_u32(cairo, box_colors.text);
|
|
|
|
cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y));
|
|
|
|
cairo_move_to(cairo, *x + width / 2 - text_width / 2, (int)floor(text_y));
|
|
|
|
pango_printf(cairo, config->font, 1, true, "%s", name);
|
|
|
|
pango_printf(cairo, config->font, output->scale, true, "%s", name);
|
|
|
|
|
|
|
|
|
|
|
|
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
|
|
|
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
|
|
|
hotspot->x = *x;
|
|
|
|
hotspot->x = *x;
|
|
|
@ -370,7 +415,7 @@ static uint32_t render_workspace_button(cairo_t *cairo,
|
|
|
|
wl_list_insert(&output->hotspots, &hotspot->link);
|
|
|
|
wl_list_insert(&output->hotspots, &hotspot->link);
|
|
|
|
|
|
|
|
|
|
|
|
*x += width;
|
|
|
|
*x += width;
|
|
|
|
return height;
|
|
|
|
return height / output->scale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static uint32_t render_to_cairo(cairo_t *cairo,
|
|
|
|
static uint32_t render_to_cairo(cairo_t *cairo,
|
|
|
@ -394,7 +439,13 @@ static uint32_t render_to_cairo(cairo_t *cairo,
|
|
|
|
* height is too tall, the render function should adapt its drawing to
|
|
|
|
* height is too tall, the render function should adapt its drawing to
|
|
|
|
* utilize the available space.
|
|
|
|
* utilize the available space.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
double x = 0;
|
|
|
|
double x = output->width * output->scale;
|
|
|
|
|
|
|
|
if (bar->status) {
|
|
|
|
|
|
|
|
uint32_t h = render_status_line(cairo, config, output,
|
|
|
|
|
|
|
|
bar->status, output->focused, &x, output->height);
|
|
|
|
|
|
|
|
max_height = h > max_height ? h : max_height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
if (config->workspace_buttons) {
|
|
|
|
if (config->workspace_buttons) {
|
|
|
|
struct swaybar_workspace *ws;
|
|
|
|
struct swaybar_workspace *ws;
|
|
|
|
wl_list_for_each_reverse(ws, &output->workspaces, link) {
|
|
|
|
wl_list_for_each_reverse(ws, &output->workspaces, link) {
|
|
|
@ -404,14 +455,8 @@ static uint32_t render_to_cairo(cairo_t *cairo,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (config->binding_mode_indicator && config->mode) {
|
|
|
|
if (config->binding_mode_indicator && config->mode) {
|
|
|
|
uint32_t h = render_binding_mode_indicator(
|
|
|
|
uint32_t h = render_binding_mode_indicator(cairo,
|
|
|
|
cairo, config, config->mode, x, output->height);
|
|
|
|
output, config, config->mode, x, output->height);
|
|
|
|
max_height = h > max_height ? h : max_height;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
x = output->width;
|
|
|
|
|
|
|
|
if (bar->status) {
|
|
|
|
|
|
|
|
uint32_t h = render_status_line(cairo, config, output, bar->status,
|
|
|
|
|
|
|
|
output->focused, &x, output->width, output->height);
|
|
|
|
|
|
|
|
max_height = h > max_height ? h : max_height;
|
|
|
|
max_height = h > max_height ? h : max_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -451,7 +496,9 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Replay recording into shm and send it off
|
|
|
|
// Replay recording into shm and send it off
|
|
|
|
output->current_buffer = get_next_buffer(bar->shm,
|
|
|
|
output->current_buffer = get_next_buffer(bar->shm,
|
|
|
|
output->buffers, output->width, output->height);
|
|
|
|
output->buffers,
|
|
|
|
|
|
|
|
output->width * output->scale,
|
|
|
|
|
|
|
|
output->height * output->scale);
|
|
|
|
cairo_t *shm = output->current_buffer->cairo;
|
|
|
|
cairo_t *shm = output->current_buffer->cairo;
|
|
|
|
|
|
|
|
|
|
|
|
cairo_save(shm);
|
|
|
|
cairo_save(shm);
|
|
|
@ -462,9 +509,11 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) {
|
|
|
|
cairo_set_source_surface(shm, recorder, 0.0, 0.0);
|
|
|
|
cairo_set_source_surface(shm, recorder, 0.0, 0.0);
|
|
|
|
cairo_paint(shm);
|
|
|
|
cairo_paint(shm);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wl_surface_set_buffer_scale(output->surface, output->scale);
|
|
|
|
wl_surface_attach(output->surface,
|
|
|
|
wl_surface_attach(output->surface,
|
|
|
|
output->current_buffer->buffer, 0, 0);
|
|
|
|
output->current_buffer->buffer, 0, 0);
|
|
|
|
wl_surface_damage(output->surface, 0, 0, output->width, output->height);
|
|
|
|
wl_surface_damage(output->surface, 0, 0,
|
|
|
|
|
|
|
|
output->width, output->height);
|
|
|
|
wl_surface_commit(output->surface);
|
|
|
|
wl_surface_commit(output->surface);
|
|
|
|
wl_display_roundtrip(bar->display);
|
|
|
|
wl_display_roundtrip(bar->display);
|
|
|
|
}
|
|
|
|
}
|
|
|
|