From 9267705f29f334bbd0b00745c0a37a954b3e3f8c Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Sat, 24 May 2025 06:48:54 +0200 Subject: [PATCH] Supress touch events after swipe Only works on swipe up, weirdly enough... --- .../assets/displaywallet.py | 3 -- internal_filesystem/boot_unix.py | 44 +++++++++++++------ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py b/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py index 2a26f176..d8a642f6 100644 --- a/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py +++ b/internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py @@ -2,17 +2,14 @@ import time import mpos.config import mpos.ui -import mpos.apps # screens: main_screen = None settings_screen = None - # Settings screen implementation class SettingsScreen(): def __init__(self): - #super().__init__(None) self.prefs = mpos.config.SharedPreferences("com.lightningpiggy.displaywallet") self.settings = [ {"title": "Wallet Type", "key": "wallet_type", "value_label": None}, diff --git a/internal_filesystem/boot_unix.py b/internal_filesystem/boot_unix.py index 3b88c221..631e2bc9 100644 --- a/internal_filesystem/boot_unix.py +++ b/internal_filesystem/boot_unix.py @@ -33,13 +33,13 @@ 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 start_x = None # Store the starting X-coordinate for left-edge swipe +swipe_detected = False # Track if a swipe was detected to suppress widget events def swipe_read_cb(indev_drv, data): - global start_y, start_x + global start_y, start_x, swipe_detected pressed = mouse.get_state() # Get mouse/touch pressed state point = lv.point_t() @@ -50,43 +50,59 @@ def swipe_read_cb(indev_drv, data): # 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 + swipe_detected = False # Reset swipe flag 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: 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 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 Y after swipe - start_x = None # Reset X to avoid conflicts + swipe_detected = True # Mark swipe detected + 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 + mpos.ui.back_screen() # Navigate to previous screen + swipe_detected = True # Mark swipe detected + start_y = None # Reset Y after swipe + start_x = None # Reset X after swipe + else: # 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() - - # Reset both coordinates on release + if start_y is not None: + if y < start_y - 50: # Threshold for swipe-up + print("Swipe Up Detected") + mpos.ui.close_drawer() + swipe_detected = True # Mark swipe detected + + # Reset coordinates start_y = None start_x = None + # Suppress widget events if any swipe was detected + if swipe_detected: + data.state = lv.INDEV_STATE.RELEASED # Ensure release state + data.point.x = -1 # Move point off-screen to prevent widget interaction + data.point.y = -1 + swipe_detected = False # Reset flag after suppression + print("Suppressing widget events after swipe") + # Register the custom read callback with the input device indev = lv.indev_create() indev.set_type(lv.INDEV_TYPE.POINTER)