From fd9af041238845059e70da90852e1d40259d2f80 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 16 Jun 2016 09:29:28 -0400 Subject: [PATCH] Implemented fullscreen on OS X. --- darwin/window.m | 38 ++++++++++++++++++++++++++++++++++++++ test/page15.c | 3 ++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/darwin/window.m b/darwin/window.m index 03c86ac1..0315e6a3 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -15,6 +15,7 @@ struct uiWindow { void (*onContentSizeChanged)(uiWindow *, void *); void *onContentSizeChangedData; BOOL suppressSizeChanged; + int fullscreen; }; @interface windowDelegateClass : NSObject { @@ -23,6 +24,8 @@ struct uiWindow { - (BOOL)windowShouldClose:(id)sender; - (void)windowDidMove:(NSNotification *)note; - (void)windowDidResize:(NSNotification *)note; +- (void)windowDidEnterFullScreen:(NSNotification *)note; +- (void)windowDidExitFullScreen:(NSNotification *)note; - (void)registerWindow:(uiWindow *)w; - (void)unregisterWindow:(uiWindow *)w; - (uiWindow *)lookupWindow:(NSWindow *)w; @@ -74,6 +77,24 @@ struct uiWindow { (*(w->onContentSizeChanged))(w, w->onContentSizeChangedData); } +- (void)windowDidEnterFullScreen:(NSNotification *)note +{ + uiWindow *w; + + w = [self lookupWindow:((NSWindow *) [note object])]; + if (!w->suppressSizeChanged) + w->fullscreen = 1; +} + +- (void)windowDidExitFullScreen:(NSNotification *)note +{ + uiWindow *w; + + w = [self lookupWindow:((NSWindow *) [note object])]; + if (!w->suppressSizeChanged) + w->fullscreen = 0; +} + - (void)registerWindow:(uiWindow *)w { mapSet(self->windows, w->window, w); @@ -290,6 +311,23 @@ void uiWindowSetContentSize(uiWindow *w, int width, int height) w->suppressSizeChanged = NO; } +int uiWindowFullscreen(uiWindow *w) +{ + return w->fullscreen; +} + +void uiWindowSetFullscreen(uiWindow *w, int fullscreen) +{ + if (w->fullscreen && fullscreen) + return; + if (!w->fullscreen && !fullscreen) + return; + w->fullscreen = fullscreen; + w->suppressSizeChanged = YES; + [w->window toggleFullScreen:w->window]; + w->suppressSizeChanged = NO; +} + void uiWindowOnContentSizeChanged(uiWindow *w, void (*f)(uiWindow *, void *), void *data) { w->onContentSizeChanged = f; diff --git a/test/page15.c b/test/page15.c index 0bd92c4f..da5f90f5 100644 --- a/test/page15.c +++ b/test/page15.c @@ -75,6 +75,7 @@ static void updatesize(uiWindow *w) uiWindowContentSize(w, &xp, &yp); uiSpinboxSetValue(width, xp); uiSpinboxSetValue(height, yp); + // TODO on OS X this is updated AFTER sending the size change, not before uiCheckboxSetChecked(fullscreen, uiWindowFullscreen(w)); } @@ -88,7 +89,7 @@ void setFullscreen(uiCheckbox *cb, void *data) { uiWindow *w = uiWindow(data); - uiWindowSetFullscreen(w, uiCheckboxChecked(tb)); + uiWindowSetFullscreen(w, uiCheckboxChecked(fullscreen)); updatesize(w); }