8000 horizontal page on Windows · Android-for-Python/gestures4kivy@347e368 · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit 347e368

Browse files
committed
horizontal page on Windows
1 parent a81d6b8 commit 347e368

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ On some touchpads pinch/spread will not be detected the if 'mouse, disable_multi
169169

170170
Some touch pads report a pinch/spread as a finger movement `cg_scale()`, and some detect the gesture internally and report it as a `cg_ctrl_wheel()`. The safe thing to do is handle both cases in an application.
171171

172-
A two finger horizontal move, when used for paging screens may exhibit latency or over sensitivity [https://github.com/kivy/kivy/issues/7707](https://github.com/kivy/kivy/issues/7707).
172+
A two finger horizontal move, used for paging screens will exhibit latency of up to 1.5 seconds [https://github.com/kivy/kivy/issues/7707](https://github.com/kivy/kivy/issues/7707).
173173

174174
### Mac
175175

src/gestures4kivy/commongestures.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ def __init__(self, **kwargs):
5151
self._SWIPE_TIME = 0.3 # sec
5252
self._SWIPE_VELOCITY = 5 # inches/sec, heuristic
5353
self._WHEEL_SENSITIVITY = 1.1 # heuristic
54+
self._PAGE_FILTER = 0.15 # heuristic
5455
self._persistent_pos = [(0,0),(0,0)]
55-
self._two_finger_time = 0
56+
self._page_schedule = None
5657

5758

5859
#####################
@@ -83,20 +84,13 @@ def on_touch_down(self, touch):
8384
scale = self._WHEEL_SENSITIVITY
8485
x, y = self._pos_to_widget(touch.x, touch.y)
8586
if touch.button == 'scrollleft':
86-
# filter bogus events https://github.com/kivy/kivy/issues/7707
87-
if platform != 'win' or\
88-
touch.time_start > self._two_finger_time + 0.6 :
89-
self.cg_swipe_horizontal(touch, False)
90-
self._two_finger_time = touch.time_start
87+
self._gesture_state = 'PotentialPage'
9188
self.cg_shift_wheel(touch,1/scale, x, y)
9289
elif touch.button == 'scrollright':
93-
# filter bogus events https://github.com/kivy/kivy/issues/7707
94-
if platform != 'win' or\
95-
touch.time_start > self._two_finger_time + 0.6 :
96-
self.cg_swipe_horizontal(touch, True)
97-
self._two_finger_time = touch.time_start
90+
self._gesture_state = 'PotentialPage'
9891
self.cg_shift_wheel(touch,scale, x, y)
9992
else:
93+
self._gesture_state = 'Wheel'
10094
if touch.button == 'scrollup':
10195
scale = 1/scale
10296
if self._CTRL:
@@ -224,6 +218,10 @@ def on_touch_up(self, touch):
224218
elif self._gesture_state == 'Long Pressed':
225219
self.cg_long_press_end(touch, x, y)
226220
self._new_gesture()
221+
222+
elif self._gesture_state == 'PotentialPage':
223+
self._potential_page(touch)
224+
self._new_gesture()
227225

228226
elif self._gesture_state == 'Wheel' or\
229227
self._gesture_state == 'Swipe':
@@ -299,6 +297,26 @@ def _velocity_now(self, touch):
299297
return distance / (period * Metrics.dpi)
300298
else:
301299
return 0
300+
301+
### potential page ####
302+
def _potential_page(self,touch):
303+
right = touch.button == 'scrollright'
304+
if platform == 'win':
305+
# https://github.com/kivy/kivy/issues/7707
306+
# Windows generates lots of events, pick the last one.
307+
# Else a new page request may occur after we have paged.
308+
# This introduces latency :(
309+
if self._page_schedule:
310+
Clock.unschedule(self._page_schedule)
311+
self._page_schedule =\
312+
Clock.schedule_once(partial(self._horizontal_page, touch,
313+
right), self._PAGE_FILTER)
314+
else:
315+
self._horizontal_page(touch, right, dt)
316+
317+
def _horizontal_page(self, touch, right, dt):
318+
self._page_schedule = None
319+
self.cg_swipe_horizontal(touch, right)
302320

303321
### touch direction ###
304322
# direction is the same with or without RelativeLayout

0 commit comments

Comments
 (0)
0