From 0e85ffe7f43f02aadcd778f4af7e3c7b788dc148 Mon Sep 17 00:00:00 2001 From: Ali Mirjamali Date: Fri, 8 Nov 2024 22:18:27 +0330 Subject: [PATCH] Add `_NET_WM_PING` support resolves: https://github.com/QubesOS/qubes-issues/issues/6950 --- gui-daemon/xside.c | 34 +++++++++++++++++++++++++++++++++- gui-daemon/xside.h | 4 ++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/gui-daemon/xside.c b/gui-daemon/xside.c index 99282356..36d01af9 100644 --- a/gui-daemon/xside.c +++ b/gui-daemon/xside.c @@ -64,6 +64,7 @@ #include "trayicon.h" #include "shm-args.h" #include "util.h" +#include "unistd.h" #include /* Supported protocol version */ @@ -385,7 +386,17 @@ static Window mkwindow(Ghandles * g, struct windowdata *vm_window) ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask | StructureNotifyMask | PropertyChangeMask); - XSetWMProtocols(g->display, child_win, &g->wmDeleteMessage, 1); + + /* setting WM_CLIENT_MACHINE, _NET_WM_PID, _NET_WM_PING */ + XSetWMClientMachine(g->display, child_win, &g->hostname); + XChangeProperty(g->display, child_win, g->wm_pid, XA_CARDINAL, + 32 /* bits */ , PropModeReplace, + (unsigned char *) &g->pid, 1); + Atom protocols[2]; + protocols[0] = g->wmDeleteMessage; + protocols[1] = g->wm_ping; + XSetWMProtocols(g->display, child_win, protocols, 2); + if (g->icon_data) { XChangeProperty(g->display, child_win, g->net_wm_icon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) g->icon_data, @@ -423,6 +434,7 @@ static Window mkwindow(Ghandles * g, struct windowdata *vm_window) 32, PropModeReplace, (const unsigned char *)&vm_window->remote_winid, 1); + /* extra properties from command line */ for (i = 0; i < MAX_EXTRA_PROPS; i++) { if (g->extra_props[i].prop) { @@ -600,6 +612,8 @@ static void intern_global_atoms(Ghandles *const g) { { &g->wm_user_time, "_NET_WM_USER_TIME" }, { &g->wmDeleteMessage, "WM_DELETE_WINDOW" }, { &g->net_supported, "_NET_SUPPORTED" }, + { &g->wm_pid, "_NET_WM_PID" }, + { &g->wm_ping, "_NET_WM_PING" }, }; Atom labels[QUBES_ARRAY_SIZE(atoms_to_intern)]; const char *names[QUBES_ARRAY_SIZE(atoms_to_intern)]; @@ -644,6 +658,14 @@ static bool qubes_get_all_atom_properties(Display *const display, * most of them are handles to local Xserver structures */ static void mkghandles(Ghandles * g) { + char buf[256]; + char *list[1] = { buf }; + if (gethostname(buf, sizeof(buf)) == -1) { + fprintf(stderr, "Cannot get GUIVM hostname!\n"); + exit(1); + } + XStringListToTextProperty(list, 1, &g->hostname); + g->pid = getpid(); int ev_base, err_base; /* ignore */ XWindowAttributes attr; int i; @@ -2649,6 +2671,15 @@ static void process_xevent(Ghandles * g) (int) event_buffer.xclient.window); process_xevent_close(g, event_buffer.xclient.window); + } else if ((Atom)event_buffer.xclient.data.l[0] == + g->wm_ping) { + XClientMessageEvent *ev = (XClientMessageEvent *) &event_buffer; + ev->window = g->root_win; + XSendEvent(g->display, g->root_win, False, + (SubstructureNotifyMask|SubstructureRedirectMask), + &event_buffer); + if (g->log_level > 1) + fprintf(stderr, "Received ping request from Window Manager\n"); } break; default:; @@ -4570,6 +4601,7 @@ static void get_boot_lock(int domid) } static void cleanup() { + XFree(ghandles.hostname.value); XCloseDisplay(ghandles.display); unset_alive_flag(); close(ghandles.inter_appviewer_lock_fd); diff --git a/gui-daemon/xside.h b/gui-daemon/xside.h index a0ad00db..01131b47 100644 --- a/gui-daemon/xside.h +++ b/gui-daemon/xside.h @@ -145,6 +145,8 @@ struct extra_prop { struct _global_handles { /* local X server handles and attributes */ Display *display; + XTextProperty hostname; /* dom0 or GUIVM hostname */ + pid_t pid; /* GUI daemon PID */ int screen; /* shortcut to the default screen */ Window root_win; /* root attributes */ int root_width; /* size of root window */ @@ -171,6 +173,8 @@ struct _global_handles { Atom wm_state_maximized_horz; /* Atom: _NET_WM_STATE_MAXIMIZED_HORZ */ Atom wm_user_time_window; /* Atom: _NET_WM_USER_TIME_WINDOW */ Atom wm_user_time; /* Atom: _NET_WM_USER_TIME */ + Atom wm_pid; /* Atom: _NET_WM_PID */ + Atom wm_ping; /* Atom: _NET_WM_PING */ int shm_major_opcode; /* MIT-SHM extension opcode */ /* shared memory handling */ struct shm_args_hdr *shm_args; /* shared memory with Xorg */