Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/desktop/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,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<WindowId, WebviewInstance>,
pub(crate) float_all: bool,
pub(crate) show_devtools: bool,
Expand Down Expand Up @@ -62,6 +63,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,
Expand Down Expand Up @@ -102,6 +104,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)
}

Expand Down Expand Up @@ -618,6 +623,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)]
Expand Down
11 changes: 11 additions & 0 deletions packages/desktop/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct Config {
pub(crate) window_close_behavior: WindowCloseBehaviour,
pub(crate) custom_event_handler: Option<CustomEventHandler>,
pub(crate) disable_file_drop_handler: bool,
pub(crate) disable_dma_buf_on_wayland: bool,

#[allow(clippy::type_complexity)]
pub(crate) on_window: Option<Box<dyn FnMut(Arc<Window>, &mut VirtualDom) + 'static>>,
Expand Down Expand Up @@ -117,6 +118,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,
}
}
Expand Down Expand Up @@ -312,6 +314,15 @@ impl Config {
self.on_window = Some(Box::new(f));
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 <https://github.com/DioxusLabs/dioxus/issues/4528#issuecomment-3476430611>
pub fn with_disable_dma_buf_on_wayland(mut self, disable: bool) -> Self {
self.disable_dma_buf_on_wayland = disable;
self
}
}

impl Default for Config {
Expand Down
Loading