From 7589f2ea1523d8d0a9a3330e1e6e017cc3251916 Mon Sep 17 00:00:00 2001 From: lotherk Date: Sun, 22 Nov 2026 09:50:29 +0100 Subject: [PATCH] dtwm: the panel finds a program's icon under either spelling CDE names its icons with a capital (Dtterm.m.pm, Dtcalc.m.pm); a client's WM_CLASS instance name is usually lower case and a kept program is written with whatever the command names. The panel tried the name as stored and in lower case only, so a lower-case class with a capitalised icon file fell back to Dtactn. ClassIcon() tries the name as given, lower case and with a capital, in that order, for the dock and for the drawers. Measured: make -C programs/dtwm rc=0 on this tree (0 errors, build/logs/dtwm-iconfix2.log). --- programs/dtwm/WmMcdePanel.c | 54 +++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/programs/dtwm/WmMcdePanel.c b/programs/dtwm/WmMcdePanel.c index 64d9fc28..402a46a6 100644 --- a/programs/dtwm/WmMcdePanel.c +++ b/programs/dtwm/WmMcdePanel.c @@ -56,6 +56,37 @@ #include
#include
#include
+ +/* The icon of a program class. CDE names them with a capital (Dtterm, + * Dtcalc); a client's WM_CLASS instance name is often lower case and the + * class a kept program was written with may be either. Try the name as + * given, then in lower case, then with a capital -- the file name is what + * decides, not the comparison, which is strcasecmp. */ +static String +ClassIcon(Screen *screen, const char *cls, unsigned int size) +{ + char lower[64], first[64]; + String icon; + int i; + + icon = _DtGetIconFileName(screen, (String) cls, NULL, NULL, size); + if (icon != NULL) + return icon; + for (i = 0; cls[i] != '\0' && i + 1 < (int) sizeof lower; i++) + lower[i] = (char) tolower((unsigned char) cls[i]); + lower[i] = '\0'; + if (strcmp(lower, cls) != 0) { + icon = _DtGetIconFileName(screen, lower, NULL, NULL, size); + if (icon != NULL) + return icon; + } + if (cls[0] >= 'a' && cls[0] <= 'z') { + (void) snprintf(first, sizeof first, "%c%s", + cls[0] - 'a' + 'A', cls + 1); + icon = _DtGetIconFileName(screen, first, NULL, NULL, size); + } + return icon; +} #include #define MAX_APPS 48 @@ -375,17 +406,8 @@ AddDrawerWidget(int idx) below = kids[k - 1]; break; } - icon = _DtGetIconFileName(XtScreen(form), (String) drawerIcons[idx].cls, - NULL, NULL, panel.sub_icon_size); - if (icon == NULL) { - for (i = 0; drawerIcons[idx].cls[i] != '\0' && - i + 1 < sizeof lower; i++) - lower[i] = (char) tolower((unsigned char) - drawerIcons[idx].cls[i]); - lower[i] = '\0'; - icon = _DtGetIconFileName(XtScreen(form), lower, NULL, NULL, - panel.sub_icon_size); - } + icon = ClassIcon(XtScreen(form), drawerIcons[idx].cls, + panel.sub_icon_size); if (icon == NULL) icon = GetIconName("Dtactn", panel.sub_icon_size); XtSetArg(al[ac], XmNbackground, panel.primary_pixel_set->bg); ac++; @@ -936,15 +958,7 @@ AddButton(const char *cls, int keptIndex) return; /* the class's icon, as CDE names them (Dtterm, Dtcalc), else in * lower case, else the icon of an action */ - icon = _DtGetIconFileName(XtScreen(area), (String) cls, NULL, NULL, - panel.main_icon_size); - if (icon == NULL) { - for (i = 0; cls[i] != '\0' && i + 1 < sizeof lower; i++) - lower[i] = (char) tolower((unsigned char) cls[i]); - lower[i] = '\0'; - icon = _DtGetIconFileName(XtScreen(area), lower, NULL, NULL, - panel.main_icon_size); - } + icon = ClassIcon(XtScreen(area), cls, panel.main_icon_size); if (icon == NULL) icon = GetIconName("Dtactn", panel.main_icon_size); XtSetArg(al[ac], XmNbackground, panel.primary_pixel_set->bg); ac++;