Added the ability to get the UIKit window through the SDL API.
authorSam Lantinga <slouken@libsdl.org>
Thu, 20 Jan 2011 16:05:59 -0800
changeset 5056 8b7988f42fcb
parent 5055 2936fc46b015
child 5057 bdff53ed6c8b
Added the ability to get the UIKit window through the SDL API. You can also do this through the native API: UIWindow *window = [[UIApplication sharedApplication] keyWindow]; Also needed to name the union for events and window info.
include/SDL_syswm.h
src/video/cocoa/SDL_cocoawindow.m
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitwindow.h
src/video/uikit/SDL_uikitwindow.m
src/video/win32/SDL_win32events.c
src/video/win32/SDL_win32window.c
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11window.c
--- a/include/SDL_syswm.h	Thu Jan 20 11:51:23 2011 -0500
+++ b/include/SDL_syswm.h	Thu Jan 20 16:05:59 2011 -0800
@@ -88,6 +88,14 @@
 #endif
 #endif
 
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+#ifdef __OBJC__
+#include <UIKit/UIKit.h>
+#else
+typedef struct _UIWindow UIWindow;
+#endif
+#endif
+
 /** 
  *  These are the various supported windowing subsystems
  */
@@ -98,6 +106,7 @@
     SDL_SYSWM_X11,
     SDL_SYSWM_DIRECTFB,
     SDL_SYSWM_COCOA,
+    SDL_SYSWM_UIKIT,
 } SDL_SYSWM_TYPE;
 
 /**
@@ -133,7 +142,13 @@
             /* No Cocoa window events yet */
         } cocoa;
 #endif
-    } /*msg*/;
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+        struct
+        {
+            /* No UIKit window events yet */
+        } uikit;
+#endif
+    } msg;
 };
 
 /**
@@ -175,7 +190,13 @@
             NSWindow *window;           /* The Cocoa window */
         } cocoa;
 #endif
-    } /*info*/;
+#if defined(SDL_VIDEO_DRIVER_UIKIT)
+        struct
+        {
+            UIWindow *window;           /* The UIKit window */
+        } uikit;
+#endif
+    } info;
 };
 
 #endif /* SDL_PROTOTYPES_ONLY */
--- a/src/video/cocoa/SDL_cocoawindow.m	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Jan 20 16:05:59 2011 -0800
@@ -747,7 +747,7 @@
 
     if (info->version.major <= SDL_MAJOR_VERSION) {
         info->subsystem = SDL_SYSWM_COCOA;
-        info->cocoa.window = nswindow;
+        info->info.cocoa.window = nswindow;
         return SDL_TRUE;
     } else {
         SDL_SetError("Application not compiled with SDL %d.%d\n",
--- a/src/video/uikit/SDL_uikitvideo.m	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/uikit/SDL_uikitvideo.m	Thu Jan 20 16:05:59 2011 -0800
@@ -87,6 +87,7 @@
     device->PumpEvents = UIKit_PumpEvents;
 	device->CreateWindow = UIKit_CreateWindow;
 	device->DestroyWindow = UIKit_DestroyWindow;
+    device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
 	
 	
 	/* OpenGL (ES) functions */
--- a/src/video/uikit/SDL_uikitwindow.h	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/uikit/SDL_uikitwindow.h	Thu Jan 20 16:05:59 2011 -0800
@@ -31,6 +31,8 @@
 
 extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
 extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
+extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
+                                      struct SDL_SysWMinfo * info);
 
 @class UIWindow;
 
--- a/src/video/uikit/SDL_uikitwindow.m	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/uikit/SDL_uikitwindow.m	Thu Jan 20 16:05:59 2011 -0800
@@ -21,6 +21,7 @@
 */
 #include "SDL_config.h"
 
+#include "SDL_syswm.h"
 #include "SDL_video.h"
 #include "SDL_mouse.h"
 #include "SDL_assert.h"
@@ -36,7 +37,6 @@
 #import "SDL_uikitopenglview.h"
 #import "SDL_renderer_sw.h"
 
-#include <UIKit/UIKit.h>
 #include <Foundation/Foundation.h>
 
 static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
@@ -85,7 +85,8 @@
     
 }
 
-int UIKit_CreateWindow(_THIS, SDL_Window *window) {
+int
+UIKit_CreateWindow(_THIS, SDL_Window *window) {
         
     SDL_VideoDisplay *display = window->display;
     UIScreen *uiscreen = (UIScreen *) display->driverdata;
@@ -154,7 +155,8 @@
     
 }
 
-void UIKit_DestroyWindow(_THIS, SDL_Window * window) {
+void
+UIKit_DestroyWindow(_THIS, SDL_Window * window) {
     SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
     if (data) {
         [data->uiwindow release];
@@ -163,4 +165,20 @@
     }
 }
 
+SDL_bool
+UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
+{
+    UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
+
+    if (info->version.major <= SDL_MAJOR_VERSION) {
+        info->subsystem = SDL_SYSWM_UIKIT;
+        info->info.uikit.window = uiwindow;
+        return SDL_TRUE;
+    } else {
+        SDL_SetError("Application not compiled with SDL %d.%d\n",
+                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
+        return SDL_FALSE;
+    }
+}
+
 /* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/win32/SDL_win32events.c	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/win32/SDL_win32events.c	Thu Jan 20 16:05:59 2011 -0800
@@ -113,10 +113,10 @@
 
         SDL_VERSION(&wmmsg.version);
         wmmsg.subsystem = SDL_SYSWM_WINDOWS;
-        wmmsg.win.hwnd = hwnd;
-        wmmsg.win.msg = msg;
-        wmmsg.win.wParam = wParam;
-        wmmsg.win.lParam = lParam;
+        wmmsg.msg.win.hwnd = hwnd;
+        wmmsg.msg.win.msg = msg;
+        wmmsg.msg.win.wParam = wParam;
+        wmmsg.msg.win.lParam = lParam;
         SDL_SendSysWMEvent(&wmmsg);
     }
 
--- a/src/video/win32/SDL_win32window.c	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/win32/SDL_win32window.c	Thu Jan 20 16:05:59 2011 -0800
@@ -549,7 +549,7 @@
     HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     if (info->version.major <= SDL_MAJOR_VERSION) {
         info->subsystem = SDL_SYSWM_WINDOWS;
-        info->win.window = hwnd;
+        info->info.win.window = hwnd;
         return SDL_TRUE;
     } else {
         SDL_SetError("Application not compiled with SDL %d.%d\n",
--- a/src/video/x11/SDL_x11events.c	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/x11/SDL_x11events.c	Thu Jan 20 16:05:59 2011 -0800
@@ -91,7 +91,7 @@
 
         SDL_VERSION(&wmmsg.version);
         wmmsg.subsystem = SDL_SYSWM_X11;
-        wmmsg.x11.event = xevent;
+        wmmsg.msg.x11.event = xevent;
         SDL_SendSysWMEvent(&wmmsg);
     }
 
--- a/src/video/x11/SDL_x11window.c	Thu Jan 20 11:51:23 2011 -0500
+++ b/src/video/x11/SDL_x11window.c	Thu Jan 20 16:05:59 2011 -0800
@@ -1137,8 +1137,8 @@
     if (info->version.major == SDL_MAJOR_VERSION &&
         info->version.minor == SDL_MINOR_VERSION) {
         info->subsystem = SDL_SYSWM_X11;
-        info->x11.display = display;
-        info->x11.window = data->xwindow;
+        info->info.x11.display = display;
+        info->info.x11.window = data->xwindow;
         return SDL_TRUE;
     } else {
         SDL_SetError("Application not compiled with SDL %d.%d\n",