mowc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/mowc
Log | Files | Refs

commit f7ed998f5eac47df41749c9d5885c5afd959ed2b
parent 346caef87a910c87787bdc14dc71cfc97929abdd
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Sat, 26 Jun 2021 18:37:21 -0500

handle power button

Diffstat:
Mmowc.c | 26+++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/mowc.c b/mowc.c @@ -1,3 +1,4 @@ +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <swc.h> @@ -53,6 +54,29 @@ quit(void *data, uint32_t time, uint32_t value, uint32_t state) wl_display_terminate(display); } +bool justawoke = false; + +static void +power_handler(void *data, uint32_t time, uint32_t value, uint32_t state) +{ + if (state) // we only care about key releases + return; + + if (justawoke) { + justawoke = false; + return; + } + + FILE *power = fopen("/sys/power/state", "w"); + if (power == NULL) + return; + + fwrite("mem\n", sizeof(char), sizeof("mem\n") - 1, power); + + fclose(power); + justawoke = true; +} + int main(int argc, char *argv[]) { @@ -71,7 +95,7 @@ main(int argc, char *argv[]) if (!swc_initialize(display, NULL, &manager)) return 1; - swc_add_binding(SWC_BINDING_KEY, SWC_MOD_LOGO, XKB_KEY_q, &quit, NULL); + swc_add_binding(SWC_BINDING_KEY, 0, XKB_KEY_XF86PowerOff, power_handler, NULL); event_loop = wl_display_get_event_loop(display); wl_display_run(display);