-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Screensaver inhibitor. #1229
Screensaver inhibitor. #1229
Changes from 6 commits
7f76595
0fb221a
7d8a0e1
1ec06ce
67d3641
4b52ac0
21ce197
e7ae731
1ae1af9
e091467
aa97512
5b810df
5c0bb98
411e6f8
7133d1c
d9a8fe7
72f7c37
5b2f437
305e697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#include "dialog/dlgabout.h" | ||
#include "preferences/dialog/dlgpreferences.h" | ||
#include "preferences/dialog/dlgprefeq.h" | ||
#include "preferences/constants.h" | ||
#include "dialog/dlgdevelopertools.h" | ||
#include "engine/enginemaster.h" | ||
#include "effects/effectsmanager.h" | ||
|
@@ -64,6 +65,7 @@ | |
#include "skin/launchimage.h" | ||
#include "preferences/settingsmanager.h" | ||
#include "widget/wmainmenubar.h" | ||
#include "util/screensaver.h" | ||
|
||
#ifdef __VINYLCONTROL__ | ||
#include "vinylcontrol/vinylcontrolmanager.h" | ||
|
@@ -367,6 +369,18 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) { | |
} | ||
emit(newSkinLoaded()); | ||
|
||
// Inhibit the screensaver if the option is set. | ||
int inhibit = pConfig->getValue<int>(ConfigKey("[Config]","InhibitScreensaver"),-1); | ||
if (inhibit == -1) { | ||
inhibit = static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON); | ||
pConfig->setValue<int>(ConfigKey("[Config]","InhibitScreensaver"), inhibit); | ||
} | ||
mixxx::ScreenSaverPreference inhiPref = mixxx::ScreenSaverPreference(inhibit); | ||
if (inhiPref == mixxx::ScreenSaverPreference::PREVENT_ON) { | ||
mixxx::ScreenSaverHelper::inhibit(); | ||
} | ||
|
||
|
||
// Wait until all other ControlObjects are set up before initializing | ||
// controllers | ||
m_pControllerManager->setUpDevices(); | ||
|
@@ -433,11 +447,15 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) { | |
m_pPlayerManager->slotLoadToDeck(musicFiles.at(i), i+1); | ||
} | ||
} | ||
|
||
connect(&PlayerInfo::instance(), | ||
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 | ||
|
@@ -451,7 +469,15 @@ void MixxxMainWindow::finalize() { | |
Timer t("MixxxMainWindow::~finalize"); | ||
t.start(); | ||
|
||
// Save the current window state (position, maximized, etc) | ||
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(); | ||
} | ||
|
||
|
||
// Save the current window state (position, maximized, etc) | ||
m_pSettingsManager->settings()->set(ConfigKey("[MainWindow]", "geometry"), | ||
QString(saveGeometry().toBase64())); | ||
m_pSettingsManager->settings()->set(ConfigKey("[MainWindow]", "state"), | ||
|
@@ -1079,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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not parse the preferences over and over again. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then I will need a slot to call when I change the setting from the preferences. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a direct call, because the DlgPrefControls holds a pointer to MixxxMainWindow. |
||
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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,13 @@ enum class TooltipsPreference { | |
TOOLTIPS_ONLY_IN_LIBRARY = 2, | ||
}; | ||
|
||
// Settings to enable or disable the prevention to run the screensaver. | ||
enum class ScreenSaverPreference { | ||
PREVENT_OFF = 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. INHIBIT_OFF sounds more natural to me, though I am not a native speaker. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, to me it's the word inhibit that isn't natural. I'm using it because that's the name used in the linux part of the solution and I kept that name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have checked google and you are probably right: |
||
PREVENT_ON = 1, | ||
PREVENT_ON_PLAY = 2 | ||
}; | ||
|
||
} // namespace mixxx | ||
|
||
#endif /* PREFERENCES_CONSTANTS_H */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,8 +35,10 @@ | |
#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" | ||
#include "defs_urls.h" | ||
|
||
DlgPrefControls::DlgPrefControls(QWidget * parent, MixxxMainWindow * mixxx, | ||
|
@@ -305,6 +307,21 @@ DlgPrefControls::DlgPrefControls(QWidget * parent, MixxxMainWindow * mixxx, | |
ConfigKey("[Config]", "StartInFullscreen")).toInt()==1); | ||
connect(checkBoxStartFullScreen, SIGNAL(toggled(bool)), | ||
this, SLOT(slotSetStartInFullScreen(bool))); | ||
|
||
// | ||
// Screensaver mode | ||
// | ||
comboBoxScreensaver->clear(); | ||
comboBoxScreensaver->addItem(tr("Allow screensaver to run"), | ||
static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_OFF)); | ||
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)); | ||
|
||
int inhibitsettings = pConfig->getValue<int>(ConfigKey("[Config]","InhibitScreensaver")); | ||
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(inhibitsettings)); | ||
|
||
// | ||
// Tooltip configuration | ||
// | ||
|
@@ -456,6 +473,10 @@ void DlgPrefControls::slotResetToDefaults() { | |
// Don't start in full screen. | ||
checkBoxStartFullScreen->setChecked(false); | ||
|
||
// Inhibit the screensaver | ||
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData( | ||
static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_ON))); | ||
|
||
// Tooltips on everywhere. | ||
radioButtonTooltipsLibraryAndSkin->setChecked(true); | ||
|
||
|
@@ -493,7 +514,6 @@ void DlgPrefControls::slotSetRateRange(int pos) { | |
slotSetRateRangePercent(ComboBoxRateRange->itemData(pos).toInt()); | ||
} | ||
|
||
|
||
void DlgPrefControls::slotSetRateRangePercent (int rateRangePercent) { | ||
double rateRange = rateRangePercent / 100.; | ||
|
||
|
@@ -681,6 +701,30 @@ void DlgPrefControls::slotApply() { | |
|
||
int configSPAutoReset = BaseTrackPlayer::RESET_NONE; | ||
|
||
// screensaver mode update | ||
int inhibitcombo = comboBoxScreensaver->itemData( | ||
comboBoxScreensaver->currentIndex()).toInt(); | ||
int inhibitsettings = m_pConfig->getValue<int>(ConfigKey("[Config]","InhibitScreensaver")); | ||
if (inhibitcombo != inhibitsettings) { | ||
m_pConfig->set(ConfigKey("[Config]", "InhibitScreensaver"), ConfigValue(inhibitcombo)); | ||
|
||
mixxx::ScreenSaverPreference inhiOld = mixxx::ScreenSaverPreference(inhibitsettings); | ||
if (inhiOld == mixxx::ScreenSaverPreference::PREVENT_ON) { | ||
mixxx::ScreenSaverHelper::uninhibit(); | ||
} else if (inhiOld == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY) { | ||
mixxx::ScreenSaverHelper::inhibitOnCondition(false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we call a plain uninhibit in this case as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Conceptually yes, but in practice no. I probably need to find a better name for this method. What it really does is either inhibit or uninhibit, depending if the parameter is the same or different than the current status. like this: Current status: inhibit on The end result is always that true leaves it enabled and false leaves it disabled, but internally it decides if it has to change anything or not. But now that I think about it, I'm not sure why i needed it as separate method. Will check and comment later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I ended incorporating the logic inside inhibit and uninhibit. |
||
} | ||
|
||
mixxx::ScreenSaverPreference inhiNew = mixxx::ScreenSaverPreference(inhibitcombo); | ||
if (inhiNew == mixxx::ScreenSaverPreference::PREVENT_ON) { | ||
mixxx::ScreenSaverHelper::inhibit(); | ||
} else if (inhiNew == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY) { | ||
mixxx::ScreenSaverHelper::inhibitOnCondition( | ||
PlayerInfo::instance().getCurrentPlayingDeck()!=-1); | ||
} | ||
} | ||
|
||
|
||
if (m_speedAutoReset && m_pitchAutoReset) { | ||
configSPAutoReset = BaseTrackPlayer::RESET_PITCH_AND_SPEED; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This casing form is not easy recognizable as cast.
Can we switch to
auto inhiPref = static_castmixxx::ScreenSaverPreference(inhibit);
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we could also avoid casting to enum and cast to int below.
The line is not aware the new PREVENT_ON_PLAY feature.
So it may look finally like that:
if (inhiPref != static_cast<int>(mixxx::ScreenSaverPreference::PREVENT_OFF)) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use of "auto" and explicit cast sounds interesting. use of static_cast sounds in contradiction with the use of "enum class".
I would preffer the oppinion of someone else before changing that from what it is now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can keep it, if you like.
I have just looked in
https://google.github.io/styleguide/cppguide.html#Casting
In this case your enum class has no constructor so I think static_cast<> it the best choice here.
We only user auto rarely, except if it helps not to repeat ourselves like in this case.