From dcf70e5a26714b941d661adc31be2b11e2114379 Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Fri, 10 Mar 2017 13:11:44 +0100
Subject: [PATCH] fix mouse moving outside window with glfw callbacks

---
 pixelgl/input.go | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/pixelgl/input.go b/pixelgl/input.go
index 7a3764e..26c914e 100644
--- a/pixelgl/input.go
+++ b/pixelgl/input.go
@@ -340,6 +340,13 @@ func (w *Window) initInput() {
 			}
 		})
 
+		w.window.SetCursorPosCallback(func(_ *glfw.Window, x, y float64) {
+			w.currInp.mouse = pixel.V(
+				x+w.bounds.X(),
+				(w.bounds.H()-y)+w.bounds.Y(),
+			)
+		})
+
 		w.window.SetScrollCallback(func(_ *glfw.Window, xoff, yoff float64) {
 			w.currInp.scroll += pixel.V(xoff, yoff)
 		})
@@ -356,20 +363,6 @@ func (w *Window) updateInput() {
 	// get events (usually calls callbacks, but callbacks can be called outside too)
 	mainthread.Call(func() {
 		glfw.PollEvents()
-
-		x, y := w.window.GetCursorPos()
-		wi, hi := w.window.GetSize()
-		width, height := float64(wi), float64(hi)
-
-		mouse := pixel.V(
-			x/width*w.bounds.W()+w.bounds.X(),
-			(height-y)/height*w.bounds.H()+w.bounds.Y(),
-		)
-
-		//TODO: do something else, this is not entirely rock solid
-		if w.bounds.Contains(mouse) {
-			w.currInp.mouse = mouse
-		}
 	})
 
 	// cache current state to temp (so that if there are callbacks outside this function,
-- 
GitLab