Skip to content

Commit

Permalink
Overlayupdate (#179)
Browse files Browse the repository at this point in the history
* Add overlay redraw flag to display

* Update display documentation

* Update HyDE for new overlay features
  • Loading branch information
echo-lalia authored Nov 25, 2024
1 parent e36c129 commit 819ee6d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/launcher/HyDE.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion src/lib/display/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
4 changes: 4 additions & 0 deletions src/lib/userinput/userinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion wiki/Display.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 819ee6d

Please sign in to comment.