From 35b9c76495704e96a4f9deeaf47874f2a0f3aca9 Mon Sep 17 00:00:00 2001 From: Cody Jung Date: Wed, 5 Jan 2022 23:00:59 -0600 Subject: [PATCH] UI: Fix flash when starting minimized Rather than showing the main window, then hiding it again when the tray icon initialization happens, just don't show the main window. When deciding whether to show the window, we need to know whether the tray icon is available or not - if it's not and we don't show the window, there would be no way to restore OBS. --- UI/window-basic-main.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 386c75bdf..0bb9021b2 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -1885,9 +1885,21 @@ void OBSBasic::OBSInit() connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay); + /* Show the main window, unless the tray icon isn't available + * or neither the setting nor flag for starting minimized is set. */ + bool sysTrayEnabled = config_get_bool(App()->GlobalConfig(), + "BasicWindow", "sysTrayEnabled"); + bool sysTrayWhenStarted = config_get_bool( + App()->GlobalConfig(), "BasicWindow", "SysTrayWhenStarted"); + bool hideWindowOnStart = QSystemTrayIcon::isSystemTrayAvailable() && + sysTrayEnabled && + (opt_minimize_tray || sysTrayWhenStarted); + #ifdef _WIN32 SetWin32DropStyle(this); - show(); + + if (!hideWindowOnStart) + show(); #endif bool alwaysOnTop = config_get_bool(App()->GlobalConfig(), "BasicWindow", @@ -1911,7 +1923,8 @@ void OBSBasic::OBSInit() } #ifndef _WIN32 - show(); + if (!hideWindowOnStart) + show(); #endif /* setup stats dock */ @@ -9064,9 +9077,7 @@ void OBSBasic::SystemTray(bool firstStarted) } else { trayIcon->show(); if (firstStarted && (sysTrayWhenStarted || opt_minimize_tray)) { - QTimer::singleShot(50, this, SLOT(hide())); EnablePreviewDisplay(false); - setVisible(false); #ifdef __APPLE__ EnableOSXDockIcon(false); #endif