mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
internal/gamepad: unify the naming convention for Win32API with other packages
This commit is contained in:
parent
124f233de0
commit
90d26305e7
@ -139,8 +139,7 @@ var (
|
|||||||
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
kernel32 = windows.NewLazySystemDLL("kernel32.dll")
|
||||||
user32 = windows.NewLazySystemDLL("user32.dll")
|
user32 = windows.NewLazySystemDLL("user32.dll")
|
||||||
|
|
||||||
procGetCurrentThreadId = kernel32.NewProc("GetCurrentThreadId")
|
procGetModuleHandleW = kernel32.NewProc("GetModuleHandleW")
|
||||||
procGetModuleHandleW = kernel32.NewProc("GetModuleHandleW")
|
|
||||||
|
|
||||||
procCallWindowProcW = user32.NewProc("CallWindowProcW")
|
procCallWindowProcW = user32.NewProc("CallWindowProcW")
|
||||||
procGetActiveWindow = user32.NewProc("GetActiveWindow")
|
procGetActiveWindow = user32.NewProc("GetActiveWindow")
|
||||||
@ -151,12 +150,7 @@ var (
|
|||||||
procSetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW") // 64-Bit Windows version.
|
procSetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW") // 64-Bit Windows version.
|
||||||
)
|
)
|
||||||
|
|
||||||
func getCurrentThreadId() uint32 {
|
func _GetModuleHandleW() (uintptr, error) {
|
||||||
t, _, _ := procGetCurrentThreadId.Call()
|
|
||||||
return uint32(t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getModuleHandleW() (uintptr, error) {
|
|
||||||
m, _, e := procGetModuleHandleW.Call(0)
|
m, _, e := procGetModuleHandleW.Call(0)
|
||||||
if m == 0 {
|
if m == 0 {
|
||||||
if e != nil && e != windows.ERROR_SUCCESS {
|
if e != nil && e != windows.ERROR_SUCCESS {
|
||||||
@ -167,17 +161,17 @@ func getModuleHandleW() (uintptr, error) {
|
|||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func callWindowProcW(lpPrevWndFunc uintptr, hWnd uintptr, msg uint32, wParam, lParam uintptr) uintptr {
|
func _CallWindowProcW(lpPrevWndFunc uintptr, hWnd uintptr, msg uint32, wParam, lParam uintptr) uintptr {
|
||||||
r, _, _ := procCallWindowProcW.Call(lpPrevWndFunc, hWnd, uintptr(msg), wParam, lParam)
|
r, _, _ := procCallWindowProcW.Call(lpPrevWndFunc, hWnd, uintptr(msg), wParam, lParam)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func getActiveWindow() uintptr {
|
func _GetActiveWindow() uintptr {
|
||||||
h, _, _ := procGetActiveWindow.Call()
|
h, _, _ := procGetActiveWindow.Call()
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRawInputDeviceInfoW(hDevice windows.Handle, uiCommand uint32, pData unsafe.Pointer, pcb *uint32) (uint32, error) {
|
func _GetRawInputDeviceInfoW(hDevice windows.Handle, uiCommand uint32, pData unsafe.Pointer, pcb *uint32) (uint32, error) {
|
||||||
r, _, e := procGetRawInputDeviceInfoW.Call(uintptr(hDevice), uintptr(uiCommand), uintptr(pData), uintptr(unsafe.Pointer(pcb)))
|
r, _, e := procGetRawInputDeviceInfoW.Call(uintptr(hDevice), uintptr(uiCommand), uintptr(pData), uintptr(unsafe.Pointer(pcb)))
|
||||||
if uint32(r) == ^uint32(0) {
|
if uint32(r) == ^uint32(0) {
|
||||||
if e != nil && e != windows.ERROR_SUCCESS {
|
if e != nil && e != windows.ERROR_SUCCESS {
|
||||||
@ -188,7 +182,7 @@ func getRawInputDeviceInfoW(hDevice windows.Handle, uiCommand uint32, pData unsa
|
|||||||
return uint32(r), nil
|
return uint32(r), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRawInputDeviceList(pRawInputDeviceList *_RAWINPUTDEVICELIST, puiNumDevices *uint32) (uint32, error) {
|
func _GetRawInputDeviceList(pRawInputDeviceList *_RAWINPUTDEVICELIST, puiNumDevices *uint32) (uint32, error) {
|
||||||
r, _, e := procGetRawInputDeviceList.Call(uintptr(unsafe.Pointer(pRawInputDeviceList)), uintptr(unsafe.Pointer(puiNumDevices)), unsafe.Sizeof(_RAWINPUTDEVICELIST{}))
|
r, _, e := procGetRawInputDeviceList.Call(uintptr(unsafe.Pointer(pRawInputDeviceList)), uintptr(unsafe.Pointer(puiNumDevices)), unsafe.Sizeof(_RAWINPUTDEVICELIST{}))
|
||||||
if uint32(r) == ^uint32(0) {
|
if uint32(r) == ^uint32(0) {
|
||||||
if e != nil && e != windows.ERROR_SUCCESS {
|
if e != nil && e != windows.ERROR_SUCCESS {
|
||||||
@ -199,7 +193,7 @@ func getRawInputDeviceList(pRawInputDeviceList *_RAWINPUTDEVICELIST, puiNumDevic
|
|||||||
return uint32(r), nil
|
return uint32(r), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setWindowLongPtrW(hWnd uintptr, nIndex int32, dwNewLong uintptr) (uintptr, error) {
|
func _SetWindowLongPtrW(hWnd uintptr, nIndex int32, dwNewLong uintptr) (uintptr, error) {
|
||||||
var p *windows.LazyProc
|
var p *windows.LazyProc
|
||||||
if procSetWindowLongPtrW.Find() == nil {
|
if procSetWindowLongPtrW.Find() == nil {
|
||||||
// 64-Bit Windows.
|
// 64-Bit Windows.
|
||||||
@ -314,11 +308,11 @@ type _DIPROPRANGE struct {
|
|||||||
lMax int32
|
lMax int32
|
||||||
}
|
}
|
||||||
|
|
||||||
type iDirectInput8W struct {
|
type _IDirectInput8W struct {
|
||||||
vtbl *iDirectInput8W_Vtbl
|
vtbl *_IDirectInput8W_Vtbl
|
||||||
}
|
}
|
||||||
|
|
||||||
type iDirectInput8W_Vtbl struct {
|
type _IDirectInput8W_Vtbl struct {
|
||||||
QueryInterface uintptr
|
QueryInterface uintptr
|
||||||
AddRef uintptr
|
AddRef uintptr
|
||||||
Release uintptr
|
Release uintptr
|
||||||
@ -333,7 +327,7 @@ type iDirectInput8W_Vtbl struct {
|
|||||||
ConfigureDevices uintptr
|
ConfigureDevices uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInput8W) CreateDevice(rguid *windows.GUID, lplpDirectInputDevice **iDirectInputDevice8W, pUnkOuter unsafe.Pointer) error {
|
func (d *_IDirectInput8W) CreateDevice(rguid *windows.GUID, lplpDirectInputDevice **_IDirectInputDevice8W, pUnkOuter unsafe.Pointer) error {
|
||||||
r, _, _ := syscall.Syscall6(d.vtbl.CreateDevice, 4,
|
r, _, _ := syscall.Syscall6(d.vtbl.CreateDevice, 4,
|
||||||
uintptr(unsafe.Pointer(d)),
|
uintptr(unsafe.Pointer(d)),
|
||||||
uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lplpDirectInputDevice)), uintptr(pUnkOuter),
|
uintptr(unsafe.Pointer(rguid)), uintptr(unsafe.Pointer(lplpDirectInputDevice)), uintptr(pUnkOuter),
|
||||||
@ -344,7 +338,7 @@ func (d *iDirectInput8W) CreateDevice(rguid *windows.GUID, lplpDirectInputDevice
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInput8W) EnumDevices(dwDevType uint32, lpCallback uintptr, pvRef unsafe.Pointer, dwFlags uint32) error {
|
func (d *_IDirectInput8W) EnumDevices(dwDevType uint32, lpCallback uintptr, pvRef unsafe.Pointer, dwFlags uint32) error {
|
||||||
r, _, _ := syscall.Syscall6(d.vtbl.EnumDevices, 5,
|
r, _, _ := syscall.Syscall6(d.vtbl.EnumDevices, 5,
|
||||||
uintptr(unsafe.Pointer(d)),
|
uintptr(unsafe.Pointer(d)),
|
||||||
uintptr(dwDevType), lpCallback, uintptr(pvRef), uintptr(dwFlags),
|
uintptr(dwDevType), lpCallback, uintptr(pvRef), uintptr(dwFlags),
|
||||||
@ -355,11 +349,11 @@ func (d *iDirectInput8W) EnumDevices(dwDevType uint32, lpCallback uintptr, pvRef
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type iDirectInputDevice8W struct {
|
type _IDirectInputDevice8W struct {
|
||||||
vtbl *iDirectInputDevice8W_Vtbl
|
vtbl *_IDirectInputDevice8W_Vtbl
|
||||||
}
|
}
|
||||||
|
|
||||||
type iDirectInputDevice8W_Vtbl struct {
|
type _IDirectInputDevice8W_Vtbl struct {
|
||||||
QueryInterface uintptr
|
QueryInterface uintptr
|
||||||
AddRef uintptr
|
AddRef uintptr
|
||||||
Release uintptr
|
Release uintptr
|
||||||
@ -395,7 +389,7 @@ type iDirectInputDevice8W_Vtbl struct {
|
|||||||
GetImageInfo uintptr
|
GetImageInfo uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) Acquire() error {
|
func (d *_IDirectInputDevice8W) Acquire() error {
|
||||||
r, _, _ := syscall.Syscall(d.vtbl.Acquire, 1, uintptr(unsafe.Pointer(d)), 0, 0)
|
r, _, _ := syscall.Syscall(d.vtbl.Acquire, 1, uintptr(unsafe.Pointer(d)), 0, 0)
|
||||||
if uint32(r) != _DI_OK && uint32(r) != _SI_FALSE {
|
if uint32(r) != _DI_OK && uint32(r) != _SI_FALSE {
|
||||||
return fmt.Errorf("gamepad: IDirectInputDevice8::Acquire failed: %w", directInputError(r))
|
return fmt.Errorf("gamepad: IDirectInputDevice8::Acquire failed: %w", directInputError(r))
|
||||||
@ -403,7 +397,7 @@ func (d *iDirectInputDevice8W) Acquire() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) EnumObjects(lpCallback uintptr, pvRef unsafe.Pointer, dwFlags uint32) error {
|
func (d *_IDirectInputDevice8W) EnumObjects(lpCallback uintptr, pvRef unsafe.Pointer, dwFlags uint32) error {
|
||||||
r, _, _ := syscall.Syscall6(d.vtbl.EnumObjects, 4,
|
r, _, _ := syscall.Syscall6(d.vtbl.EnumObjects, 4,
|
||||||
uintptr(unsafe.Pointer(d)),
|
uintptr(unsafe.Pointer(d)),
|
||||||
lpCallback, uintptr(pvRef), uintptr(dwFlags),
|
lpCallback, uintptr(pvRef), uintptr(dwFlags),
|
||||||
@ -414,7 +408,7 @@ func (d *iDirectInputDevice8W) EnumObjects(lpCallback uintptr, pvRef unsafe.Poin
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) GetCapabilities(lpDIDevCaps *_DIDEVCAPS) error {
|
func (d *_IDirectInputDevice8W) GetCapabilities(lpDIDevCaps *_DIDEVCAPS) error {
|
||||||
r, _, _ := syscall.Syscall(d.vtbl.GetCapabilities, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpDIDevCaps)), 0)
|
r, _, _ := syscall.Syscall(d.vtbl.GetCapabilities, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpDIDevCaps)), 0)
|
||||||
if uint32(r) != _DI_OK {
|
if uint32(r) != _DI_OK {
|
||||||
return fmt.Errorf("gamepad: IDirectInputDevice8::GetCapabilities failed: %w", directInputError(r))
|
return fmt.Errorf("gamepad: IDirectInputDevice8::GetCapabilities failed: %w", directInputError(r))
|
||||||
@ -422,7 +416,7 @@ func (d *iDirectInputDevice8W) GetCapabilities(lpDIDevCaps *_DIDEVCAPS) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) GetDeviceState(cbData uint32, lpvData unsafe.Pointer) error {
|
func (d *_IDirectInputDevice8W) GetDeviceState(cbData uint32, lpvData unsafe.Pointer) error {
|
||||||
r, _, _ := syscall.Syscall(d.vtbl.GetDeviceState, 3, uintptr(unsafe.Pointer(d)), uintptr(cbData), uintptr(lpvData))
|
r, _, _ := syscall.Syscall(d.vtbl.GetDeviceState, 3, uintptr(unsafe.Pointer(d)), uintptr(cbData), uintptr(lpvData))
|
||||||
if uint32(r) != _DI_OK {
|
if uint32(r) != _DI_OK {
|
||||||
return fmt.Errorf("gamepad: IDirectInputDevice8::GetDeviceState failed: %w", directInputError(r))
|
return fmt.Errorf("gamepad: IDirectInputDevice8::GetDeviceState failed: %w", directInputError(r))
|
||||||
@ -430,7 +424,7 @@ func (d *iDirectInputDevice8W) GetDeviceState(cbData uint32, lpvData unsafe.Poin
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) Poll() error {
|
func (d *_IDirectInputDevice8W) Poll() error {
|
||||||
r, _, _ := syscall.Syscall(d.vtbl.Poll, 1, uintptr(unsafe.Pointer(d)), 0, 0)
|
r, _, _ := syscall.Syscall(d.vtbl.Poll, 1, uintptr(unsafe.Pointer(d)), 0, 0)
|
||||||
if uint32(r) != _DI_OK && uint32(r) != _DI_NOEFFECT {
|
if uint32(r) != _DI_OK && uint32(r) != _DI_NOEFFECT {
|
||||||
return fmt.Errorf("gamepad: IDirectInputDevice8::Poll failed: %w", directInputError(r))
|
return fmt.Errorf("gamepad: IDirectInputDevice8::Poll failed: %w", directInputError(r))
|
||||||
@ -438,12 +432,12 @@ func (d *iDirectInputDevice8W) Poll() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) Release() uint32 {
|
func (d *_IDirectInputDevice8W) Release() uint32 {
|
||||||
r, _, _ := syscall.Syscall(d.vtbl.Release, 1, uintptr(unsafe.Pointer(d)), 0, 0)
|
r, _, _ := syscall.Syscall(d.vtbl.Release, 1, uintptr(unsafe.Pointer(d)), 0, 0)
|
||||||
return uint32(r)
|
return uint32(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) SetDataFormat(lpdf *_DIDATAFORMAT) error {
|
func (d *_IDirectInputDevice8W) SetDataFormat(lpdf *_DIDATAFORMAT) error {
|
||||||
r, _, _ := syscall.Syscall(d.vtbl.SetDataFormat, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpdf)), 0)
|
r, _, _ := syscall.Syscall(d.vtbl.SetDataFormat, 2, uintptr(unsafe.Pointer(d)), uintptr(unsafe.Pointer(lpdf)), 0)
|
||||||
if uint32(r) != _DI_OK {
|
if uint32(r) != _DI_OK {
|
||||||
return fmt.Errorf("gamepad: IDirectInputDevice8::SetDataFormat failed: %w", directInputError(r))
|
return fmt.Errorf("gamepad: IDirectInputDevice8::SetDataFormat failed: %w", directInputError(r))
|
||||||
@ -451,7 +445,7 @@ func (d *iDirectInputDevice8W) SetDataFormat(lpdf *_DIDATAFORMAT) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *iDirectInputDevice8W) SetProperty(rguidProp uintptr, pdiph *_DIPROPHEADER) error {
|
func (d *_IDirectInputDevice8W) SetProperty(rguidProp uintptr, pdiph *_DIPROPHEADER) error {
|
||||||
r, _, _ := syscall.Syscall(d.vtbl.SetProperty, 3, uintptr(unsafe.Pointer(d)), rguidProp, uintptr(unsafe.Pointer(pdiph)))
|
r, _, _ := syscall.Syscall(d.vtbl.SetProperty, 3, uintptr(unsafe.Pointer(d)), rguidProp, uintptr(unsafe.Pointer(pdiph)))
|
||||||
if uint32(r) != _DI_OK && uint32(r) != _DI_PROPNOEFFECT {
|
if uint32(r) != _DI_OK && uint32(r) != _DI_PROPNOEFFECT {
|
||||||
return fmt.Errorf("gamepad: IDirectInputDevice8::SetProperty failed: %w", directInputError(r))
|
return fmt.Errorf("gamepad: IDirectInputDevice8::SetProperty failed: %w", directInputError(r))
|
||||||
@ -480,15 +474,15 @@ type _RAWINPUTDEVICELIST struct {
|
|||||||
dwType uint32
|
dwType uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
type xinputCapabilities struct {
|
type _XINPUT_CAPABILITIES struct {
|
||||||
typ byte
|
typ byte
|
||||||
subType byte
|
subType byte
|
||||||
flags uint16
|
flags uint16
|
||||||
gamepad xinputGamepad
|
gamepad _XINPUT_GAMEPAD
|
||||||
vibration xinputVibration
|
vibration _XINPUT_VIBRATION
|
||||||
}
|
}
|
||||||
|
|
||||||
type xinputGamepad struct {
|
type _XINPUT_GAMEPAD struct {
|
||||||
wButtons uint16
|
wButtons uint16
|
||||||
bLeftTrigger byte
|
bLeftTrigger byte
|
||||||
bRightTrigger byte
|
bRightTrigger byte
|
||||||
@ -498,12 +492,12 @@ type xinputGamepad struct {
|
|||||||
sThumbRY int16
|
sThumbRY int16
|
||||||
}
|
}
|
||||||
|
|
||||||
type xinputState struct {
|
type _XINPUT_STATE struct {
|
||||||
dwPacketNumber uint32
|
dwPacketNumber uint32
|
||||||
Gamepad xinputGamepad
|
Gamepad _XINPUT_GAMEPAD
|
||||||
}
|
}
|
||||||
|
|
||||||
type xinputVibration struct {
|
type _XINPUT_VIBRATION struct {
|
||||||
wLeftMotorSpeed uint16
|
wLeftMotorSpeed uint16
|
||||||
wRightMotorSpeed uint16
|
wRightMotorSpeed uint16
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ var xinputButtons = []uint16{
|
|||||||
|
|
||||||
type nativeGamepads struct {
|
type nativeGamepads struct {
|
||||||
dinput8 windows.Handle
|
dinput8 windows.Handle
|
||||||
dinput8API *iDirectInput8W
|
dinput8API *_IDirectInput8W
|
||||||
xinput windows.Handle
|
xinput windows.Handle
|
||||||
|
|
||||||
procDirectInput8Create uintptr
|
procDirectInput8Create uintptr
|
||||||
@ -123,7 +123,7 @@ type dinputObject struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type enumObjectsContext struct {
|
type enumObjectsContext struct {
|
||||||
device *iDirectInputDevice8W
|
device *_IDirectInputDevice8W
|
||||||
objects []dinputObject
|
objects []dinputObject
|
||||||
axisCount int
|
axisCount int
|
||||||
sliderCount int
|
sliderCount int
|
||||||
@ -174,12 +174,12 @@ func (g *nativeGamepads) init(gamepads *gamepads) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if g.dinput8 != 0 {
|
if g.dinput8 != 0 {
|
||||||
m, err := getModuleHandleW()
|
m, err := _GetModuleHandleW()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var api *iDirectInput8W
|
var api *_IDirectInput8W
|
||||||
if err := g.directInput8Create(m, _DIRECTINPUT_VERSION, &_IID_IDirectInput8W, &api, nil); err != nil {
|
if err := g.directInput8Create(m, _DIRECTINPUT_VERSION, &_IID_IDirectInput8W, &api, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ func (g *nativeGamepads) init(gamepads *gamepads) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepads) directInput8Create(hinst uintptr, dwVersion uint32, riidltf *windows.GUID, ppvOut **iDirectInput8W, punkOuter unsafe.Pointer) error {
|
func (g *nativeGamepads) directInput8Create(hinst uintptr, dwVersion uint32, riidltf *windows.GUID, ppvOut **_IDirectInput8W, punkOuter unsafe.Pointer) error {
|
||||||
r, _, _ := syscall.Syscall6(g.procDirectInput8Create, 5,
|
r, _, _ := syscall.Syscall6(g.procDirectInput8Create, 5,
|
||||||
hinst, uintptr(dwVersion), uintptr(unsafe.Pointer(riidltf)), uintptr(unsafe.Pointer(ppvOut)), uintptr(punkOuter),
|
hinst, uintptr(dwVersion), uintptr(unsafe.Pointer(riidltf)), uintptr(unsafe.Pointer(ppvOut)), uintptr(punkOuter),
|
||||||
0)
|
0)
|
||||||
@ -203,7 +203,7 @@ func (g *nativeGamepads) directInput8Create(hinst uintptr, dwVersion uint32, rii
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepads) xinputGetCapabilities(dwUserIndex uint32, dwFlags uint32, pCapabilities *xinputCapabilities) error {
|
func (g *nativeGamepads) xinputGetCapabilities(dwUserIndex uint32, dwFlags uint32, pCapabilities *_XINPUT_CAPABILITIES) error {
|
||||||
// XInputGetCapabilities doesn't call SetLastError and returns an error code directly.
|
// XInputGetCapabilities doesn't call SetLastError and returns an error code directly.
|
||||||
r, _, _ := syscall.Syscall(g.procXInputGetCapabilities, 3,
|
r, _, _ := syscall.Syscall(g.procXInputGetCapabilities, 3,
|
||||||
uintptr(dwUserIndex), uintptr(dwFlags), uintptr(unsafe.Pointer(pCapabilities)))
|
uintptr(dwUserIndex), uintptr(dwFlags), uintptr(unsafe.Pointer(pCapabilities)))
|
||||||
@ -213,7 +213,7 @@ func (g *nativeGamepads) xinputGetCapabilities(dwUserIndex uint32, dwFlags uint3
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *nativeGamepads) xinputGetState(dwUserIndex uint32, pState *xinputState) error {
|
func (g *nativeGamepads) xinputGetState(dwUserIndex uint32, pState *_XINPUT_STATE) error {
|
||||||
// XInputGetState doesn't call SetLastError and returns an error code directly.
|
// XInputGetState doesn't call SetLastError and returns an error code directly.
|
||||||
r, _, _ := syscall.Syscall(g.procXInputGetState, 2,
|
r, _, _ := syscall.Syscall(g.procXInputGetState, 2,
|
||||||
uintptr(dwUserIndex), uintptr(unsafe.Pointer(pState)), 0)
|
uintptr(dwUserIndex), uintptr(unsafe.Pointer(pState)), 0)
|
||||||
@ -245,7 +245,7 @@ func (g *nativeGamepads) detectConnection(gamepads *gamepads) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var xic xinputCapabilities
|
var xic _XINPUT_CAPABILITIES
|
||||||
if err := g.xinputGetCapabilities(uint32(i), 0, &xic); err != nil {
|
if err := g.xinputGetCapabilities(uint32(i), 0, &xic); err != nil {
|
||||||
if !errors.Is(err, windows.ERROR_DEVICE_NOT_CONNECTED) {
|
if !errors.Is(err, windows.ERROR_DEVICE_NOT_CONNECTED) {
|
||||||
return err
|
return err
|
||||||
@ -305,7 +305,7 @@ func (g *nativeGamepads) dinput8EnumDevicesCallback(lpddi *_DIDEVICEINSTANCEW, p
|
|||||||
return _DIENUM_CONTINUE
|
return _DIENUM_CONTINUE
|
||||||
}
|
}
|
||||||
|
|
||||||
var device *iDirectInputDevice8W
|
var device *_IDirectInputDevice8W
|
||||||
if err := g.dinput8API.CreateDevice(&lpddi.guidInstance, &device, nil); err != nil {
|
if err := g.dinput8API.CreateDevice(&lpddi.guidInstance, &device, nil); err != nil {
|
||||||
g.err = err
|
g.err = err
|
||||||
return _DIENUM_STOP
|
return _DIENUM_STOP
|
||||||
@ -400,14 +400,14 @@ func (g *nativeGamepads) dinput8EnumDevicesCallback(lpddi *_DIDEVICEINSTANCEW, p
|
|||||||
|
|
||||||
func supportsXInput(guid windows.GUID) (bool, error) {
|
func supportsXInput(guid windows.GUID) (bool, error) {
|
||||||
var count uint32
|
var count uint32
|
||||||
if r, err := getRawInputDeviceList(nil, &count); err != nil {
|
if r, err := _GetRawInputDeviceList(nil, &count); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
} else if r != 0 {
|
} else if r != 0 {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
ridl := make([]_RAWINPUTDEVICELIST, count)
|
ridl := make([]_RAWINPUTDEVICELIST, count)
|
||||||
if _, err := getRawInputDeviceList(&ridl[0], &count); err != nil {
|
if _, err := _GetRawInputDeviceList(&ridl[0], &count); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,7 +420,7 @@ func supportsXInput(guid windows.GUID) (bool, error) {
|
|||||||
cbSize: uint32(unsafe.Sizeof(_RID_DEVICE_INFO{})),
|
cbSize: uint32(unsafe.Sizeof(_RID_DEVICE_INFO{})),
|
||||||
}
|
}
|
||||||
size := uint32(unsafe.Sizeof(rdi))
|
size := uint32(unsafe.Sizeof(rdi))
|
||||||
if _, err := getRawInputDeviceInfoW(ridl[i].hDevice, _RIDI_DEVICEINFO, unsafe.Pointer(&rdi), &size); err != nil {
|
if _, err := _GetRawInputDeviceInfoW(ridl[i].hDevice, _RIDI_DEVICEINFO, unsafe.Pointer(&rdi), &size); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,7 +430,7 @@ func supportsXInput(guid windows.GUID) (bool, error) {
|
|||||||
|
|
||||||
var name [256]uint16
|
var name [256]uint16
|
||||||
size = uint32(unsafe.Sizeof(name))
|
size = uint32(unsafe.Sizeof(name))
|
||||||
if _, err := getRawInputDeviceInfoW(ridl[i].hDevice, _RIDI_DEVICENAME, unsafe.Pointer(&name[0]), &size); err != nil {
|
if _, err := _GetRawInputDeviceInfoW(ridl[i].hDevice, _RIDI_DEVICENAME, unsafe.Pointer(&name[0]), &size); err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -518,7 +518,7 @@ func (g *nativeGamepads) update(gamepads *gamepads) error {
|
|||||||
if g.wndProcCallback == 0 {
|
if g.wndProcCallback == 0 {
|
||||||
g.wndProcCallback = windows.NewCallback(g.wndProc)
|
g.wndProcCallback = windows.NewCallback(g.wndProc)
|
||||||
}
|
}
|
||||||
h, err := setWindowLongPtrW(getActiveWindow(), _GWL_WNDPROC, g.wndProcCallback)
|
h, err := _SetWindowLongPtrW(_GetActiveWindow(), _GWL_WNDPROC, g.wndProcCallback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -540,11 +540,11 @@ func (g *nativeGamepads) wndProc(hWnd uintptr, uMsg uint32, wParam, lParam uintp
|
|||||||
case _WM_DEVICECHANGE:
|
case _WM_DEVICECHANGE:
|
||||||
atomic.StoreInt32(&g.deviceChanged, 1)
|
atomic.StoreInt32(&g.deviceChanged, 1)
|
||||||
}
|
}
|
||||||
return callWindowProcW(g.origWndProc, hWnd, uMsg, wParam, lParam)
|
return _CallWindowProcW(g.origWndProc, hWnd, uMsg, wParam, lParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
type nativeGamepad struct {
|
type nativeGamepad struct {
|
||||||
dinputDevice *iDirectInputDevice8W
|
dinputDevice *_IDirectInputDevice8W
|
||||||
dinputObjects []dinputObject
|
dinputObjects []dinputObject
|
||||||
dinputGUID windows.GUID
|
dinputGUID windows.GUID
|
||||||
dinputAxes []float64
|
dinputAxes []float64
|
||||||
@ -552,7 +552,7 @@ type nativeGamepad struct {
|
|||||||
dinputHats []int
|
dinputHats []int
|
||||||
|
|
||||||
xinputIndex int
|
xinputIndex int
|
||||||
xinputState xinputState
|
xinputState _XINPUT_STATE
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*nativeGamepad) hasOwnStandardLayoutMapping() bool {
|
func (*nativeGamepad) hasOwnStandardLayoutMapping() bool {
|
||||||
@ -659,7 +659,7 @@ func (g *nativeGamepad) update(gamepads *gamepads) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var state xinputState
|
var state _XINPUT_STATE
|
||||||
if err := gamepads.xinputGetState(uint32(g.xinputIndex), &state); err != nil {
|
if err := gamepads.xinputGetState(uint32(g.xinputIndex), &state); err != nil {
|
||||||
if !errors.Is(err, windows.ERROR_DEVICE_NOT_CONNECTED) {
|
if !errors.Is(err, windows.ERROR_DEVICE_NOT_CONNECTED) {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user