From 946a925f41858d3b968b83363437684b4e8c6e96 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Thu, 4 Dec 2025 18:18:13 -0500 Subject: [PATCH] disable dma buf on wayland linux (#4957) * disable dma buf on linux * allow configuring --- packages/desktop/src/app.rs | 27 +++++++++++++++++++++++++++ packages/desktop/src/config.rs | 11 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/packages/desktop/src/app.rs b/packages/desktop/src/app.rs index 7c5892b61..73f947541 100644 --- a/packages/desktop/src/app.rs +++ b/packages/desktop/src/app.rs @@ -32,6 +32,7 @@ pub(crate) struct App { pub(crate) control_flow: ControlFlow, pub(crate) is_visible_before_start: bool, pub(crate) exit_on_last_window_close: bool, + pub(crate) disable_dma_buf_on_wayland: bool, pub(crate) webviews: HashMap, pub(crate) float_all: bool, pub(crate) show_devtools: bool, @@ -61,6 +62,7 @@ impl App { let app = Self { exit_on_last_window_close: cfg.exit_on_last_window_close, + disable_dma_buf_on_wayland: cfg.disable_dma_buf_on_wayland, is_visible_before_start: true, webviews: HashMap::new(), control_flow: ControlFlow::Wait, @@ -101,6 +103,9 @@ impl App { #[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))] app.connect_preserve_window_state_handler(); + // Make sure to disable DMA buffer rendering on Linux Wayland sessions + app.disable_dma_buf(); + (event_loop, app) } @@ -609,6 +614,28 @@ impl App { }); } } + + /// Disable DMA buffer rendering on Linux Wayland sessions to avoid bugs with WebKitGTK + fn disable_dma_buf(&self) { + if cfg!(target_os = "linux") && self.disable_dma_buf_on_wayland { + static INIT: std::sync::Once = std::sync::Once::new(); + INIT.call_once(|| { + if std::path::Path::new("/dev/dri").exists() + && std::env::var("XDG_SESSION_TYPE").unwrap_or_default() == "wayland" + { + // Gnome Webkit is currently buggy under Wayland and KDE, so we will run it with XWayland mode. + // See: https://github.com/DioxusLabs/dioxus/issues/3667 + unsafe { + // Disable explicit sync for NVIDIA drivers on Linux when using Way + std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1"); + } + } + unsafe { + std::env::set_var("GDK_BACKEND", "x11"); + } + }); + } + } } #[derive(Debug, serde::Serialize, serde::Deserialize)] diff --git a/packages/desktop/src/config.rs b/packages/desktop/src/config.rs index fb35bb43c..ec570cdc3 100644 --- a/packages/desktop/src/config.rs +++ b/packages/desktop/src/config.rs @@ -67,6 +67,7 @@ pub struct Config { pub(crate) window_close_behavior: WindowCloseBehaviour, pub(crate) custom_event_handler: Option, pub(crate) disable_file_drop_handler: bool, + pub(crate) disable_dma_buf_on_wayland: bool, pub(crate) additional_windows_args: Option, #[allow(clippy::type_complexity)] @@ -118,6 +119,7 @@ impl Config { window_close_behavior: WindowCloseBehaviour::WindowCloses, custom_event_handler: None, disable_file_drop_handler: false, + disable_dma_buf_on_wayland: true, on_window: None, additional_windows_args: None, } @@ -315,6 +317,15 @@ impl Config { self } + /// Set whether or not DMA-BUF usage should be disabled on Wayland. + /// + /// Defaults to true to avoid issues on some systems. If you want to enable DMA-BUF usage, set this to false. + /// See + pub fn with_disable_dma_buf_on_wayland(mut self, disable: bool) -> Self { + self.disable_dma_buf_on_wayland = disable; + self + } + /// Add additional windows only launch arguments for webview2 pub fn with_windows_browser_args(mut self, additional_args: impl ToString) -> Self { self.additional_windows_args = Some(additional_args.to_string());