Krolyxon
Commit d8ec6f9

Branches

Refs →

nsxivd8ec6f9

Set the _NET_WM_PID and WM_CLIENT_MACHINE X properties (#13)

Set the _NET_WM_PID and WM_CLIENT_MACHINE X properties
Author
eylles
Date
2021-09-11 08:14 -0600
Committer
Berke Kocaoğlu · 2021-09-16 22:55 +0300
Parent
46a54c4
Commit
d8ec6f91a9857fb651f39de7929f17543d1c996c

+21 −0

2 files changed

  1. M sxiv.h +1 −0
  2. M window.c +20 −0
M sxiv.h View
@@ -385,6 +385,7 @@ enum {
385385 ATOM__NET_WM_ICON_NAME,
386386 ATOM__NET_WM_ICON,
387387 ATOM__NET_WM_STATE,
388+ ATOM__NET_WM_PID,
388389 ATOM__NET_WM_STATE_FULLSCREEN,
389390 ATOM_COUNT
390391 };
M window.c View
@@ -25,6 +25,7 @@
2525 #include <stdlib.h>
2626 #include <string.h>
2727 #include <locale.h>
28+#include <unistd.h>
2829 #include <X11/cursorfont.h>
2930 #include <X11/Xatom.h>
3031 #include <X11/Xresource.h>
@@ -151,6 +152,7 @@ void win_init(win_t *win)
151152 INIT_ATOM_(_NET_WM_ICON_NAME);
152153 INIT_ATOM_(_NET_WM_ICON);
153154 INIT_ATOM_(_NET_WM_STATE);
155+ INIT_ATOM_(_NET_WM_PID);
154156 INIT_ATOM_(_NET_WM_STATE_FULLSCREEN);
155157 }
156158
@@ -168,6 +170,8 @@ void win_open(win_t *win)
168170 int gmask;
169171 XSizeHints sizehints;
170172 XWMHints hints;
173+ pid_t pid;
174+ char hostname[255];
171175
172176 e = &win->env;
173177 parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr);
@@ -215,6 +219,22 @@ void win_open(win_t *win)
215219 if (win->xwin == None)
216220 error(EXIT_FAILURE, 0, "Error creating X window");
217221
222+ /* set the _NET_WM_PID */
223+ pid = getpid();
224+ XChangeProperty(e->dpy, win->xwin,
225+ atoms[ATOM__NET_WM_PID], XA_CARDINAL, sizeof(pid_t) * 8,
226+ PropModeReplace, (unsigned char *) &pid, 1);
227+
228+ /* set the _NET_WM_PID */
229+ if (gethostname(hostname, sizeof(hostname)) == 0) {
230+ XTextProperty tp;
231+ tp.value = (unsigned char *)hostname;
232+ tp.nitems = strnlen(hostname, sizeof(hostname));
233+ tp.encoding = XA_STRING;
234+ tp.format = 8;
235+ XSetWMClientMachine(e->dpy, win->xwin, &tp);
236+ }
237+
218238 XSelectInput(e->dpy, win->xwin,
219239 ButtonReleaseMask | ButtonPressMask | KeyPressMask |
220240 PointerMotionMask | StructureNotifyMask);