Skip to content

Commit

Permalink
Fixed pausing idleness checks when fullscreen (#256)
Browse files Browse the repository at this point in the history
For whatever reason, if user activity is simulated inside the slot that is connected to `KIdleTime::timeoutReached`, `KIdleTime` won't time out anymore. The patch fixes the issue by using a singleshot timer.

Closes #255

NOTE: Simulating user activity is needed in this case because a window may lose its fullscreen state without the user's interaction (as when a video ends).
  • Loading branch information
tsujan authored Apr 22, 2021
1 parent 601c56c commit e5b5626
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/idlenesswatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "idlenesswatcher.h"

#include <QCoreApplication>
#include <QTimer>
#include <KIdleTime>
#include <Solid/Device>
#include <Solid/Battery>
Expand All @@ -38,7 +39,7 @@ IdlenessWatcher::IdlenessWatcher(QObject* parent):
Watcher(parent)
{
qDebug() << "Starting idlenesswatcher";

mIdleACWatcher = mIdleBatteryWatcher = mIdleBacklightWatcher = mBacklightActualValue = -1;
mBacklight = nullptr;
mDischarging = false;
Expand All @@ -65,7 +66,7 @@ IdlenessWatcher::IdlenessWatcher(QObject* parent):
}

connect(&mPSettings, &LXQt::Settings::settingsChanged, this, &IdlenessWatcher::onSettingsChanged);

setup();
}

Expand All @@ -88,7 +89,7 @@ void IdlenessWatcher::setup()
BATmsecs -= 10; // just 10 msecs less... ;)
}
mIdleBatteryWatcher = KIdleTime::instance()->addIdleTimeout(BATmsecs);

// Enable backlight control:
if(mPSettings.isIdlenessBacklightWatcherEnabled() &&
(
Expand Down Expand Up @@ -117,7 +118,9 @@ void IdlenessWatcher::timeoutReached(int identifier,int /*msec*/)
WId w = KWindowSystem::activeWindow();
KWindowInfo info(w, NET::WMState);
if (info.hasState(NET::FullScreen)) {
KIdleTime::instance()->simulateUserActivity();
QTimer::singleShot(0, this, [] {
KIdleTime::instance()->simulateUserActivity();
});
return;
}
}
Expand All @@ -137,21 +140,21 @@ void IdlenessWatcher::timeoutReached(int identifier,int /*msec*/)
doAction(mPSettings.getIdlenessBatteryAction());
return;
}

if(identifier == mIdleBacklightWatcher && mBacklightActualValue < 0) {
if(mBacklight == nullptr) {
mBacklight = new LXQt::Backlight();
connect(mBacklight, &QObject::destroyed, this, [this](QObject *) {mBacklight = nullptr;} );
}

//LXQt::Notification::notify(QStringLiteral("IdlenessWatcher::timeoutReached"),
// mBacklight->isBacklightAvailable() ?
// QStringLiteral("").setNum(mBacklightActualValue):QStringLiteral("Error!!"));

mBacklightActualValue = mBacklight->getBacklight();
if(mBacklight->isBacklightAvailable() && !mBacklight->isBacklightOff())
mBacklight->setBacklight((float)mBacklightActualValue * (float)(mPSettings.getBacklight())/100.0f);

KIdleTime::instance()->removeIdleTimeout(mIdleBacklightWatcher);
KIdleTime::instance()->catchNextResumeEvent();

Expand Down Expand Up @@ -181,7 +184,7 @@ void IdlenessWatcher::resumingFromIdle()
void IdlenessWatcher::onBatteryChanged(int, const QString &)
{
const QList<Solid::Device> devices = Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString());

mDischarging = false;

for (Solid::Device device : devices) {
Expand Down

0 comments on commit e5b5626

Please sign in to comment.