mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix synthesized mouse event ignoring code not working on QT 5. Use Qt 5's new API to ignore such events instead.
This commit is contained in:
parent
ccaf8c5507
commit
e3b9f76569
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import time, ctypes, sys
|
||||
import time, sys
|
||||
from functools import partial
|
||||
from PyQt5.Qt import (
|
||||
QObject, QPointF, pyqtSignal, QEvent, QApplication, QMouseEvent, Qt,
|
||||
@ -16,7 +16,6 @@ from calibre.constants import iswindows
|
||||
|
||||
touch_supported = False
|
||||
if iswindows and sys.getwindowsversion()[:2] >= (6, 2): # At least windows 7
|
||||
from ctypes import wintypes
|
||||
touch_supported = True
|
||||
|
||||
SWIPE_HOLD_INTERVAL = 0.5 # seconds
|
||||
@ -263,34 +262,14 @@ class GestureHandler(QObject):
|
||||
self.state.pinched.connect(self.handle_pinch)
|
||||
self.evmap = {QEvent.TouchBegin: 'start', QEvent.TouchUpdate: 'update', QEvent.TouchEnd: 'end'}
|
||||
|
||||
# Ignore fake mouse events generated by the window system from touch
|
||||
# events. At least on windows, we know how to identify these fake
|
||||
# events. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms703320(v=vs.85).aspx
|
||||
self.is_fake_mouse_event = lambda : False
|
||||
if touch_supported and iswindows:
|
||||
MI_WP_SIGNATURE = 0xFF515700
|
||||
SIGNATURE_MASK = 0xFFFFFF00
|
||||
try:
|
||||
f = ctypes.windll.user32.GetMessageExtraInfo
|
||||
f.restype = wintypes.LPARAM
|
||||
def is_fake_mouse_event():
|
||||
val = f()
|
||||
ans = (val & SIGNATURE_MASK) == MI_WP_SIGNATURE
|
||||
return ans
|
||||
self.is_fake_mouse_event = is_fake_mouse_event
|
||||
except Exception:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def __call__(self, ev):
|
||||
if not touch_supported:
|
||||
return False
|
||||
etype = ev.type()
|
||||
if etype in (
|
||||
QEvent.MouseMove, QEvent.MouseButtonPress,
|
||||
QEvent.MouseButtonRelease, QEvent.MouseButtonDblClick,
|
||||
QEvent.ContextMenu) and self.is_fake_mouse_event():
|
||||
# swallow fake mouse events that the windowing system generates from touch events
|
||||
QEvent.MouseButtonRelease, QEvent.MouseButtonDblClick) and ev.source() != Qt.MouseEventNotSynthesized:
|
||||
# swallow fake mouse events generated from touch events
|
||||
ev.accept()
|
||||
return True
|
||||
boundary = self.evmap.get(etype, None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user