]> git.mdlowis.com Git - proto/labwc.git/commitdiff
icon-loader: fix a few more missing icons
authorJohn Lindgren <john@jlindgren.net>
Fri, 4 Oct 2024 21:31:58 +0000 (17:31 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sat, 5 Oct 2024 20:01:55 +0000 (21:01 +0100)
By:
- stripping extensions from relative icon filenames (for example,
  gdmap.desktop has "Icon=gdmap_icon.png")
- using the WM_CLASS "instance" rather than "class" string, which
  is usually the same but lowercase

src/icon-loader.c
src/xwayland.c

index a9444fe482636bd87ade1e6b90b2fc0a8f90efc9..60f82029004a2d963154e86086e691623ab86271 100644 (file)
@@ -113,6 +113,23 @@ struct icon_ctx {
        enum sfdo_icon_file_format format;
 };
 
+/*
+ * Return the length of a filename minus any known extension
+ */
+static size_t
+length_without_extension(const char *name)
+{
+       size_t len = strlen(name);
+       if (len >= 4 && name[len - 4] == '.') {
+               const char *ext = &name[len - 3];
+               if (!strcmp(ext, "png") || !strcmp(ext, "svg")
+                               || !strcmp(ext, "xpm")) {
+                       len -= 4;
+               }
+       }
+       return len;
+}
+
 /*
  * Return 0 on success and -1 on error
  * The calling function is responsible for free()ing ctx->path
@@ -126,8 +143,15 @@ process_rel_name(struct icon_ctx *ctx, const char *icon_name,
 #if !HAVE_RSVG
        lookup_options |= SFDO_ICON_THEME_LOOKUP_OPTION_NO_SVG;
 #endif
+
+       /*
+        * Relative icon names are not supposed to include an extension,
+        * but some .desktop files include one anyway. libsfdo does not
+        * allow this in lookups, so strip the extension first.
+        */
+       size_t name_len = length_without_extension(icon_name);
        struct sfdo_icon_file *icon_file = sfdo_icon_theme_lookup(
-               loader->icon_theme, icon_name, SFDO_NT, size, scale,
+               loader->icon_theme, icon_name, name_len, size, scale,
                lookup_options);
        if (!icon_file || icon_file == SFDO_ICON_FILE_INVALID) {
                ret = -1;
index c7f0568bbfc342aeac93d33d2400405794d5c492..af3bb87152eee6e541ab6af4d5fd4b6ba48da92b 100644 (file)
@@ -489,9 +489,17 @@ xwayland_view_get_string_prop(struct view *view, const char *prop)
        if (!strcmp(prop, "class")) {
                return xwayland_surface->class;
        }
-       /* We give 'class' for wlr_foreign_toplevel_handle_v1_set_app_id() */
+       /*
+        * Use the WM_CLASS 'instance' (1st string) for the app_id. Per
+        * ICCCM, this is usually "the trailing part of the name used to
+        * invoke the program (argv[0] stripped of any directory names)".
+        *
+        * In most cases, the 'class' (2nd string) is the same as the
+        * 'instance' except for being capitalized. We want lowercase
+        * here since we use the app_id for icon lookups.
+        */
        if (!strcmp(prop, "app_id")) {
-               return xwayland_surface->class;
+               return xwayland_surface->instance;
        }
        return "";
 }