Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions src/powerkit_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,6 @@ namespace PowerKit
#define POWERKIT_DBUS_PROPERTIES "org.freedesktop.DBus.Properties"
#define POWERKIT_SCREENSAVER_LOCK_CMD "xsecurelock"
#define POWERKIT_SCREENSAVER_TIMEOUT_BLANK 300
#define POWERKIT_SCREENSAVER_TIMEOUT_LOCK 600

#endif // POWERKIT_COMMON_H
25 changes: 24 additions & 1 deletion src/powerkit_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Dialog::Dialog(QWidget *parent,
, cpuFreqLabel(nullptr)
, cpuTempLabel(nullptr)
, screensaverBlank(nullptr)
, screensaverLock(nullptr)
, hasCpuCoreTemp(false)
, hasBattery(false)
{
Expand Down Expand Up @@ -437,7 +438,7 @@ void Dialog::setupWidgets()
const auto ssContainerLayout = new QHBoxLayout(ssContainer);
ssContainerLayout->setMargin(0);

const auto screensaverBlankLabel = new QLabel(tr("Screen Saver Timeout"), this);
const auto screensaverBlankLabel = new QLabel(tr("Blank screen"), this);
screensaverBlank = new QSpinBox(this);
screensaverBlank->setMaximumWidth(MAX_WIDTH);
screensaverBlank->setMinimumWidth(MAX_WIDTH);
Expand All @@ -449,6 +450,18 @@ void Dialog::setupWidgets()
ssContainerLayout->addWidget(screensaverBlankLabel);
ssContainerLayout->addWidget(screensaverBlank);

const auto screensaverLockLabel = new QLabel(tr("Lock screen"), this);
screensaverLock = new QSpinBox(this);
screensaverLock->setMaximumWidth(MAX_WIDTH);
screensaverLock->setMinimumWidth(MAX_WIDTH);
screensaverLock->setMinimum(1);
screensaverLock->setMaximum(1000);
screensaverLock->setSuffix(QString(" %1").arg(tr("min")));
screensaverLock->setPrefix(tr("After "));

ssContainerLayout->addWidget(screensaverLockLabel);
ssContainerLayout->addWidget(screensaverLock);

// notify
const auto notifyContainer = new QGroupBox(this);
notifyContainer->setTitle(tr("Notifications"));
Expand Down Expand Up @@ -615,6 +628,8 @@ void Dialog::connectWidgets()
this, SLOT(handleBacklightMouseWheel(bool)));
connect(screensaverBlank, SIGNAL(valueChanged(int)),
this, SLOT(handleScreensaverBlank(int)));
connect(screensaverLock, SIGNAL(valueChanged(int)),
this, SLOT(handleScreensaverLock(int)));
}

// load settings and set defaults
Expand Down Expand Up @@ -774,6 +789,9 @@ void Dialog::loadSettings()

screensaverBlank->setValue(Settings::getValue(CONF_SCREENSAVER_TIMEOUT_BLANK,
POWERKIT_SCREENSAVER_TIMEOUT_BLANK).toInt() / 60);

screensaverLock->setValue(Settings::getValue(CONF_SCREENSAVER_TIMEOUT_LOCK,
POWERKIT_SCREENSAVER_TIMEOUT_LOCK).toInt() / 60);
}

void Dialog::saveSettings()
Expand Down Expand Up @@ -1151,3 +1169,8 @@ void Dialog::handleScreensaverBlank(int value)
{
Settings::setValue(CONF_SCREENSAVER_TIMEOUT_BLANK, value * 60);
}

void Dialog::handleScreensaverLock(int value)
{
Settings::setValue(CONF_SCREENSAVER_TIMEOUT_LOCK, value * 60);
}
2 changes: 2 additions & 0 deletions src/powerkit_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace PowerKit
QLabel *cpuTempLabel;

QSpinBox *screensaverBlank;
QSpinBox *screensaverLock;

bool hasCpuCoreTemp;
bool hasBattery;
Expand Down Expand Up @@ -127,6 +128,7 @@ namespace PowerKit
void enableLid(bool enabled);
void handleBacklightMouseWheel(bool triggered);
void handleScreensaverBlank(int value);
void handleScreensaverLock(int value);
};
}

Expand Down
26 changes: 19 additions & 7 deletions src/powerkit_screensaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ using namespace PowerKit;

ScreenSaver::ScreenSaver(QObject *parent)
: QObject(parent)
, blank(POWERKIT_SCREENSAVER_TIMEOUT_BLANK)
, blank_time(POWERKIT_SCREENSAVER_TIMEOUT_BLANK)
, lock_time(POWERKIT_SCREENSAVER_TIMEOUT_LOCK)
{
timer.setInterval(PK_SCREENSAVER_TIMER);
connect(&timer, SIGNAL(timeout()),
Expand Down Expand Up @@ -91,24 +92,36 @@ void ScreenSaver::timeOut()
SimulateUserActivity();
return;
}
int idle = GetSessionIdleTime();
qDebug() << "screensaver idle" << idle << blank;
if (idle >= blank) { Lock(); }
int idle_time = GetSessionIdleTime();
qDebug() << "screensaver idle" << idle_time << blank_time << lock_time;
if (idle_time >= lock_time) {
Lock();
}
if (idle_time >= blank_time) {
setDisplaysOff(true);
}
}

void ScreenSaver::Update()
{
xlock = Settings::getValue(CONF_SCREENSAVER_LOCK_CMD,
POWERKIT_SCREENSAVER_LOCK_CMD).toString();
blank = Settings::getValue(CONF_SCREENSAVER_TIMEOUT_BLANK,
blank_time = Settings::getValue(CONF_SCREENSAVER_TIMEOUT_BLANK,
POWERKIT_SCREENSAVER_TIMEOUT_BLANK).toInt();
lock_time = Settings::getValue(CONF_SCREENSAVER_TIMEOUT_LOCK,
POWERKIT_SCREENSAVER_TIMEOUT_LOCK).toInt();
int exe1 = QProcess::execute("xset",
QStringList() << "-dpms");
int exe2 = QProcess::execute("xset",
QStringList() << "s" << "on");
int exe3 = QProcess::execute("xset",
QStringList() << "s" << QString::number(blank));
QStringList() << "s" << QString::number(lock_time));
qDebug() << "screensaver update" << exe1 << exe2 << exe3;
if (lock_time < blank_time) {
int lock_before_blank = QProcess::execute("xset",
QStringList() << "s" << "noblank");
qDebug() << "screensaver update noblank" << lock_before_blank;
}
SimulateUserActivity();
}

Expand All @@ -117,7 +130,6 @@ void ScreenSaver::Lock()
if (xlock.isEmpty()) { return; }
qDebug() << "screensaver lock";
QProcess::startDetached(xlock, QStringList());
setDisplaysOff(true);
}

void ScreenSaver::SimulateUserActivity()
Expand Down
3 changes: 2 additions & 1 deletion src/powerkit_screensaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ namespace PowerKit
private:
QTimer timer;
QMap<quint32, QTime> clients;
int blank;
int blank_time;
int lock_time;
QString xlock;

signals:
Expand Down
1 change: 1 addition & 0 deletions src/powerkit_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#define CONF_KERNEL_BYPASS "kernel_cmd_bypass"
#define CONF_SCREENSAVER_LOCK_CMD "screensaver_lock_cmd"
#define CONF_SCREENSAVER_TIMEOUT_BLANK "screensaver_blank_timeout"
#define CONF_SCREENSAVER_TIMEOUT_LOCK "screensaver_lock_timeout"

namespace PowerKit
{
Expand Down