Skip to content

Commit 139b078

Browse files
SiegeLordExSiegeLord
authored andcommitted
Store the old window size on OSX when toggling fullscreen windows.
On other systems the WM handles this, but on OSX for some reason you need to do this yourself?
1 parent c6a692e commit 139b078

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/macosx/osxgl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ typedef struct ALLEGRO_DISPLAY_OSX_WIN {
4040
ALLEGRO_MUTEX *flip_mutex;
4141
ALLEGRO_COND *flip_cond;
4242
int num_flips;
43+
/* These two store the old window size when restoring from a FS window. */
44+
int old_w;
45+
int old_h;
4346
} ALLEGRO_DISPLAY_OSX_WIN;
4447

4548
/* This is our version of ALLEGRO_MOUSE_CURSOR */

src/macosx/osxgl.m

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ -(void) viewDidEndLiveResize
543543
ALLEGRO_INFO("Window finished resizing %d x %d\n", event.display.width, event.display.height);
544544
}
545545
_al_event_source_unlock(es);
546+
dpy->old_w = NSWidth(content);
547+
dpy->old_h = NSWidth(content);
546548
}
547549
/* Window switch in/out */
548550
-(void) windowDidBecomeMain:(NSNotification*) notification
@@ -1512,6 +1514,8 @@ static void init_new_vsync(ALLEGRO_DISPLAY_OSX_WIN *dpy)
15121514
#endif
15131515
display->w = w;
15141516
display->h = h;
1517+
dpy->old_w = w;
1518+
dpy->old_h = h;
15151519
_al_event_source_init(&display->es);
15161520
_al_osx_change_cursor(dpy, [NSCursor arrowCursor]);
15171521
dpy->show_cursor = YES;
@@ -2072,6 +2076,10 @@ static bool resize_display_win(ALLEGRO_DISPLAY *d, int w, int h)
20722076
});
20732077
// must be done on the thread the user calls it from, not the main thread
20742078
setup_gl(d);
2079+
// Only update the old values in response to user-initiated resizes.
2080+
ALLEGRO_DISPLAY_OSX_WIN *dpy = (ALLEGRO_DISPLAY_OSX_WIN *)d;
2081+
dpy->old_w = w;
2082+
dpy->old_h = h;
20752083
return rc;
20762084
}
20772085

@@ -2458,7 +2466,7 @@ static bool set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
24582466
display->flags |= ALLEGRO_MAXIMIZED;
24592467
else
24602468
display->flags &= ~ALLEGRO_MAXIMIZED;
2461-
[dpy->view maximize];
2469+
[view maximize];
24622470
break;
24632471
case ALLEGRO_FULLSCREEN_WINDOW:
24642472
if (onoff) {
@@ -2471,12 +2479,8 @@ static bool set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
24712479
display->flags |= ALLEGRO_FULLSCREEN_WINDOW;
24722480
} else {
24732481
[view exitFullScreenWindowMode];
2474-
NSRect sc = [view frame];
2475-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
2476-
sc = [win convertRectToBacking: sc];
2477-
#endif
24782482
display->flags &= ~ALLEGRO_FULLSCREEN_WINDOW;
2479-
resize_display_win_main_thread(display, sc.size.width, sc.size.height);
2483+
resize_display_win_main_thread(display, dpy->old_w, dpy->old_h);
24802484
[view finishExitingFullScreenWindowMode];
24812485
}
24822486
need_setup_gl = true;

0 commit comments

Comments
 (0)