Skip to content

Commit 6afa4d3

Browse files
authored
back/x11: set _NET_WM_PID and WM_CLIENT_MACHINE on each window (#159)
An EWMH window manager uses _NET_WM_PID to find the process that owns a window, for example to kill a window that does not answer _NET_WM_PING. The property was only set on the root window, so it was missing from the actual client windows. The specification also requires WM_CLIENT_MACHINE to be set whenever _NET_WM_PID is. Set both on each window in -window:::: for EWMH window managers, using -[NSProcessInfo hostName] for the client machine so the value is consistent with the rest of GNUstep.
1 parent 2dd18e6 commit 6afa4d3

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Source/x11/XGServerWindow.m

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,35 @@ - (int) window: (NSRect)frame : (NSBackingStoreType)type : (unsigned int)style
19921992
(unsigned char *)&window->win_attrs,
19931993
sizeof(GNUstepWMAttributes)/sizeof(CARD32));
19941994

1995+
// Let an EWMH window manager associate this window with our process.
1996+
// The specification requires WM_CLIENT_MACHINE to accompany _NET_WM_PID.
1997+
if ((generic.wm & XGWM_EWMH) != 0)
1998+
{
1999+
NSProcessInfo *pInfo = [NSProcessInfo processInfo];
2000+
long pid = [pInfo processIdentifier];
2001+
const char *host_name = [[pInfo hostName] UTF8String];
2002+
2003+
/* Warning ... X-bug .. when we specify 32bit data X actually expects data
2004+
* of type 'long' or 'unsigned long' even on machines where those types
2005+
* hold 64bit values.
2006+
*/
2007+
XChangeProperty(dpy, window->ident,
2008+
generic._NET_WM_PID_ATOM, XA_CARDINAL,
2009+
32, PropModeReplace,
2010+
(unsigned char *)&pid, 1);
2011+
2012+
if (host_name != NULL && *host_name != '\0')
2013+
{
2014+
XTextProperty machine;
2015+
2016+
if (XStringListToTextProperty((char **)&host_name, 1, &machine) != 0)
2017+
{
2018+
XSetWMClientMachine(dpy, window->ident, &machine);
2019+
XFree(machine.value);
2020+
}
2021+
}
2022+
}
2023+
19952024
// send to the WM window style hints
19962025
if ((generic.wm & XGWM_WINDOWMAKER) == 0)
19972026
{

0 commit comments

Comments
 (0)