|
|
|
@ -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);
|
|
|
|
|