Skip to content
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

Merged
merged 19 commits into from
Apr 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ def configure(self, build, conf):
raise Exception('Qt >= 5.0 not found')
elif not qt5 and not conf.CheckForPKG('QtCore', '4.6'):
raise Exception('QT >= 4.6 not found')


qt_modules.extend(['QtDBus'])
# This automatically converts QtXXX to Qt5XXX where appropriate.
if qt5:
build.env.EnableQt5Modules(qt_modules, debug=False)
Expand Down Expand Up @@ -435,7 +436,6 @@ def configure(self, build, conf):
build.env.Append(CPPPATH="#lib/gtest-1.7.0/include")

class FidLib(Dependence):

def sources(self, build):
symbol = None
if build.platform_is_windows:
Expand Down Expand Up @@ -1119,6 +1119,7 @@ def sources(self, build):
"util/cmdlineargs.cpp",
"util/audiosignal.cpp",
"util/autohidpi.cpp",
"util/screensaver.cpp",

'#res/mixxx.qrc'
]
Expand Down
12 changes: 12 additions & 0 deletions src/controllers/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "controllers/controller.h"
#include "controllers/controllerdebug.h"
#include "controllers/defs_controllers.h"
#include "util/screensaver.h"

Controller::Controller()
: QObject(),
Expand All @@ -19,6 +20,7 @@ Controller::Controller()
m_bIsInputDevice(false),
m_bIsOpen(false),
m_bLearning(false) {
m_userActivityInhibitTimer.start();
}

Controller::~Controller() {
Expand Down Expand Up @@ -95,13 +97,23 @@ void Controller::send(QList<int> data, unsigned int length) {
send(msg);
}

void Controller::triggerActivity()
{
// Inhibit Updates for 1000 milliseconds
if (m_userActivityInhibitTimer.elapsed() > 1000) {
mixxx::ScreenSaverHelper::triggerUserActivity();
m_userActivityInhibitTimer.start();
}
}
void Controller::receive(const QByteArray data, mixxx::Duration timestamp) {

if (m_pEngine == NULL) {
//qWarning() << "Controller::receive called with no active engine!";
// Don't complain, since this will always show after closing a device as
// queued signals flush out
return;
}
triggerActivity();

int length = data.size();
if (ControllerDebug::enabled()) {
Expand Down
4 changes: 4 additions & 0 deletions src/controllers/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class Controller : public QObject, ConstControllerPresetVisitor {
// To be called in sub-class' close() functions after stopping any input
// polling/processing but before closing the device.
void stopEngine();

// To be called when receiving events
void triggerActivity();

inline ControllerEngine* getEngine() const {
return m_pEngine;
Expand Down Expand Up @@ -157,6 +160,7 @@ class Controller : public QObject, ConstControllerPresetVisitor {
// Indicates whether or not the device has been opened for input/output.
bool m_bIsOpen;
bool m_bLearning;
QTime m_userActivityInhibitTimer;

// accesses lots of our stuff, but in the same thread
friend class ControllerManager;
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/midi/midicontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "errordialoghandler.h"
#include "mixer/playermanager.h"
#include "util/math.h"
#include "util/screensaver.h"

MidiController::MidiController()
: Controller() {
Expand Down Expand Up @@ -206,6 +207,7 @@ void MidiController::receive(unsigned char status, unsigned char control,
channel, opCode, timestamp));
MidiKey mappingKey(status, control);

triggerActivity();
if (isLearning()) {
emit(messageReceived(status, control, value));

Expand Down Expand Up @@ -455,6 +457,7 @@ void MidiController::receive(QByteArray data, mixxx::Duration timestamp) {

MidiKey mappingKey(data.at(0), 0xFF);

triggerActivity();
// TODO(rryan): Need to review how MIDI learn works with sysex messages. I
// don't think this actually does anything useful.
if (isLearning()) {
Expand Down
3 changes: 1 addition & 2 deletions src/mixer/playerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void PlayerInfo::updateCurrentPlayingDeck() {
continue;
}

if (pDc->m_pregain.get() <= 0.5) {
if (pDc->m_pregain.get() <= 0.25) {
continue;
}

Expand Down Expand Up @@ -150,7 +150,6 @@ void PlayerInfo::updateCurrentPlayingDeck() {
maxVolume = dvol;
}
}

if (maxDeck != m_currentlyPlayingDeck) {
m_currentlyPlayingDeck = maxDeck;
locker.unlock();
Expand Down
2 changes: 1 addition & 1 deletion src/mixer/playerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,7 +63,6 @@ class PlayerInfo : public QObject {
void clearControlCache();
void timerEvent(QTimerEvent* pTimerEvent);
void updateCurrentPlayingDeck();
int getCurrentPlayingDeck();
DeckControls* getDeckControls(int i);

PlayerInfo();
Expand Down
60 changes: 59 additions & 1 deletion src/mixxx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -304,6 +306,17 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {
connect(this, SIGNAL(newSkinLoaded()),
m_pLibrary, SLOT(onSkinLoadFinished()));

// Inhibit the screensaver if the option is set. (Do it before creating the preferences dialog)
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);
}
m_inhibitScreensaver = static_cast<mixxx::ScreenSaverPreference>(inhibit);
if (m_inhibitScreensaver == mixxx::ScreenSaverPreference::PREVENT_ON) {
mixxx::ScreenSaverHelper::inhibit();
}

// Initialize preference dialog
m_pPrefDlg = new DlgPreferences(this, m_pSkinLoader, m_pSoundManager, m_pPlayerManager,
m_pControllerManager, m_pVCManager, m_pEffectsManager,
Expand Down Expand Up @@ -368,6 +381,7 @@ void MixxxMainWindow::initialize(QApplication* pApp, const CmdlineArgs& args) {
}
emit(newSkinLoaded());


// Wait until all other ControlObjects are set up before initializing
// controllers
m_pControllerManager->setUpDevices();
Expand Down Expand Up @@ -441,6 +455,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
Expand All @@ -454,7 +472,12 @@ void MixxxMainWindow::finalize() {
Timer t("MixxxMainWindow::~finalize");
t.start();

// Save the current window state (position, maximized, etc)
if (m_inhibitScreensaver != mixxx::ScreenSaverPreference::PREVENT_OFF) {
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"),
Expand Down Expand Up @@ -1082,6 +1105,17 @@ void MixxxMainWindow::slotNoMicrophoneInputConfigured() {
m_pPrefDlg->showSoundHardwarePage();
}

void MixxxMainWindow::slotChangedPlayingDeck(int deck) {
if (m_inhibitScreensaver == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY) {
if (deck==-1) {
// If no deck is playing, allow the screensaver to run.
mixxx::ScreenSaverHelper::uninhibit();
} else {
mixxx::ScreenSaverHelper::inhibit();
}
}
}

void MixxxMainWindow::slotHelpAbout() {
DlgAbout* about = new DlgAbout(this);
about->show();
Expand Down Expand Up @@ -1287,6 +1321,30 @@ bool MixxxMainWindow::confirmExit() {
return true;
}

void MixxxMainWindow::setInhibitScreensaver(mixxx::ScreenSaverPreference newInhibit)
{
UserSettingsPointer pConfig = m_pSettingsManager->settings();

if (m_inhibitScreensaver != mixxx::ScreenSaverPreference::PREVENT_OFF) {
mixxx::ScreenSaverHelper::uninhibit();
}

if (newInhibit == mixxx::ScreenSaverPreference::PREVENT_ON) {
mixxx::ScreenSaverHelper::inhibit();
} else if (newInhibit == mixxx::ScreenSaverPreference::PREVENT_ON_PLAY
&& PlayerInfo::instance().getCurrentPlayingDeck()!=-1) {
mixxx::ScreenSaverHelper::inhibit();
}
int inhibit_int = static_cast<int>(newInhibit);
pConfig->setValue<int>(ConfigKey("[Config]","InhibitScreensaver"), inhibit_int);
m_inhibitScreensaver = newInhibit;
}

mixxx::ScreenSaverPreference MixxxMainWindow::getInhibitScreensaver()
{
return m_inhibitScreensaver;
}

void MixxxMainWindow::launchProgress(int progress) {
if (m_pLaunchImage) {
m_pLaunchImage->progress(progress);
Expand Down
4 changes: 4 additions & 0 deletions src/mixxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class MixxxMainWindow : public QMainWindow {
// creates the menu_bar and inserts the file Menu
void createMenuBar();
void connectMenuBar();
void setInhibitScreensaver(mixxx::ScreenSaverPreference inhibit);
mixxx::ScreenSaverPreference getInhibitScreensaver();

void setToolTipsCfg(mixxx::TooltipsPreference tt);
inline mixxx::TooltipsPreference getToolTipsCfg() { return m_toolTipsCfg; }
Expand All @@ -88,6 +90,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();
Expand Down Expand Up @@ -175,6 +178,7 @@ class MixxxMainWindow : public QMainWindow {
const CmdlineArgs& m_cmdLineArgs;

ControlPushButton* m_pTouchShift;
mixxx::ScreenSaverPreference m_inhibitScreensaver;

static const int kMicrophoneCount;
static const int kAuxiliaryCount;
Expand Down
7 changes: 7 additions & 0 deletions src/preferences/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
http://dictionary.cambridge.org/dictionary/english/prevent
http://dictionary.cambridge.org/dictionary/english/prevent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked google and you are probably right:
"prevent screensaver" 4550 Hits
"inhibit screensaver" 1020 Hits

PREVENT_ON = 1,
PREVENT_ON_PLAY = 2
};

} // namespace mixxx

#endif /* PREFERENCES_CONSTANTS_H */
31 changes: 30 additions & 1 deletion src/preferences/dialog/dlgprefcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
#include "util/autohidpi.h"

Expand Down Expand Up @@ -390,6 +392,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 = static_cast<int>(mixxx->getInhibitScreensaver());
comboBoxScreensaver->setCurrentIndex(comboBoxScreensaver->findData(inhibitsettings));

//
// Tooltip configuration
//
Expand Down Expand Up @@ -551,6 +568,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);

Expand Down Expand Up @@ -592,7 +613,6 @@ void DlgPrefControls::slotSetRateRange(int pos) {
slotSetRateRangePercent(ComboBoxRateRange->itemData(pos).toInt());
}


void DlgPrefControls::slotSetRateRangePercent (int rateRangePercent) {
double rateRange = rateRangePercent / 100.;

Expand Down Expand Up @@ -818,6 +838,15 @@ void DlgPrefControls::slotApply() {

int configSPAutoReset = BaseTrackPlayer::RESET_NONE;

// screensaver mode update
int inhibitcombo = comboBoxScreensaver->itemData(
comboBoxScreensaver->currentIndex()).toInt();
int inhibitsettings = static_cast<int>(m_mixxx->getInhibitScreensaver());
if (inhibitcombo != inhibitsettings) {
m_mixxx->setInhibitScreensaver(static_cast<mixxx::ScreenSaverPreference>(inhibitcombo));
}


if (m_speedAutoReset && m_pitchAutoReset) {
configSPAutoReset = BaseTrackPlayer::RESET_PITCH_AND_SPEED;
}
Expand Down
12 changes: 11 additions & 1 deletion src/preferences/dialog/dlgprefcontrolsdlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>562</width>
<height>711</height>
<height>723</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -211,6 +211,16 @@
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Screen saver</string>
</property>
</widget>
</item>
<item row="10" column="1" colspan="2">
<widget class="QComboBox" name="comboBoxScreensaver"/>
</item>
</layout>
</widget>
</item>
Expand Down
Loading