diff --git a/src/launcher/HyDE.py b/src/launcher/HyDE.py index 27c8ae4..ef20a1b 100644 --- a/src/launcher/HyDE.py +++ b/src/launcher/HyDE.py @@ -1153,9 +1153,12 @@ def main_loop(): if prev_locked_keys != INPUT.locked_keys: prev_locked_keys = INPUT.locked_keys.copy() redraw_display = True + display.Display.draw_overlays = True if keys: redraw_display = True + display.Display.draw_overlays = True + for key in keys: if "CTL" in mod_keys: diff --git a/src/lib/display/display.py b/src/lib/display/display.py index def7d50..232fe4d 100644 --- a/src/lib/display/display.py +++ b/src/lib/display/display.py @@ -27,6 +27,9 @@ class Display(st7789.ST7789): Subclasses the device-specific display driver. """ + # Set to True to redraw all overlays next time show is called + draw_overlays = False + # A public list of overlay functions, to be called in order. overlay_callbacks = [] def __new__(cls, **kwargs): # noqa: ARG003, D102 @@ -85,5 +88,7 @@ def _draw_overlays(self): def show(self): """Write changes to display.""" - self._draw_overlays() + if Display.draw_overlays: + self._draw_overlays() + Display.draw_overlays = False super().show() diff --git a/src/lib/userinput/userinput.py b/src/lib/userinput/userinput.py index 1e74c0a..ad01545 100644 --- a/src/lib/userinput/userinput.py +++ b/src/lib/userinput/userinput.py @@ -215,6 +215,8 @@ def handle_locking_keys(self): # key already in locked keys, must have been pressed twice. locked_keys.remove(key) tracker[key] = False + # Redraw the locked keys overlay + Display.draw_overlays = True elif len(self.key_state) > 1: # multiple keys are being pressed together, dont lock this key @@ -223,6 +225,8 @@ def handle_locking_keys(self): # key has just been released and should be locked locked_keys.append(key) tracker.pop(key) + # Redraw the locked keys overlay + Display.draw_overlays = True # tracker val is False elif not is_being_pressed: diff --git a/wiki/Display.md b/wiki/Display.md index fe33c06..9abfb07 100644 --- a/wiki/Display.md +++ b/wiki/Display.md @@ -277,7 +277,10 @@ display.show() ## Overlay Callbacks: The Display also has an attribute for storing overlay drawing functions. -`Display.overlay_callbacks` is a list of callbacks, to be called every time `Display.show()` is called (before writing the framebuffer). +`Display.draw_overlays` is a boolean flag that tells the display to redraw the overlays. *(Set this to `True` to flag that something on the display has changed, and so the overlays should be redrawn)* + +`Display.overlay_callbacks` is a public list of callback functions, to be called when `Display.show()` is called *(If `Display.draw_overlays` is `True`).* + The callbacks should accept the the `Display` object as a single positional argument. This is how the `userinput` module is able to draw 'locked' modifier keys over top of the other graphics on screen.