Mercurial > sdl-ios-xcode
changeset 2580:64fa227c01ce gsoc2008_force_feedback
Added the concept of the HelperWindow to help with DirectInput.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Mon, 04 Aug 2008 11:22:01 +0000 |
parents | bd2a6c70cb29 |
children | a1c00531ee00 |
files | src/SDL.c src/haptic/win32/SDL_syshaptic.c src/joystick/win32/SDL_dxjoystick.c src/video/win32/SDL_win32window.c |
diffstat | 4 files changed, 69 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/SDL.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/SDL.c Mon Aug 04 11:22:01 2008 +0000 @@ -51,6 +51,10 @@ extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); #endif +#if defined(__WIN32__) +extern int SDL_HelperWindowCreate(void); +extern int SDL_HelperWindowDestroy(void); +#endif /* The initialized subsystems */ static Uint32 SDL_initialized = 0; @@ -172,6 +176,12 @@ /* Clear the error message */ SDL_ClearError(); +#if defined(__WIN32__) + if (SDL_HelperWindowCreate() < 0) { + return -1; + } +#endif + /* Initialize the desired subsystems */ if (SDL_InitSubSystem(flags) < 0) { return (-1); @@ -243,6 +253,10 @@ printf("[SDL_Quit] : Enter! Calling QuitSubSystem()\n"); fflush(stdout); #endif + +#if defined(__WIN32__) + SDL_HelperWindowDestroy(); +#endif SDL_QuitSubSystem(SDL_INIT_EVERYTHING); #ifdef CHECK_LEAKS
--- a/src/haptic/win32/SDL_syshaptic.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/haptic/win32/SDL_syshaptic.c Mon Aug 04 11:22:01 2008 +0000 @@ -36,7 +36,9 @@ #include <dinput.h> #include <dxerr.h> #ifdef _MSC_VER -# pragma comment (lib, "dxerr.lib") +# pragma comment (lib, "dinput8.lib") +# pragma comment (lib, "dxguid.lib") +# pragma comment (lib, "dxerr.lib") #endif /* _MSC_VER */ /* an ISO hack for VisualC++ */ @@ -88,7 +90,7 @@ * External stuff. */ extern HINSTANCE SDL_Instance; -extern HWND SDL_Window; +extern HWND SDL_HelperWindow; /* @@ -274,7 +276,7 @@ /* Grab it exclusively to use force feedback stuff. */ ret =IDirectInputDevice2_SetCooperativeLevel( haptic->hwdata->device, - SDL_Window, + SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND ); if (FAILED(ret)) { DI_SetError("Setting cooperative level to exclusive",ret);
--- a/src/joystick/win32/SDL_dxjoystick.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/joystick/win32/SDL_dxjoystick.c Mon Aug 04 11:22:01 2008 +0000 @@ -67,7 +67,7 @@ /* external variables referenced. */ extern HINSTANCE SDL_Instance; -extern HWND SDL_Window; +extern HWND SDL_HelperWindow; /* local variables */ @@ -250,7 +250,7 @@ * though. */ result = IDirectInputDevice2_SetCooperativeLevel(joystick->hwdata-> - InputDevice, SDL_Window, + InputDevice, SDL_HelperWindow, DISCL_EXCLUSIVE | DISCL_BACKGROUND); if (FAILED(result)) {
--- a/src/video/win32/SDL_win32window.c Sun Aug 03 10:25:25 2008 +0000 +++ b/src/video/win32/SDL_win32window.c Mon Aug 04 11:22:01 2008 +0000 @@ -30,6 +30,10 @@ #include "SDL_syswm.h" +/* Fake window to help with DirectInput events. */ +HWND SDL_HelperWindow = NULL; + + static int SetupWindowData(_THIS, SDL_Window * window, HWND hwnd, SDL_bool created) { @@ -409,4 +413,48 @@ } } + +/* + * Creates a HelperWindow used for DirectInput events. + */ +int +SDL_HelperWindowCreate(void) +{ + HINSTANCE hInstance = pGetModuleHandleA(NULL); + const char *class_name = "SDLHelperWindowInputCatcher"; + const char *win_name = "SDLHelperWindowInputMsgWindow"; + WNDCLASSEX wce; + + ZeroMemory(&wce, sizeof (wce)); + wce.cbSize = sizeof(WNDCLASSEX); + wce.lpfnWndProc = RawWndProc; + wce.lpszClassName = class_name; + wce.hInstance = hInstance; + + SDL_HelperWindow = pCreateWindowExA(0, class_name, win_name, WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, HWND_MESSAGE, NULL, hInstance, NULL); + + if (SDL_HelperWindow == NULL) { + SDL_SetError("Unable to create Helper Window."); + return -1; + } + + return 0; +} + + +/* + * Destroys the HelperWindow previously created with SDL_HelperWindowCreate. + */ +void +SDL_HelperWindowDestroy(void) +{ + if (SDL_HelperWindow) { + pDestroyWindow(SDL_HelperWindow); + SDL_HelperWindow = NULL; + } +} + + /* vi: set ts=4 sw=4 expandtab: */