summaryrefslogtreecommitdiffstats
path: root/src/hardware.cpp
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2016-05-07 04:03:59 +1000
committerMichele Calgaro <michele.calgaro@yahoo.it>2016-05-07 04:03:59 +1000
commita3caab905b3c008aaa0ff9627c6647615330205d (patch)
tree36800621beebc1279d89a5cc3d0daef59522058a /src/hardware.cpp
parent676fba0b9f08d41e68b115bc91931b5d0aa53376 (diff)
downloadtdepowersave-a3caab905b3c008aaa0ff9627c6647615330205d.tar.gz
tdepowersave-a3caab905b3c008aaa0ff9627c6647615330205d.zip
Added support for hybrid suspend (aka suspend to RAM + suspend to disk).
This relates to bug 2601. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src/hardware.cpp')
-rw-r--r--src/hardware.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/hardware.cpp b/src/hardware.cpp
index 7b1c215..54d5027 100644
--- a/src/hardware.cpp
+++ b/src/hardware.cpp
@@ -390,6 +390,9 @@ void HardwareInfo::checkSuspend() {
suspend_states.standby = false;
suspend_states.standby_can = false;
suspend_states.standby_allowed = -1;
+ suspend_states.suspend_hybrid = false;
+ suspend_states.suspend_hybrid_can = false;
+ suspend_states.suspend_hybrid_allowed = -1;
TDERootSystemDevice* rdevice = m_hwdevices->rootSystemDevice();
TDESystemPowerStateList powerStates = rdevice->powerStates();
@@ -399,27 +402,32 @@ void HardwareInfo::checkSuspend() {
if ((*it) == TDESystemPowerState::Active) {
//
}
- if ((*it) == TDESystemPowerState::Standby) {
+ else if ((*it) == TDESystemPowerState::Standby) {
suspend_states.standby = true;
suspend_states.standby_allowed = rdevice->canStandby();
- suspend_states.standby_can = suspend_states.standby_allowed & suspend_states.standby;
+ suspend_states.standby_can = suspend_states.standby_allowed && suspend_states.standby;
}
- if ((*it) == TDESystemPowerState::Freeze) {
+ else if ((*it) == TDESystemPowerState::Freeze) {
suspend_states.freeze = true;
suspend_states.freeze_allowed = rdevice->canFreeze();
- suspend_states.freeze_can = suspend_states.freeze_allowed & suspend_states.freeze;
+ suspend_states.freeze_can = suspend_states.freeze_allowed && suspend_states.freeze;
}
- if ((*it) == TDESystemPowerState::Suspend) {
+ else if ((*it) == TDESystemPowerState::Suspend) {
suspend_states.suspend2ram = true;
suspend_states.suspend2ram_allowed = rdevice->canSuspend();
- suspend_states.suspend2ram_can = suspend_states.suspend2ram_allowed & suspend_states.suspend2ram;
+ suspend_states.suspend2ram_can = suspend_states.suspend2ram_allowed && suspend_states.suspend2ram;
}
- if ((*it) == TDESystemPowerState::Hibernate) {
+ else if ((*it) == TDESystemPowerState::Hibernate) {
suspend_states.suspend2disk = true;
suspend_states.suspend2disk_allowed = rdevice->canHibernate();
- suspend_states.suspend2disk_can = suspend_states.suspend2disk_allowed & suspend_states.suspend2disk;
+ suspend_states.suspend2disk_can = suspend_states.suspend2disk_allowed && suspend_states.suspend2disk;
}
- if ((*it) == TDESystemPowerState::PowerOff) {
+ else if ((*it) == TDESystemPowerState::HybridSuspend) {
+ suspend_states.suspend_hybrid = true;
+ suspend_states.suspend_hybrid_allowed = rdevice->canHybridSuspend();
+ suspend_states.suspend_hybrid_can = suspend_states.suspend_hybrid_allowed && suspend_states.suspend_hybrid;
+ }
+ else if ((*it) == TDESystemPowerState::PowerOff) {
//
}
}
@@ -801,6 +809,27 @@ bool HardwareInfo::suspend( suspend_type suspend ) {
return false;
}
break;
+
+ case SUSPEND_HYBRID:
+ if (suspend_states.suspend_hybrid && (suspend_states.suspend_hybrid_allowed != 0)) {
+ if (rdevice->setPowerState(TDESystemPowerState::HybridSuspend)) {
+ calledSuspend.start();
+ handleResumeSignal(0);
+ return true;
+ } else {
+ handleResumeSignal(-1);
+ return false;
+ }
+ } else {
+ if ( !suspend_states.suspend_hybrid )
+ kdDebug() << "The machine does not support hybrid suspension." << endl;
+ else
+ kdWarning() << "Policy forbid user to trigger hybrid suspension" << endl;
+
+ return false;
+ }
+ break;
+
case SUSPEND2RAM:
if (suspend_states.suspend2ram && (suspend_states.suspend2ram_allowed != 0)) {
if (rdevice->setPowerState(TDESystemPowerState::Suspend)) {
@@ -820,6 +849,7 @@ bool HardwareInfo::suspend( suspend_type suspend ) {
return false;
}
break;
+
case FREEZE:
if (suspend_states.freeze && (suspend_states.freeze_allowed != 0)) {
if (rdevice->setPowerState(TDESystemPowerState::Freeze)) {
@@ -839,6 +869,7 @@ bool HardwareInfo::suspend( suspend_type suspend ) {
return false;
}
break;
+
case STANDBY:
if (suspend_states.standby && (suspend_states.standby_allowed != 0)) {
if (rdevice->setPowerState(TDESystemPowerState::Standby)) {
@@ -858,6 +889,7 @@ bool HardwareInfo::suspend( suspend_type suspend ) {
return false;
}
break;
+
default:
return false;
}