From f575e445ec36dec5fe7f5674a4dae8096a833d6f Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 25 Jun 2021 13:49:47 +0200 Subject: [PATCH] xwayland: terminate when no client is connected Automatically shutdown Xwayland 10s after all X11 clients have gone away. --- include/xwayland/xwm.h | 1 + xwayland/meson.build | 6 ++++++ xwayland/xwayland.c | 3 +++ xwayland/xwm.c | 9 +++++++++ 4 files changed, 19 insertions(+) diff --git a/include/xwayland/xwm.h b/include/xwayland/xwm.h index 0cdf6ea1a..41e35ef39 100644 --- a/include/xwayland/xwm.h +++ b/include/xwayland/xwm.h @@ -122,6 +122,7 @@ struct wlr_xwm { const xcb_query_extension_reply_t *xfixes; const xcb_query_extension_reply_t *xres; + uint32_t xfixes_major_version; #if HAS_XCB_ERRORS xcb_errors_context_t *errors_context; #endif diff --git a/xwayland/meson.build b/xwayland/meson.build index b7bbcaf1c..4d8ed5f45 100644 --- a/xwayland/meson.build +++ b/xwayland/meson.build @@ -74,3 +74,9 @@ wlr_files += files( ) wlr_deps += xwayland_libs features += { 'xwayland': true } + +have = cc.has_function('xcb_xfixes_set_client_disconnect_mode', dependencies: xwayland_libs) +add_project_arguments( + '-DHAS_XCB_XFIXES_SET_CLIENT_DISCONNECT_MODE=@0@'.format(have.to_int()), + language: 'c', +) diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index e09b05cfc..cb62fcc14 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -88,6 +88,9 @@ struct wlr_xwayland *wlr_xwayland_create(struct wl_display *wl_display, struct wlr_xwayland_server_options options = { .lazy = lazy, .enable_wm = true, +#if HAS_XCB_XFIXES_SET_CLIENT_DISCONNECT_MODE + .terminate_delay = lazy ? 10 : 0, +#endif }; xwayland->server = wlr_xwayland_server_create(wl_display, &options); if (xwayland->server == NULL) { diff --git a/xwayland/xwm.c b/xwayland/xwm.c index a80e47643..b398f2abf 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -1842,6 +1842,7 @@ static void xwm_get_resources(struct wlr_xwm *xwm) { wlr_log(WLR_DEBUG, "xfixes version: %" PRIu32 ".%" PRIu32, xfixes_reply->major_version, xfixes_reply->minor_version); + xwm->xfixes_major_version = xfixes_reply->major_version; free(xfixes_reply); @@ -2103,6 +2104,14 @@ struct wlr_xwm *xwm_create(struct wlr_xwayland *xwayland, int wm_fd) { sizeof(supported)/sizeof(*supported), supported); +#if HAS_XCB_XFIXES_SET_CLIENT_DISCONNECT_MODE + if (xwm->xwayland->server->options.terminate_delay > 0 && + xwm->xfixes_major_version >= 6) { + xcb_xfixes_set_client_disconnect_mode(xwm->xcb_conn, + XCB_XFIXES_CLIENT_DISCONNECT_FLAGS_TERMINATE); + } +#endif + xcb_flush(xwm->xcb_conn); xwm_set_net_active_window(xwm, XCB_WINDOW_NONE);