|
|
|
@ -254,7 +254,7 @@ void reply_SetBrightness(DBusMessage* msg, DBusConnection* conn) {
|
|
|
|
|
free(safepath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool check_CanSetSuspend(char* state, char* disk, char* mem) {
|
|
|
|
|
bool CanSetPowerState(const char* state, const char* disk, const char* mem) {
|
|
|
|
|
// check if required files are writable
|
|
|
|
|
bool files_writable = (access("/sys/power/state", W_OK) == 0);
|
|
|
|
|
if (disk)
|
|
|
|
@ -327,7 +327,7 @@ bool check_CanSetSuspend(char* state, char* disk, char* mem) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool do_SetSuspend(char* state, char* disk, char* mem) {
|
|
|
|
|
bool SetPowerState(const char* state, const char* disk, const char* mem) {
|
|
|
|
|
// check if required files are writable
|
|
|
|
|
bool files_writable = (access("/sys/power/state", W_OK) == 0);
|
|
|
|
|
if (disk)
|
|
|
|
@ -373,31 +373,6 @@ bool do_SetSuspend(char* state, char* disk, char* mem) {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
// add the arguments to the reply
|
|
|
|
|
DBusMessageIter args;
|
|
|
|
|
dbus_message_iter_init_append(reply, &args);
|
|
|
|
|
if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_BOOLEAN, &result)) {
|
|
|
|
|
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_message_iter_append_basic failed\n", member);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// send the reply && flush the connection
|
|
|
|
|
dbus_uint32_t serial = 0;
|
|
|
|
|
if (!dbus_connection_send(conn, reply, &serial)) {
|
|
|
|
|
fprintf(stderr, "[tde_dbus_hardwarecontrol] %s: dbus_connection_send failed\n", member);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dbus_connection_flush(conn);
|
|
|
|
|
|
|
|
|
|
// free the reply
|
|
|
|
|
dbus_message_unref(reply);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reply_CanSetHibernationMethod(DBusMessage* msg, DBusConnection* conn) {
|
|
|
|
|
// check if path is writable
|
|
|
|
|
reply_CanSetGivenPath(msg, conn, "/sys/power/disk");
|
|
|
|
@ -778,69 +753,69 @@ void listen() {
|
|
|
|
|
reply_SetBrightness(msg, conn);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanFreeze")) {
|
|
|
|
|
bool result = check_CanSetSuspend("freeze", NULL, NULL) || check_CanSetSuspend("mem", NULL, "s2idle");
|
|
|
|
|
bool result = CanSetPowerState("freeze", NULL, NULL) || CanSetPowerState("mem", NULL, "s2idle");
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Freeze")) {
|
|
|
|
|
bool result = false;
|
|
|
|
|
if (check_CanSetSuspend("freeze", NULL, NULL)) {
|
|
|
|
|
result = do_SetSuspend("freeze", NULL, NULL);
|
|
|
|
|
if (CanSetPowerState("freeze", NULL, NULL)) {
|
|
|
|
|
result = SetPowerState("freeze", NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
else if (check_CanSetSuspend("mem", NULL, "s2idle")) {
|
|
|
|
|
result = do_SetSuspend("mem", NULL, "s2idle");
|
|
|
|
|
else if (CanSetPowerState("mem", NULL, "s2idle")) {
|
|
|
|
|
result = SetPowerState("mem", NULL, "s2idle");
|
|
|
|
|
}
|
|
|
|
|
reply_SetSuspend(msg, conn, result);
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanStandby")) {
|
|
|
|
|
bool result = check_CanSetSuspend("standby", NULL, NULL) || check_CanSetSuspend("mem", NULL, "shallow");
|
|
|
|
|
bool result = CanSetPowerState("standby", NULL, NULL) || CanSetPowerState("mem", NULL, "shallow");
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Standby")) {
|
|
|
|
|
bool result = false;
|
|
|
|
|
if (check_CanSetSuspend("standby", NULL, NULL)) {
|
|
|
|
|
result = do_SetSuspend("standby", NULL, NULL);
|
|
|
|
|
if (CanSetPowerState("standby", NULL, NULL)) {
|
|
|
|
|
result = SetPowerState("standby", NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
else if (check_CanSetSuspend("mem", NULL, "shallow")) {
|
|
|
|
|
result = do_SetSuspend("mem", NULL, "shallow");
|
|
|
|
|
else if (CanSetPowerState("mem", NULL, "shallow")) {
|
|
|
|
|
result = SetPowerState("mem", NULL, "shallow");
|
|
|
|
|
}
|
|
|
|
|
reply_SetSuspend(msg, conn, result);
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSuspend")) {
|
|
|
|
|
bool result = (check_CanSetSuspend("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) ||
|
|
|
|
|
check_CanSetSuspend("mem", NULL, "deep");
|
|
|
|
|
bool result = (CanSetPowerState("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) ||
|
|
|
|
|
CanSetPowerState("mem", NULL, "deep");
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Suspend")) {
|
|
|
|
|
bool result = false;
|
|
|
|
|
if (check_CanSetSuspend("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) {
|
|
|
|
|
result = do_SetSuspend("mem", NULL, NULL);
|
|
|
|
|
if (CanSetPowerState("mem", NULL, NULL) && access("/sys/power/mem_sleep", R_OK) != 0) {
|
|
|
|
|
result = SetPowerState("mem", NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
else if (check_CanSetSuspend("mem", NULL, "deep")) {
|
|
|
|
|
result = do_SetSuspend("mem", NULL, "deep");
|
|
|
|
|
else if (CanSetPowerState("mem", NULL, "deep")) {
|
|
|
|
|
result = SetPowerState("mem", NULL, "deep");
|
|
|
|
|
}
|
|
|
|
|
reply_SetSuspend(msg, conn, result);
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHybridSuspend")) {
|
|
|
|
|
bool result = check_CanSetSuspend("disk", "suspend", NULL);
|
|
|
|
|
bool result = CanSetPowerState("disk", "suspend", NULL);
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "HybridSuspend")) {
|
|
|
|
|
bool result = do_SetSuspend("disk", "suspend", NULL);
|
|
|
|
|
reply_SetSuspend(msg, conn, result);
|
|
|
|
|
bool result = SetPowerState("disk", "suspend", NULL);
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanHibernate")) {
|
|
|
|
|
bool result = check_CanSetSuspend("disk", "shutdown", NULL) || check_CanSetSuspend("disk", "platform", NULL);
|
|
|
|
|
bool result = CanSetPowerState("disk", "shutdown", NULL) || CanSetPowerState("disk", "platform", NULL);
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "Hibernate")) {
|
|
|
|
|
bool result = false;
|
|
|
|
|
if (check_CanSetSuspend("disk", "shutdown", NULL)) {
|
|
|
|
|
result = do_SetSuspend("disk", "shutdown", NULL);
|
|
|
|
|
if (CanSetPowerState("disk", "shutdown", NULL)) {
|
|
|
|
|
result = SetPowerState("disk", "shutdown", NULL);
|
|
|
|
|
}
|
|
|
|
|
else if (check_CanSetSuspend("disk", "platform", NULL)) {
|
|
|
|
|
result = do_SetSuspend("disk", "platform", NULL);
|
|
|
|
|
else if (CanSetPowerState("disk", "platform", NULL)) {
|
|
|
|
|
result = SetPowerState("disk", "platform", NULL);
|
|
|
|
|
}
|
|
|
|
|
reply_SetSuspend(msg, conn, result);
|
|
|
|
|
reply_Bool(msg, conn, result);
|
|
|
|
|
}
|
|
|
|
|
else if (dbus_message_is_method_call(msg, "org.trinitydesktop.hardwarecontrol.Power", "CanSetHibernationMethod")) {
|
|
|
|
|
reply_CanSetHibernationMethod(msg, conn);
|
|
|
|
|