Skip to content

Commit c6a692e

Browse files
SiegeLordExSiegeLord
authored andcommitted
OSX: Keep an explicit reference to our view.
When going fullscreen window, the view gets attached to a new window (of type NSFullScreenWindow) which causes code that fetches the view from our old window to fail. This keeps the view reference in our display, which seems to cause things ot work. Fixes #1447
1 parent fb8d438 commit c6a692e

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/macosx/osxgl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ typedef struct ALLEGRO_DISPLAY_OSX_WIN {
2626
NSOpenGLContext* ctx;
2727
NSOpenGLPixelFormatAttribute attributes[AL_OSX_NUM_PFA];
2828
ALWindow* win;
29+
NSView* view;
2930
NSCursor* cursor;
3031
CGDirectDisplayID display_id;
3132
BOOL show_cursor;

src/macosx/osxgl.m

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ -(void) enterFullScreenWindowMode
636636
/* HACK? For some reason, we need to disable the chrome. If we don't, the fullscreen window
637637
will be created with space left over for it. Are we creating a fullscreen window in the wrong way? */
638638
[dpy->win setStyleMask: [dpy->win styleMask] & ~NSWindowStyleMaskTitled];
639-
[[dpy->win contentView] enterFullScreenMode: [dpy->win screen] withOptions: dict];
639+
[dpy->view enterFullScreenMode: [dpy->win screen] withOptions: dict];
640640
[dict release];
641641
#endif
642642
}
@@ -692,7 +692,7 @@ -(void) exitFullScreenWindowMode
692692
* crash. To avoid it, remove the tracking area and add it back after exiting fullscreen.
693693
* (my theory)
694694
*/
695-
[dpy->win orderOut:[dpy->win contentView]];
695+
[dpy->win orderOut: dpy->view];
696696
[self exitFullScreenModeWithOptions: nil];
697697
/* Restore the title bar disabled in enterFullScreenWindowMode. */
698698
if (!(dpy_ptr->flags & ALLEGRO_FRAMELESS)) {
@@ -705,7 +705,7 @@ -(void) finishExitingFullScreenWindowMode
705705
ALLEGRO_DISPLAY_OSX_WIN *dpy = (ALLEGRO_DISPLAY_OSX_WIN*) dpy_ptr;
706706

707707
[dpy->win center];
708-
[dpy->win makeKeyAndOrderFront:[dpy->win contentView]];
708+
[dpy->win makeKeyAndOrderFront: dpy->view];
709709
[[self window] makeFirstResponder: self];
710710
}
711711

@@ -1583,6 +1583,7 @@ static void init_new_vsync(ALLEGRO_DISPLAY_OSX_WIN *dpy)
15831583

15841584
return;
15851585
}
1586+
dpy->view = view;
15861587
/* Hook up the view to its display */
15871588
[view setAllegroDisplay: &dpy->parent];
15881589
[view setOpenGLContext: dpy->ctx];
@@ -1767,7 +1768,7 @@ static void destroy_display(ALLEGRO_DISPLAY* d)
17671768
CGDisplayModeRelease(dpy->original_mode);
17681769
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
17691770
if (dpy->win) {
1770-
[[dpy->win contentView] exitFullScreenModeWithOptions: nil];
1771+
[dpy->view exitFullScreenModeWithOptions: nil];
17711772
}
17721773
#endif
17731774
CGDisplayRelease(dpy->display_id);
@@ -1776,7 +1777,7 @@ static void destroy_display(ALLEGRO_DISPLAY* d)
17761777
else if (display->flags & ALLEGRO_FULLSCREEN_WINDOW) {
17771778
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
17781779
if (dpy->win) {
1779-
[[dpy->win contentView] exitFullScreenModeWithOptions: nil];
1780+
[dpy->view exitFullScreenModeWithOptions: nil];
17801781
}
17811782
#endif
17821783
}
@@ -2416,7 +2417,7 @@ static bool set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
24162417
bool __block retcode = true;
24172418
dispatch_sync(dispatch_get_main_queue(), ^{
24182419
NSWindowStyleMask mask = [win styleMask];
2419-
ALOpenGLView *view = (ALOpenGLView *)[win contentView];
2420+
ALOpenGLView *view = (ALOpenGLView *)dpy->view;
24202421
switch (flag) {
24212422
case ALLEGRO_FRAMELESS:
24222423
if (onoff)
@@ -2457,7 +2458,7 @@ static bool set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
24572458
display->flags |= ALLEGRO_MAXIMIZED;
24582459
else
24592460
display->flags &= ~ALLEGRO_MAXIMIZED;
2460-
[[win contentView] maximize];
2461+
[dpy->view maximize];
24612462
break;
24622463
case ALLEGRO_FULLSCREEN_WINDOW:
24632464
if (onoff) {

0 commit comments

Comments
 (0)