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).
This commit is contained in:
lotherk committed 2026-11-22 09:50:29 +01:00
1 parent bc84289d25
commit 7589f2ea15
1 file changed
+34 -20
+34 -20
View File
@@ -56,6 +56,37 @@
#include <Dt/Icon.h>
#include <Dt/Control.h>
#include <Dt/IconFile.h>
/* 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 <Mcde/McdeSys.h>
#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++;