mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-26 21:58:08 +01:00
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).
This commit is contained in:
parent
b81c4da494
commit
ff07eab85b
4 changed files with 36 additions and 30 deletions
|
@ -163,6 +163,8 @@ struct sway_debug {
|
|||
|
||||
extern struct sway_debug debug;
|
||||
|
||||
extern bool allow_unsupported_gpu;
|
||||
|
||||
bool server_init(struct sway_server *server);
|
||||
void server_fini(struct sway_server *server);
|
||||
bool server_start(struct sway_server *server);
|
||||
|
|
|
@ -77,8 +77,7 @@ pixman = dependency('pixman-1')
|
|||
libevdev = dependency('libevdev')
|
||||
libinput = wlroots_features['libinput_backend'] ? dependency('libinput', version: '>=1.21.0') : null_dep
|
||||
xcb = dependency('xcb', required: get_option('xwayland'))
|
||||
drm_full = dependency('libdrm') # only needed for drm_fourcc.h
|
||||
drm = drm_full.partial_dependency(compile_args: true, includes: true)
|
||||
drm = dependency('libdrm')
|
||||
libudev = wlroots_features['libinput_backend'] ? dependency('libudev') : null_dep
|
||||
math = cc.find_library('m')
|
||||
rt = cc.find_library('rt')
|
||||
|
|
29
sway/main.c
29
sway/main.c
|
@ -49,32 +49,6 @@ void sig_handler(int signal) {
|
|||
sway_terminate(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
void detect_proprietary(int allow_unsupported_gpu) {
|
||||
FILE *f = fopen("/proc/modules", "r");
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
char *line = NULL;
|
||||
size_t line_size = 0;
|
||||
while (getline(&line, &line_size, f) != -1) {
|
||||
if (strncmp(line, "nvidia ", 7) == 0) {
|
||||
if (allow_unsupported_gpu) {
|
||||
sway_log(SWAY_ERROR,
|
||||
"!!! Proprietary Nvidia drivers are in use !!!");
|
||||
} else {
|
||||
sway_log(SWAY_ERROR,
|
||||
"Proprietary Nvidia drivers are NOT supported. "
|
||||
"Use Nouveau. To launch sway anyway, launch with "
|
||||
"--unsupported-gpu and DO NOT report issues.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(line);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void run_as_ipc_client(char *command, char *socket_path) {
|
||||
int socketfd = ipc_open_socket(socket_path);
|
||||
uint32_t len = strlen(command);
|
||||
|
@ -243,7 +217,7 @@ static const char usage[] =
|
|||
"\n";
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
static bool verbose = false, debug = false, validate = false, allow_unsupported_gpu = false;
|
||||
static bool verbose = false, debug = false, validate = false;
|
||||
|
||||
char *config_path = NULL;
|
||||
|
||||
|
@ -351,7 +325,6 @@ int main(int argc, char **argv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
detect_proprietary(allow_unsupported_gpu);
|
||||
increase_nofile_limit();
|
||||
|
||||
// handle SIGTERM signals
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <wlr/types/wlr_xdg_foreign_v1.h>
|
||||
#include <wlr/types/wlr_xdg_foreign_v2.h>
|
||||
#include <wlr/types/wlr_xdg_output_v1.h>
|
||||
#include <xf86drm.h>
|
||||
#include "config.h"
|
||||
#include "list.h"
|
||||
#include "log.h"
|
||||
|
@ -60,6 +61,8 @@
|
|||
#define SWAY_XDG_SHELL_VERSION 2
|
||||
#define SWAY_LAYER_SHELL_VERSION 4
|
||||
|
||||
bool allow_unsupported_gpu = false;
|
||||
|
||||
#if WLR_HAS_DRM_BACKEND
|
||||
static void handle_drm_lease_request(struct wl_listener *listener, void *data) {
|
||||
/* 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,
|
|||
return true;
|
||||
}
|
||||
|
||||
static void detect_proprietary(struct wlr_backend *backend, void *data) {
|
||||
int drm_fd = wlr_backend_get_drm_fd(backend);
|
||||
if (drm_fd < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
drmVersion *version = drmGetVersion(drm_fd);
|
||||
if (version == NULL) {
|
||||
sway_log(SWAY_ERROR, "drmGetVersion() failed");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(version->name, "nvidia-drm") == 0) {
|
||||
if (allow_unsupported_gpu) {
|
||||
sway_log(SWAY_ERROR, "!!! Proprietary Nvidia drivers are in use !!!");
|
||||
} else {
|
||||
sway_log(SWAY_ERROR,
|
||||
"Proprietary Nvidia drivers are NOT supported. "
|
||||
"Use Nouveau. To launch sway anyway, launch with "
|
||||
"--unsupported-gpu and DO NOT report issues.");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
drmFreeVersion(version);
|
||||
}
|
||||
|
||||
bool server_init(struct sway_server *server) {
|
||||
sway_log(SWAY_DEBUG, "Initializing Wayland server");
|
||||
server->wl_display = wl_display_create();
|
||||
|
@ -128,6 +158,8 @@ bool server_init(struct sway_server *server) {
|
|||
return false;
|
||||
}
|
||||
|
||||
wlr_multi_for_each_backend(server->backend, detect_proprietary, NULL);
|
||||
|
||||
server->renderer = wlr_renderer_autocreate(server->backend);
|
||||
if (!server->renderer) {
|
||||
sway_log(SWAY_ERROR, "Failed to create renderer");
|
||||
|
|
Loading…
Reference in a new issue