solid: correct cookie type and remove obsolete standby sleep mode

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-12-01 23:49:20 +02:00
parent f345af3c29
commit 3ab393c337
2 changed files with 19 additions and 20 deletions

View file

@ -101,7 +101,6 @@ void Solid::PowerManagement::requestSleep(SleepState state, QObject *receiver, c
Q_ASSERT(managerIface); Q_ASSERT(managerIface);
switch (state) { switch (state) {
case StandbyState:
case SuspendState: { case SuspendState: {
globalPowerManager()->managerIface->asyncCall("Suspend"); globalPowerManager()->managerIface->asyncCall("Suspend");
break; break;
@ -117,26 +116,25 @@ void Solid::PowerManagement::requestSleep(SleepState state, QObject *receiver, c
} }
} }
int Solid::PowerManagement::beginSuppressingSleep(const QString &reason) uint Solid::PowerManagement::beginSuppressingSleep(const QString &reason)
{ {
QDBusReply<uint> reply = globalPowerManager()->inhibitIface.call("Inhibit", QCoreApplication::applicationName(), reason); QDBusReply<uint> reply = globalPowerManager()->inhibitIface.call("Inhibit", QCoreApplication::applicationName(), reason);
if (reply.isValid()) if (reply.isValid())
return reply; return reply;
return -1; return 0;
} }
bool Solid::PowerManagement::stopSuppressingSleep(int cookie) bool Solid::PowerManagement::stopSuppressingSleep(uint cookie)
{ {
if (globalPowerManager()->inhibitIface.isValid()) { if (globalPowerManager()->inhibitIface.isValid()) {
globalPowerManager()->inhibitIface.asyncCall("UnInhibit", uint(cookie)); globalPowerManager()->inhibitIface.asyncCall("UnInhibit", cookie);
return true; return true;
} }
return false; return false;
} }
int Solid::PowerManagement::beginSuppressingScreenPowerManagement(const QString& reason) uint Solid::PowerManagement::beginSuppressingScreenPowerManagement(const QString& reason)
{ {
#warning TODO: the return type should be uint
if (globalPowerManager()->saverIface.isValid()) { if (globalPowerManager()->saverIface.isValid()) {
QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ScreenSaver"), QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ScreenSaver"),
QLatin1String("/ScreenSaver"), QLatin1String("/ScreenSaver"),
@ -152,20 +150,19 @@ int Solid::PowerManagement::beginSuppressingScreenPowerManagement(const QString&
return ssReply; return ssReply;
} }
// No way to fallback on something, hence return failure // No way to fallback on something, hence return failure (0 is invalid cookie)
return -1; return 0;
} }
bool Solid::PowerManagement::stopSuppressingScreenPowerManagement(int cookie) bool Solid::PowerManagement::stopSuppressingScreenPowerManagement(uint cookie)
{ {
#warning TODO: the cookie type should be uint
if (globalPowerManager()->saverIface.isValid()) { if (globalPowerManager()->saverIface.isValid()) {
if (globalPowerManager()->screensaverCookies.contains(cookie)) { if (globalPowerManager()->screensaverCookies.contains(cookie)) {
QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ScreenSaver"), QDBusMessage message = QDBusMessage::createMethodCall(QLatin1String("org.freedesktop.ScreenSaver"),
QLatin1String("/ScreenSaver"), QLatin1String("/ScreenSaver"),
QLatin1String("org.freedesktop.ScreenSaver"), QLatin1String("org.freedesktop.ScreenSaver"),
QLatin1String("UnInhibit")); QLatin1String("UnInhibit"));
message << uint(cookie); message << cookie;
QDBusReply<void> ssReply = QDBusConnection::sessionBus().call(message); QDBusReply<void> ssReply = QDBusConnection::sessionBus().call(message);
if (ssReply.isValid()) { if (ssReply.isValid()) {
globalPowerManager()->screensaverCookies.removeAll(cookie); globalPowerManager()->screensaverCookies.removeAll(cookie);

View file

@ -45,15 +45,17 @@ namespace Solid
/** /**
* This enum type defines the different suspend methods. * This enum type defines the different suspend methods.
* *
* - StandbyState: Processes are stopped, some hardware is deactivated (ACPI S1)
* - SuspendState: Most devices are deactivated, only RAM is powered (ACPI S3) * - SuspendState: Most devices are deactivated, only RAM is powered (ACPI S3)
* - HibernateState: State of the machine is saved to disk, and the machine is powered down (ACPI S4) * - HibernateState: State of the machine is saved to disk, and the machine is powered down (ACPI S4)
* - HybridSleepState: The contents of RAM are first copied to non-volatile storage like for regular hibernation, * - HybridSleepState: The contents of RAM are first copied to non-volatile storage like for regular hibernation,
* but then, instead of powering down, the computer enters sleep mode * but then, instead of powering down, the computer enters sleep mode
*/ */
enum SleepState { StandbyState = 1, SuspendState = 2, HibernateState = 4, enum SleepState {
SuspendState = 1,
HibernateState = 2,
/// @since 4.11 /// @since 4.11
HybridSuspendState = 8 }; HybridSuspendState = 4
};
/** /**
* Retrieves a high level indication of how applications should behave according to the * Retrieves a high level indication of how applications should behave according to the
@ -92,7 +94,7 @@ namespace Solid
* track the application's outstanding suppression requests. Returns -1 if the request was * track the application's outstanding suppression requests. Returns -1 if the request was
* denied. * denied.
*/ */
SOLID_EXPORT int beginSuppressingSleep(const QString &reason = QString()); SOLID_EXPORT uint beginSuppressingSleep(const QString &reason = QString());
/** /**
* Tell the power management that a particular sleep suppression is no longer needed. When * Tell the power management that a particular sleep suppression is no longer needed. When
@ -100,7 +102,7 @@ namespace Solid
* @param cookie The cookie acquired when requesting sleep suppression * @param cookie The cookie acquired when requesting sleep suppression
* @return true if the suppression was stopped, false if an invalid cookie was given * @return true if the suppression was stopped, false if an invalid cookie was given
*/ */
SOLID_EXPORT bool stopSuppressingSleep(int cookie); SOLID_EXPORT bool stopSuppressingSleep(uint cookie);
/** /**
* Tell the power management subsystem to suppress automatic screen power management until * Tell the power management subsystem to suppress automatic screen power management until
@ -114,7 +116,7 @@ namespace Solid
* *
* @since 4.6 * @since 4.6
*/ */
SOLID_EXPORT int beginSuppressingScreenPowerManagement(const QString &reason = QString()); SOLID_EXPORT uint beginSuppressingScreenPowerManagement(const QString &reason = QString());
/** /**
* Tell the power management that a particular screen power management suppression is no longer needed. When * Tell the power management that a particular screen power management suppression is no longer needed. When
@ -126,7 +128,7 @@ namespace Solid
* *
* @since 4.6 * @since 4.6
*/ */
SOLID_EXPORT bool stopSuppressingScreenPowerManagement(int cookie); SOLID_EXPORT bool stopSuppressingScreenPowerManagement(uint cookie);
class SOLID_EXPORT Notifier : public QObject class SOLID_EXPORT Notifier : public QObject
{ {