UI: Add option to always minimize to tray

Closes jp9000/obs-studio#737
master
SuslikV 2017-01-24 23:01:24 -08:00 committed by jp9000
parent cdf8a40bf1
commit abe4bfd96e
5 changed files with 53 additions and 4 deletions

View File

@ -414,6 +414,7 @@ Basic.Settings.General.RecordWhenStreaming="Automatically record when streaming"
Basic.Settings.General.KeepRecordingWhenStreamStops="Keep recording when stream stops" Basic.Settings.General.KeepRecordingWhenStreamStops="Keep recording when stream stops"
Basic.Settings.General.SysTrayEnabled="Enable system tray icon" Basic.Settings.General.SysTrayEnabled="Enable system tray icon"
Basic.Settings.General.SysTrayWhenStarted="Minimize to system tray when started" 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 mode 'stream' settings
Basic.Settings.Stream="Stream" Basic.Settings.Stream="Stream"

View File

@ -209,14 +209,24 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="0" colspan="2"> <item row="11" column="1">
<widget class="QCheckBox" name="systemTrayAlways">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Basic.Settings.General.SystemTrayHideMinimize</string>
</property>
</widget>
</item>
<item row="12" column="0" colspan="2">
<widget class="Line" name="line_4"> <widget class="Line" name="line_4">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="12" column="0" colspan="2"> <item row="13" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_10"> <widget class="QGroupBox" name="groupBox_10">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
@ -4189,5 +4199,11 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>systemTrayEnabled</sender>
<signal>toggled(bool)</signal>
<receiver>systemTrayAlways</receiver>
<slot>setEnabled(bool)</slot>
</connection>
</connections> </connections>
</ui> </ui>

View File

@ -2787,8 +2787,13 @@ void OBSBasic::closeEvent(QCloseEvent *event)
void OBSBasic::changeEvent(QEvent *event) void OBSBasic::changeEvent(QEvent *event)
{ {
/* TODO */ if (event->type() == QEvent::WindowStateChange &&
UNUSED_PARAMETER(event); isMinimized() &&
trayIcon->isVisible() &&
sysTrayMinimizeToTray()) {
ToggleShowHide();
}
} }
void OBSBasic::on_actionShow_Recordings_triggered() void OBSBasic::on_actionShow_Recordings_triggered()
@ -4906,6 +4911,15 @@ void OBSBasic::SetShowing(bool showing)
EnablePreviewDisplay(true); EnablePreviewDisplay(true);
setVisible(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 else
showHide->setText(QTStr("Basic.SystemTray.Show")); showHide->setText(QTStr("Basic.SystemTray.Show"));
} }
bool OBSBasic::sysTrayMinimizeToTray()
{
return config_get_bool(GetGlobalConfig(),
"BasicWindow", "SysTrayMinimizeToTray");
}

View File

@ -321,6 +321,8 @@ private:
void ReplayBufferClicked(); void ReplayBufferClicked();
bool sysTrayMinimizeToTray();
public slots: public slots:
void StartStreaming(); void StartStreaming();
void StopStreaming(); void StopStreaming();

View File

@ -281,6 +281,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
HookWidget(ui->keepRecordStreamStops,CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->keepRecordStreamStops,CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->systemTrayEnabled, CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->systemTrayEnabled, CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->systemTrayWhenStarted,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->snappingEnabled, CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->screenSnapping, CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->screenSnapping, CHECK_CHANGED, GENERAL_CHANGED);
HookWidget(ui->centerSnapping, CHECK_CHANGED, GENERAL_CHANGED); HookWidget(ui->centerSnapping, CHECK_CHANGED, GENERAL_CHANGED);
@ -891,6 +892,10 @@ void OBSBasicSettings::LoadGeneralSettings()
"BasicWindow", "SysTrayWhenStarted"); "BasicWindow", "SysTrayWhenStarted");
ui->systemTrayWhenStarted->setChecked(systemTrayWhenStarted); ui->systemTrayWhenStarted->setChecked(systemTrayWhenStarted);
bool systemTrayAlways = config_get_bool(GetGlobalConfig(),
"BasicWindow", "SysTrayMinimizeToTray");
ui->systemTrayAlways->setChecked(systemTrayAlways);
bool snappingEnabled = config_get_bool(GetGlobalConfig(), bool snappingEnabled = config_get_bool(GetGlobalConfig(),
"BasicWindow", "SnappingEnabled"); "BasicWindow", "SnappingEnabled");
ui->snappingEnabled->setChecked(snappingEnabled); ui->snappingEnabled->setChecked(snappingEnabled);
@ -2341,6 +2346,11 @@ void OBSBasicSettings::SaveGeneralSettings()
config_set_bool(GetGlobalConfig(), "BasicWindow", config_set_bool(GetGlobalConfig(), "BasicWindow",
"SysTrayWhenStarted", "SysTrayWhenStarted",
ui->systemTrayWhenStarted->isChecked()); ui->systemTrayWhenStarted->isChecked());
if (WidgetChanged(ui->systemTrayAlways))
config_set_bool(GetGlobalConfig(),
"BasicWindow", "SysTrayMinimizeToTray",
ui->systemTrayAlways->isChecked());
} }
void OBSBasicSettings::SaveStream1Settings() void OBSBasicSettings::SaveStream1Settings()