Add support for freeze suspend state

pull/16/head
Slávek Banko 11 years ago
parent 101d86a3fc
commit 645e8c58a7

@ -356,6 +356,12 @@ void reply_Introspect(DBusMessage* msg, DBusConnection* conn) {
" <method name=\"Standby\">\n" " <method name=\"Standby\">\n"
" <arg name=\"value\" direction=\"out\" type=\"b\" />\n" " <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
" </method>\n" " </method>\n"
" <method name=\"CanFreeze\">\n"
" <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
" </method>\n"
" <method name=\"Freeze\">\n"
" <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
" </method>\n"
" <method name=\"CanSuspend\">\n" " <method name=\"CanSuspend\">\n"
" <arg name=\"value\" direction=\"out\" type=\"b\" />\n" " <arg name=\"value\" direction=\"out\" type=\"b\" />\n"
" </method>\n" " </method>\n"
@ -487,6 +493,12 @@ void listen() {
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) {
reply_SetPower(msg, conn, "standby"); reply_SetPower(msg, conn, "standby");
} }
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanFreeze")) {
reply_CanSetPower(msg, conn, "freeze");
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) {
reply_SetPower(msg, conn, "freeze");
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) { else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) {
reply_CanSetPower(msg, conn, "mem"); reply_CanSetPower(msg, conn, "mem");
} }

@ -147,6 +147,45 @@ bool TDERootSystemDevice::canStandby() {
return FALSE; return FALSE;
} }
bool TDERootSystemDevice::canFreeze() {
// Network file systems mounted on $HOME typically cause nasty suspend/resume failures
// See Bug 1615 for details
if (isNetworkFileSystem(TDEStorageDevice::determineFileSystemType(TDEGlobal::dirs()->localtdedir()))) {
return FALSE;
}
TQString statenode = "/sys/power/state";
int rval = access (statenode.ascii(), W_OK);
if (rval == 0) {
if (powerStates().contains(TDESystemPowerState::Freeze)) {
return TRUE;
}
else {
return FALSE;
}
}
#ifdef WITH_TDEHWLIB_DAEMONS
{
TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
if (dbusConn.isConnected()) {
// can freeze?
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
"CanFreeze");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
return reply[0].toBool();
}
}
}
#endif // WITH_TDEHWLIB_DAEMONS
return FALSE;
}
bool TDERootSystemDevice::canSuspend() { bool TDERootSystemDevice::canSuspend() {
// Network file systems mounted on $HOME typically cause nasty suspend/resume failures // Network file systems mounted on $HOME typically cause nasty suspend/resume failures
// See Bug 1615 for details // See Bug 1615 for details
@ -460,7 +499,7 @@ void TDERootSystemDevice::setHibernationMethod(TDESystemHibernationMethod::TDESy
} }
bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState ps) { bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState ps) {
if ((ps == TDESystemPowerState::Standby) || (ps == TDESystemPowerState::Suspend) || (ps == TDESystemPowerState::Hibernate)) { if ((ps == TDESystemPowerState::Standby) || (ps == TDESystemPowerState::Freeze) || (ps == TDESystemPowerState::Suspend) || (ps == TDESystemPowerState::Hibernate)) {
TQString statenode = "/sys/power/state"; TQString statenode = "/sys/power/state";
TQFile file( statenode ); TQFile file( statenode );
if ( file.open( IO_WriteOnly ) ) { if ( file.open( IO_WriteOnly ) ) {
@ -468,6 +507,9 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
if (ps == TDESystemPowerState::Standby) { if (ps == TDESystemPowerState::Standby) {
powerCommand = "standby"; powerCommand = "standby";
} }
if (ps == TDESystemPowerState::Freeze) {
powerCommand = "freeze";
}
if (ps == TDESystemPowerState::Suspend) { if (ps == TDESystemPowerState::Suspend) {
powerCommand = "mem"; powerCommand = "mem";
} }
@ -591,6 +633,17 @@ bool TDERootSystemDevice::setPowerState(TDESystemPowerState::TDESystemPowerState
return true; return true;
} }
} }
else if (ps == TDESystemPowerState::Freeze) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol",
"/org/trinitydesktop/hardwarecontrol",
"org.trinitydesktop.hardwarecontrol.Power",
"Freeze");
TQT_DBusMessage reply = dbusConn.sendWithReply(msg);
if (reply.type() == TQT_DBusMessage::ReplyMessage) {
return true;
}
}
else if (ps == TDESystemPowerState::Suspend) { else if (ps == TDESystemPowerState::Suspend) {
TQT_DBusMessage msg = TQT_DBusMessage::methodCall( TQT_DBusMessage msg = TQT_DBusMessage::methodCall(
"org.trinitydesktop.hardwarecontrol", "org.trinitydesktop.hardwarecontrol",

@ -37,6 +37,7 @@ namespace TDESystemPowerState {
enum TDESystemPowerState { enum TDESystemPowerState {
Active, Active,
Standby, Standby,
Freeze,
Suspend, Suspend,
Hibernate, Hibernate,
PowerOff, PowerOff,
@ -107,6 +108,11 @@ class TDECORE_EXPORT TDERootSystemDevice : public TDEGenericDevice
*/ */
bool canStandby(); bool canStandby();
/**
* @return TRUE if hardware and permissions allow the system to enter freeze state, FALSE if not
*/
bool canFreeze();
/** /**
* @return TRUE if hardware and permissions allow the system to be suspended, FALSE if not * @return TRUE if hardware and permissions allow the system to be suspended, FALSE if not
*/ */

Loading…
Cancel
Save