2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "SDL_config.h"
24 #include "SDL_QuartzVideo.h"
25 #include "SDL_QuartzWM.h"
26 #include "SDL_QuartzWindow.h"
29 This function makes the *SDL region* of the window 100% opaque.
30 The genie effect uses the alpha component. Otherwise,
31 it doesn't seem to matter what value it has.
33 static void QZ_SetPortAlphaOpaque () {
35 SDL_Surface *surface = current_video->screen;
38 bpp = surface->format->BitsPerPixel;
42 Uint32 *pixels = (Uint32*) surface->pixels;
43 Uint32 rowPixels = surface->pitch / 4;
46 for (i = 0; i < surface->h; i++)
47 for (j = 0; j < surface->w; j++) {
49 pixels[ (i * rowPixels) + j ] |= 0xFF000000;
54 @implementation SDL_QuartzWindow
56 /* we override these methods to fix the miniaturize animation/dock icon bug */
57 - (void)miniaturize:(id)sender
59 if (SDL_VideoSurface->flags & SDL_OPENGL) {
62 Future: Grab framebuffer and put into NSImage
63 [ qz_window setMiniwindowImage:image ];
68 /* make the alpha channel opaque so anim won't have holes in it */
69 QZ_SetPortAlphaOpaque ();
72 /* window is hidden now */
73 SDL_PrivateAppActive (0, SDL_APPACTIVE);
75 [ super miniaturize:sender ];
81 This method fires just before the window deminaturizes from the Dock.
83 We'll save the current visible surface, let the window manager redraw any
84 UI elements, and restore the SDL surface. This way, no expose event
85 is required, and the deminiaturize works perfectly.
87 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
89 /* make sure pixels are fully opaque */
90 if (! ( SDL_VideoSurface->flags & SDL_OPENGL ) )
91 QZ_SetPortAlphaOpaque ();
93 /* save current visible SDL surface */
94 [ self cacheImageInRect:[ window_view frame ] ];
96 /* let the window manager redraw controls, border, etc */
99 /* restore visible SDL surface */
100 [ self restoreCachedImage ];
102 /* window is visible again */
103 SDL_PrivateAppActive (1, SDL_APPACTIVE);
106 - (void)setFrame:(NSRect)frameRect display:(BOOL)flag
110 If the video surface is NULL, this originated from QZ_SetVideoMode,
111 so don't send the resize event.
113 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
115 if (this && SDL_VideoSurface == NULL) {
117 [ super setFrame:frameRect display:flag ];
119 else if (this && qz_window) {
123 [ super setFrame:frameRect display:flag ];
125 newViewFrame = [ window_view frame ];
127 SDL_PrivateResize (newViewFrame.size.width, newViewFrame.size.height);
131 /* QZ_DoActivate() calls a low-level CoreGraphics routine to adjust
132 the cursor position, if input is being grabbed. If app activation is
133 triggered by a mouse click in the title bar, then the window manager
134 gets confused and thinks we're dragging the window. The solution
135 below postpones the activate event to avoid this scenario. */
136 - (void)becomeKeyWindow
138 NSEvent *event = [self currentEvent];
139 if ([event type] == NSLeftMouseDown && [event window] == self)
140 watchForMouseUp = YES;
142 [super becomeKeyWindow];
145 - (void)sendEvent:(NSEvent *)event
147 [super sendEvent:event];
148 if (watchForMouseUp && [event type] == NSLeftMouseUp)
150 watchForMouseUp = NO;
151 [super becomeKeyWindow];
155 - (void)appDidHide:(NSNotification*)note
157 SDL_PrivateAppActive (0, SDL_APPACTIVE);
160 - (void)appWillUnhide:(NSNotification*)note
162 SDL_VideoDevice *this = (SDL_VideoDevice*)current_video;
166 /* make sure pixels are fully opaque */
167 if (! ( SDL_VideoSurface->flags & SDL_OPENGL ) )
168 QZ_SetPortAlphaOpaque ();
170 /* save current visible SDL surface */
171 [ self cacheImageInRect:[ window_view frame ] ];
175 - (void)appDidUnhide:(NSNotification*)note
177 /* restore cached image, since it may not be current, post expose event too */
178 [ self restoreCachedImage ];
180 /*SDL_PrivateExpose ();*/
182 SDL_PrivateAppActive (1, SDL_APPACTIVE);
185 - (id)initWithContentRect:(NSRect)contentRect styleMask:(NSUInteger)styleMask backing:(NSBackingStoreType)backingType defer:(BOOL)flag
187 /* Make our window subclass receive these application notifications */
188 [ [ NSNotificationCenter defaultCenter ] addObserver:self
189 selector:@selector(appDidHide:) name:NSApplicationDidHideNotification object:NSApp ];
191 [ [ NSNotificationCenter defaultCenter ] addObserver:self
192 selector:@selector(appDidUnhide:) name:NSApplicationDidUnhideNotification object:NSApp ];
194 [ [ NSNotificationCenter defaultCenter ] addObserver:self
195 selector:@selector(appWillUnhide:) name:NSApplicationWillUnhideNotification object:NSApp ];
197 return [ super initWithContentRect:contentRect styleMask:styleMask backing:backingType defer:flag ];
202 @implementation SDL_QuartzWindowDelegate
203 - (BOOL)windowShouldClose:(id)sender
209 - (void)windowDidBecomeKey:(NSNotification *)aNotification
211 QZ_DoActivate (current_video);
214 - (void)windowDidResignKey:(NSNotification *)aNotification
216 QZ_DoDeactivate (current_video);
221 @implementation SDL_QuartzView
223 - (void)resetCursorRects
225 SDL_Cursor *sdlc = SDL_GetCursor();
226 if (sdlc != NULL && sdlc->wm_cursor != NULL) {
227 [self addCursorRect: [self visibleRect] cursor: sdlc->wm_cursor->nscursor];