Add theme option to configure boxes from workspace OSD

This allows to configure width and height of "boxes" displayed in the
workspace OSD. A setting of `0` disables the boxes.
This commit is contained in:
kyak 2023-12-11 12:41:33 +03:00 committed by GitHub
parent 45e0dad3f1
commit 268191fce8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 14 deletions

View file

@ -60,14 +60,16 @@ _osd_update(struct server *server)
/* Settings */
uint16_t margin = 10;
uint16_t padding = 2;
uint16_t rect_height = 20;
uint16_t rect_width = 20;
uint16_t rect_height = theme->osd_workspace_switcher_boxes_height;
uint16_t rect_width = theme->osd_workspace_switcher_boxes_width;
bool hide_boxes = theme->osd_workspace_switcher_boxes_width == 0 ||
theme->osd_workspace_switcher_boxes_height == 0;
/* Dimensions */
size_t workspace_count = wl_list_length(&server->workspaces);
uint16_t marker_width = workspace_count * (rect_width + padding) - padding;
uint16_t width = margin * 2 + (marker_width < 200 ? 200 : marker_width);
uint16_t height = margin * 3 + rect_height + font_height(&rc.font_osd);
uint16_t height = margin * (hide_boxes ? 2 : 3) + rect_height + font_height(&rc.font_osd);
cairo_t *cairo;
cairo_surface_t *surface;
@ -100,19 +102,23 @@ _osd_update(struct server *server)
};
draw_cairo_border(cairo, fbox, theme->osd_border_width);
uint16_t x = (width - marker_width) / 2;
wl_list_for_each(workspace, &server->workspaces, link) {
bool active = workspace == server->workspace_current;
set_cairo_color(cairo, server->theme->osd_label_text_color);
cairo_rectangle(cairo, x, margin,
rect_width - padding, rect_height);
cairo_stroke(cairo);
if (active) {
/* Boxes */
uint16_t x;
if (!hide_boxes) {
x = (width - marker_width) / 2;
wl_list_for_each(workspace, &server->workspaces, link) {
bool active = workspace == server->workspace_current;
set_cairo_color(cairo, server->theme->osd_label_text_color);
cairo_rectangle(cairo, x, margin,
rect_width - padding, rect_height);
cairo_fill(cairo);
cairo_stroke(cairo);
if (active) {
cairo_rectangle(cairo, x, margin,
rect_width - padding, rect_height);
cairo_fill(cairo);
}
x += rect_width + padding;
}
x += rect_width + padding;
}
/* Text */
@ -127,7 +133,11 @@ _osd_update(struct server *server)
/* Center workspace indicator on the x axis */
x = font_width(&rc.font_osd, server->workspace_current->name);
x = (width - x) / 2;
cairo_move_to(cairo, x, margin * 2 + rect_height);
if (!hide_boxes) {
cairo_move_to(cairo, x, margin * 2 + rect_height);
} else {
cairo_move_to(cairo, x, (height - font_height(&rc.font_osd)) / 2.0);
}
//pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
pango_layout_set_font_description(layout, desc);
pango_font_description_free(desc);