]> git.mdlowis.com Git - proto/labwc.git/commitdiff
osd: add osd.window-switcher.item.icon.size
authortokyo4j <hrak1529@gmail.com>
Tue, 1 Apr 2025 07:53:15 +0000 (16:53 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 1 Apr 2025 20:14:20 +0000 (21:14 +0100)
This allows users to make the icon in window switcher bigger (or smaller)
than the font size, which enables more Openbox-like appearance.

Example configuration:
  osd.window-switcher.item.icon.size: 50

This commit also makes the icon smaller than the font size if the width
allocated with <windowSwitcher><fields><field width=""> is smaller than
that.

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

index c8b8815728f4b5deae8153f2e25a3c58ee0e5db4..fff52721f8247030440c3625ddf803dbb51f301f 100644 (file)
@@ -256,6 +256,11 @@ all are supported.
        Border width of the selection box in the window switcher in pixels.
        Default is 2.
 
+*osd.window-switcher.item.icon.size*
+       Size of the icon in window switcher, in pixels.
+       If not set, the font size derived from <theme><font place="OnScreenDisplay">
+       is used.
+
 *osd.window-switcher.preview.border.width*
        Border width of the outlines shown as the preview of the window selected
        by window switcher. Inherits *osd.border.width* if not set.
index 1ab3934b8b39f5439be553a6dd1228f232fad08b..6417d5bdc21e35b0e8e909e2409f74222971d38e 100644 (file)
@@ -89,6 +89,8 @@ 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
+# The icon size the same as the font size by default
+# osd.window-switcher.item.icon.size: 50
 osd.window-switcher.preview.border.width: 1
 osd.window-switcher.preview.border.color: #dddda6,#000000,#dddda6
 
index c2c7e8be0e07929bbda63f5a23158c2d8b4019cb..cbdee13570e960b21f61fdf9aafcc1997afc0032 100644 (file)
@@ -135,6 +135,7 @@ struct theme {
        int osd_window_switcher_item_padding_x;
        int osd_window_switcher_item_padding_y;
        int osd_window_switcher_item_active_border_width;
+       int osd_window_switcher_item_icon_size;
        bool osd_window_switcher_width_is_percent;
        int osd_window_switcher_preview_border_width;
        float osd_window_switcher_preview_border_color[3][4];
index df15595460b2016c1227d3f668796a273f4cca0c..0dbe23e5b4cde1e9f249fdc79c620f22a533c81f 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -6,6 +6,7 @@
 #include "common/array.h"
 #include "common/buf.h"
 #include "common/font.h"
+#include "common/macros.h"
 #include "common/scaled-font-buffer.h"
 #include "common/scaled-icon-buffer.h"
 #include "common/scaled-rect-buffer.h"
@@ -352,15 +353,18 @@ create_osd_scene(struct output *output, struct wl_array *views)
                                * theme->osd_window_switcher_item_padding_x)
                                * field->width / 100.0;
                        struct wlr_scene_node *node = NULL;
+                       int height = -1;
 
                        if (field->content == LAB_FIELD_ICON) {
-                               int icon_size = font_height(&rc.font_osd);
+                               int icon_size = MIN(field_width,
+                                       theme->osd_window_switcher_item_icon_size);
                                struct scaled_icon_buffer *icon_buffer =
                                        scaled_icon_buffer_create(item_root,
                                                server, icon_size, icon_size);
                                scaled_icon_buffer_set_app_id(icon_buffer,
                                        view_get_string_prop(*view, "app_id"));
                                node = &icon_buffer->scene_buffer->node;
+                               height = icon_size;
                        } else {
                                buf_clear(&buf);
                                osd_field_get_content(field, &buf, *view);
@@ -370,11 +374,11 @@ create_osd_scene(struct output *output, struct wl_array *views)
                                scaled_font_buffer_update(font_buffer, buf.data, field_width,
                                        &rc.font_osd, text_color, bg_color);
                                node = &font_buffer->scene_buffer->node;
+                               height = font_height(&rc.font_osd);
                        }
 
                        wlr_scene_node_set_position(node, x,
-                               y + theme->osd_window_switcher_item_padding_y
-                                       + theme->osd_window_switcher_item_active_border_width);
+                               y + (theme->osd_window_switcher_item_height - height) / 2);
                        x += field_width + theme->osd_window_switcher_item_padding_x;
                }
 
index 51468e020c5a7d434a9c6f8d1c8e76ee04eda3c4..c987ad2d61861821961312184fdf662b908b3e3e 100644 (file)
@@ -542,6 +542,7 @@ theme_builtin(struct theme *theme, struct server *server)
        theme->osd_window_switcher_item_padding_x = 10;
        theme->osd_window_switcher_item_padding_y = 1;
        theme->osd_window_switcher_item_active_border_width = 2;
+       theme->osd_window_switcher_item_icon_size = -1;
 
        /* inherit settings in post_processing() if not set elsewhere */
        theme->osd_window_switcher_preview_border_width = INT_MIN;
@@ -879,6 +880,11 @@ entry(struct theme *theme, const char *key, const char *value)
                        get_int_if_positive(
                                value, "osd.window-switcher.item.active.border.width");
        }
+       if (match_glob(key, "osd.window-switcher.item.icon.size")) {
+               theme->osd_window_switcher_item_icon_size =
+                       get_int_if_positive(
+                               value, "osd.window-switcher.item.icon.size");
+       }
        if (match_glob(key, "osd.window-switcher.preview.border.width")) {
                theme->osd_window_switcher_preview_border_width =
                        get_int_if_positive(
@@ -1380,7 +1386,13 @@ post_processing(struct theme *theme)
        theme->menu_header_height = font_height(&rc.font_menuheader)
                + 2 * theme->menu_items_padding_y;
 
-       theme->osd_window_switcher_item_height = font_height(&rc.font_osd)
+       int osd_font_height = font_height(&rc.font_osd);
+       if (theme->osd_window_switcher_item_icon_size <= 0) {
+               theme->osd_window_switcher_item_icon_size = osd_font_height;
+       }
+       int osd_field_height =
+               MAX(osd_font_height, theme->osd_window_switcher_item_icon_size);
+       theme->osd_window_switcher_item_height = osd_field_height
                + 2 * theme->osd_window_switcher_item_padding_y
                + 2 * theme->osd_window_switcher_item_active_border_width;