Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Feb 10, 2024
1 parent a7a1c4a commit 0178e00
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 176 deletions.
4 changes: 2 additions & 2 deletions src/powerkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ int main(int argc, char *argv[])
return a.exec();
} else if (setBrightness) {
int val = PowerKit::Backlight::getCurrentBrightness();
if (args.contains(CMD_OPT_BRIGHTNESS_UP)) { val += BACKLIGHT_MOVE_VALUE; }
else if (args.contains(CMD_OPT_BRIGHTNESS_DOWN)) { val -= BACKLIGHT_MOVE_VALUE; }
if (args.contains(CMD_OPT_BRIGHTNESS_UP)) { val += POWERKIT_BACKLIGHT_STEP; }
else if (args.contains(CMD_OPT_BRIGHTNESS_DOWN)) { val -= POWERKIT_BACKLIGHT_STEP; }
return PowerKit::Backlight::setBrightness(val);
} else if (setSleep || setHibernate || setLock) {
QDBusInterface manager(POWERKIT_SERVICE,
Expand Down
41 changes: 24 additions & 17 deletions src/powerkit_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@

#define VIRTUAL_MONITOR "VIRTUAL"

#define PK_SCREENSAVER_SERVICE "org.freedesktop.ScreenSaver"
#define PK_SCREENSAVER_PATH_ROOT "/ScreenSaver"
#define PK_SCREENSAVER_PATH_FULL "/org/freedesktop/ScreenSaver"

#define PM_SERVICE_INHIBIT "org.freedesktop.PowerManagement.Inhibit"
#define PM_FULL_PATH_INHIBIT "/org/freedesktop/PowerManagement/Inhibit"

#define PM_SERVICE "org.freedesktop.PowerManagement"
#define PM_FULL_PATH "/org/freedesktop/PowerManagement"
#define POWERKIT_FULL_PATH "/org/freedesktop/PowerKit"

using namespace PowerKit;

App::App(QObject *parent)
Expand All @@ -35,21 +46,21 @@ App::App(QObject *parent)
, ss(nullptr)
, wasLowBattery(false)
, wasVeryLowBattery(false)
, lowBatteryValue(LOW_BATTERY)
, critBatteryValue(CRITICAL_BATTERY)
, lowBatteryValue(POWERKIT_LOW_BATTERY)
, critBatteryValue(POWERKIT_CRITICAL_BATTERY)
, hasService(false)
, lidActionBattery(LID_BATTERY_DEFAULT)
, lidActionAC(LID_AC_DEFAULT)
, criticalAction(CRITICAL_DEFAULT)
, autoSuspendBattery(AUTO_SLEEP_BATTERY)
, lidActionBattery(POWERKIT_LID_BATTERY_ACTION)
, lidActionAC(POWERKIT_LID_AC_ACTION)
, criticalAction(POWERKIT_CRITICAL_ACTION)
, autoSuspendBattery(POWERKIT_AUTO_SLEEP_BATTERY)
, autoSuspendAC(0)
, timer(nullptr)
, timeouts(0)
, showNotifications(true)
, showTray(true)
, disableLidOnExternalMonitors(false)
, autoSuspendBatteryAction(suspendSleep)
, autoSuspendACAction(suspendNone)
, autoSuspendBatteryAction(POWERKIT_SUSPEND_BATTERY_ACTION)
, autoSuspendACAction(POWERKIT_SUSPEND_AC_ACTION)
, watcher(nullptr)
, lidXrandr(false)
, lidWasClosed(false)
Expand Down Expand Up @@ -188,7 +199,7 @@ App::App(QObject *parent)
Theme::setAppTheme();
Theme::setIconTheme();
if (tray->icon().isNull()) {
tray->setIcon(QIcon::fromTheme(DEFAULT_AC_ICON));
tray->setIcon(QIcon::fromTheme(POWERKIT_ICON));
}

loadSettings();
Expand Down Expand Up @@ -590,11 +601,6 @@ void App::drawBattery(double left)
!tray->isVisible() &&
showTray) { tray->show(); }

if (!man->HasBattery()) {
tray->setIcon(QIcon::fromTheme(DEFAULT_AC_ICON));
return;
}

QColor colorBg = Qt::green;
QColor colorFg = Qt::white;
int pixelSize = 22;
Expand All @@ -605,7 +611,8 @@ void App::drawBattery(double left)
colorBg = Qt::red;
}
} else {
if (left == 100) { colorFg = Qt::green; }
if (!man->HasBattery()) { left = 100; }
else if (left == 100) { colorFg = Qt::green; }
}

tray->setIcon(Theme::drawCircleProgress(left,
Expand Down Expand Up @@ -903,11 +910,11 @@ void App::handleTrayWheel(TrayIcon::WheelAction action)
switch (action) {
case TrayIcon::WheelUp:
Backlight::setBrightness(backlightDevice,
Backlight::getCurrentBrightness(backlightDevice)+BACKLIGHT_MOVE_VALUE);
Backlight::getCurrentBrightness(backlightDevice)+POWERKIT_BACKLIGHT_STEP);
break;
case TrayIcon::WheelDown:
Backlight::setBrightness(backlightDevice,
Backlight::getCurrentBrightness(backlightDevice)-BACKLIGHT_MOVE_VALUE);
Backlight::getCurrentBrightness(backlightDevice)-POWERKIT_BACKLIGHT_STEP);
break;
default:;
}
Expand Down
2 changes: 1 addition & 1 deletion src/powerkit_backlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool Backlight::setCurrentBrightness(int value)
bool Backlight::setBrightness(const QString &device,
int value)
{
QDBusInterface iface(LOGIND_SERVICE,
QDBusInterface iface(POWERKIT_LOGIND_SERVICE,
LOGIND_PATH_SESSION,
LOGIND_SESSION,
QDBusConnection::systemBus());
Expand Down
121 changes: 15 additions & 106 deletions src/powerkit_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,115 +51,24 @@ namespace PowerKit
};
}

#define LID_BATTERY_DEFAULT PowerKit::lidSleep
#define LID_AC_DEFAULT PowerKit::lidLock
#define CRITICAL_DEFAULT PowerKit::criticalNone

#define BACKLIGHT_MOVE_VALUE 10
#define LOW_BATTERY 5 // % over critical
#define CRITICAL_BATTERY 10
#define AUTO_SLEEP_BATTERY 15
#define DEFAULT_THEME "Adwaita"
#define DEFAULT_AC_ICON "ac-adapter"
#define DEFAULT_BATTERY_ICON "battery"
#define DEFAULT_BATTERY_ICON_CRIT "battery-caution"
#define DEFAULT_BATTERY_ICON_CRIT_AC "battery-caution-charging"
#define DEFAULT_BATTERY_ICON_LOW "battery-low"
#define DEFAULT_BATTERY_ICON_LOW_AC "battery-low-charging"
#define DEFAULT_BATTERY_ICON_GOOD "battery-good"
#define DEFAULT_BATTERY_ICON_GOOD_AC "battery-good-charging"
#define DEFAULT_BATTERY_ICON_FULL "battery-full"
#define DEFAULT_BATTERY_ICON_FULL_AC "battery-full-charging"
#define DEFAULT_BATTERY_ICON_CHARGED "battery-full-charged"
#define DEFAULT_BATTERY_EMPTY "battery-empty"
#define DEFAULT_BATTERY_MISSING "battery-missing"
#define DEFAULT_VIDEO_ICON "video-display"
#define DEFAULT_SUSPEND_ICON "system-suspend"
#define DEFAULT_TRAY_ICON "preferences-other"
#define DEFAULT_NOTIFY_ICON "user-available"
#define DEFAULT_LOCK_ICON "system-lock-screen"
#define DEFAULT_HIBERNATE_ICON "system-hibernate"
#define DEFAULT_SHUTDOWN_ICON "system-shutdown"
#define DEFAULT_NONE_ICON "emblem-unreadable"
#define DEFAULT_BACKLIGHT_ICON "weather-clear"
#define DEFAULT_INFO_ICON "dialog-information"
#define DEFAULT_KEYBOARD_ICON "input-keyboard"
#define DEFAULT_MOUSE_ICON "input-mouse"
#define DEFAULT_ABOUT_ICON "dialog-question"
#define DEFAULT_SETTINGS_ICON "preferences-system"
#define DEFAULT_HELP_ICON "system-help"
#define DEFAULT_INHIBITOR_ICON "preferences-desktop-screensaver"
#define DEFAULT_APP_ICON "applications-system"

#define DEFAULT_SUSPEND_BATTERY_ACTION PowerKit::suspendSleep
#define DEFAULT_SUSPEND_AC_ACTION PowerKit::suspendNone

#define POWERKIT_LID_BATTERY_ACTION PowerKit::lidSleep
#define POWERKIT_LID_AC_ACTION PowerKit::lidLock
#define POWERKIT_CRITICAL_ACTION PowerKit::criticalNone
#define POWERKIT_SUSPEND_BATTERY_ACTION PowerKit::suspendSleep
#define POWERKIT_SUSPEND_AC_ACTION PowerKit::suspendNone
#define POWERKIT_BACKLIGHT_STEP 10 // +/-
#define POWERKIT_LOW_BATTERY 5 // % over critical
#define POWERKIT_CRITICAL_BATTERY 10 // %
#define POWERKIT_AUTO_SLEEP_BATTERY 15 // min
#define POWERKIT_ICON "ac-adapter"
#define POWERKIT_SERVICE "org.freedesktop.PowerKit"
#define POWERKIT_PATH "/PowerKit"
#define POWERKIT_FULL_PATH "/org/freedesktop/PowerKit"
#define POWERKIT_MANAGER "org.freedesktop.PowerKit.Manager"
#define POWERKIT_CONFIG "org.freedesktop.PowerKit.Configuration"

#define PM_SERVICE "org.freedesktop.PowerManagement"
#define PM_PATH "/PowerManagement"
#define PM_FULL_PATH "/org/freedesktop/PowerManagement"
#define PM_TIMEOUT 60000
#define PM_MAX_INHIBIT 18000

#define PM_SERVICE_INHIBIT "org.freedesktop.PowerManagement.Inhibit"
#define PM_FULL_PATH_INHIBIT "/org/freedesktop/PowerManagement/Inhibit"

#define LOGIND_SERVICE "org.freedesktop.login1"

#define UPOWER_SERVICE "org.freedesktop.UPower"
#define DBUS_PROPERTIES "org.freedesktop.DBus.Properties"
#define DBUS_DEVICE "Device"
#define DBUS_CHANGED "Changed"
#define DBUS_PROPERTIES_CHANGED "PropertiesChanged"

// config keys
#define CONF_DIALOG_GEOMETRY "dialog_geometry"
#define CONF_SUSPEND_BATTERY_TIMEOUT "suspend_battery_timeout"
#define CONF_SUSPEND_BATTERY_ACTION "suspend_battery_action"
#define CONF_SUSPEND_AC_TIMEOUT "suspend_ac_timeout"
#define CONF_SUSPEND_AC_ACTION "suspend_ac_action"
#define CONF_SUSPEND_WAKEUP_HIBERNATE_BATTERY "suspend_wakeup_hibernate_battery"
#define CONF_SUSPEND_WAKEUP_HIBERNATE_AC "suspend_wakeup_hibernate_ac"
#define CONF_CRITICAL_BATTERY_TIMEOUT "critical_battery_timeout"
#define CONF_CRITICAL_BATTERY_ACTION "critical_battery_action"
#define CONF_LID_BATTERY_ACTION "lid_battery_action"
#define CONF_LID_AC_ACTION "lid_ac_action"
#define CONF_LID_DISABLE_IF_EXTERNAL "disable_lid_action_external_monitor"
#define CONF_TRAY_NOTIFY "tray_notify"
#define CONF_TRAY_SHOW "show_tray"
#define CONF_LID_XRANDR "lid_xrandr_action"
#define CONF_BACKLIGHT_BATTERY "backlight_battery_value"
#define CONF_BACKLIGHT_BATTERY_ENABLE "backlight_battery_enable"
#define CONF_BACKLIGHT_BATTERY_DISABLE_IF_LOWER "backlight_battery_disable_if_lower"
#define CONF_BACKLIGHT_AC "backlight_ac_value"
#define CONF_BACKLIGHT_AC_ENABLE "backlight_ac_enable"
#define CONF_BACKLIGHT_AC_DISABLE_IF_HIGHER "backlight_ac_disable_if_higher"
#define CONF_BACKLIGHT_MOUSE_WHEEL "backlight_mouse_wheel"
#define CONF_DIALOG "dialog_geometry"
#define CONF_WARN_ON_LOW_BATTERY "warn_on_low_battery"
#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"
#define CONF_NATIVE_THEME "native_theme"
#define CONF_KERNEL_BYPASS "kernel_cmd_bypass"
#define CONF_SCREENSAVER_LOCK_CMD "screensaver_lock_cmd"
#define CONF_SCREENSAVER_TIMEOUT_BLANK "screensaver_blank_timeout"

// screensaver

#define PK_SCREENSAVER_LOCK_CMD "xsecurelock"
#define PK_SCREENSAVER_SERVICE "org.freedesktop.ScreenSaver"
#define PK_SCREENSAVER_PATH_ROOT "/ScreenSaver"
#define PK_SCREENSAVER_PATH_FULL "/org/freedesktop/ScreenSaver"
#define PK_SCREENSAVER_TIMEOUT_BLANK 300
#define POWERKIT_LOGIND_SERVICE "org.freedesktop.login1"
#define POWERKIT_UPOWER_SERVICE "org.freedesktop.UPower"
#define POWERKIT_DBUS_PROPERTIES "org.freedesktop.DBus.Properties"
#define POWERKIT_SCREENSAVER_LOCK_CMD "xsecurelock"
#define POWERKIT_SCREENSAVER_TIMEOUT_BLANK 300

#endif // POWERKIT_COMMON_H
15 changes: 9 additions & 6 deletions src/powerkit_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#define PROP_DEV_VENDOR "Vendor"
#define PROP_DEV_NATIVEPATH "NativePath"

#define DBUS_CHANGED "Changed"
#define DBUS_DEVICE "Device"

using namespace PowerKit;

Device::Device(const QString block, QObject *parent)
Expand All @@ -51,25 +54,25 @@ Device::Device(const QString block, QObject *parent)
, dbusp(nullptr)
{
QDBusConnection system = QDBusConnection::systemBus();
dbus = new QDBusInterface(UPOWER_SERVICE,
dbus = new QDBusInterface(POWERKIT_UPOWER_SERVICE,
path,
QString("%1.%2").arg(UPOWER_SERVICE, DBUS_DEVICE),
QString("%1.%2").arg(POWERKIT_UPOWER_SERVICE, DBUS_DEVICE),
system,
parent);
system.connect(dbus->service(),
dbus->path(),
QString("%1.%2").arg(UPOWER_SERVICE, DBUS_DEVICE),
QString("%1.%2").arg(POWERKIT_UPOWER_SERVICE, DBUS_DEVICE),
DBUS_CHANGED,
this,
SLOT(updateDeviceProperties()));
dbusp = new QDBusInterface(UPOWER_SERVICE,
dbusp = new QDBusInterface(POWERKIT_UPOWER_SERVICE,
path,
DBUS_PROPERTIES,
POWERKIT_DBUS_PROPERTIES,
system,
parent);
system.connect(dbusp->service(),
dbusp->path(),
DBUS_PROPERTIES,
POWERKIT_DBUS_PROPERTIES,
PROP_CHANGED,
this,
SLOT(updateDeviceProperties()));
Expand Down
20 changes: 10 additions & 10 deletions src/powerkit_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void Dialog::setupWidgets()
Theme::setAppTheme();
Theme::setIconTheme();
setStyleSheet("QLabel { font-weight: bold; }");
setWindowIcon(QIcon::fromTheme(DEFAULT_AC_ICON));
setWindowIcon(QIcon::fromTheme(POWERKIT_ICON));

// setup widgets
const auto layout = new QVBoxLayout(this);
Expand Down Expand Up @@ -461,7 +461,7 @@ void Dialog::setupWidgets()
warnOnLowBattery = new QCheckBox(this);
warnOnLowBattery->setText(tr("Notify on low battery"));
warnOnLowBattery->setToolTip(tr("Show a notification when on low battery (%1% over critical)")
.arg(LOW_BATTERY));
.arg(POWERKIT_LOW_BATTERY));

warnOnVeryLowBattery = new QCheckBox(this);
warnOnVeryLowBattery->setText(tr("Notify on very low battery"));
Expand Down Expand Up @@ -624,13 +624,13 @@ void Dialog::loadSettings()
restoreGeometry(Settings::getValue(CONF_DIALOG_GEOMETRY).toByteArray());
}

int defaultAutoSleepBattery = AUTO_SLEEP_BATTERY;
int defaultAutoSleepBattery = POWERKIT_AUTO_SLEEP_BATTERY;
if (Settings::isValid(CONF_SUSPEND_BATTERY_TIMEOUT)) {
defaultAutoSleepBattery = Settings::getValue(CONF_SUSPEND_BATTERY_TIMEOUT).toInt();
}
setDefaultAction(autoSleepBattery, defaultAutoSleepBattery);

int defaultAutoSleepBatteryAction = DEFAULT_SUSPEND_BATTERY_ACTION;
int defaultAutoSleepBatteryAction = POWERKIT_SUSPEND_BATTERY_ACTION;
if (Settings::isValid(CONF_SUSPEND_BATTERY_ACTION)) {
defaultAutoSleepBatteryAction = Settings::getValue(CONF_SUSPEND_BATTERY_ACTION).toInt();
}
Expand All @@ -642,31 +642,31 @@ void Dialog::loadSettings()
}
setDefaultAction(autoSleepAC, defaultAutoSleepAC);

int defaultAutoSleepACAction = DEFAULT_SUSPEND_AC_ACTION;
int defaultAutoSleepACAction = POWERKIT_SUSPEND_AC_ACTION;
if (Settings::isValid(CONF_SUSPEND_AC_ACTION)) {
defaultAutoSleepACAction = Settings::getValue(CONF_SUSPEND_AC_ACTION).toInt();
}
setDefaultAction(autoSleepACAction, defaultAutoSleepACAction);

int defaultCriticalBattery = CRITICAL_BATTERY;
int defaultCriticalBattery = POWERKIT_CRITICAL_BATTERY;
if (Settings::isValid(CONF_CRITICAL_BATTERY_TIMEOUT)) {
defaultCriticalBattery = Settings::getValue(CONF_CRITICAL_BATTERY_TIMEOUT).toInt();
}
setDefaultAction(criticalBattery, defaultCriticalBattery);

int defaultLidActionBattery = LID_BATTERY_DEFAULT;
int defaultLidActionBattery = POWERKIT_LID_BATTERY_ACTION;
if (Settings::isValid(CONF_LID_BATTERY_ACTION)) {
defaultLidActionBattery = Settings::getValue(CONF_LID_BATTERY_ACTION).toInt();
}
setDefaultAction(lidActionBattery, defaultLidActionBattery);

int defaultLidActionAC = LID_AC_DEFAULT;
int defaultLidActionAC = POWERKIT_LID_AC_ACTION;
if (Settings::isValid(CONF_LID_AC_ACTION)) {
defaultLidActionAC = Settings::getValue(CONF_LID_AC_ACTION).toInt();
}
setDefaultAction(lidActionAC, defaultLidActionAC);

int defaultCriticalAction = CRITICAL_DEFAULT;
int defaultCriticalAction = POWERKIT_CRITICAL_ACTION;
if (Settings::isValid(CONF_CRITICAL_BATTERY_ACTION)) {
defaultCriticalAction = Settings::getValue(CONF_CRITICAL_BATTERY_ACTION).toInt();
}
Expand Down Expand Up @@ -773,7 +773,7 @@ void Dialog::loadSettings()
if (!hasCpuCoreTemp) { cpuTempLabel->setVisible(false); }

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

void Dialog::saveSettings()
Expand Down
Loading

0 comments on commit 0178e00

Please sign in to comment.