From 79ee2ff6e733dd047984dc75eeaf169618510449 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 20 Jan 2011 16:05:59 -0800 Subject: [PATCH] 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 | 25 +++++++++++++++++++++++-- src/video/cocoa/SDL_cocoawindow.m | 2 +- src/video/uikit/SDL_uikitvideo.m | 1 + src/video/uikit/SDL_uikitwindow.h | 2 ++ src/video/uikit/SDL_uikitwindow.m | 24 +++++++++++++++++++++--- src/video/win32/SDL_win32events.c | 8 ++++---- src/video/win32/SDL_win32window.c | 2 +- src/video/x11/SDL_x11events.c | 2 +- src/video/x11/SDL_x11window.c | 4 ++-- 9 files changed, 56 insertions(+), 14 deletions(-) diff --git a/include/SDL_syswm.h b/include/SDL_syswm.h index f0e240889..aaf0d2092 100644 --- a/include/SDL_syswm.h +++ b/include/SDL_syswm.h @@ -88,6 +88,14 @@ typedef struct _NSWindow NSWindow; #endif #endif +#if defined(SDL_VIDEO_DRIVER_UIKIT) +#ifdef __OBJC__ +#include +#else +typedef struct _UIWindow UIWindow; +#endif +#endif + /** * These are the various supported windowing subsystems */ @@ -98,6 +106,7 @@ typedef enum SDL_SYSWM_X11, SDL_SYSWM_DIRECTFB, SDL_SYSWM_COCOA, + SDL_SYSWM_UIKIT, } SDL_SYSWM_TYPE; /** @@ -133,7 +142,13 @@ struct SDL_SysWMmsg /* 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 @@ struct SDL_SysWMinfo 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 */ diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 68c0cbe48..c3fe97121 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -747,7 +747,7 @@ - (void)rightMouseDown:(NSEvent *)theEvent 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", diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index 1d9a6e75a..3d0b1a2b9 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -87,6 +87,7 @@ static void UIKit_DeleteDevice(SDL_VideoDevice * device) device->PumpEvents = UIKit_PumpEvents; device->CreateWindow = UIKit_CreateWindow; device->DestroyWindow = UIKit_DestroyWindow; + device->GetWindowWMInfo = UIKit_GetWindowWMInfo; /* OpenGL (ES) functions */ diff --git a/src/video/uikit/SDL_uikitwindow.h b/src/video/uikit/SDL_uikitwindow.h index f0f64f3b0..413ea6ba1 100644 --- a/src/video/uikit/SDL_uikitwindow.h +++ b/src/video/uikit/SDL_uikitwindow.h @@ -31,6 +31,8 @@ typedef struct SDL_WindowData SDL_WindowData; 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; diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index f2337809e..33d24f7cd 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -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 #include static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bool created) @@ -85,7 +85,8 @@ static int SetupWindowData(_THIS, SDL_Window *window, UIWindow *uiwindow, SDL_bo } -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 @@ int UIKit_CreateWindow(_THIS, SDL_Window *window) { } -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 @@ void UIKit_DestroyWindow(_THIS, SDL_Window * window) { } } +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: */ diff --git a/src/video/win32/SDL_win32events.c b/src/video/win32/SDL_win32events.c index 852664e20..fc0cc1769 100644 --- a/src/video/win32/SDL_win32events.c +++ b/src/video/win32/SDL_win32events.c @@ -113,10 +113,10 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) 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); } diff --git a/src/video/win32/SDL_win32window.c b/src/video/win32/SDL_win32window.c index 56e424fe4..e8a75899b 100644 --- a/src/video/win32/SDL_win32window.c +++ b/src/video/win32/SDL_win32window.c @@ -549,7 +549,7 @@ WIN_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) 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", diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 48f7e1093..a45ea7925 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -91,7 +91,7 @@ X11_DispatchEvent(_THIS) SDL_VERSION(&wmmsg.version); wmmsg.subsystem = SDL_SYSWM_X11; - wmmsg.x11.event = xevent; + wmmsg.msg.x11.event = xevent; SDL_SendSysWMEvent(&wmmsg); } diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 47c1e323b..9decd08db 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -1137,8 +1137,8 @@ X11_GetWindowWMInfo(_THIS, SDL_Window * window, SDL_SysWMinfo * info) 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",