mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 10:25:37 +00:00
app: detect fullscreen mode for macOS and Windows
When an application goes into or out of fullscreen mode, Gio now emits a ConfigEvent with the current window mode. Signed-off-by: Pierre Curto <pierre.curto@gmail.com>
This commit is contained in:
@@ -679,6 +679,10 @@ func UpdateWindow(hwnd syscall.Handle) {
|
|||||||
_UpdateWindow.Call(uintptr(hwnd))
|
_UpdateWindow.Call(uintptr(hwnd))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p WindowPlacement) Rect() Rect {
|
||||||
|
return p.rcNormalPosition
|
||||||
|
}
|
||||||
|
|
||||||
// issue34474KeepAlive calls runtime.KeepAlive as a
|
// issue34474KeepAlive calls runtime.KeepAlive as a
|
||||||
// workaround for golang.org/issue/34474.
|
// workaround for golang.org/issue/34474.
|
||||||
func issue34474KeepAlive(v interface{}) {
|
func issue34474KeepAlive(v interface{}) {
|
||||||
|
|||||||
@@ -97,6 +97,11 @@ static void toggleFullScreen(CFTypeRef windowRef) {
|
|||||||
[window toggleFullScreen:nil];
|
[window toggleFullScreen:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static NSWindowStyleMask getWindowStyleMask(CFTypeRef windowRef) {
|
||||||
|
NSWindow *window = (__bridge NSWindow *)windowRef;
|
||||||
|
return [window styleMask];
|
||||||
|
}
|
||||||
|
|
||||||
static void closeWindow(CFTypeRef windowRef) {
|
static void closeWindow(CFTypeRef windowRef) {
|
||||||
NSWindow* window = (__bridge NSWindow *)windowRef;
|
NSWindow* window = (__bridge NSWindow *)windowRef;
|
||||||
[window performClose:nil];
|
[window performClose:nil];
|
||||||
@@ -227,10 +232,20 @@ func (w *window) WriteClipboard(s string) {
|
|||||||
C.writeClipboard(chars, C.NSUInteger(len(u16)))
|
C.writeClipboard(chars, C.NSUInteger(len(u16)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *window) updateWindowMode() {
|
||||||
|
style := int(C.getWindowStyleMask(w.window))
|
||||||
|
if style&C.NSWindowStyleMaskFullScreen > 0 {
|
||||||
|
w.config.Mode = Fullscreen
|
||||||
|
} else {
|
||||||
|
w.config.Mode = Windowed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *window) Configure(options []Option) {
|
func (w *window) Configure(options []Option) {
|
||||||
screenScale := float32(C.getScreenBackingScale())
|
screenScale := float32(C.getScreenBackingScale())
|
||||||
cfg := configFor(screenScale)
|
cfg := configFor(screenScale)
|
||||||
prev := w.config
|
prev := w.config
|
||||||
|
w.updateWindowMode()
|
||||||
cnf := w.config
|
cnf := w.config
|
||||||
cnf.apply(cfg, options)
|
cnf.apply(cfg, options)
|
||||||
cnf.Size = cnf.Size.Div(int(screenScale))
|
cnf.Size = cnf.Size.Div(int(screenScale))
|
||||||
@@ -473,6 +488,20 @@ func gio_onShow(view C.CFTypeRef) {
|
|||||||
w.setStage(system.StageRunning)
|
w.setStage(system.StageRunning)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//export gio_onFullscreen
|
||||||
|
func gio_onFullscreen(view C.CFTypeRef) {
|
||||||
|
w := mustView(view)
|
||||||
|
w.config.Mode = Fullscreen
|
||||||
|
w.w.Event(ConfigEvent{Config: w.config})
|
||||||
|
}
|
||||||
|
|
||||||
|
//export gio_onWindowed
|
||||||
|
func gio_onWindowed(view C.CFTypeRef) {
|
||||||
|
w := mustView(view)
|
||||||
|
w.config.Mode = Windowed
|
||||||
|
w.w.Event(ConfigEvent{Config: w.config})
|
||||||
|
}
|
||||||
|
|
||||||
//export gio_onAppHide
|
//export gio_onAppHide
|
||||||
func gio_onAppHide() {
|
func gio_onAppHide() {
|
||||||
for _, w := range viewMap {
|
for _, w := range viewMap {
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ __attribute__ ((visibility ("hidden"))) CALayer *gio_layerFactory(void);
|
|||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
gio_onShow((__bridge CFTypeRef)window.contentView);
|
gio_onShow((__bridge CFTypeRef)window.contentView);
|
||||||
}
|
}
|
||||||
|
- (void)windowWillEnterFullScreen:(NSNotification *)notification {
|
||||||
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
|
gio_onFullscreen((__bridge CFTypeRef)window.contentView);
|
||||||
|
}
|
||||||
|
- (void)windowWillExitFullScreen:(NSNotification *)notification {
|
||||||
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
|
gio_onWindowed((__bridge CFTypeRef)window.contentView);
|
||||||
|
}
|
||||||
- (void)windowDidChangeScreen:(NSNotification *)notification {
|
- (void)windowDidChangeScreen:(NSNotification *)notification {
|
||||||
NSWindow *window = (NSWindow *)[notification object];
|
NSWindow *window = (NSWindow *)[notification object];
|
||||||
CGDirectDisplayID dispID = [[[window screen] deviceDescription][@"NSScreenNumber"] unsignedIntValue];
|
CGDirectDisplayID dispID = [[[window screen] deviceDescription][@"NSScreenNumber"] unsignedIntValue];
|
||||||
|
|||||||
+33
-10
@@ -282,6 +282,27 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
|
|||||||
case windows.SIZE_MINIMIZED:
|
case windows.SIZE_MINIMIZED:
|
||||||
w.setStage(system.StagePaused)
|
w.setStage(system.StagePaused)
|
||||||
case windows.SIZE_MAXIMIZED, windows.SIZE_RESTORED:
|
case windows.SIZE_MAXIMIZED, windows.SIZE_RESTORED:
|
||||||
|
var triggerEvent bool
|
||||||
|
// Check the window size change.
|
||||||
|
var r windows.Rect
|
||||||
|
windows.GetClientRect(w.hwnd, &r)
|
||||||
|
size := image.Point{
|
||||||
|
X: int(r.Right - r.Left),
|
||||||
|
Y: int(r.Bottom - r.Top),
|
||||||
|
}
|
||||||
|
if size != w.config.Size {
|
||||||
|
w.config.Size = size
|
||||||
|
triggerEvent = true
|
||||||
|
}
|
||||||
|
// Check the window mode.
|
||||||
|
mode := w.config.Mode
|
||||||
|
w.updateWindowMode()
|
||||||
|
if mode != w.config.Mode {
|
||||||
|
triggerEvent = true
|
||||||
|
}
|
||||||
|
if triggerEvent {
|
||||||
|
w.w.Event(ConfigEvent{Config: w.config})
|
||||||
|
}
|
||||||
w.setStage(system.StageRunning)
|
w.setStage(system.StageRunning)
|
||||||
}
|
}
|
||||||
case windows.WM_GETMINMAXINFO:
|
case windows.WM_GETMINMAXINFO:
|
||||||
@@ -426,16 +447,6 @@ func (w *window) setStage(s system.Stage) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *window) draw(sync bool) {
|
func (w *window) draw(sync bool) {
|
||||||
var r windows.Rect
|
|
||||||
windows.GetClientRect(w.hwnd, &r)
|
|
||||||
size := image.Point{
|
|
||||||
X: int(r.Right - r.Left),
|
|
||||||
Y: int(r.Bottom - r.Top),
|
|
||||||
}
|
|
||||||
if size != w.config.Size {
|
|
||||||
w.config.Size = size
|
|
||||||
w.w.Event(ConfigEvent{Config: w.config})
|
|
||||||
}
|
|
||||||
if w.config.Size.X == 0 || w.config.Size.Y == 0 {
|
if w.config.Size.X == 0 || w.config.Size.Y == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -492,10 +503,22 @@ func (w *window) readClipboard() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *window) updateWindowMode() {
|
||||||
|
p := windows.GetWindowPlacement(w.hwnd)
|
||||||
|
r := p.Rect()
|
||||||
|
mi := windows.GetMonitorInfo(w.hwnd)
|
||||||
|
if r == mi.Monitor {
|
||||||
|
w.config.Mode = Fullscreen
|
||||||
|
} else {
|
||||||
|
w.config.Mode = Windowed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (w *window) Configure(options []Option) {
|
func (w *window) Configure(options []Option) {
|
||||||
dpi := windows.GetSystemDPI()
|
dpi := windows.GetSystemDPI()
|
||||||
cfg := configForDPI(dpi)
|
cfg := configForDPI(dpi)
|
||||||
prev := w.config
|
prev := w.config
|
||||||
|
w.updateWindowMode()
|
||||||
cnf := w.config
|
cnf := w.config
|
||||||
cnf.apply(cfg, options)
|
cnf.apply(cfg, options)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user