feat: add persistent Force X11 setting for Wayland crash workaround

Add a toggle in Settings > Appearance to force X11 (XWayland) backend
on Wayland sessions. Persisted in graphics_settings.db, env var
QBZ_FORCE_X11=1|0 overrides for crash recovery. Also fixes the
display server log to report effective GDK backend instead of
session type.
This commit is contained in:
vicrodh committed 2026-02-10 07:18:15 -06:00
1 parent d3d719c609
commit 0f31dcd310
9 files changed
+83 -8

No files matched your search

+36 -3
View File
@@ -5,6 +5,8 @@
//! //!
//! - hardware_acceleration: opt-in GPU rendering (default: off) //! - hardware_acceleration: opt-in GPU rendering (default: off)
//! Env var QBZ_HARDWARE_ACCEL=1|0 always overrides the stored value. //! Env var QBZ_HARDWARE_ACCEL=1|0 always overrides the stored value.
//! - force_x11: force X11/XWayland backend on Wayland sessions (default: off)
//! Env var QBZ_FORCE_X11=1|0 always overrides the stored value.
use rusqlite::{Connection, params}; use rusqlite::{Connection, params};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@@ -14,12 +16,15 @@ use std::sync::{Arc, Mutex};
pub struct GraphicsSettings { pub struct GraphicsSettings {
/// Enable hardware-accelerated rendering (requires restart) /// Enable hardware-accelerated rendering (requires restart)
pub hardware_acceleration: bool, pub hardware_acceleration: bool,
/// Force X11 (XWayland) backend on Wayland sessions (requires restart)
pub force_x11: bool,
} }
impl Default for GraphicsSettings { impl Default for GraphicsSettings {
fn default() -> Self { fn default() -> Self {
Self { Self {
hardware_acceleration: false, hardware_acceleration: false,
force_x11: false,
} }
} }
} }
@@ -44,22 +49,29 @@ impl GraphicsSettingsStore {
conn.execute_batch( conn.execute_batch(
"CREATE TABLE IF NOT EXISTS graphics_settings ( "CREATE TABLE IF NOT EXISTS graphics_settings (
id INTEGER PRIMARY KEY CHECK (id = 1), id INTEGER PRIMARY KEY CHECK (id = 1),
hardware_acceleration INTEGER NOT NULL DEFAULT 0 hardware_acceleration INTEGER NOT NULL DEFAULT 0,
force_x11 INTEGER NOT NULL DEFAULT 0
); );
INSERT OR IGNORE INTO graphics_settings (id, hardware_acceleration) VALUES (1, 0);" INSERT OR IGNORE INTO graphics_settings (id, hardware_acceleration, force_x11) VALUES (1, 0, 0);"
).map_err(|e| format!("Failed to create graphics settings table: {}", e))?; ).map_err(|e| format!("Failed to create graphics settings table: {}", e))?;
// Migration: add force_x11 column for existing databases
let _ = conn.execute_batch(
"ALTER TABLE graphics_settings ADD COLUMN force_x11 INTEGER NOT NULL DEFAULT 0;"
);
Ok(Self { conn }) Ok(Self { conn })
} }
pub fn get_settings(&self) -> Result<GraphicsSettings, String> { pub fn get_settings(&self) -> Result<GraphicsSettings, String> {
self.conn self.conn
.query_row( .query_row(
"SELECT hardware_acceleration FROM graphics_settings WHERE id = 1", "SELECT hardware_acceleration, force_x11 FROM graphics_settings WHERE id = 1",
[], [],
|row| { |row| {
Ok(GraphicsSettings { Ok(GraphicsSettings {
hardware_acceleration: row.get::<_, i64>(0)? != 0, hardware_acceleration: row.get::<_, i64>(0)? != 0,
force_x11: row.get::<_, i64>(1)? != 0,
}) })
}, },
) )
@@ -75,6 +87,16 @@ impl GraphicsSettingsStore {
.map_err(|e| format!("Failed to set hardware_acceleration: {}", e))?; .map_err(|e| format!("Failed to set hardware_acceleration: {}", e))?;
Ok(()) Ok(())
} }
pub fn set_force_x11(&self, enabled: bool) -> Result<(), String> {
self.conn
.execute(
"UPDATE graphics_settings SET force_x11 = ?1 WHERE id = 1",
params![enabled as i64],
)
.map_err(|e| format!("Failed to set force_x11: {}", e))?;
Ok(())
}
} }
/// Thread-safe wrapper for Tauri state management /// Thread-safe wrapper for Tauri state management
@@ -117,3 +139,14 @@ pub fn set_hardware_acceleration(
let store = guard.as_ref().ok_or("Graphics settings store not initialized")?; let store = guard.as_ref().ok_or("Graphics settings store not initialized")?;
store.set_hardware_acceleration(enabled) store.set_hardware_acceleration(enabled)
} }
#[tauri::command]
pub fn set_force_x11(
state: tauri::State<'_, GraphicsSettingsState>,
enabled: bool,
) -> Result<(), String> {
log::info!("[GraphicsSettings] Setting force_x11 to {} (restart required)", enabled);
let guard = state.store.lock().map_err(|e| format!("Lock error: {}", e))?;
let store = guard.as_ref().ok_or("Graphics settings store not initialized")?;
store.set_force_x11(enabled)
}
+1
View File
@@ -119,6 +119,7 @@ pub use graphics_settings::{
GraphicsSettingsState, GraphicsSettingsState,
get_graphics_settings, get_graphics_settings,
set_hardware_acceleration, set_hardware_acceleration,
set_force_x11,
}; };
pub use window_settings::{ pub use window_settings::{
+1
View File
@@ -995,6 +995,7 @@ pub fn run() {
// Graphics settings commands // Graphics settings commands
config::graphics_settings::get_graphics_settings, config::graphics_settings::get_graphics_settings,
config::graphics_settings::set_hardware_acceleration, config::graphics_settings::set_hardware_acceleration,
config::graphics_settings::set_force_x11,
// Window settings commands // Window settings commands
config::window_settings::get_window_settings, config::window_settings::get_window_settings,
config::window_settings::set_use_system_titlebar, config::window_settings::set_use_system_titlebar,
+17 -5
View File
@@ -126,11 +126,10 @@ fn main() {
// Graphics settings: hardware acceleration opt-in (from Settings > Appearance) // Graphics settings: hardware acceleration opt-in (from Settings > Appearance)
// Default is OFF — safest for AppImage across heterogeneous hardware. // Default is OFF — safest for AppImage across heterogeneous hardware.
// Env var QBZ_HARDWARE_ACCEL=1|0 ALWAYS overrides the DB value (crash recovery). // Env var QBZ_HARDWARE_ACCEL=1|0 ALWAYS overrides the DB value (crash recovery).
let hw_accel_db = qbz_nix_lib::config::graphics_settings::GraphicsSettingsStore::new() let graphics_db = qbz_nix_lib::config::graphics_settings::GraphicsSettingsStore::new()
.ok() .ok()
.and_then(|store| store.get_settings().ok()) .and_then(|store| store.get_settings().ok());
.map(|s| s.hardware_acceleration) let hw_accel_db = graphics_db.as_ref().map(|s| s.hardware_acceleration).unwrap_or(false);
.unwrap_or(false);
let hardware_accel = match std::env::var("QBZ_HARDWARE_ACCEL").as_deref() { let hardware_accel = match std::env::var("QBZ_HARDWARE_ACCEL").as_deref() {
Ok("1") => { Ok("1") => {
qbz_nix_lib::logging::log_startup("[QBZ] Env override: QBZ_HARDWARE_ACCEL=1 (GPU rendering forced on)"); qbz_nix_lib::logging::log_startup("[QBZ] Env override: QBZ_HARDWARE_ACCEL=1 (GPU rendering forced on)");
@@ -159,7 +158,20 @@ fn main() {
// User overrides // User overrides
let force_dmabuf = std::env::var("QBZ_FORCE_DMABUF").as_deref() == Ok("1"); let force_dmabuf = std::env::var("QBZ_FORCE_DMABUF").as_deref() == Ok("1");
let disable_dmabuf = std::env::var("QBZ_DISABLE_DMABUF").as_deref() == Ok("1"); let disable_dmabuf = std::env::var("QBZ_DISABLE_DMABUF").as_deref() == Ok("1");
let force_x11 = std::env::var("QBZ_FORCE_X11").as_deref() == Ok("1");
// Force X11: persistent setting from DB, env var overrides (crash recovery)
let force_x11_db = graphics_db.as_ref().map(|s| s.force_x11).unwrap_or(false);
let force_x11 = match std::env::var("QBZ_FORCE_X11").as_deref() {
Ok("1") => {
qbz_nix_lib::logging::log_startup("[QBZ] Env override: QBZ_FORCE_X11=1");
true
}
Ok("0") => {
qbz_nix_lib::logging::log_startup("[QBZ] Env override: QBZ_FORCE_X11=0");
false
}
_ => force_x11_db,
};
// Diagnostic logging (display server logged after GDK backend selection below) // Diagnostic logging (display server logged after GDK backend selection below)
if has_nvidia { if has_nvidia {
@@ -265,6 +265,7 @@
let developerCollapsed = $state(true); let developerCollapsed = $state(true);
let forceDmabuf = $state(false); let forceDmabuf = $state(false);
let hardwareAcceleration = $state(false); let hardwareAcceleration = $state(false);
let forceX11 = $state(false);
let showLogsModal = $state(false); let showLogsModal = $state(false);
// Navigation section IDs with translation keys // Navigation section IDs with translation keys
@@ -892,6 +893,7 @@
// Load graphics settings // Load graphics settings
invoke('get_graphics_settings').then((settings: any) => { invoke('get_graphics_settings').then((settings: any) => {
hardwareAcceleration = settings.hardware_acceleration; hardwareAcceleration = settings.hardware_acceleration;
forceX11 = settings.force_x11;
}).catch(() => {}); }).catch(() => {});
// Subscribe to offline state changes // Subscribe to offline state changes
@@ -2717,6 +2719,17 @@
} }
} }
async function handleForceX11Change(enabled: boolean) {
try {
await invoke('set_force_x11', { enabled });
forceX11 = enabled;
showToast($t('settings.developer.restartRequired'), 'info');
} catch (err) {
console.error('Failed to set force_x11:', err);
showToast(String(err), 'error');
}
}
async function handleForceDmabufChange(enabled: boolean) { async function handleForceDmabufChange(enabled: boolean) {
try { try {
await invoke('set_developer_force_dmabuf', { enabled }); await invoke('set_developer_force_dmabuf', { enabled });
@@ -3224,6 +3237,13 @@
</div> </div>
<Toggle enabled={hardwareAcceleration} onchange={(v) => handleHardwareAccelerationChange(v)} /> <Toggle enabled={hardwareAcceleration} onchange={(v) => handleHardwareAccelerationChange(v)} />
</div> </div>
<div class="setting-row">
<div class="setting-info">
<span class="setting-label">{$t('settings.appearance.forceX11')}</span>
<span class="setting-desc">{$t('settings.appearance.forceX11Desc')}</span>
</div>
<Toggle enabled={forceX11} onchange={(v) => handleForceX11Change(v)} />
</div>
<!-- System Tray subsection --> <!-- System Tray subsection -->
<h4 class="subsection-title">{$t('settings.appearance.tray.title')}</h4> <h4 class="subsection-title">{$t('settings.appearance.tray.title')}</h4>
+2
View File
@@ -642,6 +642,8 @@
}, },
"hardwareAcceleration": "Hardwarebeschleunigung (GPU)", "hardwareAcceleration": "Hardwarebeschleunigung (GPU)",
"hardwareAccelerationDesc": "GPU-beschleunigtes Rendering aktivieren. Standardmäßig deaktiviert für maximale Kompatibilität. Falls QBZ nach dem Aktivieren beim Start abstürzt: QBZ_HARDWARE_ACCEL=0 qbz", "hardwareAccelerationDesc": "GPU-beschleunigtes Rendering aktivieren. Standardmäßig deaktiviert für maximale Kompatibilität. Falls QBZ nach dem Aktivieren beim Start abstürzt: QBZ_HARDWARE_ACCEL=0 qbz",
"forceX11": "X11-Backend erzwingen (Wayland)",
"forceX11Desc": "X11 (XWayland) statt nativem Wayland verwenden. Hilft bei Abstürzen mit bestimmten NVIDIA/Wayland-Konfigurationen. Neustart erforderlich. Override: QBZ_FORCE_X11=0 qbz",
"tray": { "tray": {
"title": "Systemtray", "title": "Systemtray",
"enableTray": "Tray-Symbol aktivieren", "enableTray": "Tray-Symbol aktivieren",
+2
View File
@@ -663,6 +663,8 @@
}, },
"hardwareAcceleration": "Hardware acceleration (GPU)", "hardwareAcceleration": "Hardware acceleration (GPU)",
"hardwareAccelerationDesc": "Enable GPU-accelerated rendering. Disabled by default for maximum compatibility. If QBZ crashes on startup after enabling, run: QBZ_HARDWARE_ACCEL=0 qbz", "hardwareAccelerationDesc": "Enable GPU-accelerated rendering. Disabled by default for maximum compatibility. If QBZ crashes on startup after enabling, run: QBZ_HARDWARE_ACCEL=0 qbz",
"forceX11": "Force X11 backend (Wayland)",
"forceX11Desc": "Use X11 (XWayland) instead of native Wayland. Helps with crashes on some NVIDIA/Wayland setups. Requires restart. Override: QBZ_FORCE_X11=0 qbz",
"tray": { "tray": {
"title": "System Tray", "title": "System Tray",
"enableTray": "Enable tray icon", "enableTray": "Enable tray icon",
+2
View File
@@ -663,6 +663,8 @@
}, },
"hardwareAcceleration": "Aceleración por hardware (GPU)", "hardwareAcceleration": "Aceleración por hardware (GPU)",
"hardwareAccelerationDesc": "Habilitar renderizado acelerado por GPU. Desactivado por defecto para máxima compatibilidad. Si QBZ se cierra al iniciar después de activar esto, ejecuta: QBZ_HARDWARE_ACCEL=0 qbz", "hardwareAccelerationDesc": "Habilitar renderizado acelerado por GPU. Desactivado por defecto para máxima compatibilidad. Si QBZ se cierra al iniciar después de activar esto, ejecuta: QBZ_HARDWARE_ACCEL=0 qbz",
"forceX11": "Forzar backend X11 (Wayland)",
"forceX11Desc": "Usar X11 (XWayland) en lugar de Wayland nativo. Ayuda con crashes en configuraciones NVIDIA/Wayland. Requiere reinicio. Override: QBZ_FORCE_X11=0 qbz",
"tray": { "tray": {
"title": "Bandeja del Sistema", "title": "Bandeja del Sistema",
"enableTray": "Habilitar icono de bandeja", "enableTray": "Habilitar icono de bandeja",
+2
View File
@@ -642,6 +642,8 @@
}, },
"hardwareAcceleration": "Accélération matérielle (GPU)", "hardwareAcceleration": "Accélération matérielle (GPU)",
"hardwareAccelerationDesc": "Activer le rendu accéléré par GPU. Désactivé par défaut pour une compatibilité maximale. Si QBZ plante au démarrage après activation : QBZ_HARDWARE_ACCEL=0 qbz", "hardwareAccelerationDesc": "Activer le rendu accéléré par GPU. Désactivé par défaut pour une compatibilité maximale. Si QBZ plante au démarrage après activation : QBZ_HARDWARE_ACCEL=0 qbz",
"forceX11": "Forcer le backend X11 (Wayland)",
"forceX11Desc": "Utiliser X11 (XWayland) au lieu de Wayland natif. Aide avec les plantages sur certaines configurations NVIDIA/Wayland. Redémarrage requis. Override : QBZ_FORCE_X11=0 qbz",
"tray": { "tray": {
"title": "Barre d'état système", "title": "Barre d'état système",
"enableTray": "Activer l'icône dans la barre système", "enableTray": "Activer l'icône dans la barre système",