From ef71bc11c0634fc575164e40bfe4afa6688c3fd9 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Tue, 16 Jan 2024 11:43:23 +0100 Subject: [PATCH] jscene: poweroff upon SHIFT+AC/ON --- include/justui/jscene.h | 8 ++++++++ src/jscene.c | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/include/justui/jscene.h b/include/justui/jscene.h index 95961cb..cb045b6 100644 --- a/include/justui/jscene.h +++ b/include/justui/jscene.h @@ -33,6 +33,8 @@ typedef struct { uint16_t lost_events; /* Whether jscene_run() returns to the main menu */ bool mainmenu; + /* Whether jscene_run() powers off */ + bool poweroff; } jscene; @@ -110,6 +112,12 @@ bool jscene_process_event(jscene *scene, jevent event); resources before invoking the main menu. */ void jscene_set_mainmenu(jscene *scene, bool mainmenu); +/* jscene_set_poweroff(): Set whether jscene_run() will poweroff + This type of poweroff (SHIFT+AC/ON) doesn't allow return to menu, so the + add-in "must" resume after powering on again, however sensitive programs + will probably want to save important data before leaving anyway. */ +void jscene_set_poweroff(jscene *scene, bool poweroff); + /* jscene_run(): Run a scene's main loop This function implements a main control loop that sleeps when there is diff --git a/src/jscene.c b/src/jscene.c index f572e09..f66e5d8 100644 --- a/src/jscene.c +++ b/src/jscene.c @@ -53,6 +53,7 @@ jscene *jscene_create(int x, int y, int w, int h, void *parent) s->queue_next = 0; s->lost_events = 0; s->mainmenu = true; + s->poweroff = true; /* Prepare first layout/paint operation */ s->widget.dirty = 1; @@ -225,6 +226,13 @@ jevent jscene_run(jscene *s) continue; } } + if(k.type == KEYEV_DOWN && k.key == KEY_ACON && k.shift && !k.alpha) { + if(s->poweroff) { + gint_poweroff(true); + jscene_queue_event(s, (jevent){ .type = JSCENE_PAINT }); + continue; + } + } #ifdef FX9860G if(k.type == KEYEV_DOWN && k.key == KEY_OPTN && k.shift && !k.alpha) { t6k11_backlight(-1);