]> git.mdlowis.com Git - proto/labwc.git/commitdiff
osd: support app icons in window switcher
authortokyo4j <hrak1529@gmail.com>
Fri, 14 Mar 2025 10:33:28 +0000 (19:33 +0900)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Sun, 16 Mar 2025 16:22:24 +0000 (01:22 +0900)
Example configuration:

  <windowSwitcher>
    <fields>
      <field content="icon" width="5%" />
      <field content="title" width="95%" />
    </fields>
  </windowSwitcher>

docs/labwc-config.5.scd
include/osd.h
src/osd-field.c
src/osd.c

index 0042aa8d4b83895e9842a374b9c53476b8718da4..f52f257dd4fa32ac68632a0dac28d5bcef0ad95f 100644 (file)
@@ -303,6 +303,8 @@ this is for compatibility with Openbox.
        - *trimmed_identifier* Show trimmed identifier. Trimming removes
          the first two nodes of 'org.' strings.
 
+       - *icon* Show application icon
+
        - *desktop_entry_name* Show application name from freedesktop.org
          desktop entry/file. Falls back to trimmed identifier
          (trimmed_identifier).
index 13c67497c66c392e4976079db45de7f462398530..d20975387ae412c40768f3bae65c51e60de51b24 100644 (file)
@@ -12,6 +12,7 @@ enum window_switcher_field_content {
        LAB_FIELD_TYPE_SHORT,
        LAB_FIELD_IDENTIFIER,
        LAB_FIELD_TRIMMED_IDENTIFIER,
+       LAB_FIELD_ICON,
        LAB_FIELD_DESKTOP_ENTRY_NAME,
        LAB_FIELD_TITLE,
        LAB_FIELD_TITLE_SHORT,
index a6b0763a923ba2ebaaeec700b2472aed03a2a0ab..7465d267d3c6425862e495b86f98af247438b049 100644 (file)
@@ -319,6 +319,8 @@ osd_field_arg_from_xml_node(struct window_switcher_field *field,
                        field->content = LAB_FIELD_IDENTIFIER;
                } else if (!strcmp(content, "trimmed_identifier")) {
                        field->content = LAB_FIELD_TRIMMED_IDENTIFIER;
+               } else if (!strcmp(content, "icon")) {
+                       field->content = LAB_FIELD_ICON;
                } else if (!strcmp(content, "desktop_entry_name")) {
                        field->content = LAB_FIELD_DESKTOP_ENTRY_NAME;
                } else if (!strcmp(content, "title")) {
index 8d5e89506efe5a4502a5a3e4e2ed82d28edffceb..ef8ec2cb3587e490eeb0cd3eb182f9e0083ca2c5 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -6,8 +6,8 @@
 #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"
 #include "common/scene-helpers.h"
 #include "config/rcxml.h"
@@ -350,17 +350,29 @@ create_osd_scene(struct output *output, struct wl_array *views)
                        int field_width = (available_width - (nr_fields + 1)
                                * theme->osd_window_switcher_item_padding_x)
                                * field->width / 100.0;
+                       struct wlr_scene_node *node = NULL;
+
+                       if (field->content == LAB_FIELD_ICON) {
+                               int icon_size = font_height(&rc.font_osd);
+                               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;
+                       } else {
+                               buf_clear(&buf);
+                               osd_field_get_content(field, &buf, *view);
+
+                               struct scaled_font_buffer *font_buffer =
+                                       scaled_font_buffer_create(item_root);
+                               scaled_font_buffer_update(font_buffer, buf.data, field_width,
+                                       &rc.font_osd, text_color, bg_color);
+                               node = &font_buffer->scene_buffer->node;
+                       }
 
-                       buf_clear(&buf);
-                       osd_field_get_content(field, &buf, *view);
-
-                       struct scaled_font_buffer *font_buffer =
-                               scaled_font_buffer_create(item_root);
-                       scaled_font_buffer_update(font_buffer, buf.data, field_width,
-                               &rc.font_osd, text_color, bg_color);
-
-                       wlr_scene_node_set_position(&font_buffer->scene_buffer->node,
-                               x, y + theme->osd_window_switcher_item_padding_y
+                       wlr_scene_node_set_position(node, x,
+                               y + theme->osd_window_switcher_item_padding_y
                                        + theme->osd_window_switcher_item_active_border_width);
                        x += field_width + theme->osd_window_switcher_item_padding_x;
                }