diff --git a/internal/glfw/native_darwin.go b/internal/glfw/native_darwin.go index 2ea6f11ac..3910f92f9 100644 --- a/internal/glfw/native_darwin.go +++ b/internal/glfw/native_darwin.go @@ -14,10 +14,6 @@ package glfw -import ( - "unsafe" -) - -func (w *Window) GetCocoaWindow() unsafe.Pointer { - return w.w.GetCocoaWindow() +func (w *Window) GetCocoaWindow() uintptr { + return uintptr(w.w.GetCocoaWindow()) } diff --git a/internal/glfw/native_windows.go b/internal/glfw/native_windows.go index 8ff993796..b694ce57f 100644 --- a/internal/glfw/native_windows.go +++ b/internal/glfw/native_windows.go @@ -14,12 +14,8 @@ package glfw -import ( - "unsafe" -) - -func (w *Window) GetWin32Window() unsafe.Pointer { +func (w *Window) GetWin32Window() uintptr { r := glfwDLL.call("glfwGetWin32Window", w.w) panicError() - return unsafe.Pointer(r) + return r } diff --git a/internal/graphicsdriver/metal/graphics.go b/internal/graphicsdriver/metal/graphics.go index f2ab7ad88..5d7388970 100644 --- a/internal/graphicsdriver/metal/graphics.go +++ b/internal/graphicsdriver/metal/graphics.go @@ -362,7 +362,7 @@ func (g *Graphics) End() { }) } -func (g *Graphics) SetWindow(window unsafe.Pointer) { +func (g *Graphics) SetWindow(window uintptr) { g.t.Call(func() error { // Note that [NSApp mainWindow] returns nil when the window is borderless. // Then the window is needed to be given explicitly. diff --git a/internal/graphicsdriver/metal/ns/ns.go b/internal/graphicsdriver/metal/ns/ns.go index f28c8d52c..7ef440c41 100644 --- a/internal/graphicsdriver/metal/ns/ns.go +++ b/internal/graphicsdriver/metal/ns/ns.go @@ -36,11 +36,11 @@ import "C" // // Reference: https://developer.apple.com/documentation/appkit/nswindow. type Window struct { - window unsafe.Pointer + window uintptr } // NewWindow returns a Window that wraps an existing NSWindow * pointer. -func NewWindow(window unsafe.Pointer) Window { +func NewWindow(window uintptr) Window { return Window{window} } @@ -49,7 +49,7 @@ func NewWindow(window unsafe.Pointer) Window { // // Reference: https://developer.apple.com/documentation/appkit/nswindow/1419160-contentview. func (w Window) ContentView() View { - return View{C.Window_ContentView(w.window)} + return View{C.Window_ContentView(C.uintptr_t(w.window))} } // View is the infrastructure for drawing, printing, and handling events in an app. diff --git a/internal/graphicsdriver/metal/ns/ns.h b/internal/graphicsdriver/metal/ns/ns.h index ca9c4c078..4858c2e99 100644 --- a/internal/graphicsdriver/metal/ns/ns.h +++ b/internal/graphicsdriver/metal/ns/ns.h @@ -14,7 +14,9 @@ // +build darwin -void *Window_ContentView(void *window); +#include "stdint.h" + +void *Window_ContentView(uintptr_t window); void View_SetLayer(void *view, void *layer); void View_SetWantsLayer(void *view, unsigned char wantsLayer); diff --git a/internal/graphicsdriver/metal/ns/ns.m b/internal/graphicsdriver/metal/ns/ns.m index 55fb09e38..da1173378 100644 --- a/internal/graphicsdriver/metal/ns/ns.m +++ b/internal/graphicsdriver/metal/ns/ns.m @@ -17,7 +17,7 @@ #include "ns.h" #import -void *Window_ContentView(void *window) { +void *Window_ContentView(uintptr_t window) { return ((NSWindow *)window).contentView; } diff --git a/internal/graphicsdriver/metal/view.go b/internal/graphicsdriver/metal/view.go index d1e5e3660..f7c9bf523 100644 --- a/internal/graphicsdriver/metal/view.go +++ b/internal/graphicsdriver/metal/view.go @@ -18,14 +18,13 @@ package metal import ( "sync" - "unsafe" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ca" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl" ) type view struct { - window unsafe.Pointer + window uintptr uiview uintptr windowChanged bool diff --git a/internal/graphicsdriver/metal/view_ios.go b/internal/graphicsdriver/metal/view_ios.go index 18374f66b..6c8e1e3e0 100644 --- a/internal/graphicsdriver/metal/view_ios.go +++ b/internal/graphicsdriver/metal/view_ios.go @@ -39,7 +39,7 @@ import ( "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl" ) -func (v *view) setWindow(window unsafe.Pointer) { +func (v *view) setWindow(window uintptr) { panic("metal: setWindow is not available on iOS") } diff --git a/internal/graphicsdriver/metal/view_macos.go b/internal/graphicsdriver/metal/view_macos.go index 1d97ddc6f..23c0f5dea 100644 --- a/internal/graphicsdriver/metal/view_macos.go +++ b/internal/graphicsdriver/metal/view_macos.go @@ -18,13 +18,11 @@ package metal import ( - "unsafe" - "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/mtl" "github.com/hajimehoshi/ebiten/internal/graphicsdriver/metal/ns" ) -func (v *view) setWindow(window unsafe.Pointer) { +func (v *view) setWindow(window uintptr) { // NSView can be updated e.g., fullscreen-state is switched. v.window = window v.windowChanged = true diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index e20290d88..76163f52c 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -26,7 +26,6 @@ import ( "runtime" "sync" "time" - "unsafe" "github.com/hajimehoshi/ebiten/internal/devicescale" "github.com/hajimehoshi/ebiten/internal/driver" @@ -768,12 +767,12 @@ func (u *UserInterface) run() error { return nil }) - var w unsafe.Pointer + var w uintptr _ = u.t.Call(func() error { w = u.nativeWindow() return nil }) - if g, ok := u.Graphics().(interface{ SetWindow(unsafe.Pointer) }); ok { + if g, ok := u.Graphics().(interface{ SetWindow(uintptr) }); ok { g.SetWindow(w) } return u.loop() @@ -1066,7 +1065,7 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) { }) if windowRecreated { - if g, ok := u.Graphics().(interface{ SetWindow(unsafe.Pointer) }); ok { + if g, ok := u.Graphics().(interface{ SetWindow(uintptr) }); ok { g.SetWindow(u.nativeWindow()) } } diff --git a/internal/uidriver/glfw/ui_darwin.go b/internal/uidriver/glfw/ui_darwin.go index 4366b90dd..61a4e8ced 100644 --- a/internal/uidriver/glfw/ui_darwin.go +++ b/internal/uidriver/glfw/ui_darwin.go @@ -22,7 +22,7 @@ package glfw // // #import // -// static void currentMonitorPos(void* windowPtr, int* x, int* y) { +// static void currentMonitorPos(uintptr_t windowPtr, int* x, int* y) { // NSScreen* screen = [NSScreen mainScreen]; // if (windowPtr) { // NSWindow* window = (NSWindow*)windowPtr; @@ -42,8 +42,6 @@ package glfw import "C" import ( - "unsafe" - "github.com/hajimehoshi/ebiten/internal/glfw" ) @@ -60,7 +58,7 @@ func currentMonitorByOS(w *glfw.Window) *glfw.Monitor { y := C.int(0) // Note: [NSApp mainWindow] is nil when it doesn't have its border. Use w here. win := w.GetCocoaWindow() - C.currentMonitorPos(win, &x, &y) + C.currentMonitorPos(C.uintptr_t(win), &x, &y) for _, m := range glfw.GetMonitors() { mx, my := m.GetPos() if int(x) == mx && int(y) == my { @@ -70,6 +68,6 @@ func currentMonitorByOS(w *glfw.Window) *glfw.Monitor { return nil } -func (u *UserInterface) nativeWindow() unsafe.Pointer { +func (u *UserInterface) nativeWindow() uintptr { return u.window.GetCocoaWindow() } diff --git a/internal/uidriver/glfw/ui_unix.go b/internal/uidriver/glfw/ui_unix.go index 15d5d8788..7b825841e 100644 --- a/internal/uidriver/glfw/ui_unix.go +++ b/internal/uidriver/glfw/ui_unix.go @@ -19,8 +19,6 @@ package glfw import ( - "unsafe" - "github.com/hajimehoshi/ebiten/internal/glfw" ) @@ -37,7 +35,7 @@ func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor { return nil } -func (u *UserInterface) nativeWindow() unsafe.Pointer { +func (u *UserInterface) nativeWindow() uintptr { // TODO: Implement this. - return nil + return 0 } diff --git a/internal/uidriver/glfw/ui_windows.go b/internal/uidriver/glfw/ui_windows.go index 05c16c0a1..679ae56e8 100644 --- a/internal/uidriver/glfw/ui_windows.go +++ b/internal/uidriver/glfw/ui_windows.go @@ -165,6 +165,6 @@ func currentMonitorByOS(_ *glfw.Window) *glfw.Monitor { return nil } -func (u *UserInterface) nativeWindow() unsafe.Pointer { +func (u *UserInterface) nativeWindow() uintptr { return u.window.GetWin32Window() }