diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 31ed2aafe..71319bd62 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -424,6 +424,9 @@ struct wlr_backend *wlr_x11_backend_create(struct wl_event_loop *loop, { .name = "_NET_WM_NAME", .atom = &x11->atoms.net_wm_name }, { .name = "UTF8_STRING", .atom = &x11->atoms.utf8_string }, { .name = "_VARIABLE_REFRESH", .atom = &x11->atoms.variable_refresh }, + { .name = "_NET_WM_PID", .atom = &x11->atoms.net_wm_pid }, + { .name = "WM_CLIENT_MACHINE", .atom = &x11->atoms.wm_client_machine }, + { .name = "WM_CLASS", .atom = &x11->atoms.wm_class }, }; for (size_t i = 0; i < sizeof(atom) / sizeof(atom[0]); ++i) { diff --git a/backend/x11/output.c b/backend/x11/output.c index b400f3df9..1b8592b14 100644 --- a/backend/x11/output.c +++ b/backend/x11/output.c @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include @@ -641,6 +643,33 @@ struct wlr_output *wlr_x11_output_create(struct wlr_backend *backend) { wlr_x11_output_set_title(wlr_output, NULL); + uint32_t pid = getpid(); + xcb_change_property(x11->xcb, XCB_PROP_MODE_REPLACE, output->win, + x11->atoms.net_wm_pid, XCB_ATOM_CARDINAL, 32, 1, + &pid); + + char hostname[_POSIX_HOST_NAME_MAX + 1]; + if (gethostname(hostname, sizeof(hostname)) != -1) { + xcb_change_property(x11->xcb, XCB_PROP_MODE_REPLACE, output->win, + x11->atoms.wm_client_machine, XCB_ATOM_STRING, 8, strlen(hostname) + 1, + hostname); + } + +#define X11_OUT_WM_CLASS_WLR "wlroots" + char wm_class[32]; + static_assert(sizeof(wm_class) > sizeof(X11_OUT_WM_CLASS_WLR), + "wm_class must be large enough to contain X11_OUT_WM_CLASS_WLR and another string"); + snprintf(wm_class, sizeof(wm_class) - sizeof(X11_OUT_WM_CLASS_WLR), "%s", wlr_output->name); + + size_t wm_class_inst_size = strlen(wm_class) + 1; + snprintf(wm_class + wm_class_inst_size, sizeof(wm_class) - wm_class_inst_size, + "%s", X11_OUT_WM_CLASS_WLR); + + xcb_change_property(x11->xcb, XCB_PROP_MODE_REPLACE, output->win, + x11->atoms.wm_class, XCB_ATOM_STRING, 8, wm_class_inst_size + sizeof(X11_OUT_WM_CLASS_WLR), + wm_class); +#undef X11_OUT_WM_CLASS_WLR + xcb_flush(x11->xcb); wl_list_insert(&x11->outputs, &output->link); diff --git a/include/backend/x11.h b/include/backend/x11.h index fcea4d257..4fa3ea79b 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -96,6 +96,9 @@ struct wlr_x11_backend { xcb_atom_t net_wm_name; xcb_atom_t utf8_string; xcb_atom_t variable_refresh; + xcb_atom_t net_wm_pid; + xcb_atom_t wm_client_machine; + xcb_atom_t wm_class; } atoms; // The time we last received an event