You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Supress touch events after swipe
Only works on swipe up, weirdly enough...
This commit is contained in:
@@ -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},
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user