mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
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:
@@ -46,7 +46,11 @@ type window struct {
|
|||||||
height int
|
height int
|
||||||
stage system.Stage
|
stage system.Stage
|
||||||
pointerBtns pointer.Buttons
|
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
|
mu sync.Mutex
|
||||||
animating bool
|
animating bool
|
||||||
@@ -56,7 +60,10 @@ type window struct {
|
|||||||
opts *Options
|
opts *Options
|
||||||
}
|
}
|
||||||
|
|
||||||
const _WM_REDRAW = windows.WM_USER + 0
|
const (
|
||||||
|
_WM_REDRAW = windows.WM_USER + iota
|
||||||
|
_WM_CURSOR
|
||||||
|
)
|
||||||
|
|
||||||
type gpuAPI struct {
|
type gpuAPI struct {
|
||||||
priority int
|
priority int
|
||||||
@@ -309,7 +316,13 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case windows.WM_SETCURSOR:
|
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)
|
return windows.DefWindowProc(hwnd, msg, wParam, lParam)
|
||||||
@@ -571,6 +584,9 @@ func (w *window) SetCursor(name pointer.CursorName) {
|
|||||||
c = resources.cursor
|
c = resources.cursor
|
||||||
}
|
}
|
||||||
w.cursor = c
|
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) {
|
func loadCursor(name pointer.CursorName) (syscall.Handle, error) {
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ const (
|
|||||||
|
|
||||||
CW_USEDEFAULT = -2147483648
|
CW_USEDEFAULT = -2147483648
|
||||||
|
|
||||||
|
HTCLIENT = 1
|
||||||
|
|
||||||
IDC_ARROW = 32512
|
IDC_ARROW = 32512
|
||||||
IDC_IBEAM = 32513
|
IDC_IBEAM = 32513
|
||||||
IDC_HAND = 32649
|
IDC_HAND = 32649
|
||||||
|
|||||||
Reference in New Issue
Block a user