Skip to content

Commit

Permalink
Misc
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Feb 9, 2024
1 parent dd52dee commit 407a44b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 24 deletions.
22 changes: 10 additions & 12 deletions src/powerkit_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ App::App(QObject *parent)
this,
SLOT(handleTrayWheel(TrayIcon::WheelAction)));

// setup manager
// setup org.freedesktop.PowerKit.Manager
man = new Manager(this);
connect(man,
SIGNAL(UpdatedDevices()),
Expand Down Expand Up @@ -191,7 +191,6 @@ App::App(QObject *parent)
tray->setIcon(QIcon::fromTheme(DEFAULT_AC_ICON));
}

// load settings and register service
loadSettings();
registerService();

Expand Down Expand Up @@ -221,7 +220,6 @@ App::~App()
{
}

// what to do when user clicks systray
void App::trayActivated(QSystemTrayIcon::ActivationReason reason)
{
Q_UNUSED(reason)
Expand All @@ -231,12 +229,7 @@ void App::trayActivated(QSystemTrayIcon::ActivationReason reason)

void App::checkDevices()
{
// show/hide tray
if (tray->isSystemTrayAvailable() &&
!tray->isVisible() &&
showTray) { tray->show(); }
if (!showTray &&
tray->isVisible()) { tray->hide(); }
updateTrayVisibility();

double batteryLeft = man->BatteryLeft();
qDebug() << "battery at" << batteryLeft;
Expand Down Expand Up @@ -653,15 +646,20 @@ void App::updateToolTip()
} else { tray->setToolTip(tr("On AC")); }
}

// timeout, check if idle
// timeouts and xss must be >= user value and service has to be empty before suspend
void App::timeout()
void App::updateTrayVisibility()
{
if (!showTray &&
tray->isVisible()) { tray->hide(); }
if (tray->isSystemTrayAvailable() &&
!tray->isVisible() &&
showTray) { tray->show(); }
}

// timeout, check if idle
// timeouts and xss must be >= user value and service has to be empty before suspend
void App::timeout()
{
updateTrayVisibility();

int uIdle = ss->GetSessionIdleTime() / 60;

Expand Down
1 change: 1 addition & 0 deletions src/powerkit_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace PowerKit
void handleCritical(double left);
void drawBattery(double left);
void updateToolTip();
void updateTrayVisibility();
void timeout();
void resetTimer();
void setInternalMonitor();
Expand Down
36 changes: 24 additions & 12 deletions src/powerkit_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,34 +280,46 @@ void Manager::deviceChanged()

void Manager::propertiesChanged()
{
bool isLidClosed = LidIsClosed();
bool isOnBattery = OnBattery();
bool closed = LidIsClosed();
bool battery = OnBattery();
bool docked = IsDocked();

qDebug() << "properties changed:"
<< "lid closed?" << wasLidClosed << isLidClosed
<< "on battery?" << wasOnBattery << isOnBattery;
<< "lid closed?" << wasLidClosed << closed
<< "on battery?" << wasOnBattery << battery
<< "is docked?" << wasDocked << docked;

if (wasLidClosed != isLidClosed) {
if (!wasLidClosed && isLidClosed) {
if (wasLidClosed != closed) {
if (!wasLidClosed && closed) {
qDebug() << "lid changed to closed";
emit LidClosed();
} else if (wasLidClosed && !isLidClosed) {
} else if (wasLidClosed && !closed) {
qDebug() << "lid changed to open";
emit LidOpened();
}
emit isLidClosedChanged(closed);
qDebug() << "is lid closed changed" << closed;
}
wasLidClosed = isLidClosed;
wasLidClosed = closed;

if (wasOnBattery != isOnBattery) {
if (!wasOnBattery && isOnBattery) {
if (wasOnBattery != battery) {
if (!wasOnBattery && battery) {
qDebug() << "switched to battery power";
emit SwitchedToBattery();
} else if (wasOnBattery && !isOnBattery) {
} else if (wasOnBattery && !battery) {
qDebug() << "switched to ac power";
emit SwitchedToAC();
}
qDebug() << "is on battery changed" << battery;
emit isOnBatteryChanged(battery);
}
wasOnBattery = isOnBattery;
wasOnBattery = battery;

if (wasDocked != docked) {
qDebug() << "is docked changed" << docked;
emit isDockedChanged(docked);
}
wasDocked = docked;

deviceChanged();
}
Expand Down
5 changes: 5 additions & 0 deletions src/powerkit_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ namespace PowerKit
void Error(const QString &message);
void Warning(const QString &message);

void isDockedChanged(bool isDocked);
void isLidClosedChanged(bool isClosed);
void isOnBatteryChanged(bool onBattery);


private slots:
bool canLogind(const QString &method);
const QDBusMessage callLogind(const QString &method);
Expand Down

0 comments on commit 407a44b

Please sign in to comment.