Skip to content

Commit

Permalink
Support notify on new inhibitor
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Jan 28, 2024
1 parent ac09cf9 commit f5fc187
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/powerkit_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ enum criticalAction
#define CONF_WARN_ON_VERYLOW_BATTERY "warn_on_verylow_battery"
#define CONF_NOTIFY_ON_BATTERY "notify_on_battery"
#define CONF_NOTIFY_ON_AC "notify_on_ac"
#define CONF_NOTIFY_NEW_INHIBITOR "notify_new_inhibitor"
#define CONF_SUSPEND_LOCK_SCREEN "lock_screen_on_suspend"
#define CONF_RESUME_LOCK_SCREEN "lock_screen_on_resume"
#define CONF_ICON_THEME "icon_theme"
Expand Down
21 changes: 21 additions & 0 deletions src/powerkit_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ Dialog::Dialog(QWidget *parent,
this, SLOT(handleNotifyBattery(bool)));
connect(notifyOnAC, SIGNAL(toggled(bool)),
this, SLOT(handleNotifyAC(bool)));
connect(notifyNewInhibitor, SIGNAL(toggled(bool)),
this, SLOT(handleNotifyNewInhibitor(bool)));
connect(backlightMouseWheel, SIGNAL(toggled(bool)),
this, SLOT(handleBacklightMouseWheel(bool)));
connect(suspendLockScreen, SIGNAL(toggled(bool)),
Expand Down Expand Up @@ -527,10 +529,16 @@ void Dialog::setupWidgets()
notifyOnAC->setText(tr("Notify on AC"));
notifyOnAC->setToolTip(tr("Notify when switched on AC power"));

notifyNewInhibitor = new QCheckBox(this);
notifyNewInhibitor->setIcon(QIcon::fromTheme(DEFAULT_NOTIFY_ICON));
notifyNewInhibitor->setText(tr("Notify new inhibitors"));
notifyNewInhibitor->setToolTip(tr("Notify on new screensaver or power inhibitors"));

notifyContainerLayout->addWidget(warnOnLowBattery);
notifyContainerLayout->addWidget(warnOnVeryLowBattery);
notifyContainerLayout->addWidget(notifyOnBattery);
notifyContainerLayout->addWidget(notifyOnAC);
notifyContainerLayout->addWidget(notifyNewInhibitor);

QWidget *settingsWidget = new QWidget(this);
QVBoxLayout *settingsLayout = new QVBoxLayout(settingsWidget);
Expand Down Expand Up @@ -726,6 +734,12 @@ void Dialog::loadSettings()
}
notifyOnAC->setChecked(defaultNotifyOnAC);

bool defaultNotifyNewInhibitor = true;
if (PowerSettings::isValid(CONF_NOTIFY_NEW_INHIBITOR)) {
defaultNotifyNewInhibitor = PowerSettings::getValue(CONF_NOTIFY_NEW_INHIBITOR).toBool();
}
notifyNewInhibitor->setChecked(defaultNotifyNewInhibitor);

bool defaultSuspendLockScreen = true;
if (PowerSettings::isValid(CONF_SUSPEND_LOCK_SCREEN)) {
defaultSuspendLockScreen = PowerSettings::getValue(CONF_SUSPEND_LOCK_SCREEN).toBool();
Expand Down Expand Up @@ -845,6 +859,8 @@ void Dialog::saveSettings()
notifyOnBattery->isChecked());
PowerSettings::setValue(CONF_NOTIFY_ON_AC,
notifyOnAC->isChecked());
PowerSettings::setValue(CONF_NOTIFY_NEW_INHIBITOR,
notifyNewInhibitor->isChecked());
PowerSettings::setValue(CONF_BACKLIGHT_MOUSE_WHEEL,
backlightMouseWheel->isChecked());
PowerSettings::setValue(CONF_SUSPEND_LOCK_SCREEN,
Expand Down Expand Up @@ -1094,6 +1110,11 @@ void Dialog::handleNotifyAC(bool triggered)
PowerSettings::setValue(CONF_NOTIFY_ON_AC, triggered);
}

void Dialog::handleNotifyNewInhibitor(bool triggered)
{
PowerSettings::setValue(CONF_NOTIFY_NEW_INHIBITOR, triggered);
}

void Dialog::enableLid(bool enabled)
{
lidActionAC->setEnabled(enabled);
Expand Down
2 changes: 2 additions & 0 deletions src/powerkit_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Dialog : public QDialog

QCheckBox *notifyOnBattery;
QCheckBox *notifyOnAC;
QCheckBox *notifyNewInhibitor;
QLabel *lidActionACLabel;
QLabel *lidActionBatteryLabel;
QLabel *batteryBacklightLabel;
Expand Down Expand Up @@ -108,6 +109,7 @@ private slots:
void handleWarnOnVeryLowBattery(bool triggered);
void handleNotifyBattery(bool triggered);
void handleNotifyAC(bool triggered);
void handleNotifyNewInhibitor(bool triggered);
void enableLid(bool enabled);
void handleBacklightMouseWheel(bool triggered);
void handleSuspendLockScreen(bool triggered);
Expand Down
22 changes: 14 additions & 8 deletions src/powerkit_systray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ SysTray::SysTray(QObject *parent)
, warnOnVeryLowBattery(true)
, notifyOnBattery(true)
, notifyOnAC(true)
, notifyNewInhibitor(true)
, backlightMouseWheel(true)
, ignoreKernelResume(false)
, powerMenu(nullptr)
Expand Down Expand Up @@ -520,6 +521,9 @@ void SysTray::loadSettings()
if (PowerSettings::isValid(CONF_NOTIFY_ON_AC)) {
notifyOnAC = PowerSettings::getValue(CONF_NOTIFY_ON_AC).toBool();
}
if (PowerSettings::isValid(CONF_NOTIFY_NEW_INHIBITOR)) {
notifyNewInhibitor = PowerSettings::getValue(CONF_NOTIFY_NEW_INHIBITOR).toBool();
}
if (PowerSettings::isValid(CONF_SUSPEND_LOCK_SCREEN)) {
man->setLockScreenOnSuspend(PowerSettings::getValue(CONF_SUSPEND_LOCK_SCREEN).toBool());
}
Expand Down Expand Up @@ -853,10 +857,11 @@ void SysTray::handleNewInhibitScreenSaver(const QString &application,
const QString &reason,
quint32 cookie)
{
qDebug() << "new screensaver inhibit" << application << reason << cookie;
Q_UNUSED(application)
Q_UNUSED(reason)
Q_UNUSED(cookie)
if (notifyNewInhibitor) {
showMessage(tr("New screen inhibitor (%1)").arg(cookie),
QString("%1: %2").arg(application, reason));
}

checkDevices();
getInhibitors();
}
Expand All @@ -865,10 +870,11 @@ void SysTray::handleNewInhibitPowerManagement(const QString &application,
const QString &reason,
quint32 cookie)
{
qDebug() << "new powermanagement inhibit" << application << reason << cookie;
Q_UNUSED(application)
Q_UNUSED(reason)
Q_UNUSED(cookie)
if (notifyNewInhibitor) {
showMessage(tr("New power inhibitor (%1)").arg(cookie),
QString("%1: %2").arg(application, reason));
}

checkDevices();
getInhibitors();
}
Expand Down
1 change: 1 addition & 0 deletions src/powerkit_systray.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class SysTray : public QObject
bool warnOnVeryLowBattery;
bool notifyOnBattery;
bool notifyOnAC;
bool notifyNewInhibitor;
bool backlightMouseWheel;
bool ignoreKernelResume;

Expand Down

0 comments on commit f5fc187

Please sign in to comment.