Set the _NET_WM_PID and WM_CLIENT_MACHINE X properties (#13)

Set the _NET_WM_PID and WM_CLIENT_MACHINE X properties

Co-authored-by: Leon Kowarschick <lkowarschick@gmail.com>
Co-authored-by: Kian Kasad <kian@kasad.com>
Co-authored-by: NRK <nrk@disroot.org>
This commit is contained in:
eylles 2021-09-11 08:14:34 -06:00 committed by Berke Kocaoğlu
parent 46a54c4b2d
commit d8ec6f91a9
2 changed files with 21 additions and 0 deletions

1
sxiv.h
View File

@ -385,6 +385,7 @@ enum {
ATOM__NET_WM_ICON_NAME, ATOM__NET_WM_ICON_NAME,
ATOM__NET_WM_ICON, ATOM__NET_WM_ICON,
ATOM__NET_WM_STATE, ATOM__NET_WM_STATE,
ATOM__NET_WM_PID,
ATOM__NET_WM_STATE_FULLSCREEN, ATOM__NET_WM_STATE_FULLSCREEN,
ATOM_COUNT ATOM_COUNT
}; };

View File

@ -25,6 +25,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <locale.h> #include <locale.h>
#include <unistd.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xresource.h> #include <X11/Xresource.h>
@ -151,6 +152,7 @@ void win_init(win_t *win)
INIT_ATOM_(_NET_WM_ICON_NAME); INIT_ATOM_(_NET_WM_ICON_NAME);
INIT_ATOM_(_NET_WM_ICON); INIT_ATOM_(_NET_WM_ICON);
INIT_ATOM_(_NET_WM_STATE); INIT_ATOM_(_NET_WM_STATE);
INIT_ATOM_(_NET_WM_PID);
INIT_ATOM_(_NET_WM_STATE_FULLSCREEN); INIT_ATOM_(_NET_WM_STATE_FULLSCREEN);
} }
@ -168,6 +170,8 @@ void win_open(win_t *win)
int gmask; int gmask;
XSizeHints sizehints; XSizeHints sizehints;
XWMHints hints; XWMHints hints;
pid_t pid;
char hostname[255];
e = &win->env; e = &win->env;
parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr); parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr);
@ -215,6 +219,22 @@ void win_open(win_t *win)
if (win->xwin == None) if (win->xwin == None)
error(EXIT_FAILURE, 0, "Error creating X window"); error(EXIT_FAILURE, 0, "Error creating X window");
/* set the _NET_WM_PID */
pid = getpid();
XChangeProperty(e->dpy, win->xwin,
atoms[ATOM__NET_WM_PID], XA_CARDINAL, sizeof(pid_t) * 8,
PropModeReplace, (unsigned char *) &pid, 1);
/* set the _NET_WM_PID */
if (gethostname(hostname, sizeof(hostname)) == 0) {
XTextProperty tp;
tp.value = (unsigned char *)hostname;
tp.nitems = strnlen(hostname, sizeof(hostname));
tp.encoding = XA_STRING;
tp.format = 8;
XSetWMClientMachine(e->dpy, win->xwin, &tp);
}
XSelectInput(e->dpy, win->xwin, XSelectInput(e->dpy, win->xwin,
ButtonReleaseMask | ButtonPressMask | KeyPressMask | ButtonReleaseMask | ButtonPressMask | KeyPressMask |
PointerMotionMask | StructureNotifyMask); PointerMotionMask | StructureNotifyMask);