From 49a67bdfce85ef997c68b77f379c4985e75ff836 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Tue, 15 Sep 2015 12:38:28 +0200 Subject: [PATCH] Add _NET_WM_PID and required WM_CLIENT_MACHINE properties to windows. --- ewmhints.c | 10 +++++++++- xproto.h | 1 + xwin.c | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ewmhints.c b/ewmhints.c index ae132e5..2978579 100644 --- a/ewmhints.c +++ b/ewmhints.c @@ -6,6 +6,7 @@ Copyright 2005-2011 Peter Astrand for Cendio AB Copyright 2007 Pierre Ossman for Cendio AB + Copyright 2015 Henrik Andersson for Cendio AB This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,7 +36,7 @@ extern Display *g_display; static Atom g_net_wm_state_maximized_vert_atom, g_net_wm_state_maximized_horz_atom, g_net_wm_state_hidden_atom, g_net_wm_name_atom, g_utf8_string_atom, g_net_wm_state_skip_taskbar_atom, g_net_wm_state_skip_pager_atom, - g_net_wm_state_modal_atom, g_net_wm_icon_atom, g_net_wm_state_above_atom; + g_net_wm_state_modal_atom, g_net_wm_icon_atom, g_net_wm_state_above_atom, g_net_wm_pid_atom; Atom g_net_wm_state_atom, g_net_wm_desktop_atom; @@ -190,6 +191,7 @@ ewmh_init() g_net_wm_desktop_atom = XInternAtom(g_display, "_NET_WM_DESKTOP", False); g_net_wm_name_atom = XInternAtom(g_display, "_NET_WM_NAME", False); g_net_wm_icon_atom = XInternAtom(g_display, "_NET_WM_ICON", False); + g_net_wm_pid_atom = XInternAtom(g_display, "_NET_WM_PID", False); g_utf8_string_atom = XInternAtom(g_display, "UTF8_STRING", False); } @@ -409,6 +411,12 @@ ewmh_set_wm_name(Window wnd, const char *title) 8, PropModeReplace, (unsigned char *) title, len); } +void +ewmh_set_wm_pid(Window wnd, pid_t pid) +{ + XChangeProperty(g_display, wnd, g_net_wm_pid_atom, + XA_CARDINAL, sizeof(pid_t) * 8, PropModeReplace, (unsigned char *) &pid, 1); +} int ewmh_set_window_popup(Window wnd) diff --git a/xproto.h b/xproto.h index e3c07a5..3b7083a 100644 --- a/xproto.h +++ b/xproto.h @@ -7,6 +7,7 @@ int ewmh_change_state(Window wnd, int state); int ewmh_move_to_desktop(Window wnd, unsigned int desktop); int ewmh_get_window_desktop(Window wnd); void ewmh_set_wm_name(Window wnd, const char *title); +void ewmh_set_wm_pid(Window wnd, pid_t pid); int ewmh_set_window_popup(Window wnd); int ewmh_set_window_modal(Window wnd); void ewmh_set_icon(Window wnd, int width, int height, const char *rgba_data); diff --git a/xwin.c b/xwin.c index 1b166f0..0a11563 100644 --- a/xwin.c +++ b/xwin.c @@ -20,6 +20,7 @@ along with this program. If not, see . */ +#include #include #include #include @@ -507,6 +508,7 @@ sw_find_group(unsigned long id, RD_BOOL dont_create) sg->wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, &attribs); + ewmh_set_wm_pid(sg->wnd, getpid()); sg->id = id; sg->refcnt = 0; @@ -1834,6 +1836,23 @@ error_handler(Display * dpy, XErrorEvent * eev) return g_old_error_handler(dpy, eev); } +static void +set_wm_client_machine(Display * dpy, Window win) +{ + XTextProperty tp; + char hostname[HOST_NAME_MAX]; + + if (gethostname(hostname, sizeof(hostname)) != 0) + return; + + tp.value = hostname; + tp.nitems = strlen(hostname); + tp.encoding = XA_STRING; + tp.format = 8; + + XSetWMClientMachine(dpy, win, &tp); +} + /* Initialize the UI. This is done once per process. */ RD_BOOL ui_init(void) @@ -2031,6 +2050,8 @@ ui_create_window(void) wndheight, 0, g_depth, InputOutput, g_visual, CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap | CWBorderPixel, &attribs); + ewmh_set_wm_pid(g_wnd, getpid()); + set_wm_client_machine(g_display, g_wnd); if (g_gc == NULL) { @@ -3942,6 +3963,8 @@ ui_seamless_create_window(unsigned long id, unsigned long group, unsigned long p wnd = XCreateWindow(g_display, RootWindowOfScreen(g_screen), -1, -1, 1, 1, 0, g_depth, InputOutput, g_visual, CWBackPixel | CWBackingStore | CWColormap | CWBorderPixel, &attribs); + ewmh_set_wm_pid(wnd, getpid()); + set_wm_client_machine(g_display, wnd); XStoreName(g_display, wnd, "SeamlessRDP"); ewmh_set_wm_name(wnd, "SeamlessRDP");