diff --git a/src/powerkit_def.h b/src/powerkit_def.h index 80c5773..f49da9d 100644 --- a/src/powerkit_def.h +++ b/src/powerkit_def.h @@ -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" diff --git a/src/powerkit_dialog.cpp b/src/powerkit_dialog.cpp index 7eda58e..1dbb5b7 100644 --- a/src/powerkit_dialog.cpp +++ b/src/powerkit_dialog.cpp @@ -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)), @@ -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); @@ -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(); @@ -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, @@ -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); diff --git a/src/powerkit_dialog.h b/src/powerkit_dialog.h index 4940d4c..a6131f8 100644 --- a/src/powerkit_dialog.h +++ b/src/powerkit_dialog.h @@ -64,6 +64,7 @@ class Dialog : public QDialog QCheckBox *notifyOnBattery; QCheckBox *notifyOnAC; + QCheckBox *notifyNewInhibitor; QLabel *lidActionACLabel; QLabel *lidActionBatteryLabel; QLabel *batteryBacklightLabel; @@ -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); diff --git a/src/powerkit_systray.cpp b/src/powerkit_systray.cpp index 9e2fb52..1c924c3 100644 --- a/src/powerkit_systray.cpp +++ b/src/powerkit_systray.cpp @@ -62,6 +62,7 @@ SysTray::SysTray(QObject *parent) , warnOnVeryLowBattery(true) , notifyOnBattery(true) , notifyOnAC(true) + , notifyNewInhibitor(true) , backlightMouseWheel(true) , ignoreKernelResume(false) , powerMenu(nullptr) @@ -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()); } @@ -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(); } @@ -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(); } diff --git a/src/powerkit_systray.h b/src/powerkit_systray.h index 25d7a91..57d421e 100644 --- a/src/powerkit_systray.h +++ b/src/powerkit_systray.h @@ -125,6 +125,7 @@ class SysTray : public QObject bool warnOnVeryLowBattery; bool notifyOnBattery; bool notifyOnAC; + bool notifyNewInhibitor; bool backlightMouseWheel; bool ignoreKernelResume;