commit 462a162e16edd7b30939f2aa4fd9c80aa5868fe3
parent 4477798299b2af7ade79fe58d76e6044745dbe41
Author: regexghost <dev@regexghost.com>
Date: Mon, 27 Jul 2026 22:27:22 +0100
net wm icon patch + line to use papirus icon
Diffstat:
5 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -4,3 +4,4 @@
st
patches/
config.h
+st.png
diff --git a/Makefile b/Makefile
@@ -25,6 +25,7 @@ $(OBJ): config.h config.mk
st: $(OBJ)
$(CC) -o $@ $(OBJ) $(STLDFLAGS)
+ magick -background none /usr/share/icons/Papirus/64x64/apps/utilities-terminal.svg st.png
clean:
rm -f config.h st $(OBJ) st-$(VERSION).tar.gz
@@ -48,10 +49,13 @@ install: st
@echo Please see the README file regarding the terminfo entry of st.
mkdir -p $(DESTDIR)$(APPPREFIX)
cp -f st.desktop $(DESTDIR)$(APPPREFIX)
+ mkdir -p $(DESTDIR)$(ICONPREFIX)
+ [ -f $(ICONNAME) ] && cp -f $(ICONNAME) $(DESTDIR)$(ICONPREFIX) || :
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/st
rm -f $(DESTDIR)$(APPPREFIX)/st.desktop
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
+ rm -f $(DESTDIR)$(ICONPREFIX)/$(ICONNAME)
.PHONY: all clean dist install uninstall
diff --git a/config.mk b/config.mk
@@ -7,6 +7,8 @@ VERSION = 0.9.3
PREFIX = /usr/local
APPPREFIX = $(PREFIX)/share/applications
MANPREFIX = $(PREFIX)/share/man
+ICONPREFIX = $(PREFIX)/share/pixmaps
+ICONNAME = st.png
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
@@ -17,12 +19,12 @@ PKG_CONFIG = pkg-config
INCS = -I$(X11INC) \
`$(PKG_CONFIG) --cflags fontconfig` \
`$(PKG_CONFIG) --cflags freetype2`
-LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lgd \
`$(PKG_CONFIG) --libs fontconfig` \
`$(PKG_CONFIG) --libs freetype2`
# flags
-STCPPFLAGS = -DVERSION=\"$(VERSION)\" -D_XOPEN_SOURCE=600
+STCPPFLAGS = -DVERSION=\"$(VERSION)\" -DICON=\"$(ICONPREFIX)/$(ICONNAME)\" -D_XOPEN_SOURCE=600
STCFLAGS = $(INCS) $(STCPPFLAGS) $(CPPFLAGS) $(CFLAGS)
STLDFLAGS = $(LIBS) $(LDFLAGS)
diff --git a/st.h b/st.h
@@ -3,6 +3,8 @@
#include <stdint.h>
#include <sys/types.h>
+#include <gd.h>
+
/* macros */
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
diff --git a/x.c b/x.c
@@ -97,7 +97,7 @@ typedef struct {
Window win;
Drawable buf;
GlyphFontSpec *specbuf; /* font spec buffer used for rendering */
- Atom xembed, wmdeletewin, netwmname, netwmiconname, netwmpid;
+ Atom xembed, wmdeletewin, netwmname, netwmicon, netwmiconname, netwmpid;
struct {
XIM xim;
XIC xic;
@@ -1335,6 +1335,41 @@ xinit(int cols, int rows)
xw.netwmiconname = XInternAtom(xw.dpy, "_NET_WM_ICON_NAME", False);
XSetWMProtocols(xw.dpy, xw.win, &xw.wmdeletewin, 1);
+ /* use a png-image to set _NET_WM_ICON */
+ FILE* file = fopen(ICON, "r");
+ if (file) {
+ /* load image in rgba-format */
+ const gdImagePtr icon_rgba = gdImageCreateFromPng(file);
+ fclose(file);
+ /* declare icon-variable which will store the image in argb-format */
+ const int width = gdImageSX(icon_rgba);
+ const int height = gdImageSY(icon_rgba);
+ const int icon_n = width * height + 2;
+ long icon_argb[icon_n];
+ /* set width and height of the icon */
+ int i = 0;
+ icon_argb[i++] = width;
+ icon_argb[i++] = height;
+ /* rgba -> argb */
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ const int pixel_rgba = gdImageGetPixel(icon_rgba, x, y);
+ unsigned char *pixel_argb = (unsigned char *) &icon_argb[i++];
+ pixel_argb[0] = gdImageBlue(icon_rgba, pixel_rgba);
+ pixel_argb[1] = gdImageGreen(icon_rgba, pixel_rgba);
+ pixel_argb[2] = gdImageRed(icon_rgba, pixel_rgba);
+ /* scale alpha from 0-127 to 0-255 */
+ const unsigned char alpha = 127 - gdImageAlpha(icon_rgba, pixel_rgba);
+ pixel_argb[3] = alpha == 127 ? 255 : alpha * 2;
+ }
+ }
+ gdImageDestroy(icon_rgba);
+ /* set _NET_WM_ICON */
+ xw.netwmicon = XInternAtom(xw.dpy, "_NET_WM_ICON", False);
+ XChangeProperty(xw.dpy, xw.win, xw.netwmicon, XA_CARDINAL, 32,
+ PropModeReplace, (uchar *) icon_argb, icon_n);
+ }
+
xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);