diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 5e3a5ac..88190d0 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,6 +1,30 @@ // Prevents additional console window on Windows in release, DO NOT REMOVE!! #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] +// Automatically sets environment variables to work around issues with WebKitGTK on NVIDIA cards. +// When running in Wayland, it sets __NV_DISABLE_EXPLICIT_SYNC to 1 +// When running in X11, it sets WEBKIT_DISABLE_COMPOSITING_MODE to 1 +#[cfg(target_os = "linux")] +fn fix_nvidia() { + let variable = match std::env::var("GDK_BACKEND") { + Ok(val) => { + match val.as_str() { + "wayland" => "__NV_DISABLE_EXPLICIT_SYNC", + _ => "WEBKIT_DISABLE_COMPOSITING_MODE" // if GDK_BACKEND is not "wayland", assume X11 is in use + } + }, + Err(_) => "WEBKIT_DISABLE_COMPOSITING_MODE" // if GDK_BACKEND is blank, assume X11 is in use + }; + + // SAFETY: There is no other thread where this is ran. + unsafe { + std::env::set_var(variable, "1"); + } +} + fn main() { + #[cfg(target_os = "linux")] + fix_nvidia(); + modfriend_lib::run() }