Skip to content

Commit d368db1

Browse files
Merge pull request MicroPythonOS#11 from QuasiKili/patch-4
fixed bug where clicking in swipe areas was ignored
2 parents a292b5a + 588a17f commit d368db1

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

internal_filesystem/lib/mpos/ui/gesture_navigation.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
downbutton = None
88
backbutton = None
99
down_start_x = 0
10+
down_start_y = 0
1011
back_start_y = 0
12+
back_start_x = 0
13+
short_movement_threshold = 10
1114

12-
13-
# Would be better to somehow save other events, like clicks, and pass them down to the layers below if released with x < 60
1415
def _back_swipe_cb(event):
1516
if drawer_open:
1617
print("ignoring back gesture because drawer is open")
1718
return
1819

19-
global backbutton, back_start_y
20+
global backbutton, back_start_y, back_start_x
2021
event_code = event.get_code()
2122
indev = lv.indev_active()
2223
if not indev:
@@ -29,22 +30,39 @@ def _back_swipe_cb(event):
2930
if event_code == lv.EVENT.PRESSED:
3031
smooth_show(backbutton)
3132
back_start_y = y
33+
back_start_x = x
3234
elif event_code == lv.EVENT.PRESSING:
3335
magnetic_x = round(x / 10)
3436
backbutton.set_pos(magnetic_x,back_start_y)
3537
elif event_code == lv.EVENT.RELEASED:
3638
smooth_hide(backbutton)
39+
dx = abs(x - back_start_x)
40+
dy = abs(y - back_start_y)
3741
if x > min(100, get_display_width() / 4):
3842
back_screen()
43+
elif dx < short_movement_threshold and dy < short_movement_threshold:
44+
# print("Short movement - treating as tap")
45+
obj = lv.indev_search_obj(lv.screen_active(), lv.point_t({'x': x, 'y': y}))
46+
# print(f"Found object: {obj}")
47+
if obj:
48+
# print(f"Simulating press/click/release on {obj}")
49+
obj.send_event(lv.EVENT.PRESSED, indev)
50+
obj.send_event(lv.EVENT.CLICKED, indev)
51+
obj.send_event(lv.EVENT.RELEASED, indev)
52+
else:
53+
# print("No object found at tap location")
54+
pass
55+
else:
56+
# print("Movement too large but not enough for back - ignoring")
57+
pass
3958

4059

41-
# Would be better to somehow save other events, like clicks, and pass them down to the layers below if released with x < 60
4260
def _top_swipe_cb(event):
4361
if drawer_open:
4462
print("ignoring top swipe gesture because drawer is open")
4563
return
4664

47-
global downbutton, down_start_x
65+
global downbutton, down_start_x, down_start_y
4866
event_code = event.get_code()
4967
indev = lv.indev_active()
5068
if not indev:
@@ -53,17 +71,35 @@ def _top_swipe_cb(event):
5371
indev.get_point(point)
5472
x = point.x
5573
y = point.y
56-
#print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
74+
# print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
5775
if event_code == lv.EVENT.PRESSED:
5876
smooth_show(downbutton)
5977
down_start_x = x
78+
down_start_y = y
6079
elif event_code == lv.EVENT.PRESSING:
6180
magnetic_y = round(y/ 10)
6281
downbutton.set_pos(down_start_x,magnetic_y)
6382
elif event_code == lv.EVENT.RELEASED:
6483
smooth_hide(downbutton)
84+
dx = abs(x - down_start_x)
85+
dy = abs(y - down_start_y)
6586
if y > min(80, get_display_height() / 4):
6687
open_drawer()
88+
elif dx < short_movement_threshold and dy < short_movement_threshold:
89+
# print("Short movement - treating as tap")
90+
obj = lv.indev_search_obj(lv.screen_active(), lv.point_t({'x': x, 'y': y}))
91+
# print(f"Found object: {obj}")
92+
if obj :
93+
# print(f"Simulating press/click/release on {obj}")
94+
obj.send_event(lv.EVENT.PRESSED, indev)
95+
obj.send_event(lv.EVENT.CLICKED, indev)
96+
obj.send_event(lv.EVENT.RELEASED, indev)
97+
else:
98+
# print("No object found at tap location")
99+
pass
100+
else:
101+
print("Movement too large but not enough for top swipe - ignoring")
102+
pass
67103

68104

69105
def handle_back_swipe():

0 commit comments

Comments
 (0)