Skip to content

Commit

Permalink
Move to a "more macOS" fullscreen mode (#5453)
Browse files Browse the repository at this point in the history
Also fixes flickering and reported screen size issues (cannot find the number)
More info at glfw/glfw#2660
  • Loading branch information
andydotxyz authored Jan 26, 2025
1 parent bb1657e commit e4211e5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
19 changes: 19 additions & 0 deletions internal/driver/glfw/window_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

package glfw

/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework AppKit
#import <stdbool.h>
void setFullScreen(bool full, void *window);
*/
import "C"
import (
"runtime"

"fyne.io/fyne/v2/driver"
)

Expand All @@ -17,3 +28,11 @@ func (w *window) RunNative(f func(any)) {

f(context)
}

func (w *window) doSetFullScreen(full bool) {
if runtime.GOOS == "darwin" {
win := w.view().GetCocoaWindow()
C.setFullScreen(C.bool(full), win)
return
}
}
14 changes: 14 additions & 0 deletions internal/driver/glfw/window_darwin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

void setFullScreen(bool full, void *win) {
NSWindow *window = (NSWindow*)win;

NSUInteger masks = [window styleMask];
bool isFull = masks & NSWindowStyleMaskFullScreen;
if (isFull == full) {
return;
}

[window toggleFullScreen:NULL];
}
16 changes: 1 addition & 15 deletions internal/driver/glfw/window_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,8 @@ type window struct {
func (w *window) SetFullScreen(full bool) {
w.runOnMainWhenCreated(func() {
w.fullScreen = full
if !w.visible {
return
}

monitor := w.getMonitorForWindow()
mode := monitor.GetVideoMode()

if full {
w.viewport.SetMonitor(monitor, 0, 0, mode.Width, mode.Height, mode.RefreshRate)
} else {
if w.width == 0 && w.height == 0 { // if we were fullscreen on creation...
s := w.canvas.Size().Max(w.canvas.MinSize())
w.width, w.height = w.screenSize(s)
}
w.viewport.SetMonitor(nil, w.xpos, w.ypos, w.width, w.height, 0)
}
w.doSetFullScreen(full)
})
}

Expand Down
18 changes: 18 additions & 0 deletions internal/driver/glfw/window_notdarwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !darwin

package glfw

func (w *window) doSetFullScreen(full bool) {
monitor := w.getMonitorForWindow()
mode := monitor.GetVideoMode()

if full {
w.viewport.SetMonitor(monitor, 0, 0, mode.Width, mode.Height, mode.RefreshRate)
} else {
if w.width == 0 && w.height == 0 { // if we were fullscreen on creation...
s := w.canvas.Size().Max(w.canvas.MinSize())
w.width, w.height = w.screenSize(s)
}
w.viewport.SetMonitor(nil, w.xpos, w.ypos, w.width, w.height, 0)
}
}

0 comments on commit e4211e5

Please sign in to comment.