UI: Only inhibit when active or if projector open

Having sleep or screensavers inhibited at all times was causing some
annoyances for people.  Sleep/screensavers are now only inhibited when
the program is active or when a projector is open.
This commit is contained in:
jp9000 2015-11-16 09:08:55 -08:00
parent 14bfa07168
commit 34bbc444eb
5 changed files with 60 additions and 14 deletions

View file

@ -524,7 +524,15 @@ bool OBSApp::InitTheme()
OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store)
: QApplication(argc, argv),
profilerNameStore(store)
{}
{
sleepInhibitor = os_inhibit_sleep_create("OBS Video/audio");
}
OBSApp::~OBSApp()
{
os_inhibit_sleep_set_active(sleepInhibitor, false);
os_inhibit_sleep_destroy(sleepInhibitor);
}
static void move_basic_to_profiles(void)
{

View file

@ -24,6 +24,7 @@
#include <util/lexer.h>
#include <util/profiler.h>
#include <util/util.hpp>
#include <util/platform.h>
#include <string>
#include <memory>
#include <vector>
@ -65,6 +66,9 @@ private:
QPointer<OBSMainWindow> mainWindow;
profiler_name_store_t *profilerNameStore = nullptr;
os_inhibit_t *sleepInhibitor = nullptr;
int sleepInhibitRefs = 0;
bool InitGlobalConfig();
bool InitGlobalConfigDefaults();
bool InitLocale();
@ -72,6 +76,7 @@ private:
public:
OBSApp(int &argc, char **argv, profiler_name_store_t *store);
~OBSApp();
void AppInit();
bool OBSInit();
@ -109,6 +114,21 @@ public:
const char *OutputAudioSource() const;
const char *GetRenderModule() const;
inline void IncrementSleepInhibition()
{
if (!sleepInhibitor) return;
if (sleepInhibitRefs++ == 0)
os_inhibit_sleep_set_active(sleepInhibitor, true);
}
inline void DecrementSleepInhibition()
{
if (!sleepInhibitor) return;
if (sleepInhibitRefs == 0) return;
if (--sleepInhibitRefs == 0)
os_inhibit_sleep_set_active(sleepInhibitor, false);
}
};
int GetConfigPath(char *path, size_t size, const char *name);

View file

@ -924,8 +924,6 @@ void OBSBasic::OBSInit()
connect(ui->preview, &OBSQTDisplay::DisplayCreated, addDisplay);
sleepInhibitor = os_inhibit_sleep_create("OBS Video/audio");
os_inhibit_sleep_set_active(sleepInhibitor, true);
show();
}
@ -1178,9 +1176,6 @@ OBSBasic::~OBSBasic()
}
}
#endif
os_inhibit_sleep_set_active(sleepInhibitor, false);
os_inhibit_sleep_destroy(sleepInhibitor);
}
void OBSBasic::SaveProjectNow()
@ -3080,8 +3075,9 @@ void OBSBasic::StopStreaming()
if (outputHandler->StreamingActive())
outputHandler->StopStreaming();
if (!outputHandler->Active()) {
if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(true);
App()->DecrementSleepInhibition();
}
}
@ -3092,8 +3088,9 @@ void OBSBasic::ForceStopStreaming()
if (outputHandler->StreamingActive())
outputHandler->ForceStopStreaming();
if (!outputHandler->Active()) {
if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(true);
App()->DecrementSleepInhibition();
}
}
@ -3113,6 +3110,11 @@ void OBSBasic::StreamDelayStarting(int sec)
ui->streamButton->setMenu(startStreamMenu);
ui->statusbar->StreamDelayStarting(sec);
if (ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(false);
App()->IncrementSleepInhibition();
}
}
void OBSBasic::StreamDelayStopping(int sec)
@ -3138,7 +3140,12 @@ void OBSBasic::StreamingStart()
ui->streamButton->setText(QTStr("Basic.Main.StopStreaming"));
ui->streamButton->setEnabled(true);
ui->statusbar->StreamStarted(outputHandler->streamOutput);
ui->profileMenu->setEnabled(false);
if (ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(false);
App()->IncrementSleepInhibition();
}
blog(LOG_INFO, STREAMING_START);
}
@ -3175,8 +3182,10 @@ void OBSBasic::StreamingStop(int code)
ui->streamButton->setText(QTStr("Basic.Main.StartStreaming"));
ui->streamButton->setEnabled(true);
if (!outputHandler->Active())
if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(true);
App()->DecrementSleepInhibition();
}
blog(LOG_INFO, STREAMING_STOP);
@ -3207,8 +3216,9 @@ void OBSBasic::StopRecording()
if (outputHandler->RecordingActive())
outputHandler->StopRecording();
if (!outputHandler->Active()) {
if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(true);
App()->DecrementSleepInhibition();
}
}
@ -3216,7 +3226,12 @@ void OBSBasic::RecordingStart()
{
ui->statusbar->RecordingStarted(outputHandler->fileOutput);
ui->recordButton->setText(QTStr("Basic.Main.StopRecording"));
ui->profileMenu->setEnabled(false);
if (ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(false);
App()->IncrementSleepInhibition();
}
blog(LOG_INFO, RECORDING_START);
}
@ -3242,8 +3257,9 @@ void OBSBasic::RecordingStop(int code)
QTStr("Output.RecordError.Msg"));
}
if (!outputHandler->Active()) {
if (!outputHandler->Active() && !ui->profileMenu->isEnabled()) {
ui->profileMenu->setEnabled(true);
App()->DecrementSleepInhibition();
}
}

View file

@ -92,7 +92,6 @@ private:
QPointer<QTimer> cpuUsageTimer;
os_cpu_usage_info_t *cpuUsageInfo = nullptr;
os_inhibit_t *sleepInhibitor = nullptr;
OBSService service;
std::unique_ptr<BasicOutputHandler> outputHandler;

View file

@ -25,12 +25,15 @@ OBSProjector::OBSProjector(QWidget *widget, obs_source_t *source_)
};
connect(this, &OBSQTDisplay::DisplayCreated, addDrawCallback);
App()->IncrementSleepInhibition();
}
OBSProjector::~OBSProjector()
{
if (source)
obs_source_dec_showing(source);
App()->DecrementSleepInhibition();
}
void OBSProjector::Init(int monitor)