Added a hint to disable window frame and title bar interaction when the cursor is hidden

This commit is contained in:
Sam Lantinga 2014-06-04 10:50:32 -07:00
parent d34184461f
commit 0d1f0fed71
4 changed files with 88 additions and 70 deletions

View File

@ -185,6 +185,17 @@ extern "C" {
*/ */
#define SDL_HINT_VIDEO_X11_XRANDR "SDL_VIDEO_X11_XRANDR" #define SDL_HINT_VIDEO_X11_XRANDR "SDL_VIDEO_X11_XRANDR"
/**
* \brief A variable controlling whether the window frame and title bar are interactive when the cursor is hidden
*
* This variable can be set to the following values:
* "0" - The window frame is not interactive when the cursor is hidden (no move, resize, etc)
* "1" - The window frame is interactive when the cursor is hidden
*
* By default SDL will allow interaction with the window frame when the cursor is hidden
*/
#define SDL_HINT_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN "SDL_WINDOW_FRAME_USABLE_WHILE_CURSOR_HIDDEN"
/** /**
* \brief A variable controlling whether grabbing input grabs the keyboard * \brief A variable controlling whether grabbing input grabs the keyboard
* *

View File

@ -83,10 +83,8 @@ WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
int nScanCode = (lParam >> 16) & 0xFF; int nScanCode = (lParam >> 16) & 0xFF;
/* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */ /* 0x45 here to work around both pause and numlock sharing the same scancode, so use the VK key to tell them apart */
if ( nScanCode == 0 || nScanCode == 0x45 ) if (nScanCode == 0 || nScanCode == 0x45) {
{ switch(wParam) {
switch( wParam )
{
case VK_CLEAR: return SDL_SCANCODE_CLEAR; case VK_CLEAR: return SDL_SCANCODE_CLEAR;
case VK_MODECHANGE: return SDL_SCANCODE_MODE; case VK_MODECHANGE: return SDL_SCANCODE_MODE;
case VK_SELECT: return SDL_SCANCODE_SELECT; case VK_SELECT: return SDL_SCANCODE_SELECT;
@ -147,10 +145,8 @@ WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
code = windows_scancode_table[nScanCode]; code = windows_scancode_table[nScanCode];
bIsExtended = (lParam & (1 << 24)) != 0; bIsExtended = (lParam & (1 << 24)) != 0;
if ( !bIsExtended ) if (!bIsExtended) {
{ switch (code) {
switch ( code )
{
case SDL_SCANCODE_HOME: case SDL_SCANCODE_HOME:
return SDL_SCANCODE_KP_7; return SDL_SCANCODE_KP_7;
case SDL_SCANCODE_UP: case SDL_SCANCODE_UP:
@ -176,11 +172,8 @@ WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
default: default:
break; break;
} }
} } else {
else switch (code) {
{
switch ( code )
{
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_RETURN:
return SDL_SCANCODE_KP_ENTER; return SDL_SCANCODE_KP_ENTER;
case SDL_SCANCODE_LALT: case SDL_SCANCODE_LALT:
@ -203,12 +196,9 @@ WindowsScanCodeToSDLScanCode( LPARAM lParam, WPARAM wParam )
void void
WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button) WIN_CheckWParamMouseButton(SDL_bool bwParamMousePressed, SDL_bool bSDLMousePressed, SDL_WindowData *data, Uint8 button)
{ {
if ( bwParamMousePressed && !bSDLMousePressed ) if (bwParamMousePressed && !bSDLMousePressed) {
{
SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button); SDL_SendMouseButton(data->window, 0, SDL_PRESSED, button);
} } else if (!bwParamMousePressed && bSDLMousePressed) {
else if ( !bwParamMousePressed && bSDLMousePressed )
{
SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button); SDL_SendMouseButton(data->window, 0, SDL_RELEASED, button);
} }
} }
@ -220,8 +210,7 @@ WIN_CheckWParamMouseButton( SDL_bool bwParamMousePressed, SDL_bool bSDLMousePres
void void
WIN_CheckWParamMouseButtons(WPARAM wParam, SDL_WindowData *data) WIN_CheckWParamMouseButtons(WPARAM wParam, SDL_WindowData *data)
{ {
if ( wParam != data->mouse_button_flags ) if (wParam != data->mouse_button_flags) {
{
Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL); Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL);
WIN_CheckWParamMouseButton((wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT); WIN_CheckWParamMouseButton((wParam & MK_LBUTTON), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT);
WIN_CheckWParamMouseButton((wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE); WIN_CheckWParamMouseButton((wParam & MK_MBUTTON), (mouseFlags & SDL_BUTTON_MMASK), data, SDL_BUTTON_MIDDLE);
@ -236,8 +225,7 @@ WIN_CheckWParamMouseButtons( WPARAM wParam, SDL_WindowData *data )
void void
WIN_CheckRawMouseButtons(ULONG rawButtons, SDL_WindowData *data) WIN_CheckRawMouseButtons(ULONG rawButtons, SDL_WindowData *data)
{ {
if ( rawButtons != data->mouse_button_flags ) if (rawButtons != data->mouse_button_flags) {
{
Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL); Uint32 mouseFlags = SDL_GetMouseState(NULL, NULL);
if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN)) if ((rawButtons & RI_MOUSE_BUTTON_1_DOWN))
WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT); WIN_CheckWParamMouseButton((rawButtons & RI_MOUSE_BUTTON_1_DOWN), (mouseFlags & SDL_BUTTON_LMASK), data, SDL_BUTTON_LEFT);
@ -736,8 +724,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_SIZE: case WM_SIZE:
{ {
switch (wParam) switch (wParam) {
{
case SIZE_MAXIMIZED: case SIZE_MAXIMIZED:
SDL_SendWindowEvent(data->window, SDL_SendWindowEvent(data->window,
SDL_WINDOWEVENT_MAXIMIZED, 0, 0); SDL_WINDOWEVENT_MAXIMIZED, 0, 0);
@ -762,6 +749,9 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if (hittest == HTCLIENT) { if (hittest == HTCLIENT) {
SetCursor(SDL_cursor); SetCursor(SDL_cursor);
returnCode = TRUE; returnCode = TRUE;
} else if (!g_WindowFrameUsableWhileCursorHidden && !SDL_cursor) {
SetCursor(NULL);
returnCode = TRUE;
} }
} }
break; break;

View File

@ -24,6 +24,7 @@
#include "SDL_main.h" #include "SDL_main.h"
#include "SDL_video.h" #include "SDL_video.h"
#include "SDL_hints.h"
#include "SDL_mouse.h" #include "SDL_mouse.h"
#include "SDL_system.h" #include "SDL_system.h"
#include "../SDL_sysvideo.h" #include "../SDL_sysvideo.h"
@ -37,6 +38,18 @@
static int WIN_VideoInit(_THIS); static int WIN_VideoInit(_THIS);
static void WIN_VideoQuit(_THIS); static void WIN_VideoQuit(_THIS);
/* Hints */
SDL_bool g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
static void UpdateWindowFrameUsableWhileCursorHidden(void *userdata, const char *name, const char *oldValue, const char *newValue)
{
if (newValue && *newValue == '0') {
g_WindowFrameUsableWhileCursorHidden = SDL_FALSE;
} else {
g_WindowFrameUsableWhileCursorHidden = SDL_TRUE;
}
}
/* Windows driver bootstrap functions */ /* Windows driver bootstrap functions */
@ -150,6 +163,7 @@ WIN_CreateDevice(int devindex)
return device; return device;
} }
VideoBootStrap WINDOWS_bootstrap = { VideoBootStrap WINDOWS_bootstrap = {
"windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice "windows", "SDL Windows video driver", WIN_Available, WIN_CreateDevice
}; };
@ -164,6 +178,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 );
return 0; return 0;
} }

View File

@ -171,6 +171,7 @@ typedef struct SDL_VideoData
TSFSink *ime_ippasink; TSFSink *ime_ippasink;
} SDL_VideoData; } SDL_VideoData;
extern SDL_bool g_WindowFrameUsableWhileCursorHidden;
typedef struct IDirect3D9 IDirect3D9; typedef struct IDirect3D9 IDirect3D9;
extern SDL_bool D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface ); extern SDL_bool D3D_LoadDLL( void **pD3DDLL, IDirect3D9 **pDirect3D9Interface );