diff --git a/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py b/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py index 530eb860..2a26f176 100644 --- a/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py +++ b/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py @@ -2,9 +2,10 @@ import time import mpos.config import mpos.ui +import mpos.apps # screens: -appscreen = lv.screen_active() +main_screen = None settings_screen = None @@ -178,13 +179,13 @@ def settings_button_tap(event): global settings_screen if not settings_screen: settings_screen = SettingsScreen().screen - lv.screen_load(settings_screen) - #mpos.ui.startActivity(settings_screen) + mpos.ui.load_screen(settings_screen) def build_main_ui(): - appscreen.clean() - appscreen.set_style_pad_all(10, 0) - balance_label = lv.label(appscreen) + global main_screen + main_screen = lv.obj() + main_screen.set_style_pad_all(10, 0) + balance_label = lv.label(main_screen) balance_label.align(lv.ALIGN.TOP_LEFT, 0, 0) balance_label.set_style_text_font(lv.font_montserrat_20, 0) balance_label.set_text('123456') @@ -193,19 +194,20 @@ def build_main_ui(): style_line.set_line_width(4) style_line.set_line_color(lv.palette_main(lv.PALETTE.PINK)) style_line.set_line_rounded(True) - balance_line = lv.line(appscreen) + balance_line = lv.line(main_screen) balance_line.set_points([{'x':0,'y':35},{'x':300,'y':35}],2) balance_line.add_style(style_line, 0) - settings_button = lv.button(appscreen) + settings_button = lv.button(main_screen) settings_button.align(lv.ALIGN.BOTTOM_RIGHT, 0, 0) snap_label = lv.label(settings_button) snap_label.set_text(lv.SYMBOL.SETTINGS) snap_label.center() settings_button.add_event_cb(settings_button_tap,lv.EVENT.CLICKED,None) + mpos.ui.load_screen(main_screen) def janitor_cb(timer): - if lv.screen_active() != appscreen and lv.screen_active() != settings_screen: + if lv.screen_active() != main_screen and lv.screen_active() != settings_screen: print("app backgrounded, cleaning up...") janitor.delete() if settings_screen: diff --git a/internal_filesystem/boot_unix.py b/internal_filesystem/boot_unix.py index 5a19fdfd..3b88c221 100644 --- a/internal_filesystem/boot_unix.py +++ b/internal_filesystem/boot_unix.py @@ -33,39 +33,59 @@ mouse = sdl_pointer.SDLPointer() #keyboard.add_event_cb(keyboard_cb, lv.EVENT.ALL, None) +# Swipe detection state # Swipe detection state start_y = None # Store the starting Y-coordinate of the mouse press -def swipe_read_cb(indev_drv, data): - global start_y +start_x = None # Store the starting X-coordinate for left-edge swipe - pressed = mouse.get_state() - #print(f"mouse_state: {pressed}") +def swipe_read_cb(indev_drv, data): + global start_y, start_x + + pressed = mouse.get_state() # Get mouse/touch pressed state point = lv.point_t() - mouse.get_point(point) - #print(f"X={point.x}, Y={point.y}") + mouse.get_point(point) # Get current coordinates x, y = point.x, point.y - if pressed and start_y is None: - start_y = y - # Mouse button pressed (start of potential swipe) + if pressed and start_y is None and start_x is None: + # Mouse/touch pressed (start of potential swipe) + start_y = y # Store Y for vertical swipe detection + start_x = x # Store X for horizontal swipe detection + print(f"Mouse press at X={start_x}, Y={start_y}") + + # Check if press is in notification bar (for swipe down) if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: - # Store starting Y if press is in the notification bar area - print(f"Mouse press at Y={start_y}") - elif pressed and start_y is not None: - # Mouse dragged while pressed (potential swipe in progress) + print(f"Press in notification bar at Y={start_y}") + # Check if press is near left edge (for swipe right) + if x <= 20: # Adjust threshold for left edge (e.g., 20 pixels) + print(f"Press near left edge at X={start_x}") + elif pressed and (start_y is not None or start_x is not None): + # Mouse/touch dragged while pressed (potential swipe in progress) + # Check for downward swipe (y increased significantly) - if y > start_y + 50: # Threshold for swipe detection (adjust as needed) - print("long swipe down") + if start_y is not None and y > start_y + 50: # Threshold for swipe down + print("Long swipe down") if start_y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: print("Swipe Down Detected from Notification Bar") mpos.ui.open_drawer() - start_y = None # Reset after swipe + start_y = None # Reset Y after swipe + start_x = None # Reset X to avoid conflicts + # Check for rightward swipe from left edge (x increased significantly) + if start_x is not None and x > start_x + 50: # Threshold for swipe right + print("Long swipe right") + if start_x <= 20: # Confirm swipe started near left edge + print("Swipe Right Detected from Left Edge") + mpos.ui.back_screen() # Call custom method for left menu + start_y = None # Reset Y after swipe + start_x = None # Reset X after swipe else: - # Mouse button released + # Mouse/touch released if start_y is not None and y < start_y - 50: # Threshold for swipe-up print("Swipe Up Detected") mpos.ui.close_drawer() - start_y = None # Reset on release + + # Reset both coordinates on release + start_y = None + start_x = None # Register the custom read callback with the input device indev = lv.indev_create() diff --git a/internal_filesystem/lib/mpos/apps.py b/internal_filesystem/lib/mpos/apps.py index fef798c0..ea59427a 100644 --- a/internal_filesystem/lib/mpos/apps.py +++ b/internal_filesystem/lib/mpos/apps.py @@ -110,7 +110,6 @@ def start_app(app_dir, is_launcher=False): else: mpos.ui.close_bar() - def restart_launcher(): # No need to stop the other launcher first, because it exits after building the screen start_app_by_name("com.example.launcher", True) diff --git a/internal_filesystem/lib/mpos/ui.py b/internal_filesystem/lib/mpos/ui.py index e8774397..f5b6d566 100644 --- a/internal_filesystem/lib/mpos/ui.py +++ b/internal_filesystem/lib/mpos/ui.py @@ -381,3 +381,28 @@ EVENT_MAP = { def get_event_name(event_code): return EVENT_MAP.get(event_code, f"Unknown event {event_code}") + + +screen_stack = [] + +def load_screen(screen): + global screen_stack + topscreen = None + if len(screen_stack) > 0: + topscreen = screen_stack[-1] + if not topscreen or screen != topscreen: + print("Appending screen to screen_stack") + screen_stack.append(screen) + else: + print("Warning: not adding new screen to screen_stack because it's already there, just bringing to foreground.") + lv.screen_load(screen) + +def back_screen(): + global screen_stack + if len(screen_stack) > 1: + print("Loading previous screen") + screen_stack.pop() # Remove current screen + prevscreen = screen_stack[-1] # load previous screen + lv.screen_load(prevscreen) + else: + print("Warning: can't go back because screen_stack is empty.")