From 6236db8134d63732c129a2731667933f0f06cf63 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Tue, 30 Apr 2024 23:09:38 +0200 Subject: [PATCH] widget_utils - Remove the overlay on cleanup --- modules/widget_utils.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/modules/widget_utils.js b/modules/widget_utils.js index 9d20e680376..aca4cbec95c 100644 --- a/modules/widget_utils.js +++ b/modules/widget_utils.js @@ -1,4 +1,3 @@ -/// hide any visible widgets exports.hide = function() { exports.cleanup(); if (!global.WIDGETS) return; @@ -29,8 +28,17 @@ exports.show = function() { /// Remove any intervals/handlers/etc that we might have added. Does NOT re-show widgets that were hidden exports.cleanup = function() { + print(exports.cleanUpOverlay); delete exports.autohide; delete Bangle.appRect; + if (exports.cleanUpOverlay){ + if (exports.origSetLCDOverlay){ + Bangle.setLCDOverlay = exports.origSetLCDOverlay; + Bangle.setLCDOverlay(); + } + delete exports.cleanUpOverlay; + } + delete exports.origSetLCDOverlay; if (exports.swipeHandler) { Bangle.removeListener("swipe", exports.swipeHandler); delete exports.swipeHandler; @@ -67,6 +75,14 @@ exports.swipeOn = function(autohide) { /* TODO: maybe when widgets are offscreen we don't even store them in an offscreen buffer? */ + if (!exports.origSetLCDOverlay) { + exports.origSetLCDOverlay = Bangle.setLCDOverlay; + Bangle.setLCDOverlay = function(){ + exports.origSetLCDOverlay.apply(Bangle, arguments); + exports.cleanUpOverlay = false; + }; + } + // force app rect to be fullscreen Bangle.appRect = { x: 0, y: 0, w: g.getWidth(), h: g.getHeight(), x2: g.getWidth()-1, y2: g.getHeight()-1 }; // setup offscreen graphics for widgets @@ -83,8 +99,12 @@ exports.swipeOn = function(autohide) { function queueDraw() { Bangle.appRect.y = offset+24; Bangle.appRect.h = 1 + Bangle.appRect.y2 - Bangle.appRect.y; - if (offset>-24) Bangle.setLCDOverlay(og, 0, offset); - else Bangle.setLCDOverlay(); + if (offset>-24) { + Bangle.setLCDOverlay(og, 0, offset); + exports.cleanUpOverlay = true; + } else { + Bangle.setLCDOverlay(); + } } for (var w of global.WIDGETS) if (!w._draw) { // already hidden @@ -144,4 +164,4 @@ exports.swipeOn = function(autohide) { }; Bangle.on("swipe", exports.swipeHandler); Bangle.drawWidgets(); -}; +}; \ No newline at end of file