internal/glfw: unify the naming convension for Win32API

This commit is contained in:
Hajime Hoshi 2022-06-01 00:37:54 +09:00
parent 6fc71e97bb
commit dcb5bb47c6

View File

@ -63,25 +63,25 @@ func (*graphicsDriverGetterImpl) getMetal() graphicsdriver.Graphics {
} }
const ( const (
smCyCaption = 4 _SM_CYCAPTION = 4
monitorDefaultToNearest = 2 _MONITOR_DEFAULTTONEAREST = 2
) )
type rect struct { type _RECT struct {
left int32 left int32
top int32 top int32
right int32 right int32
bottom int32 bottom int32
} }
type monitorInfo struct { type _MONITORINFO struct {
cbSize uint32 cbSize uint32
rcMonitor rect rcMonitor _RECT
rcWork rect rcWork _RECT
dwFlags uint32 dwFlags uint32
} }
type point struct { type _POINT struct {
x int32 x int32
y int32 y int32
} }
@ -95,7 +95,7 @@ var (
procGetCursorPos = user32.NewProc("GetCursorPos") procGetCursorPos = user32.NewProc("GetCursorPos")
) )
func getSystemMetrics(nIndex int) (int32, error) { func _GetSystemMetrics(nIndex int) (int32, error) {
r, _, _ := procGetSystemMetrics.Call(uintptr(nIndex)) r, _, _ := procGetSystemMetrics.Call(uintptr(nIndex))
if int32(r) == 0 { if int32(r) == 0 {
// GetLastError doesn't provide an extended information. // GetLastError doesn't provide an extended information.
@ -105,24 +105,27 @@ func getSystemMetrics(nIndex int) (int32, error) {
return int32(r), nil return int32(r), nil
} }
func monitorFromWindow_(hwnd windows.HWND, dwFlags uint32) uintptr { func _MonitorFromWindow(hwnd windows.HWND, dwFlags uint32) uintptr {
r, _, _ := procMonitorFromWindow.Call(uintptr(hwnd), uintptr(dwFlags)) r, _, _ := procMonitorFromWindow.Call(uintptr(hwnd), uintptr(dwFlags))
return r return r
} }
func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error { func _GetMonitorInfoW(hMonitor uintptr) (_MONITORINFO, error) {
r, _, e := procGetMonitorInfoW.Call(hMonitor, uintptr(unsafe.Pointer(lpmi))) mi := _MONITORINFO{}
mi.cbSize = uint32(unsafe.Sizeof(mi))
r, _, e := procGetMonitorInfoW.Call(hMonitor, uintptr(unsafe.Pointer(&mi)))
if int32(r) == 0 { if int32(r) == 0 {
if e != nil && e != windows.ERROR_SUCCESS { if e != nil && e != windows.ERROR_SUCCESS {
return fmt.Errorf("ui: GetMonitorInfoW failed: error code: %w", e) return _MONITORINFO{}, fmt.Errorf("ui: GetMonitorInfoW failed: error code: %w", e)
} }
return fmt.Errorf("ui: GetMonitorInfoW failed: returned 0") return _MONITORINFO{}, fmt.Errorf("ui: GetMonitorInfoW failed: returned 0")
} }
return nil return mi, nil
} }
func getCursorPos() (int32, int32, error) { func _GetCursorPos() (int32, int32, error) {
var pt point var pt _POINT
r, _, e := procGetCursorPos.Call(uintptr(unsafe.Pointer(&pt))) r, _, e := procGetCursorPos.Call(uintptr(unsafe.Pointer(&pt)))
if int32(r) == 0 { if int32(r) == 0 {
if e != nil && e != windows.ERROR_SUCCESS { if e != nil && e != windows.ERROR_SUCCESS {
@ -158,7 +161,7 @@ func (u *userInterfaceImpl) adjustWindowPosition(x, y int, monitor *glfw.Monitor
if x < mx { if x < mx {
x = mx x = mx
} }
t, err := getSystemMetrics(smCyCaption) t, err := _GetSystemMetrics(_SM_CYCAPTION)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -169,7 +172,7 @@ func (u *userInterfaceImpl) adjustWindowPosition(x, y int, monitor *glfw.Monitor
} }
func initialMonitorByOS() (*glfw.Monitor, error) { func initialMonitorByOS() (*glfw.Monitor, error) {
px, py, err := getCursorPos() px, py, err := _GetCursorPos()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -194,15 +197,14 @@ func monitorFromWin32Window(w windows.HWND) *glfw.Monitor {
// Get the current monitor by the window handle instead of the window position. It is because the window // Get the current monitor by the window handle instead of the window position. It is because the window
// position is not relaiable in some cases e.g. when the window is put across multiple monitors. // position is not relaiable in some cases e.g. when the window is put across multiple monitors.
m := monitorFromWindow_(w, monitorDefaultToNearest) m := _MonitorFromWindow(w, _MONITOR_DEFAULTTONEAREST)
if m == 0 { if m == 0 {
// monitorFromWindow can return error on Wine. Ignore this. // monitorFromWindow can return error on Wine. Ignore this.
return nil return nil
} }
mi := monitorInfo{} mi, err := _GetMonitorInfoW(m)
mi.cbSize = uint32(unsafe.Sizeof(mi)) if err != nil {
if err := getMonitorInfoW(m, &mi); err != nil {
panic(err) panic(err)
} }