From bda18df757c312038b298fb72ed6b6ec10736669 Mon Sep 17 00:00:00 2001 From: Droc Date: Mon, 25 Mar 2024 18:22:27 -0500 Subject: [PATCH] Window switcher, allow to use percent of monitor width. OSD will size per monitor. With this the width stays relative sized on my 4k as well as my 1080p monitor example from my theme osd.window-switcher.width: 60% --- docs/labwc-theme.5.scd | 2 ++ docs/themerc | 3 +++ include/theme.h | 1 + src/osd.c | 7 +++++-- src/theme.c | 6 ++++++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/labwc-theme.5.scd b/docs/labwc-theme.5.scd index dabfa6a6..4df2590a 100644 --- a/docs/labwc-theme.5.scd +++ b/docs/labwc-theme.5.scd @@ -164,6 +164,8 @@ elements are not listed here, but are supported. *osd.window-switcher.width* Width of window switcher in pixels. Default is 600. + Width can also be percent of the width of the monitor. + % is mandatory as last character, max 100% *osd.window-switcher.padding* Padding of window switcher in pixels. This is the space between the diff --git a/docs/themerc b/docs/themerc index 67d7d5df..aa1e322c 100644 --- a/docs/themerc +++ b/docs/themerc @@ -60,7 +60,10 @@ osd.border.color: #000000 osd.border.width: 1 osd.label.text.color: #000000 +# width can be set as percent (of screen width) +# example 50% or 75% instead of 600, max 100% osd.window-switcher.width: 600 + osd.window-switcher.padding: 4 osd.window-switcher.item.padding.x: 10 osd.window-switcher.item.padding.y: 1 diff --git a/include/theme.h b/include/theme.h index b4c0e738..f958c4f8 100644 --- a/include/theme.h +++ b/include/theme.h @@ -112,6 +112,7 @@ struct theme { /* not set in rc.xml/themerc, but derived from font & padding_height */ int osd_window_switcher_item_height; + bool osd_width_should_parse_as_percentage; }; /** diff --git a/src/osd.c b/src/osd.c index d6d6be56..2fab7d04 100644 --- a/src/osd.c +++ b/src/osd.c @@ -321,7 +321,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h, if (show_workspace) { /* Center workspace indicator on the x axis */ int x = font_width(&rc.font_osd, workspace_name); - x = (theme->osd_window_switcher_width - x) / 2; + x = (w - x) / 2; cairo_move_to(cairo, x, y + theme->osd_window_switcher_item_active_border_width); PangoWeight weight = pango_font_description_get_weight(desc); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); @@ -432,7 +432,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h, struct wlr_fbox fbox = { .x = theme->osd_border_width + theme->osd_window_switcher_padding, .y = y, - .width = theme->osd_window_switcher_width + .width = w - 2 * theme->osd_border_width - 2 * theme->osd_window_switcher_padding, .height = theme->osd_window_switcher_item_height, @@ -460,6 +460,9 @@ display_osd(struct output *output, struct wl_array *views) float scale = output->wlr_output->scale; int w = theme->osd_window_switcher_width; + if (theme->osd_width_should_parse_as_percentage) { + w = output->wlr_output->width * theme->osd_window_switcher_width / 100; + } int h = wl_array_len(views) * rc.theme->osd_window_switcher_item_height + 2 * rc.theme->osd_border_width + 2 * rc.theme->osd_window_switcher_padding; diff --git a/src/theme.c b/src/theme.c index 8ad93384..3de7a7dd 100644 --- a/src/theme.c +++ b/src/theme.c @@ -670,6 +670,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_width_should_parse_as_percentage = false; + char *p = strrchr(value, '%'); + if (p) { + *p = '\0'; + theme->osd_width_should_parse_as_percentage = true; + } theme->osd_window_switcher_width = atoi(value); } if (match_glob(key, "osd.window-switcher.padding")) {