Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed minimizing fullscreen windows.
Browse files Browse the repository at this point in the history
Removed misleading hide/unhide Cocoa notifications.
We have no way of knowing when a Cocoa window is maximized and then restored (right?)
Disabled spamy mouse motion events by default.
  • Loading branch information
slouken committed Feb 28, 2011
1 parent 58788f3 commit ddd6885
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 37 deletions.
50 changes: 29 additions & 21 deletions src/video/SDL_video.c
Expand Up @@ -1018,12 +1018,12 @@ SDL_GetWindowPixelFormat(SDL_Window * window)
}

static void
SDL_UpdateFullscreenMode(SDL_Window * window)
SDL_UpdateFullscreenMode(SDL_Window * window, SDL_bool fullscreen)
{
SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
SDL_Window *other;

if (FULLSCREEN_VISIBLE(window)) {
if (fullscreen) {
/* Hide any other fullscreen windows */
if (display->fullscreen_window &&
display->fullscreen_window != window) {
Expand All @@ -1032,15 +1032,24 @@ SDL_UpdateFullscreenMode(SDL_Window * window)
}

/* See if anything needs to be done now */
if ((display->fullscreen_window == window) == FULLSCREEN_VISIBLE(window)) {
if ((display->fullscreen_window == window) == fullscreen) {
return;
}

/* See if there are any fullscreen windows */
for (other = _this->windows; other; other = other->next) {
if (FULLSCREEN_VISIBLE(other) &&
SDL_GetDisplayForWindow(other) == display) {
SDL_bool setDisplayMode = SDL_FALSE;

if (other == window) {
setDisplayMode = fullscreen;
} else if (FULLSCREEN_VISIBLE(other) &&
SDL_GetDisplayForWindow(other) == display) {
setDisplayMode = SDL_TRUE;
}

if (setDisplayMode) {
SDL_DisplayMode fullscreen_mode;

if (SDL_GetWindowDisplayMode(other, &fullscreen_mode) == 0) {
SDL_bool resized = SDL_TRUE;

Expand Down Expand Up @@ -1144,7 +1153,7 @@ SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags)

displayIndex = SDL_GetIndexOfDisplay(display);
SDL_GetDisplayBounds(displayIndex, &bounds);
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISCENTERED(x)) {
window->x = bounds.x + (bounds.w - w) / 2;
}
if (SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(y)) {
Expand Down Expand Up @@ -1512,6 +1521,8 @@ SDL_HideWindow(SDL_Window * window)
return;
}

SDL_UpdateFullscreenMode(window, SDL_FALSE);

if (_this->HideWindow) {
_this->HideWindow(_this, window);
}
Expand All @@ -1528,9 +1539,6 @@ SDL_RaiseWindow(SDL_Window * window)
}
if (_this->RaiseWindow) {
_this->RaiseWindow(_this, window);
} else {
/* FIXME: What we really want is a way to request focus */
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_FOCUS_GAINED, 0, 0);
}
}

Expand All @@ -1557,6 +1565,8 @@ SDL_MinimizeWindow(SDL_Window * window)
return;
}

SDL_UpdateFullscreenMode(window, SDL_FALSE);

if (_this->MinimizeWindow) {
_this->MinimizeWindow(_this, window);
}
Expand All @@ -1574,26 +1584,22 @@ SDL_RestoreWindow(SDL_Window * window)
if (_this->RestoreWindow) {
_this->RestoreWindow(_this, window);
}
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESTORED, 0, 0);
}

int
SDL_SetWindowFullscreen(SDL_Window * window, SDL_bool fullscreen)
{
CHECK_WINDOW_MAGIC(window, -1);

if (fullscreen) {
fullscreen = SDL_WINDOW_FULLSCREEN;
}
if ((window->flags & SDL_WINDOW_FULLSCREEN) == fullscreen) {
if (!!fullscreen == !!(window->flags & SDL_WINDOW_FULLSCREEN)) {
return 0;
}
if (fullscreen) {
window->flags |= SDL_WINDOW_FULLSCREEN;
} else {
window->flags &= ~SDL_WINDOW_FULLSCREEN;
}
SDL_UpdateFullscreenMode(window);
SDL_UpdateFullscreenMode(window, FULLSCREEN_VISIBLE(window));

return 0;
}
Expand Down Expand Up @@ -1682,7 +1688,7 @@ SDL_SetWindowGrab(SDL_Window * window, SDL_bool grabbed)
{
CHECK_WINDOW_MAGIC(window, );

if ((!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED))) {
if (!!grabbed == !!(window->flags & SDL_WINDOW_INPUT_GRABBED)) {
return;
}
if (grabbed) {
Expand All @@ -1704,14 +1710,13 @@ SDL_GetWindowGrab(SDL_Window * window)
void
SDL_OnWindowShown(SDL_Window * window)
{
SDL_RaiseWindow(window);
SDL_UpdateFullscreenMode(window);
SDL_OnWindowRestored(window);
}

void
SDL_OnWindowHidden(SDL_Window * window)
{
SDL_UpdateFullscreenMode(window);
SDL_UpdateFullscreenMode(window, SDL_FALSE);
}

void
Expand All @@ -1724,14 +1729,17 @@ SDL_OnWindowResized(SDL_Window * window)
void
SDL_OnWindowMinimized(SDL_Window * window)
{
SDL_UpdateFullscreenMode(window);
SDL_UpdateFullscreenMode(window, SDL_FALSE);
}

void
SDL_OnWindowRestored(SDL_Window * window)
{
SDL_RaiseWindow(window);
SDL_UpdateFullscreenMode(window);

if (FULLSCREEN_VISIBLE(window)) {
SDL_UpdateFullscreenMode(window, SDL_TRUE);
}
}

void
Expand Down
2 changes: 0 additions & 2 deletions src/video/cocoa/SDL_cocoawindow.h
Expand Up @@ -49,8 +49,6 @@ typedef struct SDL_WindowData SDL_WindowData;
-(void) windowDidDeminiaturize:(NSNotification *) aNotification;
-(void) windowDidBecomeKey:(NSNotification *) aNotification;
-(void) windowDidResignKey:(NSNotification *) aNotification;
-(void) windowDidHide:(NSNotification *) aNotification;
-(void) windowDidUnhide:(NSNotification *) aNotification;

/* Window event handling */
-(void) mouseDown:(NSEvent *) theEvent;
Expand Down
14 changes: 0 additions & 14 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -63,8 +63,6 @@ - (void)listen:(SDL_WindowData *)data
} else {
[window setDelegate:self];
}
[center addObserver:self selector:@selector(windowDidHide:) name:NSApplicationDidHideNotification object:NSApp];
[center addObserver:self selector:@selector(windowDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp];

[window setNextResponder:self];
[window setAcceptsMouseMovedEvents:YES];
Expand Down Expand Up @@ -94,8 +92,6 @@ - (void)close
} else {
[window setDelegate:nil];
}
[center removeObserver:self name:NSApplicationDidHideNotification object:NSApp];
[center removeObserver:self name:NSApplicationDidUnhideNotification object:NSApp];

if ([window nextResponder] == self) {
[window setNextResponder:nil];
Expand Down Expand Up @@ -206,16 +202,6 @@ - (void)windowDidResignKey:(NSNotification *)aNotification
}
}

- (void)windowDidHide:(NSNotification *)aNotification
{
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
}

- (void)windowDidUnhide:(NSNotification *)aNotification
{
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
}

- (void)mouseDown:(NSEvent *)theEvent
{
int button;
Expand Down
5 changes: 5 additions & 0 deletions test/common.c
Expand Up @@ -810,6 +810,11 @@ CommonInit(CommonState * state)
static void
PrintEvent(SDL_Event * event)
{
if (event->type == SDL_MOUSEMOTION) {
/* Mouse motion is really spammy */
return;
}

fprintf(stderr, "SDL EVENT: ");
switch (event->type) {
case SDL_WINDOWEVENT:
Expand Down

0 comments on commit ddd6885

Please sign in to comment.