123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- /******************************************************************************
- Copyright (C) 2023 by Lain Bailey <[email protected]>
- Zachary Lund <[email protected]>
- Philippe Groarke <[email protected]>
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- ******************************************************************************/
- #include "OBSBasic.hpp"
- extern bool opt_minimize_tray;
- void OBSBasic::SystemTrayInit()
- {
- #ifdef __APPLE__
- QIcon trayIconFile = QIcon(":/res/images/obs_macos.svg");
- trayIconFile.setIsMask(true);
- #else
- QIcon trayIconFile = QIcon(":/res/images/obs.png");
- #endif
- trayIcon.reset(new QSystemTrayIcon(QIcon::fromTheme("obs-tray", trayIconFile), this));
- trayIcon->setToolTip("OBS Studio");
- showHide = new QAction(QTStr("Basic.SystemTray.Show"), trayIcon.data());
- sysTrayStream =
- new QAction(StreamingActive() ? QTStr("Basic.Main.StopStreaming") : QTStr("Basic.Main.StartStreaming"),
- trayIcon.data());
- sysTrayRecord =
- new QAction(RecordingActive() ? QTStr("Basic.Main.StopRecording") : QTStr("Basic.Main.StartRecording"),
- trayIcon.data());
- sysTrayReplayBuffer = new QAction(ReplayBufferActive() ? QTStr("Basic.Main.StopReplayBuffer")
- : QTStr("Basic.Main.StartReplayBuffer"),
- trayIcon.data());
- sysTrayVirtualCam = new QAction(VirtualCamActive() ? QTStr("Basic.Main.StopVirtualCam")
- : QTStr("Basic.Main.StartVirtualCam"),
- trayIcon.data());
- exit = new QAction(QTStr("Exit"), trayIcon.data());
- trayMenu = new QMenu;
- previewProjector = new QMenu(QTStr("Projector.Open.Preview"));
- studioProgramProjector = new QMenu(QTStr("Projector.Open.Program"));
- OBSBasic::updateSysTrayProjectorMenu();
- trayMenu->addAction(showHide);
- trayMenu->addSeparator();
- trayMenu->addMenu(previewProjector);
- trayMenu->addMenu(studioProgramProjector);
- trayMenu->addSeparator();
- trayMenu->addAction(sysTrayStream);
- trayMenu->addAction(sysTrayRecord);
- trayMenu->addAction(sysTrayReplayBuffer);
- trayMenu->addAction(sysTrayVirtualCam);
- trayMenu->addSeparator();
- trayMenu->addAction(exit);
- trayIcon->setContextMenu(trayMenu);
- trayIcon->show();
- if (outputHandler && !outputHandler->replayBuffer)
- sysTrayReplayBuffer->setEnabled(false);
- sysTrayVirtualCam->setEnabled(vcamEnabled);
- if (Active())
- OnActivate(true);
- connect(trayIcon.data(), &QSystemTrayIcon::activated, this, &OBSBasic::IconActivated);
- connect(showHide, &QAction::triggered, this, &OBSBasic::ToggleShowHide);
- connect(sysTrayStream, &QAction::triggered, this, &OBSBasic::StreamActionTriggered);
- connect(sysTrayRecord, &QAction::triggered, this, &OBSBasic::RecordActionTriggered);
- connect(sysTrayReplayBuffer.data(), &QAction::triggered, this, &OBSBasic::ReplayBufferActionTriggered);
- connect(sysTrayVirtualCam.data(), &QAction::triggered, this, &OBSBasic::VirtualCamActionTriggered);
- connect(exit, &QAction::triggered, this, &OBSBasic::close);
- }
- void OBSBasic::IconActivated(QSystemTrayIcon::ActivationReason reason)
- {
- OBSBasic::updateSysTrayProjectorMenu();
- #ifdef __APPLE__
- UNUSED_PARAMETER(reason);
- #else
- if (reason == QSystemTrayIcon::Trigger) {
- EnablePreviewDisplay(previewEnabled && !isVisible());
- ToggleShowHide();
- }
- #endif
- }
- void OBSBasic::SysTrayNotify(const QString &text, QSystemTrayIcon::MessageIcon n)
- {
- if (trayIcon && trayIcon->isVisible() && QSystemTrayIcon::supportsMessages()) {
- QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon(n);
- trayIcon->showMessage("OBS Studio", text, icon, 10000);
- }
- }
- void OBSBasic::SystemTray(bool firstStarted)
- {
- if (!QSystemTrayIcon::isSystemTrayAvailable())
- return;
- if (!trayIcon && !firstStarted)
- return;
- bool sysTrayWhenStarted = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SysTrayWhenStarted");
- bool sysTrayEnabled = config_get_bool(App()->GetUserConfig(), "BasicWindow", "SysTrayEnabled");
- if (firstStarted)
- SystemTrayInit();
- if (!sysTrayEnabled) {
- trayIcon->hide();
- } else {
- trayIcon->show();
- if (firstStarted && (sysTrayWhenStarted || opt_minimize_tray)) {
- EnablePreviewDisplay(false);
- #ifdef __APPLE__
- EnableOSXDockIcon(false);
- #endif
- opt_minimize_tray = false;
- }
- }
- if (isVisible())
- showHide->setText(QTStr("Basic.SystemTray.Hide"));
- else
- showHide->setText(QTStr("Basic.SystemTray.Show"));
- }
- bool OBSBasic::sysTrayMinimizeToTray()
- {
- return config_get_bool(App()->GetUserConfig(), "BasicWindow", "SysTrayMinimizeToTray");
- }
- void OBSBasic::updateSysTrayProjectorMenu()
- {
- previewProjector->clear();
- studioProgramProjector->clear();
- AddProjectorMenuMonitors(previewProjector, this, &OBSBasic::OpenPreviewProjector);
- previewProjector->addSeparator();
- previewProjector->addAction(QTStr("Projector.Window"), this, &OBSBasic::OpenPreviewWindow);
- AddProjectorMenuMonitors(studioProgramProjector, this, &OBSBasic::OpenStudioProgramProjector);
- studioProgramProjector->addSeparator();
- studioProgramProjector->addAction(QTStr("Projector.Window"), this, &OBSBasic::OpenStudioProgramWindow);
- }
|