]> git.mdlowis.com Git - proto/labwc.git/commitdiff
theme: add window-switcher width/padding
authorJohan Malm <jgm323@gmail.com>
Mon, 24 Apr 2023 20:31:28 +0000 (21:31 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 29 Jun 2023 18:14:08 +0000 (19:14 +0100)
...and calculate item-height based on font-height

Add theme options
  - osd.window-switcher.width
  - osd.window-switcher.item.padding.x
  - osd.window-switcher.item.padding.y

Issue #879

docs/labwc-theme.5.scd
docs/themerc
include/theme.h
src/osd.c
src/theme.c

index 61d4123f59b5d2b6a3e170c166963e716d02a957..2a530f3572a5d6a7a42985a11888ddcd6601cb5e 100644 (file)
@@ -146,6 +146,17 @@ elements are not listed here, but are supported.
 *osd.label.text.color*
        Text color of on-screen-display
 
+*osd.window-switcher.width*
+       Width of window switcher in pixels. Default is 600.
+
+*osd.window-switcher.item.padding.x*
+       Horizontal padding of window switcher entries in pixels.
+       Default is 10.
+
+*osd.window-switcher.item.padding.y*
+       Vertical padding of window switcher entries in pixels.
+       Default is 6.
+
 *border.color*
        Set all border colors. This is obsolete, but supported for backward
        compatibility as some themes still contain it.
index f72f848093239d4d5104dd1b21ad2ca54f3b9cf3..0ad6e3db06fdeeb5040503fc6a00850f21f07e67 100644 (file)
@@ -52,3 +52,7 @@ osd.bg.color: #dddda6
 osd.border.color: #000000
 osd.border.width: 1
 osd.label.text.color: #000000
+
+osd.window-switcher.width: 600
+osd.window-switcher.item.padding.x: 10
+osd.window-switcher.item.padding.y: 6
index b457b87b2e286a7583114c929746ae161c14cf3c..4183cfd5011c71853464a11313d8a8930fa79b0d 100644 (file)
@@ -62,10 +62,15 @@ struct theme {
        float menu_separator_color[4];
 
        int osd_border_width;
+
        float osd_bg_color[4];
        float osd_border_color[4];
        float osd_label_text_color[4];
 
+       int osd_window_switcher_width;
+       int osd_window_switcher_item_padding_x;
+       int osd_window_switcher_item_padding_y;
+
        /* textures */
        struct lab_data_buffer *xbm_close_active_unpressed;
        struct lab_data_buffer *xbm_maximize_active_unpressed;
@@ -84,6 +89,7 @@ struct theme {
 
        /* not set in rc.xml/themerc, but derived from font & padding_height */
        int title_height;
+       int osd_window_switcher_item_height;
 };
 
 /**
index 5bf1f1cc41b316a9c980e47bfefe3d7cfd101e4c..123397fcbe902ad5eaec0af6e327a8067a59a9bd 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
 #include "window-rules.h"
 #include "workspaces.h"
 
-#define OSD_ITEM_HEIGHT (20)
-#define OSD_ITEM_WIDTH (600)
-#define OSD_ITEM_PADDING (10)
-
 /* is title different from app_id/class? */
 static int
 is_title_different(struct view *view)
@@ -73,7 +69,7 @@ get_osd_height(struct wl_list *node_list)
                if (!isfocusable(view) || skip == LAB_PROP_TRUE) {
                        continue;
                }
-               height += OSD_ITEM_HEIGHT;
+               height += rc.theme->osd_window_switcher_item_height;
        }
        height += 2 * rc.theme->osd_border_width;
        return height;
@@ -301,10 +297,9 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
        draw_cairo_border(cairo, w, h, theme->osd_border_width);
 
        /* Set up text rendering */
+       int item_width = w - 2 * theme->osd_border_width;
        set_cairo_color(cairo, theme->osd_label_text_color);
        PangoLayout *layout = pango_cairo_create_layout(cairo);
-       pango_layout_set_width(layout,
-               (OSD_ITEM_WIDTH - 2 * OSD_ITEM_PADDING) * PANGO_SCALE);
        pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
 
        PangoFontDescription *desc = font_to_pango_desc(&rc.font_osd);
@@ -314,15 +309,11 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
 
        int y = theme->osd_border_width;
 
-       /* Center text entries on the y axis */
-       int y_offset = (OSD_ITEM_HEIGHT - font_height(&rc.font_osd)) / 2;
-       y += y_offset;
-
        /* Draw workspace indicator */
        if (show_workspace) {
                /* Center workspace indicator on the x axis */
                int x = font_width(&rc.font_osd, workspace_name);
-               x = (OSD_ITEM_WIDTH - x) / 2;
+               x = (theme->osd_window_switcher_width - x) / 2;
                cairo_move_to(cairo, x, y);
                PangoWeight weight = pango_font_description_get_weight(desc);
                pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD);
@@ -331,7 +322,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
                pango_cairo_show_layout(cairo, layout);
                pango_font_description_set_weight(desc, weight);
                pango_layout_set_font_description(layout, desc);
-               y += OSD_ITEM_HEIGHT;
+               y += theme->osd_window_switcher_item_height;
        }
        pango_font_description_free(desc);
 
@@ -350,11 +341,11 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
                        continue;
                }
 
-               int x = theme->osd_border_width + OSD_ITEM_PADDING;
+               int x = theme->osd_border_width + theme->osd_window_switcher_item_padding_x;
                struct window_switcher_field *field;
                wl_list_for_each(field, &rc.window_switcher.fields, link) {
                        buf.len = 0;
-                       cairo_move_to(cairo, x, y);
+                       cairo_move_to(cairo, x, y + theme->osd_window_switcher_item_padding_y - 1);
 
                        switch (field->content) {
                        case LAB_FIELD_TYPE:
@@ -369,21 +360,23 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
                        default:
                                break;
                        }
-                       int field_width = field->width / 100.0 * OSD_ITEM_WIDTH;
+                       int field_width = field->width / 100.0 * item_width
+                               - 2 * theme->osd_window_switcher_item_padding_x;
                        pango_layout_set_width(layout, field_width * PANGO_SCALE);
                        pango_layout_set_text(layout, buf.buf, -1);
                        pango_cairo_show_layout(cairo, layout);
-                       x += field_width;
+                       x += field_width + theme->osd_window_switcher_item_padding_x;
                }
 
                if (view == cycle_view) {
                        /* Highlight current window */
-                       cairo_rectangle(cairo, theme->osd_border_width,
-                               y - y_offset, OSD_ITEM_WIDTH, OSD_ITEM_HEIGHT);
+                       cairo_rectangle(cairo, theme->osd_border_width, y,
+                               theme->osd_window_switcher_width - 2 * theme->osd_border_width,
+                               theme->osd_window_switcher_item_height);
                        cairo_stroke(cairo);
                }
 
-               y += OSD_ITEM_HEIGHT;
+               y += theme->osd_window_switcher_item_height;
        }
        free(buf.buf);
        g_object_unref(layout);
@@ -395,17 +388,18 @@ static void
 display_osd(struct output *output)
 {
        struct server *server = output->server;
+       struct theme *theme = server->theme;
        struct wl_list *node_list =
                &server->workspace_current->tree->children;
        bool show_workspace = wl_list_length(&rc.workspace_config.workspaces) > 1;
        const char *workspace_name = server->workspace_current->name;
 
        float scale = output->wlr_output->scale;
-       int w = OSD_ITEM_WIDTH + (2 * server->theme->osd_border_width);
+       int w = theme->osd_window_switcher_width;
        int h = get_osd_height(node_list);
        if (show_workspace) {
                /* workspace indicator */
-               h += OSD_ITEM_HEIGHT;
+               h += theme->osd_window_switcher_item_height;
        }
 
        /* Reset buffer */
index 98a387d35c0933fee6923e5d7f288b634c7361cd..d1aed200849ca232d6cde2877e1b1d3783e56066 100644 (file)
@@ -140,6 +140,10 @@ theme_builtin(struct theme *theme)
        theme->menu_separator_padding_height = 3;
        parse_hexstr("#888888", theme->menu_separator_color);
 
+       theme->osd_window_switcher_width = 600;
+       theme->osd_window_switcher_item_padding_x = 10;
+       theme->osd_window_switcher_item_padding_y = 6;
+
        /* inherit settings in post_processing() if not set elsewhere */
        theme->osd_bg_color[0] = FLT_MIN;
        theme->osd_border_width = INT_MIN;
@@ -304,6 +308,15 @@ entry(struct theme *theme, const char *key, const char *value)
        if (match_glob(key, "osd.border.color")) {
                parse_hexstr(value, theme->osd_border_color);
        }
+       if (match_glob(key, "osd.window-switcher.width")) {
+               theme->osd_window_switcher_width = atoi(value);
+       }
+       if (match_glob(key, "osd.window-switcher.item.padding.x")) {
+               theme->osd_window_switcher_item_padding_x = atoi(value);
+       }
+       if (match_glob(key, "osd.window-switcher.item.padding.y")) {
+               theme->osd_window_switcher_item_padding_y = atoi(value);
+       }
        if (match_glob(key, "osd.label.text.color")) {
                parse_hexstr(value, theme->osd_label_text_color);
        }
@@ -518,6 +531,8 @@ post_processing(struct theme *theme)
 {
        theme->title_height = font_height(&rc.font_activewindow)
                + 2 * theme->padding_height;
+       theme->osd_window_switcher_item_height = font_height(&rc.font_osd)
+               + 2 * theme->osd_window_switcher_item_padding_y;
 
        if (rc.corner_radius >= theme->title_height) {
                theme->title_height = rc.corner_radius + 1;