8000 windows 2 finger swipe · Android-for-Python/gestures4kivy@455cec0 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit 455cec0

Browse files
committed
windows 2 finger swipe
1 parent 44118cf commit 455cec0

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
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, 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).
172+
A two finger horizontal move is inhibited for 2 second following the previous horizontal move [https://github.com/kivy/kivy/issues/7707](https://github.com/kivy/kivy/issues/7707).
173173

174174
### Mac
175175

src/gestures4kivy/commongestures.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
from time import time
3030
from math import sqrt
3131

32+
# This is a workaround for a Kivy issue described below.
33+
ENABLE_HORIZONTAL_PAGE = True
34+
3235
class CommonGestures(Widget):
3336

3437
def __init__(self, **kwargs):
@@ -51,9 +54,9 @@ def __init__(self, **kwargs):
5154
self._SWIPE_TIME = 0.3 # sec
5255
self._SWIPE_VELOCITY = 5 # inches/sec, heuristic
5356
self._WHEEL_SENSITIVITY = 1.1 # heuristic
54-
self._PAGE_FILTER = 0.15 # heuristic
57+
self._PAGE_FILTER = 2.0 # heuristic
5558
self._persistent_pos = [(0,0),(0,0)]
56-
self._page_schedule = None
59+
5760

5861

5962
#####################
@@ -83,6 +86,7 @@ def on_touch_down(self, touch):
8386
self._gesture_state = 'Wheel'
8487
scale = self._WHEEL_SENSITIVITY
8588
x, y = self._pos_to_widget(touch.x, touch.y)
89+
8690
if touch.button == 'scrollleft':
8791
self._gesture_state = 'PotentialPage'
8892
self.cg_shift_wheel(touch,1/scale, x, y)
@@ -303,20 +307,26 @@ def _potential_page(self,touch):
303307
right = touch.button == 'scrollright'
304308
if platform == 'win':
305309
# 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)
310+
# Windows generates lots of extra events in this case.
311+
# Pick the first one and inhibit responding to the
312+
# following ones for the next 2 seconds
313+
# A following event may be processed after we have
314+
# changed screens, in which case we get events sent
315+
# to the new screen, and an extra screen change, or more.
316+
# Local fix is a global, which is shared between screens.
317+
# A better fix would be a Kivy event filter.
318+
global ENABLE_HORIZONTAL_PAGE
319+
if ENABLE_HORIZONTAL_PAGE:
320+
ENABLE_HORIZONTAL_PAGE = False
321+
Clock.schedule_once(self._re_enable_horizontal_page,
322+
self._PAGE_FILTER)
323+
self.cg_swipe_horizontal(touch, right)
314324
else:
315-
self._horizontal_page(touch, right, 0)
325+
self.cg_swipe_horizontal(touch, right)
316326

317-
def _horizontal_page(self, touch, right, dt):
318-
self._page_schedule = None
319-
self.cg_swipe_horizontal(touch, right)
327+
def _re_enable_horizontal_page(self, dt):
328+
global ENABLE_HORIZONTAL_PAGE
329+
ENABLE_HORIZONTAL_PAGE = True
320330

321331
### touch direction ###
322332
# direction is the same with or without RelativeLayout

0 commit comments

Comments
 (0)
0