Date: Mon, 5 May 2003 00:08:51 -0400
authorSam Lantinga <slouken@libsdl.org>
Thu, 29 May 2003 04:52:36 +0000
changeset 63152864d66d168
parent 630 550bccdf04bd
child 632 85e104fe14c2
Date: Mon, 5 May 2003 00:08:51 -0400
From: Darrell Walisser
Subject: SDL Active Events Patch

Hi Guys,
I was reading sdl-devel the other day and remembered we don't handle
SDL_APPACTIVE and SDL_APPMOUSEFOCUS. I hacked together a quick patch to
do just this. One thing to note - there are actually two ways to
"iconify" the SDL window (which sets SDL_APPACTIVE): hiding the entire
application (for example, option-click on some other window) and
minimizing the window to the dock. I treat both as SDL_APPACTIVE, since
the window is no longer visible.

Cheers,
Darrell
src/video/quartz/SDL_QuartzEvents.m
src/video/quartz/SDL_QuartzWindow.m
     1.1 --- a/src/video/quartz/SDL_QuartzEvents.m	Thu May 29 04:44:13 2003 +0000
     1.2 +++ b/src/video/quartz/SDL_QuartzEvents.m	Thu May 29 04:52:36 2003 +0000
     1.3 @@ -583,6 +583,16 @@
     1.4                          
     1.5                          QZ_PrivateWarpCursor (this, p.x, p.y);
     1.6                      }
     1.7 +                    else
     1.8 +                    if ( !isInGameWin && (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
     1.9 +                    
    1.10 +                        SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS);
    1.11 +                    }
    1.12 +                    else
    1.13 +                    if ( isInGameWin && !(SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
    1.14 +                    
    1.15 +                        SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS);
    1.16 +                    }
    1.17                      break;
    1.18                  case NSScrollWheel:
    1.19                      if ( isInGameWin ) {
     2.1 --- a/src/video/quartz/SDL_QuartzWindow.m	Thu May 29 04:44:13 2003 +0000
     2.2 +++ b/src/video/quartz/SDL_QuartzWindow.m	Thu May 29 04:52:36 2003 +0000
     2.3 @@ -31,6 +31,9 @@
     2.4  - (void)miniaturize:(id)sender;
     2.5  - (void)display;
     2.6  - (void)setFrame:(NSRect)frameRect display:(BOOL)flag;
     2.7 +- (void)appDidHide:(NSNotification*)note;
     2.8 +- (void)appDidUnhide:(NSNotification*)note;
     2.9 +- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag;
    2.10  @end
    2.11  
    2.12  @implementation SDL_QuartzWindow
    2.13 @@ -51,6 +54,9 @@
    2.14          QZ_SetPortAlphaOpaque ();
    2.15      }
    2.16      
    2.17 +    /* window is hidden now */
    2.18 +    SDL_PrivateAppActive (0, SDL_APPACTIVE);
    2.19 +    
    2.20      [ super miniaturize:sender ];
    2.21  }
    2.22  
    2.23 @@ -63,6 +69,9 @@
    2.24      */
    2.25      if ( (SDL_VideoSurface->flags & SDL_OPENGL) == 0)
    2.26          QZ_SetPortAlphaOpaque ();
    2.27 +
    2.28 +    /* window is visible again */
    2.29 +    SDL_PrivateAppActive (1, SDL_APPACTIVE);
    2.30  }
    2.31  
    2.32  - (void)setFrame:(NSRect)frameRect display:(BOOL)flag
    2.33 @@ -100,6 +109,28 @@
    2.34      }
    2.35  }
    2.36  
    2.37 +- (void)appDidHide:(NSNotification*)note
    2.38 +{
    2.39 +    SDL_PrivateAppActive (0, SDL_APPACTIVE);
    2.40 +}
    2.41 +
    2.42 +- (void)appDidUnhide:(NSNotification*)note
    2.43 +{
    2.44 +    SDL_PrivateAppActive (1, SDL_APPACTIVE);
    2.45 +}
    2.46 +
    2.47 +- (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
    2.48 +{
    2.49 +    /* Make our window subclass receive these application notifications */
    2.50 +    [ [ NSNotificationCenter defaultCenter ] addObserver:self
    2.51 +        selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ];
    2.52 +    
    2.53 +    [ [ NSNotificationCenter defaultCenter ] addObserver:self
    2.54 +        selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ];
    2.55 +        
    2.56 +    return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ];
    2.57 +}
    2.58 +
    2.59  @end
    2.60  
    2.61  /* Delegate for our NSWindow to send SDLQuit() on close */