]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add theme option to configure boxes from workspace OSD
authorkyak <699631+kyak@users.noreply.github.com>
Mon, 11 Dec 2023 09:41:33 +0000 (12:41 +0300)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2023 09:41:33 +0000 (10:41 +0100)
This allows to configure width and height of "boxes" displayed in the
workspace OSD. A setting of `0` disables the boxes.

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

index b75ea1161d5498647fa560473f969a092ffcb03a..18932f1b4bb63a97b59ba741310bd1c0122242e6 100644 (file)
@@ -174,6 +174,12 @@ elements are not listed here, but are supported.
        Border width of the selection box in the window switcher in pixels.
        Default is 2.
 
+*osd.workspace-switcher.boxes.width*
+       Width of boxes in workspace switcher in pixels. Setting to 0 disables boxes. Default is 20.
+
+*osd.workspace-switcher.boxes.height*
+       Height of boxes in workspace switcher in pixels. Setting to 0 disables boxes.  Default is 20.
+
 *border.color*
        Set all border colors. This is obsolete, but supported for backward
        compatibility as some themes still contain it.
index 1e5d8dd48a9521bdf209ee4f86a793bad8d8f303..67d7d5dfcf6fcfe6d45700c214d211c02917d9e2 100644 (file)
@@ -65,3 +65,6 @@ osd.window-switcher.padding: 4
 osd.window-switcher.item.padding.x: 10
 osd.window-switcher.item.padding.y: 1
 osd.window-switcher.item.active.border.width: 2
+
+osd.workspace-switcher.boxes.width: 20
+osd.workspace-switcher.boxes.height: 20
index e814f45140b19400b449196b5b205c6b60737380..5f958d2ebe3462c5821e1e5fde41e2b21500652f 100644 (file)
@@ -76,6 +76,9 @@ struct theme {
        int osd_window_switcher_item_padding_y;
        int osd_window_switcher_item_active_border_width;
 
+       int osd_workspace_switcher_boxes_width;
+       int osd_workspace_switcher_boxes_height;
+
        /* textures */
        struct lab_data_buffer *button_close_active_unpressed;
        struct lab_data_buffer *button_maximize_active_unpressed;
index ed5e6a90e031c6cd8f382c69a64fac47db8a13e7..624c015fd6b7b2202ec8a6702477c66f84f75198 100644 (file)
@@ -326,6 +326,9 @@ theme_builtin(struct theme *theme)
        theme->osd_window_switcher_item_padding_y = 1;
        theme->osd_window_switcher_item_active_border_width = 2;
 
+       theme->osd_workspace_switcher_boxes_width = 20;
+       theme->osd_workspace_switcher_boxes_height = 20;
+
        /* inherit settings in post_processing() if not set elsewhere */
        theme->osd_bg_color[0] = FLT_MIN;
        theme->osd_border_width = INT_MIN;
@@ -512,6 +515,12 @@ entry(struct theme *theme, const char *key, const char *value)
        if (match_glob(key, "osd.window-switcher.item.active.border.width")) {
                theme->osd_window_switcher_item_active_border_width = atoi(value);
        }
+       if (match_glob(key, "osd.workspace-switcher.boxes.width")) {
+               theme->osd_workspace_switcher_boxes_width = atoi(value);
+       }
+       if (match_glob(key, "osd.workspace-switcher.boxes.height")) {
+               theme->osd_workspace_switcher_boxes_height = atoi(value);
+       }
        if (match_glob(key, "osd.label.text.color")) {
                parse_hexstr(value, theme->osd_label_text_color);
        }
@@ -860,6 +869,12 @@ post_processing(struct theme *theme)
                memcpy(theme->osd_border_color, theme->osd_label_text_color,
                        sizeof(theme->osd_border_color));
        }
+       if (theme->osd_workspace_switcher_boxes_width == 0) {
+               theme->osd_workspace_switcher_boxes_height = 0;
+       }
+       if (theme->osd_workspace_switcher_boxes_height == 0) {
+               theme->osd_workspace_switcher_boxes_width = 0;
+       }
 }
 
 void
index e7707c5feafd2b2d67d5636699a83f881726b282..2ca5f9f1e2006dd2b2be3ccd7f8a96754bf34620 100644 (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);