sway: change unsupported GPU message to swaynag

This commit shows a swaynag message when an unsupported GPU is detected
which must be acknowledged by users. It also adds an environment
variable (`SWAY_UNSUPPORTED_GPU`) which may be used instead of the
`--unsupported-gpu` argument.

The `static` storage class for flag variables in main has also been
removed, as this should have no effect on the program.

Resolves: #8999
This commit is contained in:
Calvin Lee 2026-02-03 10:26:50 +00:00
parent e3c2412565
commit 8d30181dc2
3 changed files with 27 additions and 16 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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);
}