diff --git a/include/sway/server.h b/include/sway/server.h index f50d48f05..978f05d0a 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -160,7 +160,7 @@ struct sway_debug { extern struct sway_debug debug; -extern bool allow_unsupported_gpu; +extern bool unsupported_gpu_detected; void sway_terminate(int exit_code); diff --git a/sway/main.c b/sway/main.c index 44d07679e..e5dc497b3 100644 --- a/sway/main.c +++ b/sway/main.c @@ -224,7 +224,7 @@ static const char usage[] = "\n"; int main(int argc, char **argv) { - static bool verbose = false, debug = false, validate = false; + bool verbose = false, debug = false, validate = false, allow_unsupported_gpu = false; char *config_path = NULL; @@ -286,6 +286,12 @@ int main(int argc, char **argv) { exit(EXIT_FAILURE); } + char *unsupported_gpu_env = getenv("SWAY_UNSUPPORTED_GPU"); + // we let the flag override the environment variable + if (!allow_unsupported_gpu && unsupported_gpu_env) { + allow_unsupported_gpu = parse_boolean(unsupported_gpu_env, false); + } + // As the 'callback' function for wlr_log is equivalent to that for // sway, we do not need to override it. if (debug) { @@ -373,6 +379,18 @@ int main(int argc, char **argv) { swaynag_show(&config->swaynag_config_errors); } + struct swaynag_instance nag_gpu = (struct swaynag_instance){ + .args = "--type error " + "--message 'Proprietary GPU drivers are not supported by sway. Do not report issues.' ", + .detailed = false, + }; + + if (unsupported_gpu_detected && !allow_unsupported_gpu) { + if (!swaynag_spawn(config->swaynag_command, &nag_gpu)) { + sway_log(SWAY_ERROR, "Unable to start swaynag"); + } + } + server_run(&server); shutdown: @@ -385,6 +403,10 @@ shutdown: free(config_path); free_config(config); + if (nag_gpu.client != NULL) { + wl_client_destroy(nag_gpu.client); + } + pango_cairo_font_map_set_default(NULL); return exit_value; diff --git a/sway/server.c b/sway/server.c index 6003f4559..aef0d0b0c 100644 --- a/sway/server.c +++ b/sway/server.c @@ -78,7 +78,7 @@ #define SWAY_FOREIGN_TOPLEVEL_LIST_VERSION 1 #define SWAY_PRESENTATION_VERSION 2 -bool allow_unsupported_gpu = false; +bool unsupported_gpu_detected = false; #if WLR_HAS_DRM_BACKEND static void handle_drm_lease_request(struct wl_listener *listener, void *data) { @@ -161,27 +161,16 @@ static void detect_proprietary(struct wlr_backend *backend, void *data) { return; } - bool is_unsupported = false; if (strcmp(version->name, "nvidia-drm") == 0) { - is_unsupported = true; + unsupported_gpu_detected = true; sway_log(SWAY_ERROR, "!!! Proprietary Nvidia drivers are in use !!!"); - if (!allow_unsupported_gpu) { - sway_log(SWAY_ERROR, "Use Nouveau instead"); - } } if (strcmp(version->name, "evdi") == 0) { - is_unsupported = true; + unsupported_gpu_detected = true; sway_log(SWAY_ERROR, "!!! Proprietary DisplayLink drivers are in use !!!"); } - if (!allow_unsupported_gpu && is_unsupported) { - sway_log(SWAY_ERROR, - "Proprietary drivers are NOT supported. To launch sway anyway, " - "launch with --unsupported-gpu and DO NOT report issues."); - exit(EXIT_FAILURE); - } - drmFreeVersion(version); }