From dec620ee4fbc60d567568924463efbab52a22f4d Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 9 Feb 2026 13:30:26 -0600 Subject: [PATCH] fix(window): create main window programmatically for correct decorations On Linux/Wayland, windows created with decorations:false cannot reliably switch to decorations:true at runtime - the WM buttons render but don't function until a maximize/restore cycle. Fix by removing the declarative window from tauri.conf.json and creating it programmatically in the setup hook with the correct decorations value from the start. The WM sees the right state when the window is first mapped, so buttons work immediately. Also fixes the empty frame flash from visible:false + early show(). --- src-tauri/src/lib.rs | 41 ++++++++++++++++++++++++++------------- src-tauri/tauri.conf.json | 16 +-------------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3c0489ab3..8075a4eef 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -277,20 +277,33 @@ pub fn run() { .manage(AppState::with_device_and_settings(saved_device, audio_settings)) .manage(user_data_paths) .setup(move |app| { - // Apply window decorations before showing the window. - // The window starts with visible:false so the WM sees correct - // decoration state when it is first mapped (shown). - if let Some(main_window) = app.get_webview_window("main") { - if use_system_titlebar { - log::info!("Enabling system window decorations (user setting)"); - if let Err(e) = main_window.set_decorations(true) { - log::error!("Failed to set window decorations: {}", e); - } - } - if let Err(e) = main_window.show() { - log::error!("Failed to show main window: {}", e); - } - } + // Create main window programmatically so we can set the correct + // decoration state at creation time. On Linux/Wayland, windows + // created with decorations:false cannot reliably switch to + // decorations:true at runtime (WM buttons don't work). By + // creating the window with the right value from the start, the + // WM sees the correct state when the window is first mapped. + log::info!( + "Creating main window (decorations={})", + use_system_titlebar + ); + tauri::WebviewWindowBuilder::new( + app, + "main", + tauri::WebviewUrl::App(std::path::PathBuf::from("index.html")), + ) + .title("QBZ") + .inner_size(1280.0, 800.0) + .min_inner_size(800.0, 600.0) + .decorations(use_system_titlebar) + .transparent(true) + .resizable(true) + .zoom_hotkeys_enabled(true) + .build() + .map_err(|e| { + log::error!("Failed to create main window: {}", e); + e + })?; // Initialize system tray icon (only if enabled) if enable_tray { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index eade01ec6..1c790c28c 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -10,21 +10,7 @@ "frontendDist": "../build" }, "app": { - "windows": [ - { - "label": "main", - "title": "QBZ", - "width": 1280, - "height": 800, - "minWidth": 800, - "minHeight": 600, - "decorations": false, - "transparent": true, - "visible": false, - "resizable": true, - "zoomHotkeysEnabled": true - } - ], + "windows": [], "security": { "csp": null, "assetProtocol": {