osd: support percent values for window switcher width

Add ability to set width with percentage of monitor instead of just pixels.
With this the OSD sizes itself properly on both my 4k and 2k monitors.

example: 50% or 75% instead of 600, max 100%
This commit is contained in:
Droc 2024-03-26 05:12:19 -05:00 committed by Consolatis
parent 6e7f1b430f
commit eb5e855b69
5 changed files with 23 additions and 3 deletions

View file

@ -494,6 +494,7 @@ theme_builtin(struct theme *theme)
parse_hexstr("#888888", theme->menu_separator_color);
theme->osd_window_switcher_width = 600;
theme->osd_window_switcher_width_is_percent = false;
theme->osd_window_switcher_padding = 4;
theme->osd_window_switcher_item_padding_x = 10;
theme->osd_window_switcher_item_padding_y = 1;
@ -674,7 +675,12 @@ entry(struct theme *theme, const char *key, const char *value)
parse_hexstr(value, theme->osd_border_color);
}
if (match_glob(key, "osd.window-switcher.width")) {
theme->osd_window_switcher_width = atoi(value);
if (strrchr(value, '%')) {
theme->osd_window_switcher_width_is_percent = true;
} else {
theme->osd_window_switcher_width_is_percent = false;
}
theme->osd_window_switcher_width = MAX(atoi(value), 0);
}
if (match_glob(key, "osd.window-switcher.padding")) {
theme->osd_window_switcher_padding = atoi(value);
@ -1011,6 +1017,10 @@ post_processing(struct theme *theme)
if (theme->osd_workspace_switcher_boxes_height == 0) {
theme->osd_workspace_switcher_boxes_width = 0;
}
if (theme->osd_window_switcher_width_is_percent) {
theme->osd_window_switcher_width =
MIN(theme->osd_window_switcher_width, 100);
}
}
void