-
Notifications
You must be signed in to change notification settings - Fork 30
/
st-netwmicon_ff-0.9-20230207-211964d.diff
111 lines (102 loc) · 3.51 KB
/
st-netwmicon_ff-0.9-20230207-211964d.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
From 4533855cf473e366d1696e41259def228d369af6 Mon Sep 17 00:00:00 2001
From: Bakkeby <[email protected]>
Date: Tue, 12 Mar 2024 11:07:36 +0100
Subject: [PATCH] Adding netwmicon patch (farbfeld variant)
---
Makefile | 3 +++
config.mk | 4 +++-
x.c | 40 +++++++++++++++++++++++++++++++++++++++-
3 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 470ac86..96e27e3 100644
--- a/Makefile
+++ b/Makefile
@@ -49,9 +49,12 @@ install: st
chmod 644 $(DESTDIR)$(MANPREFIX)/man1/st.1
tic -sx st.info
@echo Please see the README file regarding the terminfo entry of st.
+ mkdir -p $(DESTDIR)$(ICONPREFIX)
+ [ -f $(ICONNAME) ] && cp -f $(ICONNAME) $(DESTDIR)$(ICONPREFIX) || :
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/st
rm -f $(DESTDIR)$(MANPREFIX)/man1/st.1
+ rm -f $(DESTDIR)$(ICONPREFIX)/$(ICONNAME)
.PHONY: all options clean dist install uninstall
diff --git a/config.mk b/config.mk
index 1e306f8..0255878 100644
--- a/config.mk
+++ b/config.mk
@@ -6,6 +6,8 @@ VERSION = 0.9
# paths
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man
+ICONPREFIX = $(PREFIX)/share/pixmaps
+ICONNAME = st.ff
X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib
@@ -21,7 +23,7 @@ LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
`$(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/x.c b/x.c
index aa09997..4940f28 100644
--- a/x.c
+++ b/x.c
@@ -93,7 +93,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;
@@ -1220,6 +1220,44 @@ 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 farbfeld image to set _NET_WM_ICON */
+ FILE* file = fopen(ICON, "r");
+ if (file) {
+ unsigned char buf[16] = {0};
+
+ int hasdata = fread(buf,1,16,file);
+ if (memcmp(buf,"farbfeld",8)) {
+ fprintf(stderr,"netwmicon: file %s is not a farbfeld image\n", ICON);
+ } else {
+ /* declare icon-variable which will store the image in bgra-format */
+ const int width=(buf[8]<<24)|(buf[9]<<16)|(buf[10]<<8)|buf[11];
+ const int height=(buf[12]<<24)|(buf[13]<<16)|(buf[14]<<8)|buf[15];
+ const int icon_n = width * height + 2;
+ long icon_bgra[icon_n];
+ /* set width and height of the icon */
+ int i = 0;
+ icon_bgra[i++] = width;
+ icon_bgra[i++] = height;
+ /* rgba -> bgra */
+ for (int y = 0; y < height && hasdata; y++) {
+ for (int x = 0; x < width && hasdata; x++) {
+ unsigned char *pixel_bgra = (unsigned char *) &icon_bgra[i++];
+ hasdata = fread(buf,1,8,file);
+ pixel_bgra[0] = buf[4];
+ pixel_bgra[1] = buf[2];
+ pixel_bgra[2] = buf[0];
+ pixel_bgra[3] = buf[6];
+ }
+ }
+
+ /* 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_bgra, icon_n);
+ }
+ fclose(file);
+ }
+
xw.netwmpid = XInternAtom(xw.dpy, "_NET_WM_PID", False);
XChangeProperty(xw.dpy, xw.win, xw.netwmpid, XA_CARDINAL, 32,
PropModeReplace, (uchar *)&thispid, 1);
--
2.45.2