Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Added the ability to get the UIKit window through the SDL API.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
slouken committed Jan 21, 2011
1 parent 13c0d5c commit 79ee2ff
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 14 deletions.
25 changes: 23 additions & 2 deletions include/SDL_syswm.h
Expand Up @@ -88,6 +88,14 @@ typedef struct _NSWindow NSWindow;
#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
*/
Expand All @@ -98,6 +106,7 @@ typedef enum
SDL_SYSWM_X11,
SDL_SYSWM_DIRECTFB,
SDL_SYSWM_COCOA,
SDL_SYSWM_UIKIT,
} SDL_SYSWM_TYPE;

/**
Expand Down Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/video/uikit/SDL_uikitvideo.m
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions src/video/uikit/SDL_uikitwindow.h
Expand Up @@ -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;

Expand Down
24 changes: 21 additions & 3 deletions src/video/uikit/SDL_uikitwindow.m
Expand Up @@ -21,6 +21,7 @@
*/
#include "SDL_config.h"

#include "SDL_syswm.h"
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "SDL_assert.h"
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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: */
8 changes: 4 additions & 4 deletions src/video/win32/SDL_win32events.c
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/video/win32/SDL_win32window.c
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/video/x11/SDL_x11events.c
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/video/x11/SDL_x11window.c
Expand Up @@ -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",
Expand Down

0 comments on commit 79ee2ff

Please sign in to comment.