Added a hint to disable window frame and title bar interaction when the cursor is hidden
authorSam Lantinga <slouken@libsdl.org>
Wed, 04 Jun 2014 10:50:32 -0700
changeset 8813beae556efafc
parent 8812 b0f96c169c97
child 8814 8a6a21356035
Added a hint to disable window frame and title bar interaction when the cursor is hidden
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:33:23 2014 -0700
     1.2 +++ b/include/SDL_hints.h	Wed Jun 04 10:50:32 2014 -0700
     1.3 @@ -186,6 +186,17 @@
     1.4  #define SDL_HINT_VIDEO_X11_XRANDR           "SDL_VIDEO_X11_XRANDR"
     1.5  
     1.6  /**
     1.7 + *  \brief  A variable controlling whether the window frame and title bar are interactive when the cursor is hidden 
     1.8 + *
     1.9 + *  This variable can be set to the following values:
    1.10 + *    "0"       - The window frame is not interactive when the cursor is hidden (no move, resize, etc)
    1.11 + *    "1"       - The window frame is interactive when the cursor is hidden
    1.12 + *
    1.13 + *  By default SDL will allow interaction with the window frame when the cursor is hidden
    1.14 + */
    1.15 +#define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN    "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"
    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:33:23 2014 -0700
     2.2 +++ b/src/video/windows/SDL_windowsevents.c	Wed Jun 04 10:50:32 2014 -0700
     2.3 @@ -76,17 +76,15 @@
     2.4  #endif
     2.5  
     2.6  static SDL_Scancode
     2.7 -WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
     2.8 +WindowsScanCodeToSDLScanCode(LPARAM lParam, WPARAM wParam)
     2.9  {
    2.10      SDL_Scancode code;
    2.11      char bIsExtended;
    2.12 -    int nScanCode = ( lParam >> 16 ) & 0xFF;
    2.13 +    int nScanCode = (lParam >> 16) & 0xFF;
    2.14  
    2.15      /* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */
    2.16 -    if ( nScanCode == 0 || nScanCode == 0x45 )
    2.17 -    {
    2.18 -        switch( wParam )
    2.19 -        {
    2.20 +    if (nScanCode == 0 || nScanCode == 0x45) {
    2.21 +        switch(wParam) {
    2.22          case VK_CLEAR: return SDL_SCANCODE_CLEAR;
    2.23          case VK_MODECHANGE: return SDL_SCANCODE_MODE;
    2.24          case VK_SELECT: return SDL_SCANCODE_SELECT;
    2.25 @@ -141,16 +139,14 @@
    2.26          }
    2.27      }
    2.28  
    2.29 -    if ( nScanCode > 127 )
    2.30 +    if (nScanCode > 127)
    2.31          return SDL_SCANCODE_UNKNOWN;
    2.32  
    2.33      code = windows_scancode_table[nScanCode];
    2.34  
    2.35 -    bIsExtended = ( lParam & ( 1 << 24 ) ) != 0;
    2.36 -    if ( !bIsExtended )
    2.37 -    {
    2.38 -        switch ( code )
    2.39 -        {
    2.40 +    bIsExtended = (lParam & (1 << 24)) != 0;
    2.41 +    if (!bIsExtended) {
    2.42 +        switch (code) {
    2.43          case SDL_SCANCODE_HOME:
    2.44              return SDL_SCANCODE_KP_7;
    2.45          case SDL_SCANCODE_UP:
    2.46 @@ -176,11 +172,8 @@
    2.47          default:
    2.48              break;
    2.49          }
    2.50 -    }
    2.51 -    else
    2.52 -    {
    2.53 -        switch ( code )
    2.54 -        {
    2.55 +    } else {
    2.56 +        switch (code) {
    2.57          case SDL_SCANCODE_RETURN:
    2.58              return SDL_SCANCODE_KP_ENTER;
    2.59          case SDL_SCANCODE_LALT:
    2.60 @@ -201,14 +194,11 @@
    2.61  
    2.62  
    2.63  void
    2.64 -WIN_CheckWParamMouseButton( SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button )
    2.65 +WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button)
    2.66  {
    2.67 -    if ( bwParamMousePressed && !bSDLMousePressed )
    2.68 -    {
    2.69 +    if (bwParamMousePressed && !bSDLMousePressed) {
    2.70          SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
    2.71 -    }
    2.72 -    else if ( !bwParamMousePressed && bSDLMousePressed )
    2.73 -    {
    2.74 +    } else if (!bwParamMousePressed && bSDLMousePressed) {
    2.75          SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button);
    2.76      }
    2.77  }
    2.78 @@ -218,53 +208,51 @@
    2.79  *  so this funciton reconciles our view of the world with the current buttons reported by windows
    2.80  */
    2.81  void
    2.82 -WIN_CheckWParamMouseButtons( WPARAM wParam, SDL_WindowData *data )
    2.83 +WIN_CheckWParamMouseButtons(WPARAM wParam, SDL_WindowData *data)
    2.84  {
    2.85 -    if ( wParam != data->mouse_button_flags )
    2.86 -    {
    2.87 -        Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
    2.88 -        WIN_CheckWParamMouseButton(  (wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
    2.89 -        WIN_CheckWParamMouseButton(  (wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
    2.90 -        WIN_CheckWParamMouseButton(  (wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
    2.91 -        WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
    2.92 -        WIN_CheckWParamMouseButton(  (wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
    2.93 +    if (wParam != data->mouse_button_flags) {
    2.94 +        Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL);
    2.95 +        WIN_CheckWParamMouseButton((wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT);
    2.96 +        WIN_CheckWParamMouseButton((wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE);
    2.97 +        WIN_CheckWParamMouseButton((wParam & MK_RBUTTON), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT);
    2.98 +        WIN_CheckWParamMouseButton((wParam & MK_XBUTTON1), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1);
    2.99 +        WIN_CheckWParamMouseButton((wParam & MK_XBUTTON2), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2);
   2.100          data->mouse_button_flags = wParam;
   2.101      }
   2.102  }
   2.103  
   2.104  
   2.105  void
   2.106 -WIN_CheckRawMouseButtons( ULONG rawButtons, SDL_WindowData *data )
   2.107 +WIN_CheckRawMouseButtons(ULONG rawButtons, SDL_WindowData *data)
   2.108  {
   2.109 -    if ( rawButtons != data->mouse_button_flags )
   2.110 -    {
   2.111 -        Uint32 mouseFlags = SDL_GetMouseState( NULL, NULL );
   2.112 -        if ( (rawButtons & RI_MOUSE_BUTTON_1_DOWN) )
   2.113 -            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   2.114 -        if ( (rawButtons & RI_MOUSE_BUTTON_1_UP) )
   2.115 -            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT );
   2.116 -        if ( (rawButtons & RI_MOUSE_BUTTON_2_DOWN) )
   2.117 -            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   2.118 -        if ( (rawButtons & RI_MOUSE_BUTTON_2_UP) )
   2.119 -            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT );
   2.120 -        if ( (rawButtons & RI_MOUSE_BUTTON_3_DOWN) )
   2.121 -            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   2.122 -        if ( (rawButtons & RI_MOUSE_BUTTON_3_UP) )
   2.123 -            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE );
   2.124 -        if ( (rawButtons & RI_MOUSE_BUTTON_4_DOWN) )
   2.125 -            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   2.126 -        if ( (rawButtons & RI_MOUSE_BUTTON_4_UP) )
   2.127 -            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1 );
   2.128 -        if ( (rawButtons & RI_MOUSE_BUTTON_5_DOWN) )
   2.129 -            WIN_CheckWParamMouseButton(  (rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   2.130 -        if ( (rawButtons & RI_MOUSE_BUTTON_5_UP) )
   2.131 -            WIN_CheckWParamMouseButton(  !(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2 );
   2.132 +    if (rawButtons != data->mouse_button_flags) {
   2.133 +        Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL);
   2.134 +        if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN))
   2.135 +            WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT);
   2.136 +        if ((rawButtons & RI_MOUSE_BUTTON_1_UP))
   2.137 +            WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_1_UP), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT);
   2.138 +        if ((rawButtons & RI_MOUSE_BUTTON_2_DOWN))
   2.139 +            WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_2_DOWN), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT);
   2.140 +        if ((rawButtons & RI_MOUSE_BUTTON_2_UP))
   2.141 +            WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_2_UP), (mouseFlags & SDL_BUTTON_RMASK), data, SDL_BUTTON_RIGHT);
   2.142 +        if ((rawButtons & RI_MOUSE_BUTTON_3_DOWN))
   2.143 +            WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_3_DOWN), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE);
   2.144 +        if ((rawButtons & RI_MOUSE_BUTTON_3_UP))
   2.145 +            WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_3_UP), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE);
   2.146 +        if ((rawButtons & RI_MOUSE_BUTTON_4_DOWN))
   2.147 +            WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_4_DOWN), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1);
   2.148 +        if ((rawButtons & RI_MOUSE_BUTTON_4_UP))
   2.149 +            WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_4_UP), (mouseFlags & SDL_BUTTON_X1MASK), data, SDL_BUTTON_X1);
   2.150 +        if ((rawButtons & RI_MOUSE_BUTTON_5_DOWN))
   2.151 +            WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_5_DOWN), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2);
   2.152 +        if ((rawButtons & RI_MOUSE_BUTTON_5_UP))
   2.153 +            WIN_CheckWParamMouseButton(!(rawButtons & RI_MOUSE_BUTTON_5_UP), (mouseFlags & SDL_BUTTON_X2MASK), data, SDL_BUTTON_X2);
   2.154          data->mouse_button_flags = rawButtons;
   2.155      }
   2.156  }
   2.157  
   2.158  void
   2.159 -WIN_CheckAsyncMouseRelease( SDL_WindowData *data )
   2.160 +WIN_CheckAsyncMouseRelease(SDL_WindowData *data)
   2.161  {
   2.162      Uint32 mouseFlags;
   2.163      SHORT keyState;
   2.164 @@ -272,9 +260,9 @@
   2.165      /* mouse buttons may have changed state here, we need to resync them,
   2.166         but we will get a WM_MOUSEMOVE right away which will fix things up if in non raw mode also
   2.167      */
   2.168 -    mouseFlags = SDL_GetMouseState( NULL, NULL );
   2.169 +    mouseFlags = SDL_GetMouseState(NULL, NULL);
   2.170  
   2.171 -    keyState = GetAsyncKeyState( VK_LBUTTON );
   2.172 +    keyState = GetAsyncKeyState(VK_LBUTTON);
   2.173      if (!(keyState & 0x8000)) {
   2.174          WIN_CheckWParamMouseButton(SDL_FALSE, (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT);
   2.175      }
   2.176 @@ -465,12 +453,12 @@
   2.177                          initialMousePoint.y = mouse->lLastY;
   2.178                      }
   2.179  
   2.180 -                    SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y) );
   2.181 +                    SDL_SendMouseMotion(data->window, 0, 1, (int)(mouse->lLastX-initialMousePoint.x), (int)(mouse->lLastY-initialMousePoint.y));
   2.182  
   2.183                      initialMousePoint.x = mouse->lLastX;
   2.184                      initialMousePoint.y = mouse->lLastY;
   2.185                  }
   2.186 -                WIN_CheckRawMouseButtons( mouse->usButtonFlags, data );
   2.187 +                WIN_CheckRawMouseButtons(mouse->usButtonFlags, data);
   2.188              }
   2.189          }
   2.190          break;
   2.191 @@ -531,9 +519,9 @@
   2.192      case WM_KEYDOWN:
   2.193      case WM_SYSKEYDOWN:
   2.194          {
   2.195 -            SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
   2.196 -            if ( code != SDL_SCANCODE_UNKNOWN ) {
   2.197 -                SDL_SendKeyboardKey(SDL_PRESSED, code );
   2.198 +            SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
   2.199 +            if (code != SDL_SCANCODE_UNKNOWN) {
   2.200 +                SDL_SendKeyboardKey(SDL_PRESSED, code);
   2.201              }
   2.202          }
   2.203          if (msg == WM_KEYDOWN) {
   2.204 @@ -556,18 +544,18 @@
   2.205      case WM_SYSKEYUP:
   2.206      case WM_KEYUP:
   2.207          {
   2.208 -            SDL_Scancode code = WindowsScanCodeToSDLScanCode( lParam, wParam );
   2.209 +            SDL_Scancode code = WindowsScanCodeToSDLScanCode(lParam, wParam);
   2.210              const Uint8 *keyboardState = SDL_GetKeyboardState(NULL);
   2.211  
   2.212              /* Detect relevant keyboard shortcuts */
   2.213 -            if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED ) {
   2.214 +            if (keyboardState[SDL_SCANCODE_LALT] == SDL_PRESSED || keyboardState[SDL_SCANCODE_RALT] == SDL_PRESSED) {
   2.215                  /* ALT+F4: Close window */
   2.216                  if (code == SDL_SCANCODE_F4) {
   2.217                      SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
   2.218                  }
   2.219              }
   2.220  
   2.221 -            if ( code != SDL_SCANCODE_UNKNOWN ) {
   2.222 +            if (code != SDL_SCANCODE_UNKNOWN) {
   2.223                  if (code == SDL_SCANCODE_PRINTSCREEN &&
   2.224                      keyboardState[code] == SDL_RELEASED) {
   2.225                      SDL_SendKeyboardKey(SDL_PRESSED, code);
   2.226 @@ -736,8 +724,7 @@
   2.227  
   2.228      case WM_SIZE:
   2.229          {
   2.230 -            switch (wParam)
   2.231 -            {
   2.232 +            switch (wParam) {
   2.233              case SIZE_MAXIMIZED:
   2.234                  SDL_SendWindowEvent(data->window,
   2.235                      SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
   2.236 @@ -762,6 +749,9 @@
   2.237              if (hittest == HTCLIENT) {
   2.238                  SetCursor(SDL_cursor);
   2.239                  returnCode = TRUE;
   2.240 +            } else if (!g_WindowFrameUsableWhileCursorHidden && !SDL_cursor) {
   2.241 +                SetCursor(NULL);
   2.242 +                returnCode = TRUE;
   2.243              }
   2.244          }
   2.245          break;
   2.246 @@ -903,7 +893,7 @@
   2.247      while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
   2.248          /* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */
   2.249          TranslateMessage(&msg);
   2.250 -        DispatchMessage( &msg );
   2.251 +        DispatchMessage(&msg);
   2.252  
   2.253          /* Make sure we don't busy loop here forever if there are lots of events coming in */
   2.254          if (SDL_TICKS_PASSED(msg.time, start_ticks)) {
     3.1 --- a/src/video/windows/SDL_windowsvideo.c	Wed Jun 04 10:33:23 2014 -0700
     3.2 +++ b/src/video/windows/SDL_windowsvideo.c	Wed Jun 04 10:50:32 2014 -0700
     3.3 @@ -24,6 +24,7 @@
     3.4  
     3.5  #include "SDL_main.h"
     3.6  #include "SDL_video.h"
     3.7 +#include "SDL_hints.h"
     3.8  #include "SDL_mouse.h"
     3.9  #include "SDL_system.h"
    3.10  #include "../SDL_sysvideo.h"
    3.11 @@ -37,6 +38,18 @@
    3.12  static int WIN_VideoInit(_THIS);
    3.13  static void WIN_VideoQuit(_THIS);
    3.14  
    3.15 +/* Hints */
    3.16 +SDL_bool g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
    3.17 +
    3.18 +static void UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const char *oldValue, const char *newValue)
    3.19 +{
    3.20 +    if (newValue && *newValue == '0') {
    3.21 +        g_WindowFrameUsableWhileCursorHidden = SDL_FALSE;
    3.22 +    } else {
    3.23 +        g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
    3.24 +    }
    3.25 +}
    3.26 +
    3.27  
    3.28  /* Windows driver bootstrap functions */
    3.29  
    3.30 @@ -150,6 +163,7 @@
    3.31      return device;
    3.32  }
    3.33  
    3.34 +
    3.35  VideoBootStrap WINDOWS_bootstrap = {
    3.36      "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
    3.37  };
    3.38 @@ -164,6 +178,8 @@
    3.39      WIN_InitKeyboard(_this);
    3.40      WIN_InitMouse(_this);
    3.41  
    3.42 +    SDL_AddHintCallback( SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN, UpdateWindowFrameUsableWhileCursorHidden, NULL );
    3.43 +
    3.44      return 0;
    3.45  }
    3.46  
     4.1 --- a/src/video/windows/SDL_windowsvideo.h	Wed Jun 04 10:33:23 2014 -0700
     4.2 +++ b/src/video/windows/SDL_windowsvideo.h	Wed Jun 04 10:50:32 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_WindowFrameUsableWhileCursorHidden;
     4.8  
     4.9  typedef struct IDirect3D9 IDirect3D9;
    4.10  extern SDL_bool D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface );