Skip to content

Commit

Permalink
Added a hint to disable windows message processing in SDL_PumpEvents()
Browse files Browse the repository at this point in the history
SDL_SetHint( SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, "0" );
  • Loading branch information
slouken committed Jun 4, 2014
1 parent 0d1f0fe commit 3e3b34a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
11 changes: 11 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -196,6 +196,17 @@ extern "C" {
*/ */
#define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN" #define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"


/**
* \brief A variable controlling whether the windows message loop is processed by SDL
*
* This variable can be set to the following values:
* "0" - The window message loop is not run
* "1" - The window message loop is processed in SDL_PumpEvents()
*
* By default SDL will process the windows message loop
*/
#define SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP "SDL_WINDOWS_ENABLE_MESSAGELOOP"

/** /**
* \brief A variable controlling whether grabbing input grabs the keyboard * \brief A variable controlling whether grabbing input grabs the keyboard
* *
Expand Down
18 changes: 10 additions & 8 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -890,14 +890,16 @@ WIN_PumpEvents(_THIS)
MSG msg; MSG msg;
DWORD start_ticks = GetTickCount(); DWORD start_ticks = GetTickCount();


while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (g_WindowsEnableMessageLoop) {
/* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */ while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg); /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
DispatchMessage(&msg); TranslateMessage(&msg);

DispatchMessage(&msg);
/* Make sure we don't busy loop here forever if there are lots of events coming in */
if (SDL_TICKS_PASSED(msg.time, start_ticks)) { /* Make sure we don't busy loop here forever if there are lots of events coming in */
break; if (SDL_TICKS_PASSED(msg.time, start_ticks)) {
break;
}
} }
} }


Expand Down
27 changes: 19 additions & 8 deletions src/video/windows/SDL_windowsvideo.c
Expand Up @@ -39,8 +39,18 @@ static int WIN_VideoInit(_THIS);
static void WIN_VideoQuit(_THIS); static void WIN_VideoQuit(_THIS);


/* Hints */ /* Hints */
SDL_bool g_WindowsEnableMessageLoop = SDL_TRUE;
SDL_bool g_WindowFrameUsableWhileCursorHidden = SDL_TRUE; SDL_bool g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;


static void UpdateWindowsEnableMessageLoop(void *userdata, const char *name, const char *oldValue, const char *newValue)
{
if (newValue && *newValue == '0') {
g_WindowsEnableMessageLoop = SDL_FALSE;
} else {
g_WindowsEnableMessageLoop = SDL_TRUE;
}
}

static void UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const char *oldValue, const char *newValue) static void UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const char *oldValue, const char *newValue)
{ {
if (newValue && *newValue == '0') { if (newValue && *newValue == '0') {
Expand Down Expand Up @@ -97,9 +107,9 @@ WIN_CreateDevice(int devindex)


data->userDLL = SDL_LoadObject("USER32.DLL"); data->userDLL = SDL_LoadObject("USER32.DLL");
if (data->userDLL) { if (data->userDLL) {
data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle"); data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo"); data->GetTouchInputInfo = (BOOL (WINAPI *)(HTOUCHINPUT, UINT, PTOUCHINPUT, int)) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow"); data->RegisterTouchWindow = (BOOL (WINAPI *)(HWND, ULONG)) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
} }


/* Set the function pointers */ /* Set the function pointers */
Expand Down Expand Up @@ -178,7 +188,8 @@ WIN_VideoInit(_THIS)
WIN_InitKeyboard(_this); WIN_InitKeyboard(_this);
WIN_InitMouse(_this); WIN_InitMouse(_this);


SDL_AddHintCallback( SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL ); SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);


return 0; return 0;
} }
Expand All @@ -196,7 +207,7 @@ WIN_VideoQuit(_THIS)
#include <d3d9.h> #include <d3d9.h>


SDL_bool SDL_bool
D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface ) D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface)
{ {
*pD3DDLL = SDL_LoadObject("D3D9.DLL"); *pD3DDLL = SDL_LoadObject("D3D9.DLL");
if (*pD3DDLL) { if (*pD3DDLL) {
Expand Down Expand Up @@ -239,7 +250,7 @@ D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )




int int
SDL_Direct3D9GetAdapterIndex( int displayIndex ) SDL_Direct3D9GetAdapterIndex(int displayIndex)
{ {
void *pD3DDLL; void *pD3DDLL;
IDirect3D9 *pD3D; IDirect3D9 *pD3D;
Expand Down Expand Up @@ -287,7 +298,7 @@ DXGI_LoadDLL(void **pDXGIDLL, IDXGIFactory **pDXGIFactory)
{ {
*pDXGIDLL = SDL_LoadObject("DXGI.DLL"); *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
if (*pDXGIDLL) { if (*pDXGIDLL) {
HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory ); HRESULT (WINAPI *CreateDXGI)(REFIID riid, void **ppFactory);


CreateDXGI = CreateDXGI =
(HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL, (HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
Expand Down Expand Up @@ -365,7 +376,7 @@ SDL_DXGIGetOutputInfo(int displayIndex, int *adapterIndex, int *outputIndex)
*adapterIndex = nAdapter; *adapterIndex = nAdapter;
*outputIndex = nOutput; *outputIndex = nOutput;
} }
SDL_free( outputName ); SDL_free(outputName);
} }
IDXGIOutput_Release(pDXGIOutput); IDXGIOutput_Release(pDXGIOutput);
nOutput++; nOutput++;
Expand Down
1 change: 1 addition & 0 deletions src/video/windows/SDL_windowsvideo.h
Expand Up @@ -171,6 +171,7 @@ typedef struct SDL_VideoData
TSFSink *ime_ippasink; TSFSink *ime_ippasink;
} SDL_VideoData; } SDL_VideoData;


extern SDL_bool g_WindowsEnableMessageLoop;
extern SDL_bool g_WindowFrameUsableWhileCursorHidden; extern SDL_bool g_WindowFrameUsableWhileCursorHidden;


typedef struct IDirect3D9 IDirect3D9; typedef struct IDirect3D9 IDirect3D9;
Expand Down

0 comments on commit 3e3b34a

Please sign in to comment.