comparison src/video/quartz/SDL_QuartzVideo.m @ 4065:0c76e6d1c3d6 SDL-1.2

Fixed bug #373 Patch contributed from Transgaming's Cider project - create a window and view in fullscreen mode so the cursor can be set
author Sam Lantinga <slouken@libsdl.org>
date Sat, 14 Jul 2007 08:00:50 +0000
parents 60f677630282
children b8f2db95145e
comparison
equal deleted inserted replaced
4064:940fddb81bea 4065:0c76e6d1c3d6
365 SDL_DestroySemaphore (sem1); 365 SDL_DestroySemaphore (sem1);
366 SDL_DestroySemaphore (sem2); 366 SDL_DestroySemaphore (sem2);
367 SDL_free (sw_buffers[0]); 367 SDL_free (sw_buffers[0]);
368 } 368 }
369 369
370 /* If we still have a valid window, close it. */
371 if ( qz_window ) {
372 [ qz_window close ];
373 [ qz_window release ];
374 qz_window = nil;
375 window_view = nil;
376 }
370 /* 377 /*
371 Release the OpenGL context 378 Release the OpenGL context
372 Do this first to avoid trash on the display before fade 379 Do this first to avoid trash on the display before fade
373 */ 380 */
374 if ( mode_flags & SDL_OPENGL ) { 381 if ( mode_flags & SDL_OPENGL ) {
409 static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width, 416 static SDL_Surface* QZ_SetVideoFullScreen (_THIS, SDL_Surface *current, int width,
410 int height, int bpp, Uint32 flags) { 417 int height, int bpp, Uint32 flags) {
411 boolean_t exact_match = 0; 418 boolean_t exact_match = 0;
412 NSRect screen_rect; 419 NSRect screen_rect;
413 CGError error; 420 CGError error;
421 NSRect contentRect;
422 BOOL isCustom = NO;
414 CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken; 423 CGDisplayFadeReservationToken fade_token = kCGDisplayFadeReservationInvalidToken;
415 424
416 /* Fade to black to hide resolution-switching flicker (and garbage 425 /* Fade to black to hide resolution-switching flicker (and garbage
417 that is displayed by a destroyed OpenGL context, if applicable) */ 426 that is displayed by a destroyed OpenGL context, if applicable) */
418 if ( CGAcquireDisplayFadeReservation (5, &fade_token) == kCGErrorSuccess ) { 427 if ( CGAcquireDisplayFadeReservation (5, &fade_token) == kCGErrorSuccess ) {
501 } 510 }
502 511
503 if ( CGDisplayCanSetPalette (display_id) ) 512 if ( CGDisplayCanSetPalette (display_id) )
504 current->flags |= SDL_HWPALETTE; 513 current->flags |= SDL_HWPALETTE;
505 514
515 /* The code below checks for any valid custom windows and views. If none are
516 available, then we create new ones. Window/View code was added in FULLSCREEN
517 so that special events like the changing of the cursor image would be handled
518 ( only the front-most and active application can change the cursor appearance
519 and with no valid window/view in FULLSCREEN, SDL wouldn't update its cursor. )
520 */
521 /* Check for user-specified window and view */
522 {
523 char *windowPtrString = getenv ("SDL_NSWindowPointer");
524 char *viewPtrString = getenv ("SDL_NSQuickDrawViewPointer");
525
526 contentRect = NSMakeRect (0, 0, width, height);
527
528 if (windowPtrString && viewPtrString) {
529 /* Release any previous window */
530 if ( qz_window ) {
531 [ qz_window release ];
532 qz_window = nil;
533 }
534
535 qz_window = (NSWindow*)atoi(windowPtrString);
536 window_view = (NSQuickDrawView*)atoi(viewPtrString);
537 isCustom = YES;
538 /*
539 Retain reference to window because we
540 might release it in QZ_UnsetVideoMode
541 */
542 [ qz_window retain ];
543 }
544 }
545 /* Check if we should recreate the window */
546 if (qz_window == nil) {
547 /* Manually create a window, avoids having a nib file resource */
548 qz_window = [ [ SDL_QuartzWindow alloc ]
549 initWithContentRect:contentRect
550 styleMask:nil
551 backing:NSBackingStoreBuffered
552 defer:NO ];
553
554 if (qz_window != nil) {
555 [ qz_window setAcceptsMouseMovedEvents:YES ];
556 [ qz_window setViewsNeedDisplay:NO ];
557 }
558 }
559 /* We already have a window, just change its size */
560 else {
561 if (!isCustom) {
562 [ qz_window setContentSize:contentRect.size ];
563 current->flags |= (SDL_NOFRAME|SDL_RESIZABLE) & mode_flags;
564 [ window_view setFrameSize:contentRect.size ];
565 }
566 }
567
506 /* Setup OpenGL for a fullscreen context */ 568 /* Setup OpenGL for a fullscreen context */
507 if (flags & SDL_OPENGL) { 569 if (flags & SDL_OPENGL) {
508 570
509 CGLError err; 571 CGLError err;
510 CGLContextObj ctx; 572 CGLContextObj ctx;
511 573
512 if ( ! QZ_SetupOpenGL (this, bpp, flags) ) { 574 if ( ! QZ_SetupOpenGL (this, bpp, flags) ) {
513 goto ERR_NO_GL; 575 goto ERR_NO_GL;
514 } 576 }
577
578 /* Initialize the NSView and add it to our window. The presence of a valid window and
579 view allow the cursor to be changed whilst in fullscreen.*/
580 window_view = [ [ NSView alloc ] initWithFrame:contentRect ];
581 [ [ qz_window contentView ] addSubview:window_view ];
582 [ window_view release ];
515 583
516 ctx = [ gl_context cglContext ]; 584 ctx = [ gl_context cglContext ];
517 err = CGLSetFullScreen (ctx); 585 err = CGLSetFullScreen (ctx);
518 586
519 if (err) { 587 if (err) {