mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/gamepad: give a window from another package instead of GetActiveWindow
GetActiveWindow doesn't work on Xbox. Updates #2084
This commit is contained in:
parent
1580e92dfc
commit
2eb4ef1a94
@ -60,6 +60,10 @@ func Get(id ID) *Gamepad {
|
|||||||
return theGamepads.get(id)
|
return theGamepads.get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetNativeWindow(nativeWindow uintptr) {
|
||||||
|
theGamepads.setNativeWindow(nativeWindow)
|
||||||
|
}
|
||||||
|
|
||||||
func (g *gamepads) appendGamepadIDs(ids []ID) []ID {
|
func (g *gamepads) appendGamepadIDs(ids []ID) []ID {
|
||||||
g.m.Lock()
|
g.m.Lock()
|
||||||
defer g.m.Unlock()
|
defer g.m.Unlock()
|
||||||
@ -158,6 +162,16 @@ func (g *gamepads) remove(cond func(*Gamepad) bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *gamepads) setNativeWindow(nativeWindow uintptr) {
|
||||||
|
g.m.Lock()
|
||||||
|
defer g.m.Unlock()
|
||||||
|
|
||||||
|
var n interface{} = &g.nativeGamepads
|
||||||
|
if n, ok := n.(interface{ setNativeWindow(uintptr) }); ok {
|
||||||
|
n.setNativeWindow(nativeWindow)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type Gamepad struct {
|
type Gamepad struct {
|
||||||
name string
|
name string
|
||||||
sdlID string
|
sdlID string
|
||||||
|
@ -113,6 +113,7 @@ type nativeGamepads struct {
|
|||||||
enumDevicesCallback uintptr
|
enumDevicesCallback uintptr
|
||||||
enumObjectsCallback uintptr
|
enumObjectsCallback uintptr
|
||||||
|
|
||||||
|
nativeWindow windows.HWND
|
||||||
deviceChanged int32
|
deviceChanged int32
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
@ -518,7 +519,8 @@ 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)
|
// Note that a Win32API GetActiveWindow doesn't work on Xbox.
|
||||||
|
h, err := _SetWindowLongPtrW(g.nativeWindow, _GWL_WNDPROC, g.wndProcCallback)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -543,6 +545,10 @@ func (g *nativeGamepads) wndProc(hWnd uintptr, uMsg uint32, wParam, lParam uintp
|
|||||||
return _CallWindowProcW(g.origWndProc, hWnd, uMsg, wParam, lParam)
|
return _CallWindowProcW(g.origWndProc, hWnd, uMsg, wParam, lParam)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *nativeGamepads) setNativeWindow(nativeWindow uintptr) {
|
||||||
|
g.nativeWindow = windows.HWND(nativeWindow)
|
||||||
|
}
|
||||||
|
|
||||||
type nativeGamepad struct {
|
type nativeGamepad struct {
|
||||||
dinputDevice *_IDirectInputDevice8W
|
dinputDevice *_IDirectInputDevice8W
|
||||||
dinputObjects []dinputObject
|
dinputObjects []dinputObject
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/devicescale"
|
"github.com/hajimehoshi/ebiten/v2/internal/devicescale"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/gamepad"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
"github.com/hajimehoshi/ebiten/v2/internal/hooks"
|
||||||
@ -921,6 +922,8 @@ func (u *userInterfaceImpl) init() error {
|
|||||||
g.SetWindow(u.nativeWindow())
|
g.SetWindow(u.nativeWindow())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gamepad.SetNativeWindow(u.nativeWindow())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user