Skip to content

Commit 0e85ffe

Browse files
committed
Add _NET_WM_PING support
resolves: QubesOS/qubes-issues#6950
1 parent 89d0254 commit 0e85ffe

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

gui-daemon/xside.c

+33-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
#include "trayicon.h"
6565
#include "shm-args.h"
6666
#include "util.h"
67+
#include "unistd.h"
6768
#include <qubes/pure.h>
6869

6970
/* Supported protocol version */
@@ -385,7 +386,17 @@ static Window mkwindow(Ghandles * g, struct windowdata *vm_window)
385386
ButtonPressMask | ButtonReleaseMask |
386387
PointerMotionMask | EnterWindowMask | LeaveWindowMask |
387388
FocusChangeMask | StructureNotifyMask | PropertyChangeMask);
388-
XSetWMProtocols(g->display, child_win, &g->wmDeleteMessage, 1);
389+
390+
/* setting WM_CLIENT_MACHINE, _NET_WM_PID, _NET_WM_PING */
391+
XSetWMClientMachine(g->display, child_win, &g->hostname);
392+
XChangeProperty(g->display, child_win, g->wm_pid, XA_CARDINAL,
393+
32 /* bits */ , PropModeReplace,
394+
(unsigned char *) &g->pid, 1);
395+
Atom protocols[2];
396+
protocols[0] = g->wmDeleteMessage;
397+
protocols[1] = g->wm_ping;
398+
XSetWMProtocols(g->display, child_win, protocols, 2);
399+
389400
if (g->icon_data) {
390401
XChangeProperty(g->display, child_win, g->net_wm_icon, XA_CARDINAL, 32,
391402
PropModeReplace, (unsigned char *) g->icon_data,
@@ -423,6 +434,7 @@ static Window mkwindow(Ghandles * g, struct windowdata *vm_window)
423434
32, PropModeReplace,
424435
(const unsigned char *)&vm_window->remote_winid,
425436
1);
437+
426438
/* extra properties from command line */
427439
for (i = 0; i < MAX_EXTRA_PROPS; i++) {
428440
if (g->extra_props[i].prop) {
@@ -600,6 +612,8 @@ static void intern_global_atoms(Ghandles *const g) {
600612
{ &g->wm_user_time, "_NET_WM_USER_TIME" },
601613
{ &g->wmDeleteMessage, "WM_DELETE_WINDOW" },
602614
{ &g->net_supported, "_NET_SUPPORTED" },
615+
{ &g->wm_pid, "_NET_WM_PID" },
616+
{ &g->wm_ping, "_NET_WM_PING" },
603617
};
604618
Atom labels[QUBES_ARRAY_SIZE(atoms_to_intern)];
605619
const char *names[QUBES_ARRAY_SIZE(atoms_to_intern)];
@@ -644,6 +658,14 @@ static bool qubes_get_all_atom_properties(Display *const display,
644658
* most of them are handles to local Xserver structures */
645659
static void mkghandles(Ghandles * g)
646660
{
661+
char buf[256];
662+
char *list[1] = { buf };
663+
if (gethostname(buf, sizeof(buf)) == -1) {
664+
fprintf(stderr, "Cannot get GUIVM hostname!\n");
665+
exit(1);
666+
}
667+
XStringListToTextProperty(list, 1, &g->hostname);
668+
g->pid = getpid();
647669
int ev_base, err_base; /* ignore */
648670
XWindowAttributes attr;
649671
int i;
@@ -2649,6 +2671,15 @@ static void process_xevent(Ghandles * g)
26492671
(int) event_buffer.xclient.window);
26502672
process_xevent_close(g,
26512673
event_buffer.xclient.window);
2674+
} else if ((Atom)event_buffer.xclient.data.l[0] ==
2675+
g->wm_ping) {
2676+
XClientMessageEvent *ev = (XClientMessageEvent *) &event_buffer;
2677+
ev->window = g->root_win;
2678+
XSendEvent(g->display, g->root_win, False,
2679+
(SubstructureNotifyMask|SubstructureRedirectMask),
2680+
&event_buffer);
2681+
if (g->log_level > 1)
2682+
fprintf(stderr, "Received ping request from Window Manager\n");
26522683
}
26532684
break;
26542685
default:;
@@ -4570,6 +4601,7 @@ static void get_boot_lock(int domid)
45704601
}
45714602

45724603
static void cleanup() {
4604+
XFree(ghandles.hostname.value);
45734605
XCloseDisplay(ghandles.display);
45744606
unset_alive_flag();
45754607
close(ghandles.inter_appviewer_lock_fd);

gui-daemon/xside.h

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ struct extra_prop {
145145
struct _global_handles {
146146
/* local X server handles and attributes */
147147
Display *display;
148+
XTextProperty hostname; /* dom0 or GUIVM hostname */
149+
pid_t pid; /* GUI daemon PID */
148150
int screen; /* shortcut to the default screen */
149151
Window root_win; /* root attributes */
150152
int root_width; /* size of root window */
@@ -171,6 +173,8 @@ struct _global_handles {
171173
Atom wm_state_maximized_horz; /* Atom: _NET_WM_STATE_MAXIMIZED_HORZ */
172174
Atom wm_user_time_window; /* Atom: _NET_WM_USER_TIME_WINDOW */
173175
Atom wm_user_time; /* Atom: _NET_WM_USER_TIME */
176+
Atom wm_pid; /* Atom: _NET_WM_PID */
177+
Atom wm_ping; /* Atom: _NET_WM_PING */
174178
int shm_major_opcode; /* MIT-SHM extension opcode */
175179
/* shared memory handling */
176180
struct shm_args_hdr *shm_args; /* shared memory with Xorg */

0 commit comments

Comments
 (0)