Skip to content

Commit 0df191b

Browse files
Add swipe from left for back
1 parent f0aaa71 commit 0df191b

File tree

4 files changed

+73
-27
lines changed

4 files changed

+73
-27
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import mpos.config
44
import mpos.ui
5+
import mpos.apps
56

67
# screens:
7-
appscreen = lv.screen_active()
8+
main_screen = None
89
settings_screen = None
910

1011

@@ -178,13 +179,13 @@ def settings_button_tap(event):
178179
global settings_screen
179180
if not settings_screen:
180181
settings_screen = SettingsScreen().screen
181-
lv.screen_load(settings_screen)
182-
#mpos.ui.startActivity(settings_screen)
182+
mpos.ui.load_screen(settings_screen)
183183

184184
def build_main_ui():
185-
appscreen.clean()
186-
appscreen.set_style_pad_all(10, 0)
187-
balance_label = lv.label(appscreen)
185+
global main_screen
186+
main_screen = lv.obj()
187+
main_screen.set_style_pad_all(10, 0)
188+
balance_label = lv.label(main_screen)
188189
balance_label.align(lv.ALIGN.TOP_LEFT, 0, 0)
189190
balance_label.set_style_text_font(lv.font_montserrat_20, 0)
190191
balance_label.set_text('123456')
@@ -193,19 +194,20 @@ def build_main_ui():
193194
style_line.set_line_width(4)
194195
style_line.set_line_color(lv.palette_main(lv.PALETTE.PINK))
195196
style_line.set_line_rounded(True)
196-
balance_line = lv.line(appscreen)
197+
balance_line = lv.line(main_screen)
197198
balance_line.set_points([{'x':0,'y':35},{'x':300,'y':35}],2)
198199
balance_line.add_style(style_line, 0)
199-
settings_button = lv.button(appscreen)
200+
settings_button = lv.button(main_screen)
200201
settings_button.align(lv.ALIGN.BOTTOM_RIGHT, 0, 0)
201202
snap_label = lv.label(settings_button)
202203
snap_label.set_text(lv.SYMBOL.SETTINGS)
203204
snap_label.center()
204205
settings_button.add_event_cb(settings_button_tap,lv.EVENT.CLICKED,None)
206+
mpos.ui.load_screen(main_screen)
205207

206208

207209
def janitor_cb(timer):
208-
if lv.screen_active() != appscreen and lv.screen_active() != settings_screen:
210+
if lv.screen_active() != main_screen and lv.screen_active() != settings_screen:
209211
print("app backgrounded, cleaning up...")
210212
janitor.delete()
211213
if settings_screen:

internal_filesystem/boot_unix.py

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

3535

36+
# Swipe detection state
3637
# Swipe detection state
3738
start_y = None # Store the starting Y-coordinate of the mouse press
39+
start_x = None # Store the starting X-coordinate for left-edge swipe
40+
3841
def swipe_read_cb(indev_drv, data):
39-
global start_y
42+
global start_y, start_x
4043

41-
pressed = mouse.get_state()
42-
#print(f"mouse_state: {pressed}")
44+
pressed = mouse.get_state() # Get mouse/touch pressed state
4345
point = lv.point_t()
44-
mouse.get_point(point)
45-
#print(f"X={point.x}, Y={point.y}")
46+
mouse.get_point(point) # Get current coordinates
4647
x, y = point.x, point.y
4748

48-
if pressed and start_y is None:
49-
start_y = y
50-
# Mouse button pressed (start of potential swipe)
49+
if pressed and start_y is None and start_x is None:
50+
# Mouse/touch pressed (start of potential swipe)
51+
start_y = y # Store Y for vertical swipe detection
52+
start_x = x # Store X for horizontal swipe detection
53+
print(f"Mouse press at X={start_x}, Y={start_y}")
54+
55+
# Check if press is in notification bar (for swipe down)
5156
if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT:
52-
# Store starting Y if press is in the notification bar area
53-
print(f"Mouse press at Y={start_y}")
54-
elif pressed and start_y is not None:
55-
# Mouse dragged while pressed (potential swipe in progress)
57+
print(f"Press in notification bar at Y={start_y}")
58+
# Check if press is near left edge (for swipe right)
59+
if x <= 20: # Adjust threshold for left edge (e.g., 20 pixels)
60+
print(f"Press near left edge at X={start_x}")
61+
elif pressed and (start_y is not None or start_x is not None):
62+
# Mouse/touch dragged while pressed (potential swipe in progress)
63+
5664
# Check for downward swipe (y increased significantly)
57-
if y > start_y + 50: # Threshold for swipe detection (adjust as needed)
58-
print("long swipe down")
65+
if start_y is not None and y > start_y + 50: # Threshold for swipe down
66+
print("Long swipe down")
5967
if start_y <= mpos.ui.NOTIFICATION_BAR_HEIGHT:
6068
print("Swipe Down Detected from Notification Bar")
6169
mpos.ui.open_drawer()
62-
start_y = None # Reset after swipe
70+
start_y = None # Reset Y after swipe
71+
start_x = None # Reset X to avoid conflicts
72+
# Check for rightward swipe from left edge (x increased significantly)
73+
if start_x is not None and x > start_x + 50: # Threshold for swipe right
74+
print("Long swipe right")
75+
if start_x <= 20: # Confirm swipe started near left edge
76+
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
6380
else:
64-
# Mouse button released
81+
# Mouse/touch released
6582
if start_y is not None and y < start_y - 50: # Threshold for swipe-up
6683
print("Swipe Up Detected")
6784
mpos.ui.close_drawer()
68-
start_y = None # Reset on release
85+
86+
# Reset both coordinates on release
87+
start_y = None
88+
start_x = None
6989

7090
# Register the custom read callback with the input device
7191
indev = lv.indev_create()

internal_filesystem/lib/mpos/apps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ def start_app(app_dir, is_launcher=False):
110110
else:
111111
mpos.ui.close_bar()
112112

113-
114113
def restart_launcher():
115114
# No need to stop the other launcher first, because it exits after building the screen
116115
start_app_by_name("com.example.launcher", True)

internal_filesystem/lib/mpos/ui.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,28 @@ def poweroff_cb(e):
381381
def get_event_name(event_code):
382382
return EVENT_MAP.get(event_code, f"Unknown event {event_code}")
383383

384+
385+
386+
screen_stack = []
387+
388+
def load_screen(screen):
389+
global screen_stack
390+
topscreen = None
391+
if len(screen_stack) > 0:
392+
topscreen = screen_stack[-1]
393+
if not topscreen or screen != topscreen:
394+
print("Appending screen to screen_stack")
395+
screen_stack.append(screen)
396+
else:
397+
print("Warning: not adding new screen to screen_stack because it's already there, just bringing to foreground.")
398+
lv.screen_load(screen)
399+
400+
def back_screen():
401+
global screen_stack
402+
if len(screen_stack) > 1:
403+
print("Loading previous screen")
404+
screen_stack.pop() # Remove current screen
405+
prevscreen = screen_stack[-1] # load previous screen
406+
lv.screen_load(prevscreen)
407+
else:
408+
print("Warning: can't go back because screen_stack is empty.")

0 commit comments

Comments
 (0)