Properly reflect hidden/shown windows on OSX.
This fixes a bug where windows would always be considered to be in the shown/hidden state they were originally created in.
This commit is contained in:
parent
53c00d6cad
commit
c59f7d106e
1 changed files with 30 additions and 0 deletions
|
@ -65,6 +65,14 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
||||||
[window setDelegate:self];
|
[window setDelegate:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Haven't found a delegate / notification that triggers when the window is
|
||||||
|
// ordered out (is not visible any more). You can be ordered out without
|
||||||
|
// minimizing, so DidMiniaturize doesn't work. (e.g. -[NSWindow orderOut:])
|
||||||
|
[window addObserver:self
|
||||||
|
forKeyPath:@"visible"
|
||||||
|
options:NSKeyValueObservingOptionNew
|
||||||
|
context:NULL];
|
||||||
|
|
||||||
[window setNextResponder:self];
|
[window setNextResponder:self];
|
||||||
[window setAcceptsMouseMovedEvents:YES];
|
[window setAcceptsMouseMovedEvents:YES];
|
||||||
|
|
||||||
|
@ -77,6 +85,21 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)observeValueForKeyPath:(NSString *)keyPath
|
||||||
|
ofObject:(id)object
|
||||||
|
change:(NSDictionary *)change
|
||||||
|
context:(void *)context
|
||||||
|
{
|
||||||
|
if (object == _data->nswindow && [keyPath isEqualToString:@"visible"]) {
|
||||||
|
int newVisibility = [[change objectForKey:@"new"] intValue];
|
||||||
|
if (newVisibility) {
|
||||||
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
|
||||||
|
} else {
|
||||||
|
SDL_SendWindowEvent(_data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close
|
||||||
{
|
{
|
||||||
NSNotificationCenter *center;
|
NSNotificationCenter *center;
|
||||||
|
@ -97,6 +120,9 @@ static __inline__ void ConvertNSRect(NSRect *r)
|
||||||
[window setDelegate:nil];
|
[window setDelegate:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[window removeObserver:self
|
||||||
|
forKeyPath:@"visible"];
|
||||||
|
|
||||||
if ([window nextResponder] == self) {
|
if ([window nextResponder] == self) {
|
||||||
[window setNextResponder:nil];
|
[window setNextResponder:nil];
|
||||||
}
|
}
|
||||||
|
@ -531,6 +557,7 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
||||||
} else {
|
} else {
|
||||||
window->flags &= ~SDL_WINDOW_SHOWN;
|
window->flags &= ~SDL_WINDOW_SHOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
unsigned int style = [nswindow styleMask];
|
unsigned int style = [nswindow styleMask];
|
||||||
|
|
||||||
|
@ -545,17 +572,20 @@ SetupWindowData(_THIS, SDL_Window * window, NSWindow *nswindow, SDL_bool created
|
||||||
window->flags &= ~SDL_WINDOW_RESIZABLE;
|
window->flags &= ~SDL_WINDOW_RESIZABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* isZoomed always returns true if the window is not resizable */
|
/* isZoomed always returns true if the window is not resizable */
|
||||||
if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
if ((window->flags & SDL_WINDOW_RESIZABLE) && [nswindow isZoomed]) {
|
||||||
window->flags |= SDL_WINDOW_MAXIMIZED;
|
window->flags |= SDL_WINDOW_MAXIMIZED;
|
||||||
} else {
|
} else {
|
||||||
window->flags &= ~SDL_WINDOW_MAXIMIZED;
|
window->flags &= ~SDL_WINDOW_MAXIMIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([nswindow isMiniaturized]) {
|
if ([nswindow isMiniaturized]) {
|
||||||
window->flags |= SDL_WINDOW_MINIMIZED;
|
window->flags |= SDL_WINDOW_MINIMIZED;
|
||||||
} else {
|
} else {
|
||||||
window->flags &= ~SDL_WINDOW_MINIMIZED;
|
window->flags &= ~SDL_WINDOW_MINIMIZED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([nswindow isKeyWindow]) {
|
if ([nswindow isKeyWindow]) {
|
||||||
window->flags |= SDL_WINDOW_INPUT_FOCUS;
|
window->flags |= SDL_WINDOW_INPUT_FOCUS;
|
||||||
SDL_SetKeyboardFocus(data->window);
|
SDL_SetKeyboardFocus(data->window);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue