ui: Remove 'syscall' package usages (#766)

This commit is contained in:
Hajime Hoshi 2019-01-04 05:28:27 +09:00
parent b1591855c0
commit f2840bb0dc
2 changed files with 18 additions and 19 deletions

View File

@ -18,7 +18,6 @@ package ui
import (
"fmt"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
@ -39,8 +38,8 @@ var (
)
func getCurrentProcessId() (uint32, error) {
r, _, e := syscall.Syscall(getCurrentProcessIdProc.Addr(), 0, 0, 0, 0)
if e != 0 {
r, _, e := getCurrentProcessIdProc.Call()
if e != nil && e.(windows.Errno) != 0 {
return 0, fmt.Errorf("ui: GetCurrentProcessId failed: %d", e)
}
return uint32(r), nil
@ -48,7 +47,7 @@ func getCurrentProcessId() (uint32, error) {
func getWindowThreadProcessId(hwnd uintptr) (uint32, error) {
pid := uint32(0)
r, _, e := syscall.Syscall(getWindowThreadProcessIdProc.Addr(), 2, hwnd, uintptr(unsafe.Pointer(&pid)), 0)
r, _, e := getWindowThreadProcessIdProc.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
if r == 0 {
return 0, fmt.Errorf("ui: GetWindowThreadProcessId failed: %d", e)
}
@ -56,16 +55,15 @@ func getWindowThreadProcessId(hwnd uintptr) (uint32, error) {
}
func getConsoleWindow() (uintptr, error) {
r, _, e := syscall.Syscall(getConsoleWindowProc.Addr(), 0, 0, 0, 0)
if e != 0 {
r, _, e := getConsoleWindowProc.Call()
if e != nil && e.(windows.Errno) != 0 {
return 0, fmt.Errorf("ui: GetConsoleWindow failed: %d", e)
}
return r, nil
}
func showWindowAsync(hwnd uintptr, show int) error {
_, _, e := syscall.Syscall(showWindowAsyncProc.Addr(), 2, hwnd, uintptr(show), 0)
if e != 0 {
if _, _, e := showWindowAsyncProc.Call(hwnd, uintptr(show)); e != nil && e.(windows.Errno) != 0 {
return fmt.Errorf("ui: ShowWindowAsync failed: %d", e)
}
return nil

View File

@ -18,9 +18,10 @@ package ui
import (
"fmt"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
"github.com/hajimehoshi/ebiten/internal/devicescale"
"github.com/hajimehoshi/ebiten/internal/glfw"
)
@ -54,32 +55,32 @@ var (
)
func getSystemMetrics(nIndex int) (int, error) {
r, _, e := syscall.Syscall(procGetSystemMetrics.Addr(), 1, uintptr(nIndex), 0, 0)
if e != 0 {
r, _, e := procGetSystemMetrics.Call(uintptr(nIndex))
if e != nil && e.(windows.Errno) != 0 {
return 0, fmt.Errorf("ui: GetSystemMetrics failed: error code: %d", e)
}
return int(r), nil
}
func getActiveWindow() (uintptr, error) {
r, _, e := syscall.Syscall(procGetActiveWindow.Addr(), 0, 0, 0, 0)
if e != 0 {
r, _, e := procGetActiveWindow.Call()
if e != nil && e.(windows.Errno) != 0 {
return 0, fmt.Errorf("ui: GetActiveWindow failed: error code: %d", e)
}
return r, nil
}
func getForegroundWindow() (uintptr, error) {
r, _, e := syscall.Syscall(procGetForegroundWindow.Addr(), 0, 0, 0, 0)
if e != 0 {
r, _, e := procGetForegroundWindow.Call()
if e != nil && e.(windows.Errno) != 0 {
return 0, fmt.Errorf("ui: GetForegroundWindow failed: error code: %d", e)
}
return r, nil
}
func monitorFromWindow(hwnd uintptr, dwFlags uint32) (uintptr, error) {
r, _, e := syscall.Syscall(procMonitorFromWindow.Addr(), 2, hwnd, uintptr(dwFlags), 0)
if e != 0 {
r, _, e := procMonitorFromWindow.Call(hwnd, uintptr(dwFlags))
if e != nil && e.(windows.Errno) != 0 {
return 0, fmt.Errorf("ui: MonitorFromWindow failed: error code: %d", e)
}
if r == 0 {
@ -89,8 +90,8 @@ func monitorFromWindow(hwnd uintptr, dwFlags uint32) (uintptr, error) {
}
func getMonitorInfoW(hMonitor uintptr, lpmi *monitorInfo) error {
r, _, e := syscall.Syscall(procGetMonitorInfoW.Addr(), 2, hMonitor, uintptr(unsafe.Pointer(lpmi)), 0)
if e != 0 {
r, _, e := procGetMonitorInfoW.Call(hMonitor, uintptr(unsafe.Pointer(lpmi)))
if e != nil && e.(windows.Errno) != 0 {
return fmt.Errorf("ui: GetMonitorInfoW failed: error code: %d", e)
}
if r == 0 {