Added a hint to disable windows message processing in SDL_PumpEvents()
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Jun 2014 10:52:34 -0700
changeset 88148a6a21356035
parent 8813 beae556efafc
child 8815 c6d0a457f3b2
Added a hint to disable windows message processing in SDL_PumpEvents()
SDL_SetHint( SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, "0" );
include/SDL_hints.h
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowsvideo.h
     1.1 --- a/include/SDL_hints.h	Wed Jun 04 10:50:32 2014 -0700
     1.2 +++ b/include/SDL_hints.h	Wed Jun 04 10:52:34 2014 -0700
     1.3 @@ -197,6 +197,17 @@
     1.4  #define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN    "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable controlling whether the windows message loop is processed by SDL 
     1.8 + *
     1.9 + *  This variable can be set to the following values:
    1.10 + *    "0"       - The window message loop is not run
    1.11 + *    "1"       - The window message loop is processed in SDL_PumpEvents()
    1.12 + *
    1.13 + *  By default SDL will process the windows message loop
    1.14 + */
    1.15 +#define SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP "SDL_WINDOWS_ENABLE_MESSAGELOOP"
    1.16 +
    1.17 +/**
    1.18   *  \brief  A variable controlling whether grabbing input grabs the keyboard
    1.19   *
    1.20   *  This variable can be set to the following values:
     2.1 --- a/src/video/windows/SDL_windowsevents.c	Wed Jun 04 10:50:32 2014 -0700
     2.2 +++ b/src/video/windows/SDL_windowsevents.c	Wed Jun 04 10:52:34 2014 -0700
     2.3 @@ -890,14 +890,16 @@
     2.4      MSG msg;
     2.5      DWORD start_ticks = GetTickCount();
     2.6  
     2.7 -    while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
     2.8 -        /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
     2.9 -        TranslateMessage(&msg);
    2.10 -        DispatchMessage(&msg);
    2.11 +    if (g_WindowsEnableMessageLoop) {
    2.12 +        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
    2.13 +            /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
    2.14 +            TranslateMessage(&msg);
    2.15 +            DispatchMessage(&msg);
    2.16  
    2.17 -        /* Make sure we don't busy loop here forever if there are lots of events coming in */
    2.18 -        if (SDL_TICKS_PASSED(msg.time, start_ticks)) {
    2.19 -            break;
    2.20 +            /* Make sure we don't busy loop here forever if there are lots of events coming in */
    2.21 +            if (SDL_TICKS_PASSED(msg.time, start_ticks)) {
    2.22 +                break;
    2.23 +            }
    2.24          }
    2.25      }
    2.26  
     3.1 --- a/src/video/windows/SDL_windowsvideo.c	Wed Jun 04 10:50:32 2014 -0700
     3.2 +++ b/src/video/windows/SDL_windowsvideo.c	Wed Jun 04 10:52:34 2014 -0700
     3.3 @@ -39,8 +39,18 @@
     3.4  static void WIN_VideoQuit(_THIS);
     3.5  
     3.6  /* Hints */
     3.7 +SDL_bool g_WindowsEnableMessageLoop = SDL_TRUE;
     3.8  SDL_bool g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
     3.9  
    3.10 +static void UpdateWindowsEnableMessageLoop(void *userdata, const char *name, const char *oldValue, const char *newValue)
    3.11 +{
    3.12 +    if (newValue && *newValue == '0') {
    3.13 +        g_WindowsEnableMessageLoop = SDL_FALSE;
    3.14 +    } else {
    3.15 +        g_WindowsEnableMessageLoop = SDL_TRUE;
    3.16 +    }
    3.17 +}
    3.18 +
    3.19  static void UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const char *oldValue, const char *newValue)
    3.20  {
    3.21      if (newValue && *newValue == '0') {
    3.22 @@ -97,9 +107,9 @@
    3.23  
    3.24      data->userDLL = SDL_LoadObject("USER32.DLL");
    3.25      if (data->userDLL) {
    3.26 -        data->CloseTouchInputHandle = (BOOL (WINAPI *)( HTOUCHINPUT )) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
    3.27 -        data->GetTouchInputInfo = (BOOL (WINAPI *)( HTOUCHINPUT, UINT, PTOUCHINPUT, int )) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
    3.28 -        data->RegisterTouchWindow = (BOOL (WINAPI *)( HWND, ULONG )) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
    3.29 +        data->CloseTouchInputHandle = (BOOL (WINAPI *)(HTOUCHINPUT)) SDL_LoadFunction(data->userDLL, "CloseTouchInputHandle");
    3.30 +        data->GetTouchInputInfo = (BOOL (WINAPI *)(HTOUCHINPUT, UINT, PTOUCHINPUT, int)) SDL_LoadFunction(data->userDLL, "GetTouchInputInfo");
    3.31 +        data->RegisterTouchWindow = (BOOL (WINAPI *)(HWND, ULONG)) SDL_LoadFunction(data->userDLL, "RegisterTouchWindow");
    3.32      }
    3.33  
    3.34      /* Set the function pointers */
    3.35 @@ -178,7 +188,8 @@
    3.36      WIN_InitKeyboard(_this);
    3.37      WIN_InitMouse(_this);
    3.38  
    3.39 -    SDL_AddHintCallback( SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL );
    3.40 +    SDL_AddHintCallback(SDL_HINT_WINDOWS_ENABLE_MESSAGELOOP, UpdateWindowsEnableMessageLoop, NULL);
    3.41 +    SDL_AddHintCallback(SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL);
    3.42  
    3.43      return 0;
    3.44  }
    3.45 @@ -196,7 +207,7 @@
    3.46  #include <d3d9.h>
    3.47  
    3.48  SDL_bool 
    3.49 -D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface )
    3.50 +D3D_LoadDLL(void **pD3DDLL, IDirect3D9 **pDirect3D9Interface)
    3.51  {
    3.52      *pD3DDLL = SDL_LoadObject("D3D9.DLL");
    3.53      if (*pD3DDLL) {
    3.54 @@ -239,7 +250,7 @@
    3.55  
    3.56  
    3.57  int
    3.58 -SDL_Direct3D9GetAdapterIndex( int displayIndex )
    3.59 +SDL_Direct3D9GetAdapterIndex(int displayIndex)
    3.60  {
    3.61      void *pD3DDLL;
    3.62      IDirect3D9 *pD3D;
    3.63 @@ -287,7 +298,7 @@
    3.64  {
    3.65      *pDXGIDLL = SDL_LoadObject("DXGI.DLL");
    3.66      if (*pDXGIDLL) {
    3.67 -        HRESULT (WINAPI *CreateDXGI)( REFIID riid, void **ppFactory );
    3.68 +        HRESULT (WINAPI *CreateDXGI)(REFIID riid, void **ppFactory);
    3.69  
    3.70          CreateDXGI =
    3.71              (HRESULT (WINAPI *) (REFIID, void**)) SDL_LoadFunction(*pDXGIDLL,
    3.72 @@ -365,7 +376,7 @@
    3.73                      *adapterIndex = nAdapter;
    3.74                      *outputIndex = nOutput;
    3.75                  }
    3.76 -                SDL_free( outputName );
    3.77 +                SDL_free(outputName);
    3.78              }
    3.79              IDXGIOutput_Release(pDXGIOutput);
    3.80              nOutput++;
     4.1 --- a/src/video/windows/SDL_windowsvideo.h	Wed Jun 04 10:50:32 2014 -0700
     4.2 +++ b/src/video/windows/SDL_windowsvideo.h	Wed Jun 04 10:52:34 2014 -0700
     4.3 @@ -171,6 +171,7 @@
     4.4      TSFSink *ime_ippasink;
     4.5  } SDL_VideoData;
     4.6  
     4.7 +extern SDL_bool g_WindowsEnableMessageLoop;
     4.8  extern SDL_bool g_WindowFrameUsableWhileCursorHidden;
     4.9  
    4.10  typedef struct IDirect3D9 IDirect3D9;