app: make cursor support more robust on Windows

Post a dedicated message upon Window.SetCursor calls.
Make sure that the cursor is only changed if the cursor is in the window.

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
pierre
2021-01-27 16:32:05 +01:00
committed by Elias Naur
parent 57872856e8
commit f7d1f46c1f
2 changed files with 21 additions and 3 deletions
+19 -3
View File
@@ -46,7 +46,11 @@ type window struct {
height int
stage system.Stage
pointerBtns pointer.Buttons
cursor syscall.Handle
// cursorIn tracks whether the cursor was inside the window according
// to the most recent WM_SETCURSOR.
cursorIn bool
cursor syscall.Handle
mu sync.Mutex
animating bool
@@ -56,7 +60,10 @@ type window struct {
opts *Options
}
const _WM_REDRAW = windows.WM_USER + 0
const (
_WM_REDRAW = windows.WM_USER + iota
_WM_CURSOR
)
type gpuAPI struct {
priority int
@@ -309,7 +316,13 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
}
}
case windows.WM_SETCURSOR:
windows.SetCursor(w.cursor)
w.cursorIn = (lParam & 0xffff) == windows.HTCLIENT
fallthrough
case _WM_CURSOR:
if w.cursorIn {
windows.SetCursor(w.cursor)
return 1
}
}
return windows.DefWindowProc(hwnd, msg, wParam, lParam)
@@ -571,6 +584,9 @@ func (w *window) SetCursor(name pointer.CursorName) {
c = resources.cursor
}
w.cursor = c
if err := windows.PostMessage(w.hwnd, _WM_CURSOR, 0, 0); err != nil {
panic(err)
}
}
func loadCursor(name pointer.CursorName) (syscall.Handle, error) {
+2
View File
@@ -61,6 +61,8 @@ const (
CW_USEDEFAULT = -2147483648
HTCLIENT = 1
IDC_ARROW = 32512
IDC_IBEAM = 32513
IDC_HAND = 32649