diff src/video/quartz/SDL_QuartzWM.m @ 761:c5b2b6d2d1fe

Date: Wed, 31 Dec 2003 21:55:30 +0100 From: Max Horn Subject: SDL: video/quartz cleanup while doing some experimental changes in the quartz code, I was annoyed by having to recompile that one big .o file over and over again. So I decided to finally realize one TODO: properly splitting the code over multiple files :-). With two exceptions, I didn't make code changes, only rearranged files and added new headers. Since there are several new files, making a patch didn't work out so well, so I decided to just send you all the new & modified files. The one source change I made is related to showing/hiding the mouse. I renamed cursor_visible to cursor_should_be_visible and cursor_hidden to cursor_visible; I think that makes reading the code easier. Then I added two new functions: QZ_ShowMouse and QZ_HideMouse. They help manage cursor_visible (the former 'cursor_hidden'). Finally I replaced the Carbon ShowCursor/HiderCuror calls by [NSCursor hide] and [NSCursor unhide]. The API docs are not conclusive, but it might be that with those the "cursor_visible" (former 'cursor_hidden') hack may not be necessary anymore; however so far I didn't test this hypothesis, so I left that in. The other change was to remove in_foreground and use [NSApp isActive] instead: Manually keeping track of whether we are in the foreground is error prone. This should work better in some corner cases.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 04 Jan 2004 14:55:35 +0000
parents 5d2f027b3349
children 68c8da837fc0
line wrap: on
line diff
--- a/src/video/quartz/SDL_QuartzWM.m	Wed Dec 31 04:48:38 2003 +0000
+++ b/src/video/quartz/SDL_QuartzWM.m	Sun Jan 04 14:55:35 2004 +0000
@@ -1,6 +1,6 @@
 /*
     SDL - Simple DirectMedia Layer
-    Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002  Sam Lantinga
+    Copyright (C) 1997-2003  Sam Lantinga
 
     This library is free software; you can redistribute it and/or
     modify it under the terms of the GNU Library General Public
@@ -20,20 +20,21 @@
     slouken@libsdl.org
 */
 
-static void QZ_ChangeGrabState (_THIS, int action);
+#include "SDL_QuartzVideo.h"
+
 
 struct WMcursor {
     Cursor curs;
 };
 
-static void QZ_FreeWMCursor     (_THIS, WMcursor *cursor) { 
+void QZ_FreeWMCursor     (_THIS, WMcursor *cursor) { 
 
     if ( cursor != NULL )
         free (cursor);
 }
 
 /* Use the Carbon cursor routines for now */
-static WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
+WMcursor*    QZ_CreateWMCursor   (_THIS, Uint8 *data, Uint8 *mask, 
                                          int w, int h, int hot_x, int hot_y) { 
     WMcursor *cursor;
     int row, bytes;
@@ -68,26 +69,34 @@
     return(cursor);
 }
 
-static int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
+void QZ_ShowMouse (_THIS) {
+    if (!cursor_visible) {
+        [ NSCursor unhide ];
+        cursor_visible = YES;
+    }
+}
+
+void QZ_HideMouse (_THIS) {
+    if (cursor_visible) {
+        [ NSCursor hide ];
+        cursor_visible = NO;
+    }
+}
+
+int QZ_ShowWMCursor (_THIS, WMcursor *cursor) { 
 
     if ( cursor == NULL) {
-        if ( cursor_visible ) {
-            if (!cursor_hidden) {
-                HideCursor ();
-                cursor_hidden = YES;
-            }
-            cursor_visible = NO;
+        if ( cursor_should_be_visible ) {
+            QZ_HideMouse (this);
+            cursor_should_be_visible = NO;
             QZ_ChangeGrabState (this, QZ_HIDECURSOR);
         }
     }
     else {
         SetCursor(&cursor->curs);
-        if ( ! cursor_visible ) {
-            if (cursor_hidden) {
-                ShowCursor ();
-                cursor_hidden = NO;
-            }
-            cursor_visible = YES;
+        if ( ! cursor_should_be_visible ) {
+            QZ_ShowMouse (this);
+            cursor_should_be_visible = YES;
             QZ_ChangeGrabState (this, QZ_SHOWCURSOR);
         }
     }
@@ -104,20 +113,20 @@
 */
 
 /* Convert Cocoa screen coordinate to Cocoa window coordinate */
-static void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
+void QZ_PrivateGlobalToLocal (_THIS, NSPoint *p) {
 
     *p = [ qz_window convertScreenToBase:*p ];
 }
 
 
 /* Convert Cocoa window coordinate to Cocoa screen coordinate */
-static void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
+void QZ_PrivateLocalToGlobal (_THIS, NSPoint *p) {
 
     *p = [ qz_window convertBaseToScreen:*p ];
 }
 
 /* Convert SDL coordinate to Cocoa coordinate */
-static void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
+void QZ_PrivateSDLToCocoa (_THIS, NSPoint *p) {
 
     if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
     
@@ -134,7 +143,7 @@
 }
 
 /* Convert Cocoa coordinate to SDL coordinate */
-static void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
+void QZ_PrivateCocoaToSDL (_THIS, NSPoint *p) {
 
     if ( CGDisplayIsCaptured (display_id) ) { /* capture signals fullscreen */
     
@@ -151,7 +160,7 @@
 }
 
 /* Convert SDL coordinate to window server (CoreGraphics) coordinate */
-static CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
+CGPoint QZ_PrivateSDLToCG (_THIS, NSPoint *p) {
     
     CGPoint cgp;
     
@@ -174,7 +183,7 @@
 
 #if 0 /* Dead code */
 /* Convert window server (CoreGraphics) coordinate to SDL coordinate */
-static void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
+void QZ_PrivateCGToSDL (_THIS, NSPoint *p) {
             
     if ( ! CGDisplayIsCaptured (display_id) ) { /* not captured => not fullscreen => local coord */
     
@@ -190,7 +199,7 @@
 }
 #endif /* Dead code */
 
-static void  QZ_PrivateWarpCursor (_THIS, int x, int y) {
+void  QZ_PrivateWarpCursor (_THIS, int x, int y) {
     
     NSPoint p;
     CGPoint cgp;
@@ -203,10 +212,10 @@
     CGWarpMouseCursorPosition (cgp);
 }
 
-static void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
+void QZ_WarpWMCursor (_THIS, Uint16 x, Uint16 y) {
 
     /* Only allow warping when in foreground */
-    if ( ! in_foreground )
+    if ( ! [ NSApp isActive ] )
         return;
             
     /* Do the actual warp */
@@ -216,10 +225,10 @@
     SDL_PrivateMouseMotion (0, 0, x, y);
 }
 
-static void QZ_MoveWMCursor     (_THIS, int x, int y) { }
-static void QZ_CheckMouseMode   (_THIS) { }
+void QZ_MoveWMCursor     (_THIS, int x, int y) { }
+void QZ_CheckMouseMode   (_THIS) { }
 
-static void QZ_SetCaption    (_THIS, const char *title, const char *icon) {
+void QZ_SetCaption    (_THIS, const char *title, const char *icon) {
 
     if ( qz_window != nil ) {
         NSString *string;
@@ -236,7 +245,7 @@
     }
 }
 
-static void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
+void QZ_SetIcon       (_THIS, SDL_Surface *icon, Uint8 *mask)
 {
     NSBitmapImageRep *imgrep;
     NSImage *img;
@@ -305,7 +314,7 @@
     [pool release];
 }
 
-static int  QZ_IconifyWindow (_THIS) { 
+int  QZ_IconifyWindow (_THIS) { 
 
     if ( ! [ qz_window isMiniaturized ] ) {
         [ qz_window miniaturize:nil ];
@@ -318,12 +327,12 @@
 }
 
 /*
-static int  QZ_GetWMInfo  (_THIS, SDL_SysWMinfo *info) { 
+int  QZ_GetWMInfo  (_THIS, SDL_SysWMinfo *info) { 
     info->nsWindowPtr = qz_window;
     return 0; 
 }*/
 
-static void QZ_ChangeGrabState (_THIS, int action) {
+void QZ_ChangeGrabState (_THIS, int action) {
 
     /* 
         Figure out what the next state should be based on the action.
@@ -331,7 +340,7 @@
     */
     if ( grab_state == QZ_UNGRABBED ) {
         if ( action == QZ_ENABLE_GRAB ) {
-            if ( cursor_visible )
+            if ( cursor_should_be_visible )
                 grab_state = QZ_VISIBLE_GRAB;
             else
                 grab_state = QZ_INVISIBLE_GRAB;
@@ -369,7 +378,7 @@
     }
 }
 
-static SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
+SDL_GrabMode QZ_GrabInput (_THIS, SDL_GrabMode grab_mode) {
 
     int doGrab = grab_mode & SDL_GRAB_ON;
     /*int fullscreen = grab_mode & SDL_GRAB_FULLSCREEN;*/
@@ -396,81 +405,3 @@
 
     return current_grab_mode;
 }
-
-/* Resize icon, BMP format */
-static unsigned char QZ_ResizeIcon[] = {
-    0x42,0x4d,0x31,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,0x28,0x00,
-    0x00,0x00,0x0d,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x00,0x00,
-    0x00,0x00,0xfb,0x01,0x00,0x00,0x13,0x0b,0x00,0x00,0x13,0x0b,0x00,0x00,0x00,0x00,
-    0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
-    0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,
-    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
-    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xda,0xda,0xda,0x87,
-    0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,
-    0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd5,0xd5,0xd5,0x87,0x87,0x87,0xe8,0xe8,0xe8,
-    0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,
-    0xda,0xda,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,
-    0xda,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,
-    0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xda,0xda,0xda,0x87,0x87,0x87,0xe8,
-    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xd7,0xd7,0xd7,0x87,0x87,0x87,0xe8,0xe8,
-    0xe8,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xd9,0xd9,0xd9,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xdc,
-    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,
-    0xdb,0x87,0x87,0x87,0xe8,0xe8,0xe8,0xff,0xff,0xff,0xff,0xff,0xff,0x0b,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdb,0xdb,0xdb,0x87,0x87,0x87,0xe8,
-    0xe8,0xe8,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xdc,0xdc,0xdc,0x87,0x87,0x87,0xff,0xff,0xff,0x0b,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xdc,
-    0xdc,0xdc,0xff,0xff,0xff,0x0b,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
-    0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0b
-};
-
-static void QZ_DrawResizeIcon (_THIS, RgnHandle dirtyRegion) {
-
-    /* Check if we should draw the resize icon */
-    if (SDL_VideoSurface->flags & SDL_RESIZABLE) {
-    
-        Rect	icon;
-        SetRect (&icon, SDL_VideoSurface->w - 13, SDL_VideoSurface->h - 13, 
-                    SDL_VideoSurface->w, SDL_VideoSurface->h);
-                    
-        if (RectInRgn (&icon, dirtyRegion)) {
-        
-            SDL_Rect icon_rect;
-            
-            /* Create the icon image */
-            if (resize_icon == NULL) {
-            
-                SDL_RWops *rw;
-                SDL_Surface *tmp;
-                
-                rw = SDL_RWFromMem (QZ_ResizeIcon, sizeof(QZ_ResizeIcon));
-                tmp = SDL_LoadBMP_RW (rw, SDL_TRUE);
-                                                                
-                resize_icon = SDL_ConvertSurface (tmp, SDL_VideoSurface->format, SDL_SRCCOLORKEY);								
-                SDL_SetColorKey (resize_icon, SDL_SRCCOLORKEY, 0xFFFFFF);
-                
-                SDL_FreeSurface (tmp);
-            }
-            
-            icon_rect.x = SDL_VideoSurface->w - 13;
-            icon_rect.y = SDL_VideoSurface->h - 13;
-            icon_rect.w = 13;
-            icon_rect.h = 13;
-            
-            SDL_BlitSurface (resize_icon, NULL, SDL_VideoSurface, &icon_rect);
-        }
-    }
-}