Skip to content

Commit e23a0cf

Browse files
committed
Use windows api rescaling to find correct touch pos in window coords.
1 parent 4985415 commit e23a0cf

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

kivy/input/providers/wm_touch.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,13 @@ def start(self):
6666
self.old_windProc = SetWindowLong_wrapper(
6767
self.hwnd, GWL_WNDPROC, self.new_windProc)
6868

69-
if Window.borderless or Window.fullscreen:
70-
self.caption_size = 0
71-
else:
72-
self.caption_size = windll.user32.GetSystemMetrics(SM_CYCAPTION)
73-
7469
def update(self, dispatch_fn):
75-
win_rect = RECT()
76-
windll.user32.GetWindowRect(self.hwnd, byref(win_rect))
77-
caption = self.caption_size
70+
c_rect = RECT()
71+
windll.user32.GetClientRect(self.hwnd, byref(c_rect))
72+
pt = POINT(x=0, y=0)
73+
windll.user32.ClientToScreen(self.hwnd, byref(pt))
74+
x_offset, y_offset = pt.x, pt.y
75+
usable_w, usable_h = float(c_rect.w), float(c_rect.h)
7876

7977
while True:
8078
try:
@@ -83,9 +81,8 @@ def update(self, dispatch_fn):
8381
break
8482

8583
# adjust x,y to window coordinates (0.0 to 1.0)
86-
x = (t.screen_x() - win_rect.x) / float(win_rect.w)
87-
y = 1.0 - (t.screen_y() - win_rect.y - caption
88-
) / float(win_rect.h)
84+
x = (t.screen_x() - x_offset) / usable_w
85+
y = 1.0 - (t.screen_y() - y_offset) / usable_h
8986

9087
# actually dispatch input
9188
if t.event_type == 'begin':

0 commit comments

Comments
 (0)