Skip to content

Commit f09a6a6

Browse files
Fix Linux CEF graphics fallback
1 parent 138ba3a commit f09a6a6

4 files changed

Lines changed: 59 additions & 10 deletions

File tree

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#!/bin/bash
2-
# Simple wrapper that preserves LD_LIBRARY_PATH from hooks
32
cd "$(dirname "$0")"
3+
4+
athas_args=()
5+
case "${ATHAS_ENABLE_LINUX_GPU:-}" in
6+
1|[Tt][Rr][Uu][Ee])
7+
;;
8+
*)
9+
export WEBKIT_DISABLE_DMABUF_RENDERER="${WEBKIT_DISABLE_DMABUF_RENDERER:-1}"
10+
export LIBGL_ALWAYS_SOFTWARE="${LIBGL_ALWAYS_SOFTWARE:-1}"
11+
athas_args+=(--disable-gpu --disable-gpu-compositing)
12+
;;
13+
esac
14+
415
if [ -x ./usr/bin/athas ]; then
5-
exec ./usr/bin/athas "$@"
16+
exec ./usr/bin/athas "${athas_args[@]}" "$@"
617
fi
7-
exec ./usr/bin/athas-code "$@"
18+
exec ./usr/bin/athas-code "${athas_args[@]}" "$@"

src-tauri/src/bootstrap/linux.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
pub fn configure_graphics_fallback() {
2+
if linux_gpu_enabled() {
3+
return;
4+
}
5+
6+
set_env_if_missing("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
7+
8+
#[cfg(feature = "linux")]
9+
set_env_if_missing("LIBGL_ALWAYS_SOFTWARE", "1");
10+
}
11+
12+
#[cfg(feature = "linux")]
13+
pub fn cef_command_line_args() -> Vec<(&'static str, Option<&'static str>)> {
14+
if linux_gpu_enabled() {
15+
return Vec::new();
16+
}
17+
18+
vec![("--disable-gpu", None), ("--disable-gpu-compositing", None)]
19+
}
20+
21+
fn linux_gpu_enabled() -> bool {
22+
std::env::var("ATHAS_ENABLE_LINUX_GPU").is_ok_and(|value| {
23+
let value = value.trim();
24+
value == "1" || value.eq_ignore_ascii_case("true")
25+
})
26+
}
27+
28+
fn set_env_if_missing(key: &str, value: &str) {
29+
if std::env::var_os(key).is_none() {
30+
// SAFETY: Called during process bootstrap before Tauri starts worker threads.
31+
unsafe {
32+
std::env::set_var(key, value);
33+
}
34+
}
35+
}

src-tauri/src/bootstrap/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
#[cfg(target_os = "linux")]
2+
pub mod linux;
3+
14
#[cfg(target_os = "macos")]
25
pub mod macos;

src-tauri/src/main.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ fn main() {
2424
let _ = rustls::crypto::ring::default_provider().install_default();
2525

2626
#[cfg(target_os = "linux")]
27-
if cfg!(not(feature = "linux")) && std::env::var("WEBKIT_DISABLE_DMABUF_RENDERER").is_err() {
28-
// SAFETY: Called at program start before any threads are spawned
29-
unsafe {
30-
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
31-
}
32-
}
27+
bootstrap::linux::configure_graphics_fallback();
3328

3429
#[cfg(target_os = "macos")]
3530
bootstrap::macos::disable_macos_autofill_heuristics();
3631

37-
tauri::Builder::<AthasRuntime>::new()
32+
let builder = tauri::Builder::<AthasRuntime>::new();
33+
34+
#[cfg(all(target_os = "linux", feature = "linux"))]
35+
let builder = builder.command_line_args(bootstrap::linux::cef_command_line_args());
36+
37+
builder
3838
.plugin(tauri_plugin_single_instance::init(|app, args, cwd| {
3939
app_setup::handle_single_instance_open(app, args, cwd);
4040
}))

0 commit comments

Comments
 (0)