comparison src/video/quartz/SDL_QuartzWM.m @ 1708:cd14138a8703 SDL-1.3

Merged fix for bug #240 from SDL 1.2
author Sam Lantinga <slouken@libsdl.org>
date Sat, 24 Jun 2006 17:31:46 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1707:57ce47f033a5 1708:cd14138a8703
24 #include "SDL_QuartzVideo.h" 24 #include "SDL_QuartzVideo.h"
25 25
26 26
27 struct WMcursor 27 struct WMcursor
28 { 28 {
29 Cursor curs; 29 NSCursor *nscursor;
30 }; 30 };
31 31
32 void 32 void
33 QZ_FreeWMCursor (_THIS, WMcursor * cursor) 33 QZ_FreeWMCursor(_THIS, WMcursor * cursor)
34 { 34 {
35 35
36 if (cursor != NULL) {
37 [cursor->nscursor release];
38 free(cursor);
39 }
40 }
41
42 WMcursor *
43 QZ_CreateWMCursor(_THIS, Uint8 * data, Uint8 * mask,
44 int w, int h, int hot_x, int hot_y)
45 {
46 WMcursor *cursor;
47 NSBitmapImageRep *imgrep;
48 NSImage *img;
49 unsigned char *planes[5];
50 int i;
51 NSAutoreleasePool *pool;
52
53 pool =[[NSAutoreleasePool alloc] init];
54
55 /* Allocate the cursor memory */
56 cursor = (WMcursor *) SDL_malloc(sizeof(WMcursor));
57 if (cursor == NULL)
58 goto outOfMemory;
59
60 /* create the image representation and get the pointers to its storage */
61 imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: w pixelsHigh: h bitsPerSample: 1 samplesPerPixel: 2 hasAlpha: YES isPlanar: YES colorSpaceName: NSDeviceBlackColorSpace bytesPerRow: (w + 7) / 8 bitsPerPixel:0] autorelease];
62 if (imgrep == nil)
63 goto outOfMemory;
64 [imgrep getBitmapDataPlanes:planes];
65
66 /* copy data and mask, extending the mask to all black pixels because the inversion effect doesn't work with Cocoa's alpha-blended cursors */
67 for (i = 0; i < (w + 7) / 8 * h; i++) {
68 planes[0][i] = data[i];
69 planes[1][i] = mask[i] | data[i];
70 }
71
72 /* create image and cursor */
73 img =[[[NSImage alloc] initWithSize:NSMakeSize(w, h)] autorelease];
74 if (img == nil)
75 goto outOfMemory;
76 [img addRepresentation:imgrep];
77 if (system_version < 0x1030) { /* on 10.2, cursors must be 16*16 */
78 if (w > 16 || h > 16) { /* too big: scale it down */
79 [img setScalesWhenResized:YES];
80 hot_x = hot_x * 16 / w;
81 hot_y = hot_y * 16 / h;
82 } else { /* too small (or just right): extend it (from the bottom left corner, so hot_y must be adjusted) */
83 hot_y += 16 - h;
84 }
85 [img setSize:NSMakeSize(16, 16)];
86 }
87 cursor->nscursor =[[NSCursor alloc] initWithImage: img hotSpot:NSMakePoint(hot_x,
88 hot_y)];
89 if (cursor->nscursor == nil)
90 goto outOfMemory;
91
92 [pool release];
93 return (cursor);
94
95 outOfMemory:
96 [pool release];
36 if (cursor != NULL) 97 if (cursor != NULL)
37 free (cursor); 98 SDL_free(cursor);
38 } 99 SDL_OutOfMemory();
39 100 return (NULL);
40 /* Use the Carbon cursor routines for now */ 101 }
41 WMcursor * 102
42 QZ_CreateWMCursor (_THIS, Uint8 * data, Uint8 * mask, 103 void
43 int w, int h, int hot_x, int hot_y) 104 QZ_ShowMouse(_THIS)
44 {
45 WMcursor *cursor;
46 int row, bytes;
47
48 /* Allocate the cursor memory */
49 cursor = (WMcursor *) SDL_malloc (sizeof (WMcursor));
50 if (cursor == NULL) {
51 SDL_OutOfMemory ();
52 return (NULL);
53 }
54 SDL_memset (cursor, 0, sizeof (*cursor));
55
56 if (w > 16)
57 w = 16;
58
59 if (h > 16)
60 h = 16;
61
62 bytes = (w + 7) / 8;
63
64 for (row = 0; row < h; ++row) {
65 SDL_memcpy (&cursor->curs.data[row], data, bytes);
66 data += bytes;
67 }
68 for (row = 0; row < h; ++row) {
69 SDL_memcpy (&cursor->curs.mask[row], mask, bytes);
70 mask += bytes;
71 }
72 cursor->curs.hotSpot.h = hot_x;
73 cursor->curs.hotSpot.v = hot_y;
74
75 return (cursor);
76 }
77
78 void
79 QZ_ShowMouse (_THIS)
80 { 105 {
81 if (!cursor_visible) { 106 if (!cursor_visible) {
82 [NSCursor unhide]; 107 [NSCursor unhide];
83 cursor_visible = YES; 108 cursor_visible = YES;
84 } 109 }
85 } 110 }
86 111
87 void 112 void
88 QZ_HideMouse (_THIS) 113 QZ_HideMouse(_THIS)
89 { 114 {
90 if ((SDL_GetAppState () & SDL_APPMOUSEFOCUS) && cursor_visible) { 115 if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS) && cursor_visible) {
91 [NSCursor hide]; 116 [NSCursor hide];
92 cursor_visible = NO; 117 cursor_visible = NO;
93 } 118 }
94 } 119 }
95 120
96 BOOL 121 BOOL
97 QZ_IsMouseInWindow (_THIS) 122 QZ_IsMouseInWindow(_THIS)
98 { 123 {
99 if (qz_window == nil) 124 if (qz_window == nil)
100 return YES; /*fullscreen */ 125 return YES; /*fullscreen */
101 else { 126 else {
102 NSPoint p =[qz_window mouseLocationOutsideOfEventStream]; 127 NSPoint p =[qz_window mouseLocationOutsideOfEventStream];
103 p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */ 128 p.y -= 1.0f; /* Apparently y goes from 1 to h, not from 0 to h-1 (i.e. the "location of the mouse" seems to be defined as "the location of the top left corner of the mouse pointer's hot pixel" */
104 return NSPointInRect (p,[window_view frame]); 129 return NSPointInRect(p,[window_view frame]);
105 } 130 }
106 } 131 }
107 132
108 int 133 int
109 QZ_ShowWMCursor (_THIS, WMcursor * cursor) 134 QZ_ShowWMCursor(_THIS, WMcursor * cursor)
110 { 135 {
111 136
112 if (cursor == NULL) { 137 if (cursor == NULL) {
113 if (cursor_should_be_visible) { 138 if (cursor_should_be_visible) {
114 QZ_HideMouse (this); 139 QZ_HideMouse(this);
115 cursor_should_be_visible = NO; 140 cursor_should_be_visible = NO;
116 QZ_ChangeGrabState (this, QZ_HIDECURSOR); 141 QZ_ChangeGrabState(this, QZ_HIDECURSOR);
117 } 142 }
118 } else { 143 } else {
119 SetCursor (&cursor->curs); 144 [cursor->nscursor set];
120 if (!cursor_should_be_visible) { 145 if (!cursor_should_be_visible) {
121 QZ_ShowMouse (this); 146 QZ_ShowMouse(this);
122 cursor_should_be_visible = YES; 147 cursor_should_be_visible = YES;
123 QZ_ChangeGrabState (this, QZ_SHOWCURSOR); 148 QZ_ChangeGrabState(this, QZ_SHOWCURSOR);
124 } 149 }
125 } 150 }
126 151
127 return 1; 152 return 1;
128 } 153 }
135 this might have limited usefulness at the moment, but the extra cost is trivial. 160 this might have limited usefulness at the moment, but the extra cost is trivial.
136 */ 161 */
137 162
138 /* Convert Cocoa screen coordinate to Cocoa window coordinate */ 163 /* Convert Cocoa screen coordinate to Cocoa window coordinate */
139 void 164 void
140 QZ_PrivateGlobalToLocal (_THIS, NSPoint * p) 165 QZ_PrivateGlobalToLocal(_THIS, NSPoint * p)
141 { 166 {
142 167
143 *p =[qz_window convertScreenToBase:*p]; 168 *p =[qz_window convertScreenToBase:*p];
144 } 169 }
145 170
146 171
147 /* Convert Cocoa window coordinate to Cocoa screen coordinate */ 172 /* Convert Cocoa window coordinate to Cocoa screen coordinate */
148 void 173 void
149 QZ_PrivateLocalToGlobal (_THIS, NSPoint * p) 174 QZ_PrivateLocalToGlobal(_THIS, NSPoint * p)
150 { 175 {
151 176
152 *p =[qz_window convertBaseToScreen:*p]; 177 *p =[qz_window convertBaseToScreen:*p];
153 } 178 }
154 179
155 /* Convert SDL coordinate to Cocoa coordinate */ 180 /* Convert SDL coordinate to Cocoa coordinate */
156 void 181 void
157 QZ_PrivateSDLToCocoa (_THIS, NSPoint * p) 182 QZ_PrivateSDLToCocoa(_THIS, NSPoint * p)
158 { 183 {
159 184
160 if (CGDisplayIsCaptured (display_id)) { /* capture signals fullscreen */ 185 if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
161 186
162 p->y = CGDisplayPixelsHigh (display_id) - p->y; 187 p->y = CGDisplayPixelsHigh(display_id) - p->y;
163 } else { 188 } else {
164 189
165 *p =[window_view convertPoint: *p toView:nil]; 190 *p =[window_view convertPoint: *p toView:nil];
166 191
167 /* We need a workaround in OpenGL mode */ 192 /* We need a workaround in OpenGL mode */
168 if (SDL_VideoSurface->flags & SDL_INTERNALOPENGL) { 193 if (SDL_VideoSurface->flags & SDL_OPENGL) {
169 p->y =[window_view frame].size.height - p->y; 194 p->y =[window_view frame].size.height - p->y;
170 } 195 }
171 } 196 }
172 } 197 }
173 198
174 /* Convert Cocoa coordinate to SDL coordinate */ 199 /* Convert Cocoa coordinate to SDL coordinate */
175 void 200 void
176 QZ_PrivateCocoaToSDL (_THIS, NSPoint * p) 201 QZ_PrivateCocoaToSDL(_THIS, NSPoint * p)
177 { 202 {
178 203
179 if (CGDisplayIsCaptured (display_id)) { /* capture signals fullscreen */ 204 if (CGDisplayIsCaptured(display_id)) { /* capture signals fullscreen */
180 205
181 p->y = CGDisplayPixelsHigh (display_id) - p->y; 206 p->y = CGDisplayPixelsHigh(display_id) - p->y;
182 } else { 207 } else {
183 208
184 *p =[window_view convertPoint: *p fromView:nil]; 209 *p =[window_view convertPoint: *p fromView:nil];
185 210
186 /* We need a workaround in OpenGL mode */ 211 /* We need a workaround in OpenGL mode */
187 if (SDL_VideoSurface != NULL 212 if (SDL_VideoSurface != NULL
188 && (SDL_VideoSurface->flags & SDL_INTERNALOPENGL)) { 213 && (SDL_VideoSurface->flags & SDL_OPENGL)) {
189 p->y =[window_view frame].size.height - p->y; 214 p->y =[window_view frame].size.height - p->y;
190 } 215 }
191 } 216 }
192 } 217 }
193 218
194 /* Convert SDL coordinate to window server (CoreGraphics) coordinate */ 219 /* Convert SDL coordinate to window server (CoreGraphics) coordinate */
195 CGPoint 220 CGPoint
196 QZ_PrivateSDLToCG (_THIS, NSPoint * p) 221 QZ_PrivateSDLToCG(_THIS, NSPoint * p)
197 { 222 {
198 223
199 CGPoint cgp; 224 CGPoint cgp;
200 225
201 if (!CGDisplayIsCaptured (display_id)) { /* not captured => not fullscreen => local coord */ 226 if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
202 227
203 int height; 228 int height;
204 229
205 QZ_PrivateSDLToCocoa (this, p); 230 QZ_PrivateSDLToCocoa(this, p);
206 QZ_PrivateLocalToGlobal (this, p); 231 QZ_PrivateLocalToGlobal(this, p);
207 232
208 height = CGDisplayPixelsHigh (display_id); 233 height = CGDisplayPixelsHigh(display_id);
209 p->y = height - p->y; 234 p->y = height - p->y;
210 } 235 }
211 236
212 cgp.x = p->x; 237 cgp.x = p->x;
213 cgp.y = p->y; 238 cgp.y = p->y;
216 } 241 }
217 242
218 #if 0 /* Dead code */ 243 #if 0 /* Dead code */
219 /* Convert window server (CoreGraphics) coordinate to SDL coordinate */ 244 /* Convert window server (CoreGraphics) coordinate to SDL coordinate */
220 void 245 void
221 QZ_PrivateCGToSDL (_THIS, NSPoint * p) 246 QZ_PrivateCGToSDL(_THIS, NSPoint * p)
222 { 247 {
223 248
224 if (!CGDisplayIsCaptured (display_id)) { /* not captured => not fullscreen => local coord */ 249 if (!CGDisplayIsCaptured(display_id)) { /* not captured => not fullscreen => local coord */
225 250
226 int height; 251 int height;
227 252
228 /* Convert CG Global to Cocoa Global */ 253 /* Convert CG Global to Cocoa Global */
229 height = CGDisplayPixelsHigh (display_id); 254 height = CGDisplayPixelsHigh(display_id);
230 p->y = height - p->y; 255 p->y = height - p->y;
231 256
232 QZ_PrivateGlobalToLocal (this, p); 257 QZ_PrivateGlobalToLocal(this, p);
233 QZ_PrivateCocoaToSDL (this, p); 258 QZ_PrivateCocoaToSDL(this, p);
234 } 259 }
235 } 260 }
236 #endif /* Dead code */ 261 #endif /* Dead code */
237 262
238 void 263 void
239 QZ_PrivateWarpCursor (_THIS, int x, int y) 264 QZ_PrivateWarpCursor(_THIS, int x, int y)
240 { 265 {
241 266
242 NSPoint p; 267 NSPoint p;
243 CGPoint cgp; 268 CGPoint cgp;
244 269
245 p = NSMakePoint (x, y); 270 p = NSMakePoint(x, y);
246 cgp = QZ_PrivateSDLToCG (this, &p); 271 cgp = QZ_PrivateSDLToCG(this, &p);
247 272
248 /* this is the magic call that fixes cursor "freezing" after warp */ 273 /* this is the magic call that fixes cursor "freezing" after warp */
249 CGSetLocalEventsSuppressionInterval (0.0); 274 CGSetLocalEventsSuppressionInterval(0.0);
250 CGWarpMouseCursorPosition (cgp); 275 CGWarpMouseCursorPosition(cgp);
251 } 276 }
252 277
253 void 278 void
254 QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) 279 QZ_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
255 { 280 {
256 281
257 /* Only allow warping when in foreground */ 282 /* Only allow warping when in foreground */
258 if (![NSApp isActive]) 283 if (![NSApp isActive])
259 return; 284 return;
260 285
261 /* Do the actual warp */ 286 /* Do the actual warp */
262 if (grab_state != QZ_INVISIBLE_GRAB) 287 if (grab_state != QZ_INVISIBLE_GRAB)
263 QZ_PrivateWarpCursor (this, x, y); 288 QZ_PrivateWarpCursor(this, x, y);
264 289
265 /* Generate the mouse moved event */ 290 /* Generate the mouse moved event */
266 SDL_PrivateMouseMotion (0, 0, x, y); 291 SDL_PrivateMouseMotion(0, 0, x, y);
267 } 292 }
268 293
269 void 294 void
270 QZ_MoveWMCursor (_THIS, int x, int y) 295 QZ_MoveWMCursor(_THIS, int x, int y)
271 { 296 {
272 } 297 }
273 void 298 void
274 QZ_CheckMouseMode (_THIS) 299 QZ_CheckMouseMode(_THIS)
275 { 300 {
276 } 301 }
277 302
278 void 303 void
279 QZ_SetCaption (_THIS, const char *title, const char *icon) 304 QZ_SetCaption(_THIS, const char *title, const char *icon)
280 { 305 {
281 306
282 if (qz_window != nil) { 307 if (qz_window != nil) {
283 NSString *string; 308 NSString *string;
284 if (title != NULL) { 309 if (title != NULL) {
293 } 318 }
294 } 319 }
295 } 320 }
296 321
297 void 322 void
298 QZ_SetIcon (_THIS, SDL_Surface * icon, Uint8 * mask) 323 QZ_SetIcon(_THIS, SDL_Surface * icon, Uint8 * mask)
299 { 324 {
300 NSBitmapImageRep *imgrep; 325 NSBitmapImageRep *imgrep;
301 NSImage *img; 326 NSImage *img;
302 SDL_Surface *mergedSurface; 327 SDL_Surface *mergedSurface;
303 NSAutoreleasePool *pool; 328 NSAutoreleasePool *pool;
310 335
311 imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4 * icon->w bitsPerPixel:32] autorelease]; 336 imgrep =[[[NSBitmapImageRep alloc] initWithBitmapDataPlanes: NULL pixelsWide: icon->w pixelsHigh: icon->h bitsPerSample: 8 samplesPerPixel: 4 hasAlpha: YES isPlanar: NO colorSpaceName: NSDeviceRGBColorSpace bytesPerRow: 4 * icon->w bitsPerPixel:32] autorelease];
312 if (imgrep == nil) 337 if (imgrep == nil)
313 goto freePool; 338 goto freePool;
314 pixels =[imgrep bitmapData]; 339 pixels =[imgrep bitmapData];
315 SDL_memset (pixels, 0, 4 * icon->w * icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */ 340 SDL_memset(pixels, 0, 4 * icon->w * icon->h); /* make the background, which will survive in colorkeyed areas, completely transparent */
316 341
317 #if SDL_BYTEORDER == SDL_BIG_ENDIAN 342 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
318 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF 343 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
319 #else 344 #else
320 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 345 #define BYTEORDER_DEPENDENT_RGBA_MASKS 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
321 #endif 346 #endif
322 mergedSurface = 347 mergedSurface =
323 SDL_CreateRGBSurfaceFrom (pixels, icon->w, icon->h, 32, 4 * icon->w, 348 SDL_CreateRGBSurfaceFrom(pixels, icon->w, icon->h, 32, 4 * icon->w,
324 BYTEORDER_DEPENDENT_RGBA_MASKS); 349 BYTEORDER_DEPENDENT_RGBA_MASKS);
325 if (mergedSurface == NULL) 350 if (mergedSurface == NULL)
326 goto freePool; 351 goto freePool;
327 352
328 /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */ 353 /* blit, with temporarily cleared SRCALPHA flag because we want to copy, not alpha-blend */
329 iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0); 354 iconSrcAlpha = ((icon->flags & SDL_SRCALPHA) != 0);
330 iconAlphaValue = icon->format->alpha; 355 iconAlphaValue = icon->format->alpha;
331 SDL_SetAlpha (icon, 0, 255); 356 SDL_SetAlpha(icon, 0, 255);
332 SDL_BlitSurface (icon, NULL, mergedSurface, NULL); 357 SDL_BlitSurface(icon, NULL, mergedSurface, NULL);
333 if (iconSrcAlpha) 358 if (iconSrcAlpha)
334 SDL_SetAlpha (icon, SDL_SRCALPHA, iconAlphaValue); 359 SDL_SetAlpha(icon, SDL_SRCALPHA, iconAlphaValue);
335 360
336 SDL_FreeSurface (mergedSurface); 361 SDL_FreeSurface(mergedSurface);
337 362
338 /* apply mask, source alpha, and premultiply color values by alpha */ 363 /* apply mask, source alpha, and premultiply color values by alpha */
339 maskPitch = (icon->w + 7) / 8; 364 maskPitch = (icon->w + 7) / 8;
340 for (i = 0; i < icon->h; i++) { 365 for (i = 0; i < icon->h; i++) {
341 for (j = 0; j < icon->w; j++) { 366 for (j = 0; j < icon->w; j++) {
359 (Uint16) pixels[index + 2] * pixels[index + 3] / 255; 384 (Uint16) pixels[index + 2] * pixels[index + 3] / 255;
360 } 385 }
361 } 386 }
362 } 387 }
363 388
364 img =[[[NSImage alloc] initWithSize:NSMakeSize (icon->w, 389 img =[[[NSImage alloc] initWithSize:NSMakeSize(icon->w,
365 icon->h)] autorelease]; 390 icon->h)] autorelease];
366 if (img == nil) 391 if (img == nil)
367 goto freePool; 392 goto freePool;
368 [img addRepresentation:imgrep]; 393 [img addRepresentation:imgrep];
369 [NSApp setApplicationIconImage:img]; 394 [NSApp setApplicationIconImage:img];
370 395
371 freePool: 396 freePool:
372 [pool release]; 397 [pool release];
373 } 398 }
374 399
375 int 400 int
376 QZ_IconifyWindow (_THIS) 401 QZ_IconifyWindow(_THIS)
377 { 402 {
378 403
379 if (![qz_window isMiniaturized]) { 404 if (![qz_window isMiniaturized]) {
380 [qz_window miniaturize:nil]; 405 [qz_window miniaturize:nil];
381 return 1; 406 return 1;
382 } else { 407 } else {
383 SDL_SetError ("window already iconified"); 408 SDL_SetError("window already iconified");
384 return 0; 409 return 0;
385 } 410 }
386 } 411 }
387 412
388 /* 413 /*
390 info->nsWindowPtr = qz_window; 415 info->nsWindowPtr = qz_window;
391 return 0; 416 return 0;
392 }*/ 417 }*/
393 418
394 void 419 void
395 QZ_ChangeGrabState (_THIS, int action) 420 QZ_ChangeGrabState(_THIS, int action)
396 { 421 {
397 422
398 /* 423 /*
399 Figure out what the next state should be based on the action. 424 Figure out what the next state should be based on the action.
400 Ignore actions that can't change the current state. 425 Ignore actions that can't change the current state.
410 if (action == QZ_DISABLE_GRAB) 435 if (action == QZ_DISABLE_GRAB)
411 grab_state = QZ_UNGRABBED; 436 grab_state = QZ_UNGRABBED;
412 else if (action == QZ_HIDECURSOR) 437 else if (action == QZ_HIDECURSOR)
413 grab_state = QZ_INVISIBLE_GRAB; 438 grab_state = QZ_INVISIBLE_GRAB;
414 } else { 439 } else {
415 assert (grab_state == QZ_INVISIBLE_GRAB); 440 assert(grab_state == QZ_INVISIBLE_GRAB);
416 441
417 if (action == QZ_DISABLE_GRAB) 442 if (action == QZ_DISABLE_GRAB)
418 grab_state = QZ_UNGRABBED; 443 grab_state = QZ_UNGRABBED;
419 else if (action == QZ_SHOWCURSOR) 444 else if (action == QZ_SHOWCURSOR)
420 grab_state = QZ_VISIBLE_GRAB; 445 grab_state = QZ_VISIBLE_GRAB;
421 } 446 }
422 447
423 /* now apply the new state */ 448 /* now apply the new state */
424 if (grab_state == QZ_UNGRABBED) { 449 if (grab_state == QZ_UNGRABBED) {
425 450
426 CGAssociateMouseAndMouseCursorPosition (1); 451 CGAssociateMouseAndMouseCursorPosition(1);
427 } else if (grab_state == QZ_VISIBLE_GRAB) { 452 } else if (grab_state == QZ_VISIBLE_GRAB) {
428 453
429 CGAssociateMouseAndMouseCursorPosition (1); 454 CGAssociateMouseAndMouseCursorPosition(1);
430 } else { 455 } else {
431 assert (grab_state == QZ_INVISIBLE_GRAB); 456 assert(grab_state == QZ_INVISIBLE_GRAB);
432 457
433 QZ_PrivateWarpCursor (this, SDL_VideoSurface->w / 2, 458 QZ_PrivateWarpCursor(this, SDL_VideoSurface->w / 2,
434 SDL_VideoSurface->h / 2); 459 SDL_VideoSurface->h / 2);
435 CGAssociateMouseAndMouseCursorPosition (0); 460 CGAssociateMouseAndMouseCursorPosition(0);
436 } 461 }
437 } 462 }
438 463
439 SDL_GrabMode 464 SDL_GrabMode
440 QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) 465 QZ_GrabInput(_THIS, SDL_GrabMode grab_mode)
441 { 466 {
442 467
443 int doGrab = grab_mode & SDL_GRAB_ON; 468 int doGrab = grab_mode & SDL_GRAB_ON;
444 /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN; */ 469 /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN; */
445 470
446 if (this->screen == NULL) { 471 if (this->screen == NULL) {
447 SDL_SetError ("QZ_GrabInput: screen is NULL"); 472 SDL_SetError("QZ_GrabInput: screen is NULL");
448 return SDL_GRAB_OFF; 473 return SDL_GRAB_OFF;
449 } 474 }
450 475
451 if (!video_set) { 476 if (!video_set) {
452 /*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */ 477 /*SDL_SetError ("QZ_GrabInput: video is not set, grab will take effect on mode switch"); */
454 return grab_mode; /* Will be set later on mode switch */ 479 return grab_mode; /* Will be set later on mode switch */
455 } 480 }
456 481
457 if (grab_mode != SDL_GRAB_QUERY) { 482 if (grab_mode != SDL_GRAB_QUERY) {
458 if (doGrab) 483 if (doGrab)
459 QZ_ChangeGrabState (this, QZ_ENABLE_GRAB); 484 QZ_ChangeGrabState(this, QZ_ENABLE_GRAB);
460 else 485 else
461 QZ_ChangeGrabState (this, QZ_DISABLE_GRAB); 486 QZ_ChangeGrabState(this, QZ_DISABLE_GRAB);
462 487
463 current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF; 488 current_grab_mode = doGrab ? SDL_GRAB_ON : SDL_GRAB_OFF;
464 } 489 }
465 490
466 return current_grab_mode; 491 return current_grab_mode;