Skip to content

Commit

Permalink
Move structs and func defs used across files to wm_common
Browse files Browse the repository at this point in the history
  • Loading branch information
matham committed May 26, 2016
1 parent 1b805a5 commit 4985415
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 132 deletions.
96 changes: 96 additions & 0 deletions kivy/input/providers/wm_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
This file provides common definitions for constants used by WM_Touch / WM_Pen.
'''
import os

WM_MOUSEFIRST = 512
WM_MOUSEMOVE = 512
Expand Down Expand Up @@ -53,3 +54,98 @@
TABLET_DISABLE_FLICKFALLBACKKEYS |
TABLET_DISABLE_TOUCHSWITCH |
TABLET_DISABLE_FLICKS)

if 'KIVY_DOC' not in os.environ:
from ctypes.wintypes import (ULONG, HANDLE, DWORD, LONG, UINT,
WPARAM, LPARAM, BOOL)
from ctypes import (windll, WINFUNCTYPE, POINTER,
c_int, Structure, sizeof, byref)

class RECT(Structure):
_fields_ = [
('left', LONG),
('top', LONG),
('right', LONG),
('bottom', LONG)]

x = property(lambda self: self.left)
y = property(lambda self: self.top)
w = property(lambda self: self.right - self.left)
h = property(lambda self: self.bottom - self.top)

class POINT(Structure):
_fields_ = [
('x', LONG),
('y', LONG)]

# check availability of RegisterTouchWindow
if not hasattr(windll.user32, 'RegisterTouchWindow'):
raise Exception('Unsupported Window version')

LRESULT = LPARAM
WNDPROC = WINFUNCTYPE(LRESULT, HANDLE, UINT, WPARAM, LPARAM)

class TOUCHINPUT(Structure):
_fields_ = [
('x', LONG),
('y', LONG),
('pSource', HANDLE),
('id', DWORD),
('flags', DWORD),
('mask', DWORD),
('time', DWORD),
('extraInfo', POINTER(ULONG)),
('size_x', DWORD),
('size_y', DWORD)]

def size(self):
return (self.size_x, self.size_y)

def screen_x(self):
return self.x / 100.0

def screen_y(self):
return self.y / 100.0

def _event_type(self):
if self.flags & TOUCHEVENTF_MOVE:
return 'update'
if self.flags & TOUCHEVENTF_DOWN:
return 'begin'
if self.flags & TOUCHEVENTF_UP:
return 'end'
event_type = property(_event_type)

try:
windll.user32.SetWindowLongPtrW.restype = WNDPROC
windll.user32.SetWindowLongPtrW.argtypes = [HANDLE, c_int, WNDPROC]
SetWindowLong_wrapper = windll.user32.SetWindowLongPtrW
except AttributeError:
windll.user32.SetWindowLongW.restype = WNDPROC
windll.user32.SetWindowLongW.argtypes = [HANDLE, c_int, WNDPROC]
SetWindowLong_wrapper = windll.user32.SetWindowLongW

windll.user32.GetMessageExtraInfo.restype = LPARAM
windll.user32.GetMessageExtraInfo.argtypes = []
windll.user32.GetClientRect.restype = BOOL
windll.user32.GetClientRect.argtypes = [HANDLE, POINTER(RECT)]
windll.user32.GetWindowRect.restype = BOOL
windll.user32.GetWindowRect.argtypes = [HANDLE, POINTER(RECT)]
windll.user32.CallWindowProcW.restype = LRESULT
windll.user32.CallWindowProcW.argtypes = [WNDPROC, HANDLE, UINT, WPARAM,
LPARAM]
windll.user32.GetActiveWindow.restype = HANDLE
windll.user32.GetActiveWindow.argtypes = []
windll.user32.RegisterTouchWindow.restype = BOOL
windll.user32.RegisterTouchWindow.argtypes = [HANDLE, ULONG]
windll.user32.UnregisterTouchWindow.restype = BOOL
windll.user32.UnregisterTouchWindow.argtypes = [HANDLE]
windll.user32.GetTouchInputInfo.restype = BOOL
windll.user32.GetTouchInputInfo.argtypes = [HANDLE, UINT,
POINTER(TOUCHINPUT), c_int]
windll.user32.GetSystemMetrics.restype = c_int
windll.user32.GetSystemMetrics.argtypes = [c_int]

windll.user32.ClientToScreen.restype = BOOL
windll.user32.ClientToScreen.argtypes = [HANDLE, POINTER(POINT)]

44 changes: 2 additions & 42 deletions kivy/input/providers/wm_pen.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
__all__ = ('WM_PenProvider', 'WM_Pen')

import os
from kivy.input.providers.wm_common import (
PEN_OR_TOUCH_SIGNATURE, PEN_OR_TOUCH_MASK, GWL_WNDPROC,
WM_MOUSEMOVE, WM_LBUTTONUP, WM_LBUTTONDOWN,
WM_TABLET_QUERYSYSTEMGESTURE, QUERYSYSTEMGESTURE_WNDPROC,
PEN_EVENT_TOUCH_MASK)
from kivy.input.providers.wm_common import *
from kivy.input.motionevent import MotionEvent


Expand All @@ -31,48 +27,12 @@ def __str__(self):

else:
from collections import deque
from ctypes.wintypes import (ULONG, UINT, WPARAM, LPARAM,
HANDLE, BOOL)
from ctypes import (Structure, windll, byref, c_int16,
c_int, WINFUNCTYPE, POINTER)
from ctypes import windll, byref, c_int16, c_int
from kivy.input.provider import MotionEventProvider
from kivy.input.factory import MotionEventFactory

LRESULT = LPARAM
WNDPROC = WINFUNCTYPE(LRESULT, HANDLE, UINT, WPARAM, LPARAM)

class RECT(Structure):
_fields_ = [
('left', ULONG),
('top', ULONG),
('right', ULONG),
('bottom', ULONG)]

x = property(lambda self: self.left)
y = property(lambda self: self.top)
w = property(lambda self: self.right - self.left)
h = property(lambda self: self.bottom - self.top)
win_rect = RECT()

try:
windll.user32.SetWindowLongPtrW.restype = WNDPROC
windll.user32.SetWindowLongPtrW.argtypes = [HANDLE, c_int, WNDPROC]
SetWindowLong_wrapper = windll.user32.SetWindowLongPtrW
except AttributeError:
windll.user32.SetWindowLongW.restype = WNDPROC
windll.user32.SetWindowLongW.argtypes = [HANDLE, c_int, WNDPROC]
SetWindowLong_wrapper = windll.user32.SetWindowLongW

windll.user32.GetMessageExtraInfo.restype = LPARAM
windll.user32.GetMessageExtraInfo.argtypes = []
windll.user32.GetClientRect.restype = BOOL
windll.user32.GetClientRect.argtypes = [HANDLE, POINTER(RECT)]
windll.user32.CallWindowProcW.restype = LRESULT
windll.user32.CallWindowProcW.argtypes = [WNDPROC, HANDLE, UINT, WPARAM,
LPARAM]
windll.user32.GetActiveWindow.restype = HANDLE
windll.user32.GetActiveWindow.argtypes = []

class WM_PenProvider(MotionEventProvider):

def _is_pen_message(self, msg):
Expand Down
93 changes: 3 additions & 90 deletions kivy/input/providers/wm_touch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
__all__ = ('WM_MotionEventProvider', 'WM_MotionEvent')

import os
from kivy.input.providers.wm_common import (
WM_TABLET_QUERYSYSTEMGESTURE,
GWL_WNDPROC, QUERYSYSTEMGESTURE_WNDPROC, WM_TOUCH, WM_MOUSEMOVE,
WM_MOUSELAST, PEN_OR_TOUCH_MASK, PEN_OR_TOUCH_SIGNATURE,
PEN_EVENT_TOUCH_MASK, TOUCHEVENTF_UP, TOUCHEVENTF_DOWN,
TOUCHEVENTF_MOVE, SM_CYCAPTION)
from kivy.input.providers.wm_common import *
from kivy.input.motionevent import MotionEvent
from kivy.input.shape import ShapeRect

Expand Down Expand Up @@ -44,94 +39,12 @@ def __str__(self):
WM_MotionEventProvider = None

else:
from ctypes.wintypes import (ULONG, HANDLE, DWORD, LONG, UINT,
WPARAM, LPARAM, BOOL)
from ctypes import (windll, WINFUNCTYPE, POINTER,
c_int, Structure, sizeof, byref)
from ctypes.wintypes import HANDLE
from ctypes import (windll, sizeof, byref)
from collections import deque
from kivy.input.provider import MotionEventProvider
from kivy.input.factory import MotionEventFactory

# check availability of RegisterTouchWindow
if not hasattr(windll.user32, 'RegisterTouchWindow'):
raise Exception('Unsupported Window version')

LRESULT = LPARAM
WNDPROC = WINFUNCTYPE(LRESULT, HANDLE, UINT, WPARAM, LPARAM)

class TOUCHINPUT(Structure):
_fields_ = [
('x', LONG),
('y', LONG),
('pSource', HANDLE),
('id', DWORD),
('flags', DWORD),
('mask', DWORD),
('time', DWORD),
('extraInfo', POINTER(ULONG)),
('size_x', DWORD),
('size_y', DWORD)]

def size(self):
return (self.size_x, self.size_y)

def screen_x(self):
return self.x / 100.0

def screen_y(self):
return self.y / 100.0

def _event_type(self):
if self.flags & TOUCHEVENTF_MOVE:
return 'update'
if self.flags & TOUCHEVENTF_DOWN:
return 'begin'
if self.flags & TOUCHEVENTF_UP:
return 'end'
event_type = property(_event_type)

class RECT(Structure):
_fields_ = [
('left', LONG),
('top', LONG),
('right', LONG),
('bottom', LONG)]

x = property(lambda self: self.left)
y = property(lambda self: self.top)
w = property(lambda self: self.right - self.left)
h = property(lambda self: self.bottom - self.top)

try:
windll.user32.SetWindowLongPtrW.restype = WNDPROC
windll.user32.SetWindowLongPtrW.argtypes = [HANDLE, c_int, WNDPROC]
SetWindowLong_wrapper = windll.user32.SetWindowLongPtrW
except AttributeError:
windll.user32.SetWindowLongW.restype = WNDPROC
windll.user32.SetWindowLongW.argtypes = [HANDLE, c_int, WNDPROC]
SetWindowLong_wrapper = windll.user32.SetWindowLongW

windll.user32.GetMessageExtraInfo.restype = LPARAM
windll.user32.GetMessageExtraInfo.argtypes = []
windll.user32.GetClientRect.restype = BOOL
windll.user32.GetClientRect.argtypes = [HANDLE, POINTER(RECT)]
windll.user32.GetWindowRect.restype = BOOL
windll.user32.GetWindowRect.argtypes = [HANDLE, POINTER(RECT)]
windll.user32.CallWindowProcW.restype = LRESULT
windll.user32.CallWindowProcW.argtypes = [WNDPROC, HANDLE, UINT, WPARAM,
LPARAM]
windll.user32.GetActiveWindow.restype = HANDLE
windll.user32.GetActiveWindow.argtypes = []
windll.user32.RegisterTouchWindow.restype = BOOL
windll.user32.RegisterTouchWindow.argtypes = [HANDLE, ULONG]
windll.user32.UnregisterTouchWindow.restype = BOOL
windll.user32.UnregisterTouchWindow.argtypes = [HANDLE]
windll.user32.GetTouchInputInfo.restype = BOOL
windll.user32.GetTouchInputInfo.argtypes = [HANDLE, UINT,
POINTER(TOUCHINPUT), c_int]
windll.user32.GetSystemMetrics.restype = c_int
windll.user32.GetSystemMetrics.argtypes = [c_int]

class WM_MotionEventProvider(MotionEventProvider):

def start(self):
Expand Down

0 comments on commit 4985415

Please sign in to comment.