diff options
-rw-r--r-- | src/mixer/playerinfo.h | 2 | ||||
-rw-r--r-- | src/mixxx.cpp | 16 | ||||
-rw-r--r-- | src/mixxx.h | 1 | ||||
-rw-r--r-- | src/preferences/dialog/dlgprefcontrols.cpp | 14 | ||||
-rw-r--r-- | src/util/screensaver.cpp | 23 | ||||
-rw-r--r-- | src/util/screensaver.h | 3 |
6 files changed, 49 insertions, 10 deletions
diff --git a/src/mixer/playerinfo.h b/src/mixer/playerinfo.h index a16537ba17..78e566e636 100644 --- a/src/mixer/playerinfo.h +++ b/src/mixer/playerinfo.h @@ -33,6 +33,7 @@ class PlayerInfo : public QObject { TrackPointer getTrackInfo(const QString& group); void setTrackInfo(const QString& group, const TrackPointer& trackInfoObj); TrackPointer getCurrentPlayingTrack(); + int getCurrentPlayingDeck(); QMap<QString, TrackPointer> getLoadedTracks(); bool isTrackLoaded(const TrackPointer& pTrack) const; bool isFileLoaded(const QString& track_location) const; @@ -62,7 +63,6 @@ class PlayerInfo : public QObject { void clearControlCache(); void timerEvent(QTimerEvent* pTimerEvent); void updateCurrentPlayingDeck(); - int getCurrentPlayingDeck(); DeckControls* getDeckControls(int i); PlayerInfo(); diff --git a/src/mixxx.cpp b/src/mixxx.cpp index 8b67941db2..c11aac01b4 100644 --- a/src/mixxx.cpp +++ b/src/mixxx.cpp @@ -452,6 +452,10 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) { SIGNAL(currentPlayingTrackChanged(TrackPointer)), this, SLOT(slotUpdateWindowTitle(TrackPointer))); + connect(&PlayerInfo::instance(), + SIGNAL(currentPlayingDeckChanged(int)), + this, SLOT(slotChangedPlayingDeck(int))); + // this has to be after the OpenGL widgets are created or depending on a // million different variables the first waveform may be horribly // corrupted. See bug 521509 -- bkgood ?? -- vrince @@ -465,7 +469,8 @@ void MixxxMainWindow::finalize() { Timer t("MixxxMainWindow::~finalize"); t.start(); - int inhibit = m_pSettingsManager->settings()->getValue<int>(ConfigKey("[Config]","InhibitScreensaver")); + UserSettingsPointer pConfig = m_pSettingsManager->settings(); + int inhibit = pConfig->getValue<int>(ConfigKey("[Config]","InhibitScreensaver")); mixxx::ScreenSaverPreference inhiPref = mixxx::ScreenSaverPreference(inhibit); if (inhiPref == mixxx::ScreenSaverPreference::PREVENT_ON) { mixxx::ScreenSaverHelper::uninhibit(); @@ -1100,6 +1105,15 @@ void MixxxMainWindow::slotNoMicrophoneInputConfigured() { m_pPrefDlg->showSoundHardwarePage(); } +void MixxxMainWindow::slotChangedPlayingDeck(int deck) { + UserSettingsPointer pConfig = m_pSettingsManager->settings(); + int inhibit = pConfig->getValue<int>(ConfigKey("[Config]","InhibitScreensaver")); + mixxx::ScreenSaverPreference inhiPref = mixxx::ScreenSaverPreference(inhibit); + if (inhiPref == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY) { + mixxx::ScreenSaverHelper::inhibitOnCondition(deck!=-1); + } +} + void MixxxMainWindow::slotHelpAbout() { DlgAbout* about = new DlgAbout(this); about->show(); diff --git a/src/mixxx.h b/src/mixxx.h index da793a5011..b3ee9c2e2e 100644 --- a/src/mixxx.h +++ b/src/mixxx.h @@ -88,6 +88,7 @@ class MixxxMainWindow : public QMainWindow { void slotDeveloperToolsClosed(); void slotUpdateWindowTitle(TrackPointer pTrack); + void slotChangedPlayingDeck(int deck); // Warn the user when inputs are not configured. void slotNoMicrophoneInputConfigured(); diff --git a/src/preferences/dialog/dlgprefcontrols.cpp b/src/preferences/dialog/dlgprefcontrols.cpp index 755411dcdd..bb3cfe7a71 100644 --- a/src/preferences/dialog/dlgprefcontrols.cpp +++ b/src/preferences/dialog/dlgprefcontrols.cpp @@ -35,6 +35,7 @@ #include "skin/skinloader.h" #include "skin/legacyskinparser.h" #include "mixer/playermanager.h" +#include "mixer/playerinfo.h" #include "control/controlobject.h" #include "mixxx.h" #include "util/screensaver.h" @@ -313,7 +314,7 @@ DlgPrefControls::DlgPrefControls(QWidget * parent, MixxxMainWindow * mixxx, comboBoxScreensaver->clear(); comboBoxScreensaver->addItem(tr("Allow screensaver to run"), static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_OFF)); - comboBoxScreensaver->addItem(tr("Prevent screensaver from runnig"), + comboBoxScreensaver->addItem(tr("Prevent screensaver from running"), static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON)); comboBoxScreensaver->addItem(tr("Prevent screensaver while playing"), static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON_PLAY)); @@ -710,17 +711,16 @@ void DlgPrefControls::slotApply() { mixxx::ScreenSaverPreference inhiOld = mixxx::ScreenSaverPreference(inhibitsettings); if (inhiOld == mixxx::ScreenSaverPreference::PREVENT_ON) { mixxx::ScreenSaverHelper::uninhibit(); - } else if (inhiOld == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY && - 1 /*TODO(JosepMaJAZ) Playing detector*/) { - mixxx::ScreenSaverHelper::uninhibit(); + } else if (inhiOld == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY) { + mixxx::ScreenSaverHelper::inhibitOnCondition(false); } mixxx::ScreenSaverPreference inhiNew = mixxx::ScreenSaverPreference(inhibitcombo); if (inhiNew == mixxx::ScreenSaverPreference::PREVENT_ON) { mixxx::ScreenSaverHelper::inhibit(); - } else if (inhiNew == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY && - 0 /*TODO(JosepMaJAZ) Playing detector*/) { - mixxx::ScreenSaverHelper::inhibit(); + } else if (inhiNew == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY) { + mixxx::ScreenSaverHelper::inhibitOnCondition( + PlayerInfo::instance().getCurrentPlayingDeck()!=-1); } } diff --git a/src/util/screensaver.cpp b/src/util/screensaver.cpp index e3880d0cfd..a8756f57b6 100644 --- a/src/util/screensaver.cpp +++ b/src/util/screensaver.cpp @@ -32,6 +32,17 @@ https://github.com/awjackson/bsnes-classic/blob/038e2e051ffc8abe7c56a3bf27e3016c namespace mixxx { +bool ScreenSaverHelper::enabled = false; + +void ScreenSaverHelper::inhibitOnCondition(bool desired) +{ + if (desired != enabled) { + if (enabled) uninhibit(); + else inhibit(); + } +} + + #ifdef Q_OS_MAC IOPMAssertionID ScreenSaverHelper::systemSleepAssertionID=0; IOPMAssertionID ScreenSaverHelper::userActivityAssertionID=0; @@ -69,6 +80,7 @@ void ScreenSaverHelper::inhibit() CFRelease(reasonForActivity); if (success == kIOReturnSuccess) { + enabled = true; qDebug() << "IOKit screensaver inhibited " << systemSleepAssertionID; } else { qWarning("failed to prevent system sleep through IOKit"); @@ -78,6 +90,7 @@ void ScreenSaverHelper::uninhibit() { /* allow the system to sleep again */ if (systemSleepAssertionID > 0) { + enabled = false; IOPMAssertionRelease(systemSleepAssertionID); qDebug() << "IOKit screensaver uninhibited " << systemSleepAssertionID; } @@ -86,13 +99,17 @@ void ScreenSaverHelper::uninhibit() #elif defined(Q_OS_WIN) void ScreenSaverHelper::inhibit() { + // Calling once without "ES_CONTINUOUS" to force the monitor to wake up. + SetThreadExecutionState( ES_DISPLAY_REQUIRED ); SetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED | ES_CONTINUOUS ); qDebug() << "screensaver inhibited"; + enabled = true; } void ScreenSaverHelper::uninhibit() { SetThreadExecutionState(ES_CONTINUOUS); qDebug() << "screensaver uninhibited"; + enabled = false; } #elif defined(Q_OS_LINUX) @@ -129,6 +146,7 @@ void ScreenSaverHelper::inhibit() if (reply.isValid()) { cookie = reply.value(); saverindex = i; + enabled = true; qDebug() << "DBus screensaver " << SCREENSAVERS[i][0] <<" inhibited"; break; } else { @@ -144,6 +162,7 @@ void ScreenSaverHelper::inhibit() void ScreenSaverHelper::uninhibit() { if (cookie > 0) { + enabled = false; QDBusInterface iface(SCREENSAVERS[saverindex][0], SCREENSAVERS[saverindex][1], SCREENSAVERS[saverindex][2], QDBusConnection::sessionBus()); if (iface.isValid()) { @@ -170,6 +189,7 @@ void ScreenSaverHelper::inhibit() name=getenv("DISPLAY"); display=XOpenDisplay(name); XScreenSaverSuspend(display,True); + enabled = true; } void ScreenSaverHelper::uninhibit() { @@ -178,7 +198,8 @@ void ScreenSaverHelper::uninhibit() if (getenv("DISPLAY")) name=getenv("DISPLAY"); display=XOpenDisplay(name); - XScreenSaverSuspend(, False); + XScreenSaverSuspend(display, False); + enabled = false; } #else diff --git a/src/util/screensaver.h b/src/util/screensaver.h index 5405c6f27b..72331f2db6 100644 --- a/src/util/screensaver.h +++ b/src/util/screensaver.h @@ -16,7 +16,10 @@ public: static void inhibit(); static void uninhibit(); + static void inhibitOnCondition(bool desired); +private: + static bool enabled; #if defined(Q_OS_MAC) /* sleep management */ static IOPMAssertionID systemSleepAssertionID; |