From 188e80d2f7b1af611c38defeb40cdc02d12b06d7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 18 Sep 2021 22:11:26 +0900 Subject: [PATCH] internal/uidriver/glfw: Bug fix: FPS is dropped when pressing the green button Updates #1745 --- internal/uidriver/glfw/ui.go | 4 ++++ internal/uidriver/glfw/ui_darwin.go | 17 ++++++++++++++--- internal/uidriver/glfw/ui_unix.go | 3 +++ internal/uidriver/glfw/ui_windows.go | 3 +++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/internal/uidriver/glfw/ui.go b/internal/uidriver/glfw/ui.go index ba3824d49..97150a2ed 100644 --- a/internal/uidriver/glfw/ui.go +++ b/internal/uidriver/glfw/ui.go @@ -776,6 +776,8 @@ func (u *UserInterface) registerWindowSetSizeCallback() { return } + u.adjustViewSize() + if u.window.GetAttrib(glfw.Resizable) == glfw.False { return } @@ -1228,6 +1230,8 @@ func (u *UserInterface) setWindowSize(width, height int, fullscreen bool) { windowRecreated := u.setWindowSizeImpl(width, height, fullscreen) + u.adjustViewSize() + // As width might be updated, update windowWidth/Height here. u.windowWidth = width u.windowHeight = height diff --git a/internal/uidriver/glfw/ui_darwin.go b/internal/uidriver/glfw/ui_darwin.go index 09a9644b7..41b4fdd45 100644 --- a/internal/uidriver/glfw/ui_darwin.go +++ b/internal/uidriver/glfw/ui_darwin.go @@ -63,17 +63,24 @@ package glfw // if (!origResizable) { // window.styleMask &= ~NSWindowStyleMaskResizable; // } +// } // +// static void adjustViewSize(uintptr_t windowPtr) { +// NSWindow* window = (NSWindow*)windowPtr; // if ((window.styleMask & NSWindowStyleMaskFullScreen) == 0) { // return; // } // // // Reduce the view height (#1745). // // https://stackoverflow.com/questions/27758027/sprite-kit-serious-fps-issue-in-full-screen-mode-on-os-x +// CGSize windowSize = [window frame].size; // NSView* view = [window contentView]; -// CGSize size = [view frame].size; -// size.width--; -// [view setFrameSize:size]; +// CGSize 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. @@ -179,3 +186,7 @@ func (u *UserInterface) setNativeFullscreen(fullscreen bool) { glfw.WaitEventsTimeout(1) C.setNativeFullscreen(C.uintptr_t(u.window.GetCocoaWindow()), C.bool(fullscreen)) } + +func (u *UserInterface) adjustViewSize() { + C.adjustViewSize(C.uintptr_t(u.window.GetCocoaWindow())) +} diff --git a/internal/uidriver/glfw/ui_unix.go b/internal/uidriver/glfw/ui_unix.go index 8abf1a7e9..7a39976c6 100644 --- a/internal/uidriver/glfw/ui_unix.go +++ b/internal/uidriver/glfw/ui_unix.go @@ -156,3 +156,6 @@ func (u *UserInterface) isNativeFullscreenAvailable() bool { func (u *UserInterface) setNativeFullscreen(fullscreen bool) { panic(fmt.Sprintf("glfw: setNativeFullscreen is not implemented in this environment: %s", runtime.GOOS)) } + +func (u *UserInterface) adjustViewSize() { +} diff --git a/internal/uidriver/glfw/ui_windows.go b/internal/uidriver/glfw/ui_windows.go index 3ac45b7e3..df9a19575 100644 --- a/internal/uidriver/glfw/ui_windows.go +++ b/internal/uidriver/glfw/ui_windows.go @@ -203,3 +203,6 @@ func (u *UserInterface) isNativeFullscreenAvailable() bool { func (u *UserInterface) setNativeFullscreen(fullscreen bool) { panic(fmt.Sprintf("glfw: setNativeFullscreen is not implemented in this environment: %s", runtime.GOOS)) } + +func (u *UserInterface) adjustViewSize() { +}