2016-06-18 22:04:38 +02:00
|
|
|
// Copyright 2016 Hajime Hoshi
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-08-12 05:40:23 +02:00
|
|
|
//go:build !ios && !nintendosdk
|
|
|
|
// +build !ios,!nintendosdk
|
2016-06-18 22:04:38 +02:00
|
|
|
|
2022-02-06 08:08:22 +01:00
|
|
|
package ui
|
2016-06-18 22:04:38 +02:00
|
|
|
|
2018-10-06 15:42:28 +02:00
|
|
|
import (
|
2022-06-16 19:10:29 +02:00
|
|
|
"fmt"
|
2022-09-16 04:53:46 +02:00
|
|
|
"unsafe"
|
2022-06-16 19:10:29 +02:00
|
|
|
|
2022-09-16 04:53:46 +02:00
|
|
|
"github.com/ebitengine/purego/objc"
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/cocoa"
|
2020-10-03 19:35:13 +02:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/glfw"
|
2022-03-22 15:33:21 +01:00
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/metal"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl"
|
2018-10-06 15:42:28 +02:00
|
|
|
)
|
|
|
|
|
2022-09-16 04:53:46 +02:00
|
|
|
var class_EbitengineWindowDelegate objc.Class
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
class_EbitengineWindowDelegate = objc.AllocateClassPair(objc.GetClass("NSObject"), "EbitengineWindowDelegate", 0)
|
|
|
|
protocol := objc.GetProtocol("NSWindowDelegate")
|
|
|
|
class_EbitengineWindowDelegate.AddProtocol(protocol)
|
|
|
|
// TODO: remove these Ivars and place them in Go since there is only ever one instance of this class
|
|
|
|
class_EbitengineWindowDelegate.AddIvar("origDelegate", objc.ID(0), "@")
|
|
|
|
class_EbitengineWindowDelegate.AddIvar("origResizable", false, "B")
|
|
|
|
origDelegateOffset := class_EbitengineWindowDelegate.InstanceVariable("origDelegate").Offset()
|
|
|
|
origResizableOffset := class_EbitengineWindowDelegate.InstanceVariable("origResizable").Offset()
|
|
|
|
getOrigDelegate := func(self objc.ID) objc.ID {
|
|
|
|
selfPtr := *(**uintptr)(unsafe.Pointer(&self))
|
|
|
|
return *(*objc.ID)(unsafe.Pointer(uintptr(unsafe.Pointer(selfPtr)) + origDelegateOffset))
|
|
|
|
}
|
|
|
|
getResizable := func(self objc.ID) bool {
|
|
|
|
selfPtr := *(**uintptr)(unsafe.Pointer(&self))
|
|
|
|
return *(*bool)(unsafe.Pointer(uintptr(unsafe.Pointer(selfPtr)) + origResizableOffset))
|
|
|
|
}
|
|
|
|
setResizable := func(self objc.ID, resizable bool) {
|
|
|
|
selfPtr := *(**uintptr)(unsafe.Pointer(&self))
|
|
|
|
*(*bool)(unsafe.Pointer(uintptr(unsafe.Pointer(selfPtr)) + origResizableOffset)) = resizable
|
|
|
|
}
|
|
|
|
pushResizableState := func(self, w objc.ID) {
|
|
|
|
window := cocoa.NSWindow{ID: w}
|
|
|
|
setResizable(self, window.StyleMask()&cocoa.NSWindowStyleMaskResizable != 0)
|
|
|
|
if !getResizable(self) {
|
|
|
|
window.SetStyleMask(window.StyleMask() | cocoa.NSWindowStyleMaskResizable)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
popResizableState := func(self, w objc.ID) {
|
|
|
|
window := cocoa.NSWindow{ID: w}
|
|
|
|
if !getResizable(self) {
|
|
|
|
window.SetStyleMask(window.StyleMask() & ^uint(cocoa.NSWindowStyleMaskResizable))
|
|
|
|
}
|
|
|
|
setResizable(self, false)
|
|
|
|
}
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("initWithOrigDelegate:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, origDelegate objc.ID) objc.ID {
|
|
|
|
self = self.SendSuper(objc.RegisterName("init"))
|
|
|
|
if self != 0 {
|
|
|
|
selfPtr := *(**uintptr)(unsafe.Pointer(&self))
|
|
|
|
*(*objc.ID)(unsafe.Pointer(uintptr(unsafe.Pointer(selfPtr)) + origDelegateOffset)) = origDelegate
|
|
|
|
}
|
|
|
|
return self
|
|
|
|
}), "@@:B")
|
|
|
|
// The method set of origDelegate_ must sync with GLFWWindowDelegate's implementation.
|
|
|
|
// See cocoa_window.m in GLFW.
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowShouldClose:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) int {
|
|
|
|
return int(getOrigDelegate(self).Send(objc.RegisterName("windowShouldClose:"), notification))
|
|
|
|
}), "B@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidResize:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
getOrigDelegate(self).Send(cmd, notification)
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidMove:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
getOrigDelegate(self).Send(cmd, notification)
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidMiniaturize:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
getOrigDelegate(self).Send(cmd, notification)
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidDeminiaturize:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
getOrigDelegate(self).Send(cmd, notification)
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidBecomeKey:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
getOrigDelegate(self).Send(cmd, notification)
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidResignKey:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
getOrigDelegate(self).Send(cmd, notification)
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidChangeOcclusionState:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
getOrigDelegate(self).Send(cmd, notification)
|
|
|
|
}), "v@:@")
|
|
|
|
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowWillEnterFullScreen:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
pushResizableState(self, cocoa.NSNotification{ID: notification}.Object())
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidEnterFullScreen:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
popResizableState(self, cocoa.NSNotification{ID: notification}.Object())
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowWillExitFullScreen:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
pushResizableState(self, cocoa.NSNotification{ID: notification}.Object())
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.AddMethod(objc.RegisterName("windowDidExitFullScreen:"), objc.NewIMP(func(self objc.ID, cmd objc.SEL, notification objc.ID) {
|
|
|
|
popResizableState(self, cocoa.NSNotification{ID: notification}.Object())
|
|
|
|
// Do not call setFrame here (#2295). setFrame here causes unexpected results.
|
|
|
|
}), "v@:@")
|
|
|
|
class_EbitengineWindowDelegate.Register()
|
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
type graphicsDriverCreatorImpl struct {
|
2022-02-11 12:38:45 +01:00
|
|
|
transparent bool
|
|
|
|
}
|
2022-03-22 15:33:21 +01:00
|
|
|
|
2022-07-30 19:56:16 +02:00
|
|
|
func (g *graphicsDriverCreatorImpl) newAuto() (graphicsdriver.Graphics, GraphicsLibrary, error) {
|
2022-06-16 19:10:29 +02:00
|
|
|
m, err1 := g.newMetal()
|
|
|
|
if err1 == nil {
|
2022-07-30 19:56:16 +02:00
|
|
|
return m, GraphicsLibraryMetal, nil
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
2022-06-16 19:10:29 +02:00
|
|
|
o, err2 := g.newOpenGL()
|
|
|
|
if err2 == nil {
|
2022-07-30 19:56:16 +02:00
|
|
|
return o, GraphicsLibraryOpenGL, nil
|
2022-06-16 19:10:29 +02:00
|
|
|
}
|
2022-07-30 19:56:16 +02:00
|
|
|
return nil, GraphicsLibraryUnknown, fmt.Errorf("ui: failed to choose graphics drivers: Metal: %v, OpenGL: %v", err1, err2)
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newOpenGL() (graphicsdriver.Graphics, error) {
|
2022-06-16 19:02:29 +02:00
|
|
|
return opengl.NewGraphics()
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2022-06-17 04:39:43 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newDirectX() (graphicsdriver.Graphics, error) {
|
|
|
|
return nil, nil
|
2022-03-25 11:43:32 +01:00
|
|
|
}
|
|
|
|
|
2022-06-16 19:10:29 +02:00
|
|
|
func (*graphicsDriverCreatorImpl) newMetal() (graphicsdriver.Graphics, error) {
|
|
|
|
return metal.NewGraphics()
|
2022-03-22 15:33:21 +01:00
|
|
|
}
|
|
|
|
|
2021-09-15 05:47:04 +02:00
|
|
|
// clearVideoModeScaleCache must be called from the main thread.
|
|
|
|
func clearVideoModeScaleCache() {}
|
|
|
|
|
2021-10-10 08:38:13 +02:00
|
|
|
// dipFromGLFWMonitorPixel must be called from the main thread.
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) dipFromGLFWMonitorPixel(x float64, monitor *glfw.Monitor) float64 {
|
2021-10-09 09:49:47 +02:00
|
|
|
return x
|
2020-09-18 17:21:08 +02:00
|
|
|
}
|
|
|
|
|
2021-10-10 08:38:13 +02:00
|
|
|
// dipFromGLFWPixel must be called from the main thread.
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) dipFromGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
|
2021-09-14 18:03:04 +02:00
|
|
|
// NOTE: On macOS, GLFW exposes the device independent coordinate system.
|
|
|
|
// Thus, the conversion functions are unnecessary,
|
|
|
|
// however we still need the deviceScaleFactor internally
|
|
|
|
// so we can create and maintain a HiDPI frame buffer.
|
2020-09-18 17:31:34 +02:00
|
|
|
return x
|
|
|
|
}
|
|
|
|
|
2021-10-10 08:38:13 +02:00
|
|
|
// dipToGLFWPixel must be called from the main thread.
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) dipToGLFWPixel(x float64, monitor *glfw.Monitor) float64 {
|
2020-09-18 17:21:08 +02:00
|
|
|
return x
|
2016-06-18 22:04:38 +02:00
|
|
|
}
|
2017-04-18 17:51:15 +02:00
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) adjustWindowPosition(x, y int, monitor *glfw.Monitor) (int, int) {
|
2017-04-18 17:51:15 +02:00
|
|
|
return x, y
|
|
|
|
}
|
2018-10-06 15:42:28 +02:00
|
|
|
|
2022-03-29 21:15:52 +02:00
|
|
|
func flipY(y int) int {
|
2022-02-07 13:56:16 +01:00
|
|
|
for _, m := range ensureMonitors() {
|
|
|
|
if m.x == 0 && m.y == 0 {
|
|
|
|
y = -y
|
|
|
|
y += m.vm.Height
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-03-29 21:15:52 +02:00
|
|
|
return y
|
|
|
|
}
|
|
|
|
|
2022-09-16 04:53:46 +02:00
|
|
|
var class_NSEvent = objc.GetClass("NSEvent")
|
|
|
|
var sel_mouseLocation = objc.RegisterName("mouseLocation")
|
|
|
|
|
|
|
|
func currentMouseLocation() (x, y int) {
|
|
|
|
sig := cocoa.NSMethodSignature_signatureWithObjCTypes("{NSPoint=dd}@:")
|
|
|
|
inv := cocoa.NSInvocation_invocationWithMethodSignature(sig)
|
|
|
|
inv.SetTarget(objc.ID(class_NSEvent))
|
|
|
|
inv.SetSelector(sel_mouseLocation)
|
|
|
|
inv.Invoke()
|
|
|
|
var point cocoa.NSPoint
|
|
|
|
inv.GetReturnValue(unsafe.Pointer(&point))
|
|
|
|
return int(point.X), int(point.Y)
|
|
|
|
}
|
|
|
|
|
2022-03-29 21:15:52 +02:00
|
|
|
func initialMonitorByOS() (*glfw.Monitor, error) {
|
2022-09-16 04:53:46 +02:00
|
|
|
x, y := currentMouseLocation()
|
2022-02-07 13:56:16 +01:00
|
|
|
|
|
|
|
// Find the monitor including the cursor.
|
|
|
|
for _, m := range ensureMonitors() {
|
|
|
|
w, h := m.vm.Width, m.vm.Height
|
|
|
|
if x >= m.x && x < m.x+w && y >= m.y && y < m.y+h {
|
2022-02-07 15:31:08 +01:00
|
|
|
return m.m, nil
|
2022-02-07 13:56:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 15:31:08 +01:00
|
|
|
return nil, nil
|
2021-10-09 09:49:47 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 16:26:49 +01:00
|
|
|
func monitorFromWindowByOS(w *glfw.Window) *glfw.Monitor {
|
2022-09-16 04:53:46 +02:00
|
|
|
window := cocoa.NSWindow{ID: objc.ID(w.GetCocoaWindow())}
|
|
|
|
pool := cocoa.NSAutoreleasePool_new()
|
|
|
|
screen := cocoa.NSScreen_mainScreen()
|
|
|
|
if window.ID != 0 && window.IsVisibile() {
|
|
|
|
// When the window is visible, the window is already initialized.
|
|
|
|
// [NSScreen mainScreen] sometimes tells a lie when the window is put across monitors (#703).
|
|
|
|
screen = window.Screen()
|
|
|
|
}
|
|
|
|
screenDictionary := screen.DeviceDescription()
|
|
|
|
screenID := cocoa.NSNumber{ID: screenDictionary.ObjectForKey(cocoa.NSString_alloc().InitWithUTF8String("NSScreenNumber").ID)}
|
|
|
|
aID := uintptr(screenID.UnsignedIntValue()) // CGDirectDisplayID
|
|
|
|
pool.Release()
|
2021-09-09 04:11:56 +02:00
|
|
|
for _, m := range ensureMonitors() {
|
2022-09-16 04:53:46 +02:00
|
|
|
if m.m.GetCocoaMonitor() == aID {
|
2021-09-09 04:11:56 +02:00
|
|
|
return m.m
|
2018-10-06 15:42:28 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-23 20:27:38 +02:00
|
|
|
return nil
|
2018-10-06 15:42:28 +02:00
|
|
|
}
|
2018-11-12 16:00:10 +01:00
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) nativeWindow() uintptr {
|
2018-12-28 06:08:44 +01:00
|
|
|
return u.window.GetCocoaWindow()
|
2018-11-12 16:00:10 +01:00
|
|
|
}
|
2021-04-18 10:35:46 +02:00
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) isNativeFullscreen() bool {
|
2022-09-16 04:53:46 +02:00
|
|
|
return cocoa.NSWindow{ID: objc.ID(u.window.GetCocoaWindow())}.StyleMask()&cocoa.NSWindowStyleMaskFullScreen != 0
|
2021-04-18 10:35:46 +02:00
|
|
|
}
|
2021-05-02 07:50:50 +02:00
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) setNativeCursor(shape CursorShape) {
|
2022-09-16 04:53:46 +02:00
|
|
|
class_NSCursor := objc.GetClass("NSCursor")
|
|
|
|
NSCursor := objc.ID(class_NSCursor).Send(objc.RegisterName("class"))
|
|
|
|
sel_performSelector := objc.RegisterName("performSelector:")
|
|
|
|
cursor := NSCursor.Send(sel_performSelector, objc.RegisterName("arrowCursor"))
|
|
|
|
switch shape {
|
|
|
|
case 0:
|
|
|
|
cursor = NSCursor.Send(sel_performSelector, objc.RegisterName("arrowCursor"))
|
|
|
|
case 1:
|
|
|
|
cursor = NSCursor.Send(sel_performSelector, objc.RegisterName("IBeamCursor"))
|
|
|
|
case 2:
|
|
|
|
cursor = NSCursor.Send(sel_performSelector, objc.RegisterName("crosshairCursor"))
|
|
|
|
case 3:
|
|
|
|
cursor = NSCursor.Send(sel_performSelector, objc.RegisterName("pointHandCursor"))
|
|
|
|
case 4:
|
|
|
|
cursor = NSCursor.Send(sel_performSelector, objc.RegisterName("_windowResizeEastWestCursor"))
|
|
|
|
case 5:
|
|
|
|
cursor = NSCursor.Send(sel_performSelector, objc.RegisterName("_windowResizeNorthSouthCursor"))
|
|
|
|
}
|
|
|
|
cursor.Send(objc.RegisterName("push"))
|
2021-05-02 07:50:50 +02:00
|
|
|
}
|
2021-09-17 19:21:24 +02:00
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) isNativeFullscreenAvailable() bool {
|
2021-10-31 10:21:00 +01:00
|
|
|
// TODO: If the window is transparent, we should use GLFW's windowed fullscreen (#1822, #1857).
|
|
|
|
// However, if the user clicks the green button, should this window be in native fullscreen mode?
|
|
|
|
return true
|
2021-09-17 19:21:24 +02:00
|
|
|
}
|
|
|
|
|
2022-09-16 04:53:46 +02:00
|
|
|
var sel_collectionBehavior = objc.RegisterName("collectionBehavior")
|
|
|
|
var sel_setCollectionBehavior = objc.RegisterName("setCollectionBehavior:")
|
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) setNativeFullscreen(fullscreen bool) {
|
2021-09-17 19:21:24 +02:00
|
|
|
// Toggling fullscreen might ignore events like keyUp. Ensure that events are fired.
|
2021-09-20 14:01:17 +02:00
|
|
|
glfw.WaitEventsTimeout(0.1)
|
2022-09-16 04:53:46 +02:00
|
|
|
window := cocoa.NSWindow{ID: objc.ID(u.window.GetCocoaWindow())}
|
|
|
|
if window.StyleMask()&cocoa.NSWindowStyleMaskFullScreen != 0 == fullscreen {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Even though EbitengineWindowDelegate is used, this hack is still required.
|
|
|
|
// toggleFullscreen doesn't work when the window is not resizable.
|
|
|
|
origFullScreen := window.Send(sel_collectionBehavior)&cocoa.NSWindowCollectionBehaviorFullScreenPrimary != 0
|
|
|
|
if !origFullScreen {
|
2022-09-25 13:10:31 +02:00
|
|
|
window.Send(sel_setCollectionBehavior, cocoa.NSUInteger(window.Send(sel_collectionBehavior))|cocoa.NSWindowCollectionBehaviorFullScreenPrimary)
|
2022-09-16 04:53:46 +02:00
|
|
|
}
|
|
|
|
window.Send(objc.RegisterName("toggleFullScreen:"), 0)
|
|
|
|
if !origFullScreen {
|
2022-09-25 13:10:31 +02:00
|
|
|
window.Send(sel_setCollectionBehavior, cocoa.NSUInteger(window.Send(sel_collectionBehavior))&^cocoa.NSUInteger(cocoa.NSWindowCollectionBehaviorFullScreenPrimary))
|
2022-09-16 04:53:46 +02:00
|
|
|
}
|
2021-09-17 19:21:24 +02:00
|
|
|
}
|
2021-09-18 15:11:26 +02:00
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) adjustViewSize() {
|
2022-03-21 16:02:37 +01:00
|
|
|
if u.graphicsDriver.IsGL() {
|
2021-09-18 16:59:37 +02:00
|
|
|
return
|
|
|
|
}
|
2022-09-16 04:53:46 +02:00
|
|
|
window := cocoa.NSWindow{ID: objc.ID(u.window.GetCocoaWindow())}
|
|
|
|
if window.StyleMask()&cocoa.NSWindowStyleMaskFullScreen == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Apparently, adjusting the view size is not needed as of macOS 12 (#1745).
|
|
|
|
if cocoa.NSProcessInfo_processInfo().IsOperatingSystemAtLeastVersion(cocoa.NSOperatingSystemVersion{
|
|
|
|
Major: 12,
|
|
|
|
}) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce the view height (#1745).
|
|
|
|
// https://stackoverflow.com/questions/27758027/sprite-kit-serious-fps-issue-in-full-screen-mode-on-os-x
|
|
|
|
windowSize := window.Frame().Size
|
|
|
|
view := window.ContentView()
|
|
|
|
viewSize := view.Frame().Size
|
|
|
|
if windowSize.Width != viewSize.Width || windowSize.Height != viewSize.Height {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
viewSize.Width--
|
|
|
|
view.SetFrameSize(viewSize)
|
|
|
|
// NSColor.blackColor (0, 0, 0, 1) didn't work.
|
|
|
|
// Use the transparent color instead.
|
|
|
|
window.SetBackgroundColor(cocoa.NSColor_colorWithSRGBRedGreenBlueAlpha(0, 0, 0, 0))
|
2021-09-18 15:11:26 +02:00
|
|
|
}
|
2021-09-24 19:46:18 +02:00
|
|
|
|
2022-03-21 15:00:50 +01:00
|
|
|
func (u *userInterfaceImpl) setWindowResizingModeForOS(mode WindowResizingMode) {
|
2021-12-29 14:08:59 +01:00
|
|
|
allowFullscreen := mode == WindowResizingModeOnlyFullscreenEnabled ||
|
|
|
|
mode == WindowResizingModeEnabled
|
2022-09-16 04:53:46 +02:00
|
|
|
collectionBehavior := int(objc.ID(u.window.GetCocoaWindow()).Send(sel_collectionBehavior))
|
|
|
|
if allowFullscreen {
|
|
|
|
collectionBehavior |= cocoa.NSWindowCollectionBehaviorFullScreenPrimary
|
|
|
|
} else {
|
|
|
|
collectionBehavior &^= cocoa.NSWindowCollectionBehaviorFullScreenPrimary
|
|
|
|
}
|
|
|
|
objc.ID(u.window.GetCocoaWindow()).Send(objc.RegisterName("setCollectionBehavior:"), collectionBehavior)
|
2021-12-29 14:08:59 +01:00
|
|
|
}
|
|
|
|
|
2021-09-24 19:46:18 +02:00
|
|
|
func initializeWindowAfterCreation(w *glfw.Window) {
|
2021-12-29 14:08:59 +01:00
|
|
|
// TODO: Register NSWindowWillEnterFullScreenNotification and so on.
|
|
|
|
// Enable resizing temporary before making the window fullscreen.
|
2022-09-16 04:53:46 +02:00
|
|
|
nswindow := objc.ID(w.GetCocoaWindow())
|
|
|
|
sel_delegate := objc.RegisterName("delegate")
|
|
|
|
delegate := objc.ID(class_EbitengineWindowDelegate).Send(objc.RegisterName("alloc")).Send(objc.RegisterName("initWithOrigDelegate:"), nswindow.Send(sel_delegate))
|
|
|
|
nswindow.Send(objc.RegisterName("setDelegate:"), delegate)
|
2021-09-24 19:46:18 +02:00
|
|
|
}
|