static int powerkey_short_pressed_cb(void *data)
{
int keycode;
+ int retval;
+ guint64 current_time_ms = 0;
+ struct timespec ts;
+
static int sleep_enabled = 0; /* initial sleep state: disabled */
+ static guint64 sleep_id = 0; /* increased by 1 on enabling sleep */
if (!data)
return 0;
sleep_enabled ^= 1; /* toggle status */
if (sleep_enabled) {
+ retval = clock_gettime(CLOCK_REALTIME, &ts);
+ if (retval == 0)
+ current_time_ms = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
+
+ ++sleep_id;
+ gdbus_signal_emit(NULL, DEVICED_PATH_POWER, DEVICED_INTERFACE_POWER,
+ "sleep", g_variant_new("(tt)", current_time_ms, sleep_id));
device_notify(DEVICE_NOTIFIER_REQUEST_ENABLE_AUTOSLEEP, NULL);
- _D("Sleep enabled");
} else {
device_notify(DEVICE_NOTIFIER_REQUEST_DISABLE_AUTOSLEEP, NULL);
- _D("Sleep disabled");
}
return 0;