mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 16:01:27 +00:00
Extract workspace size computation from render_workspace_button()
Also remove some unnecessary strtup()s and rename a few variables and functions.
This commit is contained in:
parent
103954dd2b
commit
c805e42635
|
@ -32,6 +32,9 @@ struct workspace {
|
||||||
bool urgent;
|
bool urgent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Global bar state */
|
||||||
|
extern struct bar swaybar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup bar.
|
* Setup bar.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -14,4 +14,9 @@ void render(struct output *output, struct config *config, struct status_line *li
|
||||||
*/
|
*/
|
||||||
void set_window_height(struct window *window, int height);
|
void set_window_height(struct window *window, int height);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the size of a workspace name
|
||||||
|
*/
|
||||||
|
void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height);
|
||||||
|
|
||||||
#endif /* _SWAYBAR_RENDER_H */
|
#endif /* _SWAYBAR_RENDER_H */
|
||||||
|
|
|
@ -172,7 +172,7 @@ static void render_block(struct window *window, struct config *config, struct st
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *handle_workspace_number(bool strip_num, const char *ws_name) {
|
static const char *strip_workspace_name(bool strip_num, const char *ws_name) {
|
||||||
bool strip = false;
|
bool strip = false;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -190,18 +190,23 @@ static char *handle_workspace_number(bool strip_num, const char *ws_name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strip) {
|
if (strip) {
|
||||||
return strdup(ws_name + i);
|
return ws_name + i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return strdup(ws_name);
|
return ws_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height) {
|
||||||
|
const char *stripped_name = strip_workspace_name(swaybar.config->strip_workspace_numbers, workspace_name);
|
||||||
|
|
||||||
|
get_text_size(window->cairo, window->font, width, height, false, "%s", stripped_name);
|
||||||
|
*width += 2 * ws_horizontal_padding;
|
||||||
|
*height += 2 * ws_vertical_padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void render_workspace_button(struct window *window, struct config *config, struct workspace *ws, double *x) {
|
static void render_workspace_button(struct window *window, struct config *config, struct workspace *ws, double *x) {
|
||||||
// strip workspace numbers if required
|
const char *stripped_name = strip_workspace_name(config->strip_workspace_numbers, ws->name);
|
||||||
char *name = handle_workspace_number(config->strip_workspace_numbers, ws->name);
|
|
||||||
|
|
||||||
int width, height;
|
|
||||||
get_text_size(window->cairo, window->font, &width, &height, false, "%s", name);
|
|
||||||
struct box_colors box_colors;
|
struct box_colors box_colors;
|
||||||
if (ws->urgent) {
|
if (ws->urgent) {
|
||||||
box_colors = config->colors.urgent_workspace;
|
box_colors = config->colors.urgent_workspace;
|
||||||
|
@ -213,26 +218,25 @@ static void render_workspace_button(struct window *window, struct config *config
|
||||||
box_colors = config->colors.inactive_workspace;
|
box_colors = config->colors.inactive_workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
workspace_button_size(window, stripped_name, &width, &height);
|
||||||
|
|
||||||
// background
|
// background
|
||||||
cairo_set_source_u32(window->cairo, box_colors.background);
|
cairo_set_source_u32(window->cairo, box_colors.background);
|
||||||
cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1,
|
cairo_rectangle(window->cairo, *x, 1.5, width - 1, height);
|
||||||
height + ws_vertical_padding * 2);
|
|
||||||
cairo_fill(window->cairo);
|
cairo_fill(window->cairo);
|
||||||
|
|
||||||
// border
|
// border
|
||||||
cairo_set_source_u32(window->cairo, box_colors.border);
|
cairo_set_source_u32(window->cairo, box_colors.border);
|
||||||
cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1,
|
cairo_rectangle(window->cairo, *x, 1.5, width - 1, height);
|
||||||
height + ws_vertical_padding * 2);
|
|
||||||
cairo_stroke(window->cairo);
|
cairo_stroke(window->cairo);
|
||||||
|
|
||||||
// text
|
// text
|
||||||
cairo_set_source_u32(window->cairo, box_colors.text);
|
cairo_set_source_u32(window->cairo, box_colors.text);
|
||||||
cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin);
|
cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin);
|
||||||
pango_printf(window->cairo, window->font, false, "%s", name);
|
pango_printf(window->cairo, window->font, false, "%s", stripped_name);
|
||||||
|
|
||||||
*x += width + ws_horizontal_padding * 2 + ws_spacing;
|
*x += width + ws_spacing;
|
||||||
|
|
||||||
free(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) {
|
static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) {
|
||||||
|
|
Loading…
Reference in a new issue