From a94cdbec67b2db3d788d6da78b1e959a32769da5 Mon Sep 17 00:00:00 2001 From: David Cohen Date: Thu, 2 Apr 2026 03:17:08 -0500 Subject: [PATCH] cage: add -x flag to disable XWayland at runtime Allows disabling XWayland support at runtime even when the binary was built with it. --- cage.c | 71 ++++++++++++++++++++++++++++++++++---------------------- server.h | 1 + 2 files changed, 44 insertions(+), 28 deletions(-) diff --git a/cage.c b/cage.c index ed8e6ca..b278cc6 100644 --- a/cage.c +++ b/cage.c @@ -248,6 +248,9 @@ usage(FILE *file, const char *cage) " -m last Use only the last connected output\n" " -s\t Allow VT switching\n" " -v\t Show the version number and exit\n" +#if CAGE_HAS_XWAYLAND + " -x\t Disable XWayland\n" +#endif "\n" " Use -- when you want to pass arguments to APPLICATION\n", cage); @@ -256,8 +259,12 @@ usage(FILE *file, const char *cage) static bool parse_args(struct cg_server *server, int argc, char *argv[]) { +#if CAGE_HAS_XWAYLAND + server->enable_xwayland = true; +#endif + int c; - while ((c = getopt(argc, argv, "dDhm:sv")) != -1) { + while ((c = getopt(argc, argv, "dDhm:svx")) != -1) { switch (c) { case 'd': server->xdg_decoration = true; @@ -281,6 +288,11 @@ parse_args(struct cg_server *server, int argc, char *argv[]) case 'v': fprintf(stdout, "Cage version " CAGE_VERSION "\n"); exit(0); +#if CAGE_HAS_XWAYLAND + case 'x': + server->enable_xwayland = false; + break; +#endif default: usage(stderr, argv[0]); return false; @@ -561,35 +573,38 @@ main(int argc, char *argv[]) #if CAGE_HAS_XWAYLAND struct wlr_xcursor_manager *xcursor_manager = NULL; - struct wlr_xwayland *xwayland = wlr_xwayland_create(server.wl_display, compositor, true); - if (!xwayland) { - wlr_log(WLR_ERROR, "Cannot create XWayland server"); - } else { - server.new_xwayland_surface.notify = handle_xwayland_surface_new; - wl_signal_add(&xwayland->events.new_surface, &server.new_xwayland_surface); - - xcursor_manager = wlr_xcursor_manager_create(DEFAULT_XCURSOR, XCURSOR_SIZE); - if (!xcursor_manager) { - wlr_log(WLR_ERROR, "Cannot create XWayland XCursor manager"); - ret = 1; - goto end; - } - - if (setenv("DISPLAY", xwayland->display_name, true) < 0) { - wlr_log_errno(WLR_ERROR, - "Unable to set DISPLAY for XWayland. Clients may not be able to connect"); + struct wlr_xwayland *xwayland = NULL; + if (server.enable_xwayland) { + xwayland = wlr_xwayland_create(server.wl_display, compositor, true); + if (!xwayland) { + wlr_log(WLR_ERROR, "Cannot create XWayland server"); } else { - wlr_log(WLR_DEBUG, "XWayland is running on display %s", xwayland->display_name); - } + server.new_xwayland_surface.notify = handle_xwayland_surface_new; + wl_signal_add(&xwayland->events.new_surface, &server.new_xwayland_surface); - if (!wlr_xcursor_manager_load(xcursor_manager, 1)) { - wlr_log(WLR_ERROR, "Cannot load XWayland XCursor theme"); - } - struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(xcursor_manager, DEFAULT_XCURSOR, 1); - if (xcursor) { - struct wlr_xcursor_image *image = xcursor->images[0]; - wlr_xwayland_set_cursor(xwayland, wlr_xcursor_image_get_buffer(image), image->hotspot_x, - image->hotspot_y); + xcursor_manager = wlr_xcursor_manager_create(DEFAULT_XCURSOR, XCURSOR_SIZE); + if (!xcursor_manager) { + wlr_log(WLR_ERROR, "Cannot create XWayland XCursor manager"); + ret = 1; + goto end; + } + + if (setenv("DISPLAY", xwayland->display_name, true) < 0) { + wlr_log_errno(WLR_ERROR, + "Unable to set DISPLAY for XWayland. Clients may not be able to connect"); + } else { + wlr_log(WLR_DEBUG, "XWayland is running on display %s", xwayland->display_name); + } + + if (!wlr_xcursor_manager_load(xcursor_manager, 1)) { + wlr_log(WLR_ERROR, "Cannot load XWayland XCursor theme"); + } + struct wlr_xcursor *xcursor = wlr_xcursor_manager_get_xcursor(xcursor_manager, DEFAULT_XCURSOR, 1); + if (xcursor) { + struct wlr_xcursor_image *image = xcursor->images[0]; + wlr_xwayland_set_cursor(xwayland, wlr_xcursor_image_get_buffer(image), image->hotspot_x, + image->hotspot_y); + } } } #endif diff --git a/server.h b/server.h index 27f212a..a5b7138 100644 --- a/server.h +++ b/server.h @@ -72,6 +72,7 @@ struct cg_server { bool xdg_decoration; bool allow_vt_switch; + bool enable_xwayland; bool return_app_code; bool terminated; enum wlr_log_importance log_level;