Repository: kivy/kivy

Issue:
Window touch coordinates always return 0.0
Binding to the root widget instead will return the correct values.
Example:

```
from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout


class Test(BoxLayout):
    def __init__(self, **kwargs):
        super(Test, self).__init__(**kwargs)
        Window.bind(on_touch_down=self.window_on_touch_down)

    def window_on_touch_down(self, *args):
        print(args[1].x)
        print(args[1].y)


class TestApp(App):
    def build(self):
        return Test()

if __name__ == '__main__':
    TestApp().run()
```



Discussion:

Resolving patch:
diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py
--- a/kivy/core/window/__init__.py
+++ b/kivy/core/window/__init__.py
@@ -595,7 +595,8 @@ def clear(self):
         cc = self._clearcolor
         if cc is not None:
             glClearColor(*cc)
-            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
+            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
+                    GL_STENCIL_BUFFER_BIT)
 
     def set_title(self, title):
         '''Set the window title.
@@ -640,6 +641,8 @@ def on_motion(self, etype, me):
                 The Motion Event currently dispatched.
         '''
         if me.is_touch:
+            w, h = self.system_size
+            me.scale_for_screen(w, h, rotation=self._rotation)
             if etype == 'begin':
                 self.dispatch('on_touch_down', me)
             elif etype == 'update':
@@ -649,27 +652,36 @@ def on_motion(self, etype, me):
 
     def on_touch_down(self, touch):
         '''Event called when a touch down event is initiated.
+
+        .. versionchanged:: 1.8.1
+            The touch `pos` is now transformed to window coordinates before
+            this method is called. Before, the touch `pos` coordinate would be
+            `(0, 0)` when this method was called.
         '''
-        w, h = self.system_size
-        touch.scale_for_screen(w, h, rotation=self._rotation)
         for w in self.children[:]:
             if w.dispatch('on_touch_down', touch):
                 return True
 
     def on_touch_move(self, touch):
         '''Event called when a touch event moves (changes location).
+
+        .. versionchanged:: 1.8.1
+            The touch `pos` is now transformed to window coordinates before
+            this method is called. Before, the touch `pos` coordinate would be
+            `(0, 0)` when this method was called.
         '''
-        w, h = self.system_size
-        touch.scale_for_screen(w, h, rotation=self._rotation)
         for w in self.children[:]:
             if w.dispatch('on_touch_move', touch):
                 return True
 
     def on_touch_up(self, touch):
         '''Event called when a touch event is released (terminated).
+
+        .. versionchanged:: 1.8.1
+            The touch `pos` is now transformed to window coordinates before
+            this method is called. Before, the touch `pos` coordinate would be
+            `(0, 0)` when this method was called.
         '''
-        w, h = self.system_size
-        touch.scale_for_screen(w, h, rotation=self._rotation)
         for w in self.children[:]:
             if w.dispatch('on_touch_up', touch):
                 return True


Test patch: