Skip to content

Commit 9267705

Browse files
Supress touch events after swipe
Only works on swipe up, weirdly enough...
1 parent 0df191b commit 9267705

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

internal_filesystem/apps/com.lightningpiggy.displaywallet/assets/displaywallet.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
import mpos.config
44
import mpos.ui
5-
import mpos.apps
65

76
# screens:
87
main_screen = None
98
settings_screen = None
109

11-
1210
# Settings screen implementation
1311
class SettingsScreen():
1412
def __init__(self):
15-
#super().__init__(None)
1613
self.prefs = mpos.config.SharedPreferences("com.lightningpiggy.displaywallet")
1714
self.settings = [
1815
{"title": "Wallet Type", "key": "wallet_type", "value_label": None},

internal_filesystem/boot_unix.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
#keyboard.add_event_cb(keyboard_cb, lv.EVENT.ALL, None)
3434

3535

36-
# Swipe detection state
3736
# Swipe detection state
3837
start_y = None # Store the starting Y-coordinate of the mouse press
3938
start_x = None # Store the starting X-coordinate for left-edge swipe
39+
swipe_detected = False # Track if a swipe was detected to suppress widget events
4040

4141
def swipe_read_cb(indev_drv, data):
42-
global start_y, start_x
42+
global start_y, start_x, swipe_detected
4343

4444
pressed = mouse.get_state() # Get mouse/touch pressed state
4545
point = lv.point_t()
@@ -50,43 +50,59 @@ def swipe_read_cb(indev_drv, data):
5050
# Mouse/touch pressed (start of potential swipe)
5151
start_y = y # Store Y for vertical swipe detection
5252
start_x = x # Store X for horizontal swipe detection
53+
swipe_detected = False # Reset swipe flag
5354
print(f"Mouse press at X={start_x}, Y={start_y}")
54-
55+
5556
# Check if press is in notification bar (for swipe down)
5657
if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT:
5758
print(f"Press in notification bar at Y={start_y}")
5859
# Check if press is near left edge (for swipe right)
5960
if x <= 20: # Adjust threshold for left edge (e.g., 20 pixels)
6061
print(f"Press near left edge at X={start_x}")
62+
6163
elif pressed and (start_y is not None or start_x is not None):
6264
# Mouse/touch dragged while pressed (potential swipe in progress)
63-
65+
6466
# Check for downward swipe (y increased significantly)
6567
if start_y is not None and y > start_y + 50: # Threshold for swipe down
6668
print("Long swipe down")
6769
if start_y <= mpos.ui.NOTIFICATION_BAR_HEIGHT:
6870
print("Swipe Down Detected from Notification Bar")
6971
mpos.ui.open_drawer()
70-
start_y = None # Reset Y after swipe
71-
start_x = None # Reset X to avoid conflicts
72+
swipe_detected = True # Mark swipe detected
73+
start_y = None # Reset Y after swipe
74+
start_x = None # Reset X to avoid conflicts
75+
7276
# Check for rightward swipe from left edge (x increased significantly)
7377
if start_x is not None and x > start_x + 50: # Threshold for swipe right
7478
print("Long swipe right")
7579
if start_x <= 20: # Confirm swipe started near left edge
7680
print("Swipe Right Detected from Left Edge")
77-
mpos.ui.back_screen() # Call custom method for left menu
78-
start_y = None # Reset Y after swipe
79-
start_x = None # Reset X after swipe
81+
mpos.ui.back_screen() # Navigate to previous screen
82+
swipe_detected = True # Mark swipe detected
83+
start_y = None # Reset Y after swipe
84+
start_x = None # Reset X after swipe
85+
8086
else:
8187
# Mouse/touch released
82-
if start_y is not None and y < start_y - 50: # Threshold for swipe-up
83-
print("Swipe Up Detected")
84-
mpos.ui.close_drawer()
85-
86-
# Reset both coordinates on release
88+
if start_y is not None:
89+
if y < start_y - 50: # Threshold for swipe-up
90+
print("Swipe Up Detected")
91+
mpos.ui.close_drawer()
92+
swipe_detected = True # Mark swipe detected
93+
94+
# Reset coordinates
8795
start_y = None
8896
start_x = None
8997

98+
# Suppress widget events if any swipe was detected
99+
if swipe_detected:
100+
data.state = lv.INDEV_STATE.RELEASED # Ensure release state
101+
data.point.x = -1 # Move point off-screen to prevent widget interaction
102+
data.point.y = -1
103+
swipe_detected = False # Reset flag after suppression
104+
print("Suppressing widget events after swipe")
105+
90106
# Register the custom read callback with the input device
91107
indev = lv.indev_create()
92108
indev.set_type(lv.INDEV_TYPE.POINTER)

0 commit comments

Comments
 (0)