From abe4bfd96ecb4716eee4484ed82f3d78c9579cc9 Mon Sep 17 00:00:00 2001 From: SuslikV Date: Tue, 24 Jan 2017 23:01:24 -0800 Subject: [PATCH] UI: Add option to always minimize to tray Closes jp9000/obs-studio#737 --- UI/data/locale/en-US.ini | 1 + UI/forms/OBSBasicSettings.ui | 20 ++++++++++++++++++-- UI/window-basic-main.cpp | 24 ++++++++++++++++++++++-- UI/window-basic-main.hpp | 2 ++ UI/window-basic-settings.cpp | 10 ++++++++++ 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 0ce1bbebd..802859d4b 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -414,6 +414,7 @@ Basic.Settings.General.RecordWhenStreaming="Automatically record when streaming" Basic.Settings.General.KeepRecordingWhenStreamStops="Keep recording when stream stops" Basic.Settings.General.SysTrayEnabled="Enable system tray icon" Basic.Settings.General.SysTrayWhenStarted="Minimize to system tray when started" +Basic.Settings.General.SystemTrayHideMinimize="Hide to system tray instead of minimize to task bar" # basic mode 'stream' settings Basic.Settings.Stream="Stream" diff --git a/UI/forms/OBSBasicSettings.ui b/UI/forms/OBSBasicSettings.ui index 3ae252e70..ea8a1ff5a 100644 --- a/UI/forms/OBSBasicSettings.ui +++ b/UI/forms/OBSBasicSettings.ui @@ -209,14 +209,24 @@ - + + + + false + + + Basic.Settings.General.SystemTrayHideMinimize + + + + Qt::Horizontal - + true @@ -4189,5 +4199,11 @@ + + systemTrayEnabled + toggled(bool) + systemTrayAlways + setEnabled(bool) + diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index fcb18835f..eb103b356 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -2787,8 +2787,13 @@ void OBSBasic::closeEvent(QCloseEvent *event) void OBSBasic::changeEvent(QEvent *event) { - /* TODO */ - UNUSED_PARAMETER(event); + if (event->type() == QEvent::WindowStateChange && + isMinimized() && + trayIcon->isVisible() && + sysTrayMinimizeToTray()) { + + ToggleShowHide(); + } } void OBSBasic::on_actionShow_Recordings_triggered() @@ -4906,6 +4911,15 @@ void OBSBasic::SetShowing(bool showing) EnablePreviewDisplay(true); setVisible(true); + + /* Unminimize window if it was hidden to tray instead of task + * bar. */ + if (sysTrayMinimizeToTray()) { + Qt::WindowStates state; + state = windowState() & ~Qt::WindowMinimized; + state |= Qt::WindowActive; + setWindowState(state); + } } } @@ -5003,3 +5017,9 @@ void OBSBasic::SystemTray(bool firstStarted) else showHide->setText(QTStr("Basic.SystemTray.Show")); } + +bool OBSBasic::sysTrayMinimizeToTray() +{ + return config_get_bool(GetGlobalConfig(), + "BasicWindow", "SysTrayMinimizeToTray"); +} diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 33591ffc0..531090aeb 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -321,6 +321,8 @@ private: void ReplayBufferClicked(); + bool sysTrayMinimizeToTray(); + public slots: void StartStreaming(); void StopStreaming(); diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index ad3c854fa..5c43567d3 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -281,6 +281,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) HookWidget(ui->keepRecordStreamStops,CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->systemTrayEnabled, CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->systemTrayWhenStarted,CHECK_CHANGED, GENERAL_CHANGED); + HookWidget(ui->systemTrayAlways, CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->snappingEnabled, CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->screenSnapping, CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->centerSnapping, CHECK_CHANGED, GENERAL_CHANGED); @@ -891,6 +892,10 @@ void OBSBasicSettings::LoadGeneralSettings() "BasicWindow", "SysTrayWhenStarted"); ui->systemTrayWhenStarted->setChecked(systemTrayWhenStarted); + bool systemTrayAlways = config_get_bool(GetGlobalConfig(), + "BasicWindow", "SysTrayMinimizeToTray"); + ui->systemTrayAlways->setChecked(systemTrayAlways); + bool snappingEnabled = config_get_bool(GetGlobalConfig(), "BasicWindow", "SnappingEnabled"); ui->snappingEnabled->setChecked(snappingEnabled); @@ -2341,6 +2346,11 @@ void OBSBasicSettings::SaveGeneralSettings() config_set_bool(GetGlobalConfig(), "BasicWindow", "SysTrayWhenStarted", ui->systemTrayWhenStarted->isChecked()); + + if (WidgetChanged(ui->systemTrayAlways)) + config_set_bool(GetGlobalConfig(), + "BasicWindow", "SysTrayMinimizeToTray", + ui->systemTrayAlways->isChecked()); } void OBSBasicSettings::SaveStream1Settings()