Skip to content

Commit

Permalink
Fix broken logind PrepareForSleep
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Jan 29, 2024
1 parent 0a01bbf commit d09be0c
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions src/powerkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,13 @@ void PowerKit::setup()
UPOWER_NOTIFY_SLEEP,
this,
SLOT(handleSuspend()));
system.connect(LOGIND_SERVICE,
// DONT WORK ANYMORE! WHY?
/*system.connect(LOGIND_SERVICE,
LOGIND_PATH,
LOGIND_MANAGER,
PK_PREPARE_FOR_SUSPEND,
this,
SLOT(handlePrepareForSuspend(bool)));
SLOT(handlePrepareForSuspend(bool)));*/
if (upower == NULL) {
upower = new QDBusInterface(UPOWER_SERVICE,
UPOWER_PATH,
Expand All @@ -285,14 +286,19 @@ void PowerKit::setup()
this);
qDebug() << "powerkitd" << pmd->isValid();
}
if (logind->isValid()) {
connect(logind,
SIGNAL(PrepareForSleep(bool)),
this,
SLOT(handlePrepareForSuspend(bool)));
}
if (!suspendLock) { registerSuspendLock(); }
scan();
} else { qWarning() << "Failed to connect to system bus"; }
}

void PowerKit::check()
{
//qDebug() << "PK CHECK";
if (!QDBusConnection::systemBus().isConnected()) {
setup();
return;
Expand All @@ -303,7 +309,6 @@ void PowerKit::check()

void PowerKit::scan()
{
qDebug() << "PK SCAN";
QStringList foundDevices = find();
for (int i=0; i < foundDevices.size(); i++) {
QString foundDevicePath = foundDevices.at(i);
Expand All @@ -321,13 +326,12 @@ void PowerKit::scan()

void PowerKit::deviceAdded(const QDBusObjectPath &obj)
{
qDebug() << "PK DEVICE ADDED" << obj.path();
deviceAdded(obj.path());
}

void PowerKit::deviceAdded(const QString &path)
{
qDebug() << "PK DEVICE ADDED" << path;
qDebug() << "device added" << path;
if (!upower->isValid()) { return; }
if (path.startsWith(QString(DBUS_JOBS).arg(UPOWER_PATH))) { return; }
emit DeviceWasAdded(path);
Expand All @@ -336,13 +340,12 @@ void PowerKit::deviceAdded(const QString &path)

void PowerKit::deviceRemoved(const QDBusObjectPath &obj)
{
qDebug() << "PK DEVICE REMOVED" << obj.path();
deviceRemoved(obj.path());
}

void PowerKit::deviceRemoved(const QString &path)
{
qDebug() << "PK DEVICE REMOVED" << path;
qDebug() << "device removed" << path;
if (!upower->isValid()) { return; }
bool deviceExists = devices.contains(path);
if (path.startsWith(QString(DBUS_JOBS).arg(UPOWER_PATH))) { return; }
Expand All @@ -356,7 +359,6 @@ void PowerKit::deviceRemoved(const QString &path)

void PowerKit::deviceChanged()
{
//qDebug() << "PK DEVICE(S) CHANGED";
if (wasLidClosed != LidIsClosed()) {
if (!wasLidClosed && LidIsClosed()) {
emit LidClosed();
Expand All @@ -380,7 +382,7 @@ void PowerKit::deviceChanged()

void PowerKit::handleDeviceChanged(const QString &device)
{
//qDebug() << "PK HANDLE DEVICE CHANGED" << device;
qDebug() << "device changed" << device;
if (device.isEmpty()) { return; }
deviceChanged();
}
Expand All @@ -404,11 +406,13 @@ void PowerKit::handlePrepareForSuspend(bool prepare)
{
qDebug() << "handle prepare for suspend/resume from consolekit/logind" << prepare;
if (prepare) {
qDebug() << "ZZZ...";
if (lockScreenOnSuspend) { LockScreen(); }
emit PrepareForSuspend();
releaseSuspendLock(); // we are ready for suspend
}
else { // resume
qDebug() << "WAKE UP!";
UpdateDevices();
if (lockScreenOnResume) { LockScreen(); }
if (hasWakeAlarm() &&
Expand Down Expand Up @@ -507,37 +511,32 @@ void PowerKit::setWakeAlarmFromSettings()

bool PowerKit::HasLogind()
{
//qDebug() << "PK CHECK FOR LOGIND";
return availableService(LOGIND_SERVICE,
LOGIND_PATH,
LOGIND_MANAGER);
}

bool PowerKit::HasUPower()
{
//qDebug() << "PK CHECK FOR UPOWER";
return availableService(UPOWER_SERVICE,
UPOWER_PATH,
UPOWER_MANAGER);
}

bool PowerKit::hasPMD()
{
//qDebug() << "PK CHECK FOR POWERKITD";
return availableService(PMD_SERVICE,
PMD_PATH,
PMD_MANAGER);
}

bool PowerKit::hasWakeAlarm()
{
//qDebug() << "PK CHECK FOR WAKE ALARM";
return wakeAlarm;
}

bool PowerKit::CanRestart()
{
//qDebug() << "PK CHECK FOR RESTART SUPPORT";
if (HasLogind()) {
return availableAction(PKCanRestart, PKLogind);
}
Expand All @@ -546,7 +545,6 @@ bool PowerKit::CanRestart()

bool PowerKit::CanPowerOff()
{
//qDebug() << "PK CHECK FOR SHUTDOWN SUPPORT";
if (HasLogind()) {
return availableAction(PKCanPowerOff, PKLogind);
}
Expand All @@ -555,7 +553,6 @@ bool PowerKit::CanPowerOff()

bool PowerKit::CanSuspend()
{
//qDebug() << "PK CHECK FOR SUSPEND SUPPORT";
if (HasLogind()) {
return availableAction(PKCanSuspend, PKLogind);
} else if (HasUPower()) {
Expand All @@ -566,7 +563,6 @@ bool PowerKit::CanSuspend()

bool PowerKit::CanHibernate()
{
//qDebug() << "PK CHECK FOR HIBERNATE SUPPORT";
if (HasLogind()) {
return availableAction(PKCanHibernate, PKLogind);
} else if (HasUPower()) {
Expand All @@ -577,7 +573,6 @@ bool PowerKit::CanHibernate()

bool PowerKit::CanHybridSleep()
{
//qDebug() << "PK CHECK FOR HYBRIDSLEEP SUPPORT";
if (HasLogind()) {
return availableAction(PKCanHybridSleep, PKLogind);
}
Expand Down Expand Up @@ -664,36 +659,31 @@ void PowerKit::clearWakeAlarm()

bool PowerKit::IsDocked()
{
//qDebug() << "PK CHECK FOR DOCK";
if (logind->isValid()) { return logind->property(LOGIND_DOCKED).toBool(); }
if (upower->isValid()) { return upower->property(UPOWER_DOCKED).toBool(); }
return false;
}

bool PowerKit::LidIsPresent()
{
//qDebug() << "PK CHECK FOR LID";
if (upower->isValid()) { return upower->property(UPOWER_LID_IS_PRESENT).toBool(); }
return false;
}

bool PowerKit::LidIsClosed()
{
//qDebug() << "PK CHECK LID STATUS";
if (upower->isValid()) { return upower->property(UPOWER_LID_IS_CLOSED).toBool(); }
return false;
}

bool PowerKit::OnBattery()
{
//qDebug() << "PK CHECK FOR ON BATTERY";
if (upower->isValid()) { return upower->property(UPOWER_ON_BATTERY).toBool(); }
return false;
}

double PowerKit::BatteryLeft()
{
//qDebug() << "PK CHECK FOR BATTERY LEFT";
if (OnBattery()) { UpdateBattery(); }
double batteryLeft = 0;
QMapIterator<QString, Device*> device(devices);
Expand Down Expand Up @@ -725,7 +715,6 @@ void PowerKit::LockScreen()

bool PowerKit::HasBattery()
{
//qDebug() << "PK CHECK IF HAS BATTERY";
QMapIterator<QString, Device*> device(devices);
while (device.hasNext()) {
device.next();
Expand All @@ -736,7 +725,6 @@ bool PowerKit::HasBattery()

qlonglong PowerKit::TimeToEmpty()
{
//qDebug() << "PK CHECK FOR TIME TO EMPTY";
if (OnBattery()) { UpdateBattery(); }
qlonglong result = 0;
QMapIterator<QString, Device*> device(devices);
Expand All @@ -752,7 +740,6 @@ qlonglong PowerKit::TimeToEmpty()

qlonglong PowerKit::TimeToFull()
{
//qDebug() << "PK CHECK FOR TIME TO FULL";
if (OnBattery()) { UpdateBattery(); }
qlonglong result = 0;
QMapIterator<QString, Device*> device(devices);
Expand All @@ -768,7 +755,6 @@ qlonglong PowerKit::TimeToFull()

void PowerKit::UpdateDevices()
{
qDebug() << "PK UPDATE DEVICES";
QMapIterator<QString, Device*> device(devices);
while (device.hasNext()) {
device.next();
Expand All @@ -778,7 +764,6 @@ void PowerKit::UpdateDevices()

void PowerKit::UpdateBattery()
{
qDebug() << "PK UPDATE BATTERY";
QMapIterator<QString, Device*> device(devices);
while (device.hasNext()) {
device.next();
Expand All @@ -790,7 +775,6 @@ void PowerKit::UpdateBattery()

void PowerKit::UpdateConfig()
{
qDebug() << "PK UPDATE CONFIG";
emit Update();
}

Expand Down

0 comments on commit d09be0c

Please sign in to comment.