summaryrefslogtreecommitdiffstats
path: root/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2018-11-10 01:06:57 +0900
committerMichele Calgaro <michele.calgaro@yahoo.it>2019-02-06 23:37:11 +0900
commitcebadfa114d50a465f9d04d59da5015fed673b26 (patch)
tree72e80ca3cebccc9a665f53830e71ee898f47b0ea /tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
parentbd468a3703ac47e559a945ed7e1afbc082bcaddf (diff)
downloadtdelibs-cebadfa114d50a465f9d04d59da5015fed673b26.tar.gz
tdelibs-cebadfa114d50a465f9d04d59da5015fed673b26.zip
Improved support for suspend modes for both older and newer kernels.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c')
-rw-r--r--tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c75
1 files changed, 54 insertions, 21 deletions
diff --git a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
index a0b6870b1..2a10d67c6 100644
--- a/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
+++ b/tdecore/tdehw/hwlibdaemons/dbus/tde_dbus_hardwarecontrol.c
@@ -254,7 +254,7 @@ void reply_SetBrightness(DBusMessage* msg, DBusConnection* conn) {
free(safepath);
}
-void reply_CanSetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, char* disk, char* mem) {
+bool check_CanSetSuspend(char* state, char* disk, char* mem) {
// check if required files are writable
bool files_writable = (access("/sys/power/state", W_OK) == 0);
if (disk)
@@ -267,7 +267,7 @@ void reply_CanSetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, ch
}
if (!files_writable)
{
- reply_Bool(msg, conn, false); // send reply
+ return false;
}
// check if method is supported
@@ -286,7 +286,7 @@ void reply_CanSetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, ch
}
if (!result)
{
- reply_Bool(msg, conn, false); // send reply
+ return false;
}
// disk
@@ -306,7 +306,7 @@ void reply_CanSetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, ch
}
if (!result)
{
- reply_Bool(msg, conn, false); // send reply
+ return false;
}
// mem_sleep
@@ -324,11 +324,10 @@ void reply_CanSetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, ch
fclose(mem_node);
}
}
-
- reply_Bool(msg, conn, result); // send reply
+ return result;
}
-void reply_SetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, char* disk, char* mem) {
+bool do_SetSuspend(char* state, char* disk, char* mem) {
// check if required files are writable
bool files_writable = (access("/sys/power/state", W_OK) == 0);
if (disk)
@@ -339,10 +338,6 @@ void reply_SetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, char*
{
files_writable &= (access("/sys/power/mem_sleep", W_OK) == 0);
}
- if (!files_writable)
- {
- reply_Bool(msg, conn, false); // send reply
- }
// set suspend mode
bool result = files_writable;
@@ -375,7 +370,10 @@ void reply_SetSuspend(DBusMessage* msg, DBusConnection* conn, char* state, char*
fclose(state_node);
}
}
+ return result;
+}
+void reply_SetSuspend(DBusMessage* msg, DBusConnection* conn, bool result) {
// create a reply from the message
DBusMessage *reply = dbus_message_new_method_return(msg);
const char* member = dbus_message_get_member(msg);
@@ -781,34 +779,69 @@ void listen() {
reply_SetBrightness(msg, conn);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanFreeze")) {
- reply_CanSetSuspend(msg, conn, "freeze", NULL, NULL);
+ bool result = check_CanSetSuspend("freeze", NULL, NULL) || check_CanSetSuspend("mem", NULL, "s2idle");
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) {
- reply_SetSuspend(msg, conn, "freeze", NULL, NULL);
+ bool result = false;
+ if (check_CanSetSuspend("freeze", NULL, NULL)) {
+ result = do_SetSuspend("freeze", NULL, NULL);
+ }
+ else if (check_CanSetSuspend("mem", NULL, "s2idle")) {
+ result = do_SetSuspend("mem", NULL, "s2idle");
+ }
+ reply_SetSuspend(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanStandby")) {
- reply_CanSetSuspend(msg, conn, "standby", NULL, NULL);
+ bool result = check_CanSetSuspend("standby", NULL, NULL) || check_CanSetSuspend("mem", NULL, "shallow");
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) {
- reply_SetSuspend(msg, conn, "standby", NULL, NULL);
+ bool result = false;
+ if (check_CanSetSuspend("standby", NULL, NULL)) {
+ result = do_SetSuspend("standby", NULL, NULL);
+ }
+ else if (check_CanSetSuspend("mem", NULL, "shallow")) {
+ result = do_SetSuspend("mem", NULL, "shallow");
+ }
+ reply_SetSuspend(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) {
- reply_CanSetSuspend(msg, conn, "mem", NULL, "deep");
+ bool result = (check_CanSetSuspend("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) ||
+ check_CanSetSuspend("mem", NULL, "deep");
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Suspend")) {
- reply_SetSuspend(msg, conn, "mem", NULL, "deep");
+ bool result = false;
+ if (check_CanSetSuspend("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) {
+ result = do_SetSuspend("mem", NULL, NULL);
+ }
+ else if (check_CanSetSuspend("mem", NULL, "deep")) {
+ result = do_SetSuspend("mem", NULL, "deep");
+ }
+ reply_SetSuspend(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHybridSuspend")) {
- reply_CanSetSuspend(msg, conn, "disk", "suspend", NULL);
+ bool result = check_CanSetSuspend("disk", "suspend", NULL);
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "HybridSuspend")) {
- reply_SetSuspend(msg, conn, "disk", "suspend", NULL);
+ bool result = do_SetSuspend("disk", "suspend", NULL);
+ reply_SetSuspend(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) {
- reply_CanSetSuspend(msg, conn, "disk", "shutdown", NULL);
+ bool result = check_CanSetSuspend("disk", "shutdown", NULL) || check_CanSetSuspend("disk", "platform", NULL);
+ reply_Bool(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) {
- reply_SetSuspend(msg, conn, "disk", "shutdown", NULL);
+ bool result = false;
+ if (check_CanSetSuspend("disk", "shutdown", NULL)) {
+ result = do_SetSuspend("disk", "shutdown", NULL);
+ }
+ else if (check_CanSetSuspend("disk", "platform", NULL)) {
+ result = do_SetSuspend("disk", "platform", NULL);
+ }
+ reply_SetSuspend(msg, conn, result);
}
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod")) {
reply_CanSetHibernationMethod(msg, conn);