Skip to content

Commit

Permalink
Store the old window size on OSX when toggling fullscreen windows.
Browse files Browse the repository at this point in the history
On other systems the WM handles this, but on OSX for some reason you need to do this yourself?
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Sep 13, 2023
1 parent c6a692e commit 139b078
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/macosx/osxgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ typedef struct ALLEGRO_DISPLAY_OSX_WIN {
ALLEGRO_MUTEX *flip_mutex;
ALLEGRO_COND *flip_cond;
int num_flips;
/* These two store the old window size when restoring from a FS window. */
int old_w;
int old_h;
} ALLEGRO_DISPLAY_OSX_WIN;

/* This is our version of ALLEGRO_MOUSE_CURSOR */
Expand Down
16 changes: 10 additions & 6 deletions src/macosx/osxgl.m
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,8 @@ -(void) viewDidEndLiveResize
ALLEGRO_INFO("Window finished resizing %d x %d\n", event.display.width, event.display.height);
}
_al_event_source_unlock(es);
dpy->old_w = NSWidth(content);
dpy->old_h = NSWidth(content);
}
/* Window switch in/out */
-(void) windowDidBecomeMain:(NSNotification*) notification
Expand Down Expand Up @@ -1512,6 +1514,8 @@ static void init_new_vsync(ALLEGRO_DISPLAY_OSX_WIN *dpy)
#endif
display->w = w;
display->h = h;
dpy->old_w = w;
dpy->old_h = h;
_al_event_source_init(&display->es);
_al_osx_change_cursor(dpy, [NSCursor arrowCursor]);
dpy->show_cursor = YES;
Expand Down Expand Up @@ -2072,6 +2076,10 @@ static bool resize_display_win(ALLEGRO_DISPLAY *d, int w, int h)
});
// must be done on the thread the user calls it from, not the main thread
setup_gl(d);
// Only update the old values in response to user-initiated resizes.
ALLEGRO_DISPLAY_OSX_WIN *dpy = (ALLEGRO_DISPLAY_OSX_WIN *)d;
dpy->old_w = w;
dpy->old_h = h;
return rc;
}

Expand Down Expand Up @@ -2458,7 +2466,7 @@ static bool set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
display->flags |= ALLEGRO_MAXIMIZED;
else
display->flags &= ~ALLEGRO_MAXIMIZED;
[dpy->view maximize];
[view maximize];
break;
case ALLEGRO_FULLSCREEN_WINDOW:
if (onoff) {
Expand All @@ -2471,12 +2479,8 @@ static bool set_display_flag(ALLEGRO_DISPLAY *display, int flag, bool onoff)
display->flags |= ALLEGRO_FULLSCREEN_WINDOW;
} else {
[view exitFullScreenWindowMode];
NSRect sc = [view frame];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
sc = [win convertRectToBacking: sc];
#endif
display->flags &= ~ALLEGRO_FULLSCREEN_WINDOW;
resize_display_win_main_thread(display, sc.size.width, sc.size.height);
resize_display_win_main_thread(display, dpy->old_w, dpy->old_h);
[view finishExitingFullScreenWindowMode];
}
need_setup_gl = true;
Expand Down

0 comments on commit 139b078

Please sign in to comment.