mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-23 09:22:01 +01:00
parent
4a00bbc299
commit
abcacc26d8
@ -175,6 +175,7 @@ func (g *nativeGamepadsDesktop) init(gamepads *gamepads) error {
|
||||
}
|
||||
|
||||
if g.dinput8 != 0 {
|
||||
// TODO: Use _GetModuleHandleExW to align with GLFW v3.3.8.
|
||||
m, err := _GetModuleHandleW()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -64,6 +64,8 @@ const (
|
||||
_ENUM_CURRENT_SETTINGS uint32 = 0xffffffff
|
||||
_GCLP_HICON = -14
|
||||
_GCLP_HICONSM = -34
|
||||
_GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS = 0x00000004
|
||||
_GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT = 0x00000002
|
||||
_GWL_EXSTYLE = -20
|
||||
_GWL_STYLE = -16
|
||||
_HTCLIENT = 1
|
||||
@ -735,7 +737,7 @@ var (
|
||||
procSetPixelFormat = gdi32.NewProc("SetPixelFormat")
|
||||
procSwapBuffers = gdi32.NewProc("SwapBuffers")
|
||||
|
||||
procGetModuleHandleW = kernel32.NewProc("GetModuleHandleW")
|
||||
procGetModuleHandleExW = kernel32.NewProc("GetModuleHandleExW")
|
||||
procSetThreadExecutionState = kernel32.NewProc("SetThreadExecutionState")
|
||||
procTlsAlloc = kernel32.NewProc("TlsAlloc")
|
||||
procTlsFree = kernel32.NewProc("TlsFree")
|
||||
@ -1260,23 +1262,31 @@ func _GetMessageTime() int32 {
|
||||
return int32(r)
|
||||
}
|
||||
|
||||
func _GetModuleHandleW(moduleName string) (_HMODULE, error) {
|
||||
var lpModuleName *uint16
|
||||
func _GetModuleHandleExW(dwFlags uint32, lpModuleName interface{}) (_HMODULE, error) {
|
||||
var ptr unsafe.Pointer
|
||||
switch moduleName := lpModuleName.(type) {
|
||||
case string:
|
||||
if moduleName != "" {
|
||||
var err error
|
||||
lpModuleName, err = windows.UTF16PtrFromString(moduleName)
|
||||
p, err := windows.UTF16PtrFromString(moduleName)
|
||||
if err != nil {
|
||||
panic("glfwwin: module name must not include a NUL character")
|
||||
}
|
||||
ptr = unsafe.Pointer(p)
|
||||
}
|
||||
case unsafe.Pointer:
|
||||
ptr = moduleName
|
||||
default:
|
||||
return 0, fmt.Errorf("glfwwin: GetModuleHandleExW: lpModuleName must be a string or an unsafe.Pointer but %T", moduleName)
|
||||
}
|
||||
|
||||
r, _, e := procGetModuleHandleW.Call(uintptr(unsafe.Pointer(lpModuleName)))
|
||||
runtime.KeepAlive(lpModuleName)
|
||||
var module _HMODULE
|
||||
r, _, e := procGetModuleHandleExW.Call(uintptr(dwFlags), uintptr(ptr), uintptr(unsafe.Pointer(&module)))
|
||||
runtime.KeepAlive(ptr)
|
||||
|
||||
if _HMODULE(r) == 0 {
|
||||
return 0, fmt.Errorf("glfwwin: GetModuleHandleW failed: %w", e)
|
||||
if int32(r) != 1 {
|
||||
return 0, fmt.Errorf("glfwwin: GetModuleHandleExW failed: %w", e)
|
||||
}
|
||||
return _HMODULE(r), nil
|
||||
return module, nil
|
||||
}
|
||||
|
||||
func _GetMonitorInfoW(hMonitor _HMONITOR) (_MONITORINFO, bool) {
|
||||
|
@ -254,6 +254,7 @@ type library struct {
|
||||
}
|
||||
|
||||
win32 struct {
|
||||
instance _HINSTANCE
|
||||
helperWindowHandle windows.HWND
|
||||
deviceNotificationHandle _HDEVNOTIFY
|
||||
acquiredMonitorCount int
|
||||
|
@ -83,7 +83,6 @@ func createKeyTables() {
|
||||
_glfw.win32.keycodes[0x151] = KeyPageDown
|
||||
_glfw.win32.keycodes[0x149] = KeyPageUp
|
||||
_glfw.win32.keycodes[0x045] = KeyPause
|
||||
_glfw.win32.keycodes[0x146] = KeyPause
|
||||
_glfw.win32.keycodes[0x039] = KeySpace
|
||||
_glfw.win32.keycodes[0x00F] = KeyTab
|
||||
_glfw.win32.keycodes[0x03A] = KeyCapsLock
|
||||
@ -153,12 +152,7 @@ func createKeyTables() {
|
||||
}
|
||||
|
||||
func createHelperWindow() error {
|
||||
m, err := _GetModuleHandleW("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := _CreateWindowExW(_WS_EX_OVERLAPPEDWINDOW, _GLFW_WNDCLASSNAME, "GLFW message window", _WS_CLIPSIBLINGS|_WS_CLIPCHILDREN, 0, 0, 1, 1, 0, 0, _HINSTANCE(m), nil)
|
||||
h, err := _CreateWindowExW(_WS_EX_OVERLAPPEDWINDOW, _GLFW_WNDCLASSNAME, "GLFW message window", _WS_CLIPSIBLINGS|_WS_CLIPCHILDREN, 0, 0, 1, 1, 0, 0, _glfw.win32.instance, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -237,6 +231,12 @@ func platformInit() error {
|
||||
// Changing the foreground lock timeout was removed from the original code.
|
||||
// See https://github.com/glfw/glfw/commit/58b48a3a00d9c2a5ca10cc23069a71d8773cc7a4
|
||||
|
||||
m, err := _GetModuleHandleExW(_GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS|_GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, unsafe.Pointer(&_glfw))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_glfw.win32.instance = _HINSTANCE(m)
|
||||
|
||||
createKeyTables()
|
||||
|
||||
if isWindows10CreatorsUpdateOrGreaterWin32() {
|
||||
|
@ -738,6 +738,21 @@ func windowProc(hWnd windows.HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM)
|
||||
scancode = _MapVirtualKeyW(uint32(wParam), _MAPVK_VK_TO_VSC)
|
||||
}
|
||||
|
||||
// HACK: Alt+PrtSc has a different scancode than just PrtSc
|
||||
if scancode == 0x54 {
|
||||
scancode = 0x137
|
||||
}
|
||||
|
||||
// HACK: Ctrl+Pause has a different scancode than just Pause
|
||||
if scancode == 0x146 {
|
||||
scancode = 0x45
|
||||
}
|
||||
|
||||
// HACK: CJK IME sets the extended bit for right Shift
|
||||
if scancode == 0x136 {
|
||||
scancode = 0x36
|
||||
}
|
||||
|
||||
key := _glfw.win32.keycodes[scancode]
|
||||
|
||||
// The Ctrl keys require special handling
|
||||
@ -1186,15 +1201,17 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er
|
||||
|
||||
var xpos, ypos, fullWidth, fullHeight int32
|
||||
if w.monitor != nil {
|
||||
mi, ok := _GetMonitorInfoW(w.monitor.win32.handle)
|
||||
if !ok {
|
||||
return fmt.Errorf("glfwwin: GetMonitorInfoW failed")
|
||||
}
|
||||
// NOTE: This window placement is temporary and approximate, as the
|
||||
// correct position and size cannot be known until the monitor
|
||||
// video mode has been picked in _glfwSetVideoModeWin32
|
||||
x, y, _ := w.monitor.platformGetMonitorPos()
|
||||
xpos, ypos = int32(x), int32(y)
|
||||
|
||||
mode := w.monitor.platformGetVideoMode()
|
||||
fullWidth = int32(mode.Width)
|
||||
fullHeight = int32(mode.Height)
|
||||
xpos = mi.rcMonitor.left
|
||||
ypos = mi.rcMonitor.top
|
||||
fullWidth = mi.rcMonitor.right - mi.rcMonitor.left
|
||||
fullHeight = mi.rcMonitor.bottom - mi.rcMonitor.top
|
||||
} else {
|
||||
xpos = _CW_USEDEFAULT
|
||||
ypos = _CW_USEDEFAULT
|
||||
@ -1211,15 +1228,10 @@ func (w *Window) createNativeWindow(wndconfig *wndconfig, fbconfig *fbconfig) er
|
||||
fullWidth, fullHeight = int32(w), int32(h)
|
||||
}
|
||||
|
||||
m, err := _GetModuleHandleW("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
h, err := _CreateWindowExW(exStyle, _GLFW_WNDCLASSNAME, wndconfig.title, style, xpos, ypos, fullWidth, fullHeight,
|
||||
0, // No parent window
|
||||
0, // No window menu
|
||||
_HINSTANCE(m), unsafe.Pointer(wndconfig))
|
||||
_glfw.win32.instance, unsafe.Pointer(wndconfig))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1335,11 +1347,7 @@ func registerWindowClassWin32() error {
|
||||
wc.cbSize = uint32(unsafe.Sizeof(wc))
|
||||
wc.style = _CS_HREDRAW | _CS_VREDRAW | _CS_OWNDC
|
||||
wc.lpfnWndProc = _WNDPROC(windowProcPtr)
|
||||
module, err := _GetModuleHandleW("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wc.hInstance = _HINSTANCE(module)
|
||||
wc.hInstance = _glfw.win32.instance
|
||||
cursor, err := _LoadCursorW(0, _IDC_ARROW)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -1370,11 +1378,7 @@ func registerWindowClassWin32() error {
|
||||
}
|
||||
|
||||
func unregisterWindowClassWin32() error {
|
||||
m, err := _GetModuleHandleW("")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := _UnregisterClassW(_GLFW_WNDCLASSNAME, _HINSTANCE(m)); err != nil {
|
||||
if err := _UnregisterClassW(_GLFW_WNDCLASSNAME, _glfw.win32.instance); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -1394,6 +1398,9 @@ func (w *Window) platformCreateWindow(wndconfig *wndconfig, ctxconfig *ctxconfig
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := w.refreshContextAttribs(ctxconfig); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if w.monitor != nil {
|
||||
@ -1407,6 +1414,20 @@ func (w *Window) platformCreateWindow(wndconfig *wndconfig, ctxconfig *ctxconfig
|
||||
if err := w.fitToMonitor(); err != nil {
|
||||
return err
|
||||
}
|
||||
if wndconfig.centerCursor {
|
||||
if err := w.centerCursorInContentArea(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if wndconfig.visible {
|
||||
w.platformShowWindow()
|
||||
if wndconfig.focused {
|
||||
if err := w.platformFocusWindow(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -146,29 +146,6 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ctxconfig.client != NoAPI {
|
||||
if err := window.refreshContextAttribs(&ctxconfig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if window.monitor != nil {
|
||||
if wndconfig.centerCursor {
|
||||
if err := window.centerCursorInContentArea(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if wndconfig.visible {
|
||||
window.platformShowWindow()
|
||||
if wndconfig.focused {
|
||||
if err := window.platformFocusWindow(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return window, nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user