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 50568b7988f42fcb
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
     1.1 --- a/include/SDL_syswm.h	Thu Jan 20 11:51:23 2011 -0500
     1.2 +++ b/include/SDL_syswm.h	Thu Jan 20 16:05:59 2011 -0800
     1.3 @@ -88,6 +88,14 @@
     1.4  #endif
     1.5  #endif
     1.6  
     1.7 +#if defined(SDL_VIDEO_DRIVER_UIKIT)
     1.8 +#ifdef __OBJC__
     1.9 +#include <UIKit/UIKit.h>
    1.10 +#else
    1.11 +typedef struct _UIWindow UIWindow;
    1.12 +#endif
    1.13 +#endif
    1.14 +
    1.15  /** 
    1.16   *  These are the various supported windowing subsystems
    1.17   */
    1.18 @@ -98,6 +106,7 @@
    1.19      SDL_SYSWM_X11,
    1.20      SDL_SYSWM_DIRECTFB,
    1.21      SDL_SYSWM_COCOA,
    1.22 +    SDL_SYSWM_UIKIT,
    1.23  } SDL_SYSWM_TYPE;
    1.24  
    1.25  /**
    1.26 @@ -133,7 +142,13 @@
    1.27              /* No Cocoa window events yet */
    1.28          } cocoa;
    1.29  #endif
    1.30 -    } /*msg*/;
    1.31 +#if defined(SDL_VIDEO_DRIVER_UIKIT)
    1.32 +        struct
    1.33 +        {
    1.34 +            /* No UIKit window events yet */
    1.35 +        } uikit;
    1.36 +#endif
    1.37 +    } msg;
    1.38  };
    1.39  
    1.40  /**
    1.41 @@ -175,7 +190,13 @@
    1.42              NSWindow *window;           /* The Cocoa window */
    1.43          } cocoa;
    1.44  #endif
    1.45 -    } /*info*/;
    1.46 +#if defined(SDL_VIDEO_DRIVER_UIKIT)
    1.47 +        struct
    1.48 +        {
    1.49 +            UIWindow *window;           /* The UIKit window */
    1.50 +        } uikit;
    1.51 +#endif
    1.52 +    } info;
    1.53  };
    1.54  
    1.55  #endif /* SDL_PROTOTYPES_ONLY */
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Jan 20 11:51:23 2011 -0500
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Jan 20 16:05:59 2011 -0800
     2.3 @@ -747,7 +747,7 @@
     2.4  
     2.5      if (info->version.major <= SDL_MAJOR_VERSION) {
     2.6          info->subsystem = SDL_SYSWM_COCOA;
     2.7 -        info->cocoa.window = nswindow;
     2.8 +        info->info.cocoa.window = nswindow;
     2.9          return SDL_TRUE;
    2.10      } else {
    2.11          SDL_SetError("Application not compiled with SDL %d.%d\n",
     3.1 --- a/src/video/uikit/SDL_uikitvideo.m	Thu Jan 20 11:51:23 2011 -0500
     3.2 +++ b/src/video/uikit/SDL_uikitvideo.m	Thu Jan 20 16:05:59 2011 -0800
     3.3 @@ -87,6 +87,7 @@
     3.4      device->PumpEvents = UIKit_PumpEvents;
     3.5  	device->CreateWindow = UIKit_CreateWindow;
     3.6  	device->DestroyWindow = UIKit_DestroyWindow;
     3.7 +    device->GetWindowWMInfo = UIKit_GetWindowWMInfo;
     3.8  	
     3.9  	
    3.10  	/* OpenGL (ES) functions */
     4.1 --- a/src/video/uikit/SDL_uikitwindow.h	Thu Jan 20 11:51:23 2011 -0500
     4.2 +++ b/src/video/uikit/SDL_uikitwindow.h	Thu Jan 20 16:05:59 2011 -0800
     4.3 @@ -31,6 +31,8 @@
     4.4  
     4.5  extern int UIKit_CreateWindow(_THIS, SDL_Window * window);
     4.6  extern void UIKit_DestroyWindow(_THIS, SDL_Window * window);
     4.7 +extern SDL_bool UIKit_GetWindowWMInfo(_THIS, SDL_Window * window,
     4.8 +                                      struct SDL_SysWMinfo * info);
     4.9  
    4.10  @class UIWindow;
    4.11  
     5.1 --- a/src/video/uikit/SDL_uikitwindow.m	Thu Jan 20 11:51:23 2011 -0500
     5.2 +++ b/src/video/uikit/SDL_uikitwindow.m	Thu Jan 20 16:05:59 2011 -0800
     5.3 @@ -21,6 +21,7 @@
     5.4  */
     5.5  #include "SDL_config.h"
     5.6  
     5.7 +#include "SDL_syswm.h"
     5.8  #include "SDL_video.h"
     5.9  #include "SDL_mouse.h"
    5.10  #include "SDL_assert.h"
    5.11 @@ -36,7 +37,6 @@
    5.12  #import "SDL_uikitopenglview.h"
    5.13  #import "SDL_renderer_sw.h"
    5.14  
    5.15 -#include <UIKit/UIKit.h>
    5.16  #include <Foundation/Foundation.h>
    5.17  
    5.18  static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created)
    5.19 @@ -85,7 +85,8 @@
    5.20      
    5.21  }
    5.22  
    5.23 -int UIKit_CreateWindow(_THIS, SDL_Window *window) {
    5.24 +int
    5.25 +UIKit_CreateWindow(_THIS, SDL_Window *window) {
    5.26          
    5.27      SDL_VideoDisplay *display = window->display;
    5.28      UIScreen *uiscreen = (UIScreen *) display->driverdata;
    5.29 @@ -154,7 +155,8 @@
    5.30      
    5.31  }
    5.32  
    5.33 -void UIKit_DestroyWindow(_THIS, SDL_Window * window) {
    5.34 +void
    5.35 +UIKit_DestroyWindow(_THIS, SDL_Window * window) {
    5.36      SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
    5.37      if (data) {
    5.38          [data->uiwindow release];
    5.39 @@ -163,4 +165,20 @@
    5.40      }
    5.41  }
    5.42  
    5.43 +SDL_bool
    5.44 +UIKit_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info)
    5.45 +{
    5.46 +    UIWindow *uiwindow = ((SDL_WindowData *) window->driverdata)->uiwindow;
    5.47 +
    5.48 +    if (info->version.major <= SDL_MAJOR_VERSION) {
    5.49 +        info->subsystem = SDL_SYSWM_UIKIT;
    5.50 +        info->info.uikit.window = uiwindow;
    5.51 +        return SDL_TRUE;
    5.52 +    } else {
    5.53 +        SDL_SetError("Application not compiled with SDL %d.%d\n",
    5.54 +                     SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
    5.55 +        return SDL_FALSE;
    5.56 +    }
    5.57 +}
    5.58 +
    5.59  /* vi: set ts=4 sw=4 expandtab: */
     6.1 --- a/src/video/win32/SDL_win32events.c	Thu Jan 20 11:51:23 2011 -0500
     6.2 +++ b/src/video/win32/SDL_win32events.c	Thu Jan 20 16:05:59 2011 -0800
     6.3 @@ -113,10 +113,10 @@
     6.4  
     6.5          SDL_VERSION(&wmmsg.version);
     6.6          wmmsg.subsystem = SDL_SYSWM_WINDOWS;
     6.7 -        wmmsg.win.hwnd = hwnd;
     6.8 -        wmmsg.win.msg = msg;
     6.9 -        wmmsg.win.wParam = wParam;
    6.10 -        wmmsg.win.lParam = lParam;
    6.11 +        wmmsg.msg.win.hwnd = hwnd;
    6.12 +        wmmsg.msg.win.msg = msg;
    6.13 +        wmmsg.msg.win.wParam = wParam;
    6.14 +        wmmsg.msg.win.lParam = lParam;
    6.15          SDL_SendSysWMEvent(&wmmsg);
    6.16      }
    6.17  
     7.1 --- a/src/video/win32/SDL_win32window.c	Thu Jan 20 11:51:23 2011 -0500
     7.2 +++ b/src/video/win32/SDL_win32window.c	Thu Jan 20 16:05:59 2011 -0800
     7.3 @@ -549,7 +549,7 @@
     7.4      HWND hwnd = ((SDL_WindowData *) window->driverdata)->hwnd;
     7.5      if (info->version.major <= SDL_MAJOR_VERSION) {
     7.6          info->subsystem = SDL_SYSWM_WINDOWS;
     7.7 -        info->win.window = hwnd;
     7.8 +        info->info.win.window = hwnd;
     7.9          return SDL_TRUE;
    7.10      } else {
    7.11          SDL_SetError("Application not compiled with SDL %d.%d\n",
     8.1 --- a/src/video/x11/SDL_x11events.c	Thu Jan 20 11:51:23 2011 -0500
     8.2 +++ b/src/video/x11/SDL_x11events.c	Thu Jan 20 16:05:59 2011 -0800
     8.3 @@ -91,7 +91,7 @@
     8.4  
     8.5          SDL_VERSION(&wmmsg.version);
     8.6          wmmsg.subsystem = SDL_SYSWM_X11;
     8.7 -        wmmsg.x11.event = xevent;
     8.8 +        wmmsg.msg.x11.event = xevent;
     8.9          SDL_SendSysWMEvent(&wmmsg);
    8.10      }
    8.11  
     9.1 --- a/src/video/x11/SDL_x11window.c	Thu Jan 20 11:51:23 2011 -0500
     9.2 +++ b/src/video/x11/SDL_x11window.c	Thu Jan 20 16:05:59 2011 -0800
     9.3 @@ -1137,8 +1137,8 @@
     9.4      if (info->version.major == SDL_MAJOR_VERSION &&
     9.5          info->version.minor == SDL_MINOR_VERSION) {
     9.6          info->subsystem = SDL_SYSWM_X11;
     9.7 -        info->x11.display = display;
     9.8 -        info->x11.window = data->xwindow;
     9.9 +        info->info.x11.display = display;
    9.10 +        info->info.x11.window = data->xwindow;
    9.11          return SDL_TRUE;
    9.12      } else {
    9.13          SDL_SetError("Application not compiled with SDL %d.%d\n",