aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2023-12-12 15:25:10 +0100
committerLibravatar Simon Zeni <simon@bl4ckb0ne.ca>2023-12-12 10:04:14 -0500
commitff07eab85b5c6b728ad3cc99d02e9f2ae8b9854f (patch)
treefc4aa760eafe3a14c37fd11d8743c3b54e31de9c
parentDrop fglrx detection (diff)
downloadsway-ff07eab85b5c6b728ad3cc99d02e9f2ae8b9854f.tar.gz
sway-ff07eab85b5c6b728ad3cc99d02e9f2ae8b9854f.tar.zst
sway-ff07eab85b5c6b728ad3cc99d02e9f2ae8b9854f.zip
Detect Nvidia proprietary driver via drmGetVersion()
This is less punishing for users with the Nvidia driver loaded but not used by Sway (e.g. for CUDA).
-rw-r--r--include/sway/server.h2
-rw-r--r--meson.build3
-rw-r--r--sway/main.c29
-rw-r--r--sway/server.c32
4 files changed, 36 insertions, 30 deletions
diff --git a/include/sway/server.h b/include/sway/server.h
index 1b3166ce..bf195706 100644
--- a/include/sway/server.h
+++ b/include/sway/server.h
@@ -163,6 +163,8 @@ struct sway_debug {
163 163
164extern struct sway_debug debug; 164extern struct sway_debug debug;
165 165
166extern bool allow_unsupported_gpu;
167
166bool server_init(struct sway_server *server); 168bool server_init(struct sway_server *server);
167void server_fini(struct sway_server *server); 169void server_fini(struct sway_server *server);
168bool server_start(struct sway_server *server); 170bool server_start(struct sway_server *server);
diff --git a/meson.build b/meson.build
index adf49c19..e65723b6 100644
--- a/meson.build
+++ b/meson.build
@@ -77,8 +77,7 @@ pixman = dependency('pixman-1')
77libevdev = dependency('libevdev') 77libevdev = dependency('libevdev')
78libinput = wlroots_features['libinput_backend'] ? dependency('libinput', version: '>=1.21.0') : null_dep 78libinput = wlroots_features['libinput_backend'] ? dependency('libinput', version: '>=1.21.0') : null_dep
79xcb = dependency('xcb', required: get_option('xwayland')) 79xcb = dependency('xcb', required: get_option('xwayland'))
80drm_full = dependency('libdrm') # only needed for drm_fourcc.h 80drm = dependency('libdrm')
81drm = drm_full.partial_dependency(compile_args: true, includes: true)
82libudev = wlroots_features['libinput_backend'] ? dependency('libudev') : null_dep 81libudev = wlroots_features['libinput_backend'] ? dependency('libudev') : null_dep
83math = cc.find_library('m') 82math = cc.find_library('m')
84rt = cc.find_library('rt') 83rt = cc.find_library('rt')
diff --git a/sway/main.c b/sway/main.c
index 0db116d3..98aba7f2 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -49,32 +49,6 @@ void sig_handler(int signal) {
49 sway_terminate(EXIT_SUCCESS); 49 sway_terminate(EXIT_SUCCESS);
50} 50}
51 51
52void detect_proprietary(int allow_unsupported_gpu) {
53 FILE *f = fopen("/proc/modules", "r");
54 if (!f) {
55 return;
56 }
57 char *line = NULL;
58 size_t line_size = 0;
59 while (getline(&line, &line_size, f) != -1) {
60 if (strncmp(line, "nvidia ", 7) == 0) {
61 if (allow_unsupported_gpu) {
62 sway_log(SWAY_ERROR,
63 "!!! Proprietary Nvidia drivers are in use !!!");
64 } else {
65 sway_log(SWAY_ERROR,
66 "Proprietary Nvidia drivers are NOT supported. "
67 "Use Nouveau. To launch sway anyway, launch with "
68 "--unsupported-gpu and DO NOT report issues.");
69 exit(EXIT_FAILURE);
70 }
71 break;
72 }
73 }
74 free(line);
75 fclose(f);
76}
77
78void run_as_ipc_client(char *command, char *socket_path) { 52void run_as_ipc_client(char *command, char *socket_path) {
79 int socketfd = ipc_open_socket(socket_path); 53 int socketfd = ipc_open_socket(socket_path);
80 uint32_t len = strlen(command); 54 uint32_t len = strlen(command);
@@ -243,7 +217,7 @@ static const char usage[] =
243 "\n"; 217 "\n";
244 218
245int main(int argc, char **argv) { 219int main(int argc, char **argv) {
246 static bool verbose = false, debug = false, validate = false, allow_unsupported_gpu = false; 220 static bool verbose = false, debug = false, validate = false;
247 221
248 char *config_path = NULL; 222 char *config_path = NULL;
249 223
@@ -351,7 +325,6 @@ int main(int argc, char **argv) {
351 return 0; 325 return 0;
352 } 326 }
353 327
354 detect_proprietary(allow_unsupported_gpu);
355 increase_nofile_limit(); 328 increase_nofile_limit();
356 329
357 // handle SIGTERM signals 330 // handle SIGTERM signals
diff --git a/sway/server.c b/sway/server.c
index be521621..267e46c0 100644
--- a/sway/server.c
+++ b/sway/server.c
@@ -37,6 +37,7 @@
37#include <wlr/types/wlr_xdg_foreign_v1.h> 37#include <wlr/types/wlr_xdg_foreign_v1.h>
38#include <wlr/types/wlr_xdg_foreign_v2.h> 38#include <wlr/types/wlr_xdg_foreign_v2.h>
39#include <wlr/types/wlr_xdg_output_v1.h> 39#include <wlr/types/wlr_xdg_output_v1.h>
40#include <xf86drm.h>
40#include "config.h" 41#include "config.h"
41#include "list.h" 42#include "list.h"
42#include "log.h" 43#include "log.h"
@@ -60,6 +61,8 @@
60#define SWAY_XDG_SHELL_VERSION 2 61#define SWAY_XDG_SHELL_VERSION 2
61#define SWAY_LAYER_SHELL_VERSION 4 62#define SWAY_LAYER_SHELL_VERSION 4
62 63
64bool allow_unsupported_gpu = false;
65
63#if WLR_HAS_DRM_BACKEND 66#if WLR_HAS_DRM_BACKEND
64static void handle_drm_lease_request(struct wl_listener *listener, void *data) { 67static void handle_drm_lease_request(struct wl_listener *listener, void *data) {
65 /* We only offer non-desktop outputs, but in the future we might want to do 68 /* We only offer non-desktop outputs, but in the future we might want to do
@@ -113,6 +116,33 @@ static bool filter_global(const struct wl_client *client,
113 return true; 116 return true;
114} 117}
115 118
119static void detect_proprietary(struct wlr_backend *backend, void *data) {
120 int drm_fd = wlr_backend_get_drm_fd(backend);
121 if (drm_fd < 0) {
122 return;
123 }
124
125 drmVersion *version = drmGetVersion(drm_fd);
126 if (version == NULL) {
127 sway_log(SWAY_ERROR, "drmGetVersion() failed");
128 return;
129 }
130
131 if (strcmp(version->name, "nvidia-drm") == 0) {
132 if (allow_unsupported_gpu) {
133 sway_log(SWAY_ERROR, "!!! Proprietary Nvidia drivers are in use !!!");
134 } else {
135 sway_log(SWAY_ERROR,
136 "Proprietary Nvidia drivers are NOT supported. "
137 "Use Nouveau. To launch sway anyway, launch with "
138 "--unsupported-gpu and DO NOT report issues.");
139 exit(EXIT_FAILURE);
140 }
141 }
142
143 drmFreeVersion(version);
144}
145
116bool server_init(struct sway_server *server) { 146bool server_init(struct sway_server *server) {
117 sway_log(SWAY_DEBUG, "Initializing Wayland server"); 147 sway_log(SWAY_DEBUG, "Initializing Wayland server");
118 server->wl_display = wl_display_create(); 148 server->wl_display = wl_display_create();
@@ -128,6 +158,8 @@ bool server_init(struct sway_server *server) {
128 return false; 158 return false;
129 } 159 }
130 160
161 wlr_multi_for_each_backend(server->backend, detect_proprietary, NULL);
162
131 server->renderer = wlr_renderer_autocreate(server->backend); 163 server->renderer = wlr_renderer_autocreate(server->backend);
132 if (!server->renderer) { 164 if (!server->renderer) {
133 sway_log(SWAY_ERROR, "Failed to create renderer"); 165 sway_log(SWAY_ERROR, "Failed to create renderer");