comparison src/video/quartz/SDL_QuartzEvents.m @ 117:aac75d5f7869

Fixed fullscreen mouse events on MacOS X Fixed crash when quitting fullscreen mode on MacOS X
author Sam Lantinga <slouken@libsdl.org>
date Sun, 22 Jul 2001 20:57:24 +0000
parents 45b1c4303f87
children 2d162219f433
comparison
equal deleted inserted replaced
116:e811db89bfbe 117:aac75d5f7869
193 } 193 }
194 194
195 currentMods = newMods; 195 currentMods = newMods;
196 } 196 }
197 197
198 static void QZ_DoActivate (_THIS, NSPoint p) { 198 static void QZ_DoActivate (_THIS)
199 199 {
200 inForeground = YES; 200 inForeground = YES;
201 201
202 /* Regrab the mouse */ 202 /* Regrab the mouse */
203 if (currentGrabMode == SDL_GRAB_ON) { 203 if (currentGrabMode == SDL_GRAB_ON) {
204 QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2); 204 QZ_WarpWMCursor (this, SDL_VideoSurface->w / 2, SDL_VideoSurface->h / 2);
218 } 218 }
219 219
220 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS); 220 SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS);
221 } 221 }
222 222
223 static void QZ_PumpEvents (_THIS) { 223 static void QZ_PumpEvents (_THIS)
224 224 {
225 NSDate *distantPast = [ NSDate distantPast ]; 225 NSDate *distantPast = [ NSDate distantPast ];
226
227 //NSAutoreleasePool *pool;
228 //pool = [ [ NSAutoreleasePool alloc ] init ];
229 226
230 NSEvent *event; 227 NSEvent *event;
231 NSRect winRect; 228 NSRect winRect;
232 NSRect titleBarRect; 229 NSRect titleBarRect;
233 230
242 untilDate:distantPast 239 untilDate:distantPast
243 inMode: NSDefaultRunLoopMode dequeue:YES ]; 240 inMode: NSDefaultRunLoopMode dequeue:YES ];
244 241
245 if (event != nil) { 242 if (event != nil) {
246 unsigned int type; 243 unsigned int type;
247 NSPoint p; 244
248 245 #define DO_MOUSE_DOWN(button, sendToWindow) \
249 type = [ event type ]; 246 if ( inForeground ) { \
250 p = [ event locationInWindow ]; 247 if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) || \
251 248 NSPointInRect([event locationInWindow], winRect) ) \
252 #define DO_MOUSE_DOWN(button, sendToWindow) \ 249 SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \
253 if ( inForeground ) { \ 250 else if (sendToWindow) \
254 if ( NSPointInRect(p,winRect)) \ 251 [ window sendEvent:event ]; \
255 SDL_PrivateMouseButton (SDL_PRESSED, button, p.x, SDL_VideoSurface->h - p.y); \ 252 } \
256 else if (sendToWindow) \ 253 else { \
257 [ window sendEvent:event ]; \ 254 QZ_DoActivate (this); \
258 } \
259 else { \
260 QZ_DoActivate (this, p); \
261 } 255 }
262 256
263 #define DO_MOUSE_UP(button, sendToWindow) \ 257 #define DO_MOUSE_UP(button, sendToWindow) \
264 if ( ! NSPointInRect (p, titleBarRect) ) \ 258 if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) || \
265 SDL_PrivateMouseButton (SDL_RELEASED, button, p.x, SDL_VideoSurface->h - p.y); \ 259 !NSPointInRect([event locationInWindow], titleBarRect) )\
266 if (sendToWindow) \ 260 SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); \
261 if (sendToWindow) \
267 [ window sendEvent:event ] 262 [ window sendEvent:event ]
268 263
269 switch ( type) { 264 type = [ event type ];
265 switch (type) {
270 266
271 case NSLeftMouseDown: 267 case NSLeftMouseDown:
272 if ( NSCommandKeyMask & currentMods ) { 268 if ( NSCommandKeyMask & currentMods ) {
273 DO_MOUSE_DOWN (3, 0); 269 DO_MOUSE_DOWN (3, 0);
274 } 270 }
300 //} 296 //}
301 break; 297 break;
302 case NSLeftMouseDragged: 298 case NSLeftMouseDragged:
303 case NSRightMouseDragged: 299 case NSRightMouseDragged:
304 case 27: 300 case 27:
305 SDL_PrivateMouseMotion (SDL_PRESSED, 0, p.x, SDL_VideoSurface->h - p.y);
306 break;
307 case NSMouseMoved: 301 case NSMouseMoved:
308 { 302 {
309 static int moves = 0; 303 static int moves = 0;
310 304 NSPoint p;
305
306 if ( SDL_VideoSurface->flags & SDL_FULLSCREEN ) {
307 p = [ NSEvent mouseLocation ];
308 p.y = [[NSScreen mainScreen] frame].size.height - p.y;
309 } else {
310 p = [ event locationInWindow ];
311 p.y = SDL_VideoSurface->h - p.y;
312 }
313
311 if ( (moves % 10) == 0 ) { 314 if ( (moves % 10) == 0 ) {
312 SDL_PrivateMouseMotion (SDL_RELEASED, 0, p.x, SDL_VideoSurface->h - p.y); 315 SDL_PrivateMouseMotion (0, 0, p.x, p.y);
313 moves = 0;
314 } 316 }
315 else { 317 else {
316 CGMouseDelta dx, dy; 318 CGMouseDelta dx, dy;
317 CGGetLastMouseDelta (&dx, &dy); 319 CGGetLastMouseDelta (&dx, &dy);
318 SDL_PrivateMouseMotion (SDL_RELEASED, 1, dx, dy); 320 SDL_PrivateMouseMotion (0, 1, dx, dy);
319 moves++;
320 } 321 }
322 moves++;
321 } 323 }
322 break; 324 break;
323 case NSScrollWheel: 325 case NSScrollWheel:
324 { 326 {
325 if (NSPointInRect(p, winRect)) { 327 if (NSPointInRect([ event locationInWindow ], winRect)) {
326 float dy; 328 float dy;
327 dy = [ event deltaY ]; 329 dy = [ event deltaY ];
328 if ( dy > 0.0 ) /* Scroll up */ 330 if ( dy > 0.0 ) /* Scroll up */
329 SDL_PrivateMouseButton (SDL_PRESSED, 4, p.x, SDL_VideoSurface->h - p.y); 331 SDL_PrivateMouseButton (SDL_PRESSED, 4, 0, 0);
330 else /* Scroll down */ 332 else /* Scroll down */
331 SDL_PrivateMouseButton (SDL_PRESSED, 5, p.x, SDL_VideoSurface->h - p.y); 333 SDL_PrivateMouseButton (SDL_PRESSED, 5, 0, 0);
332 } 334 }
333 } 335 }
334 break; 336 break;
335 case NSKeyUp: 337 case NSKeyUp:
336 QZ_DoKey (SDL_RELEASED, event); 338 QZ_DoKey (SDL_RELEASED, event);
344 case NSMouseEntered: break; 346 case NSMouseEntered: break;
345 case NSMouseExited: break; 347 case NSMouseExited: break;
346 case NSAppKitDefined: 348 case NSAppKitDefined:
347 switch ( [ event subtype ] ) { 349 switch ( [ event subtype ] ) {
348 case NSApplicationActivatedEventType: 350 case NSApplicationActivatedEventType:
349 QZ_DoActivate (this, p); 351 QZ_DoActivate (this);
350 break; 352 break;
351 case NSApplicationDeactivatedEventType: 353 case NSApplicationDeactivatedEventType:
352 QZ_DoDeactivate (this); 354 QZ_DoDeactivate (this);
353 break; 355 break;
354 case NSWindowMovedEventType: 356 case NSWindowMovedEventType:
359 case NSApplicationDefined: break; 361 case NSApplicationDefined: break;
360 case NSPeriodic: break; 362 case NSPeriodic: break;
361 case NSCursorUpdate: break; 363 case NSCursorUpdate: break;
362 } 364 }
363 } 365 }
364 // [ pool release ];
365
366 } while (event != nil); 366 } while (event != nil);
367 } 367 }
368 368