1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Removed GLFW_SYSTEM_KEYS from the GLFW API

Rationale: Disabling system commands is inherently
dangerous, and should not be encouraged. Also, it's very
difficult to define and implement a reliable and
consistent cross-platform mechanism.
This commit is contained in:
m@bitsnbites.eu 2012-10-28 00:50:38 +02:00 committed by m
parent 424e7c7b53
commit 1c21fc1383
12 changed files with 5 additions and 295 deletions

View File

@ -434,8 +434,7 @@ extern "C" {
#define GLFW_CURSOR_MODE 0x00030001 #define GLFW_CURSOR_MODE 0x00030001
#define GLFW_STICKY_KEYS 0x00030002 #define GLFW_STICKY_KEYS 0x00030002
#define GLFW_STICKY_MOUSE_BUTTONS 0x00030003 #define GLFW_STICKY_MOUSE_BUTTONS 0x00030003
#define GLFW_SYSTEM_KEYS 0x00030004 #define GLFW_KEY_REPEAT 0x00030004
#define GLFW_KEY_REPEAT 0x00030005
/* GLFW_CURSOR_MODE values */ /* GLFW_CURSOR_MODE values */
#define GLFW_CURSOR_NORMAL 0x00040001 #define GLFW_CURSOR_NORMAL 0x00040001

View File

@ -13,7 +13,7 @@ set(common_SOURCES clipboard.c fullscreen.c gamma.c init.c input.c
if (_GLFW_COCOA_NSGL) if (_GLFW_COCOA_NSGL)
set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h)
set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_fullscreen.m set(glfw_SOURCES ${common_SOURCES} cocoa_clipboard.m cocoa_fullscreen.m
cocoa_gamma.c cocoa_init.m cocoa_input.m cocoa_joystick.m cocoa_gamma.c cocoa_init.m cocoa_joystick.m
cocoa_opengl.m cocoa_time.c cocoa_window.m) cocoa_opengl.m cocoa_time.c cocoa_window.m)
if (GLFW_NATIVE_API) if (GLFW_NATIVE_API)
@ -25,7 +25,7 @@ if (_GLFW_COCOA_NSGL)
elseif (_GLFW_WIN32_WGL) elseif (_GLFW_WIN32_WGL)
set(glfw_HEADERS ${common_HEADERS} win32_platform.h) set(glfw_HEADERS ${common_HEADERS} win32_platform.h)
set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c set(glfw_SOURCES ${common_SOURCES} win32_clipboard.c win32_fullscreen.c
win32_gamma.c win32_init.c win32_input.c win32_joystick.c win32_gamma.c win32_init.c win32_joystick.c
win32_opengl.c win32_time.c win32_window.c) win32_opengl.c win32_time.c win32_window.c)
if (GLFW_NATIVE_API) if (GLFW_NATIVE_API)
@ -34,7 +34,7 @@ elseif (_GLFW_WIN32_WGL)
elseif (_GLFW_X11_GLX) elseif (_GLFW_X11_GLX)
set(glfw_HEADERS ${common_HEADERS} x11_platform.h) set(glfw_HEADERS ${common_HEADERS} x11_platform.h)
set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c set(glfw_SOURCES ${common_SOURCES} x11_clipboard.c x11_fullscreen.c
x11_gamma.c x11_init.c x11_input.c x11_joystick.c x11_gamma.c x11_init.c x11_joystick.c
x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c)
if (GLFW_NATIVE_API) if (GLFW_NATIVE_API)

View File

@ -1,53 +0,0 @@
//========================================================================
// GLFW - An OpenGL library
// Platform: Cocoa
// API Version: 3.0
// WWW: http://www.glfw.org/
//------------------------------------------------------------------------
// Copyright (c) 2009-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Enable and disable system keys
//========================================================================
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
{
// This is checked in cocoa_window.m; no action needed here
}
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window)
{
// This is checked in cocoa_window.m; no action needed here
// Note that it may not be possible to disable things like Exposé
// except in full-screen mode.
}

View File

@ -455,8 +455,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
if ([event modifierFlags] & NSCommandKeyMask) if ([event modifierFlags] & NSCommandKeyMask)
{ {
if (window->systemKeys) [super keyDown:event];
[super keyDown:event];
} }
else else
{ {

View File

@ -115,24 +115,6 @@ static void setStickyMouseButtons(_GLFWwindow* window, int enabled)
} }
//========================================================================
// Set system keys for the specified window
//========================================================================
static void setSystemKeys(_GLFWwindow* window, int enabled)
{
if (window->systemKeys == enabled)
return;
if (enabled)
_glfwPlatformEnableSystemKeys(window);
else
_glfwPlatformDisableSystemKeys(window);
window->systemKeys = enabled;
}
//======================================================================== //========================================================================
// Set key repeat for the specified window // Set key repeat for the specified window
//======================================================================== //========================================================================
@ -295,8 +277,6 @@ GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode)
return window->stickyKeys; return window->stickyKeys;
case GLFW_STICKY_MOUSE_BUTTONS: case GLFW_STICKY_MOUSE_BUTTONS:
return window->stickyMouseButtons; return window->stickyMouseButtons;
case GLFW_SYSTEM_KEYS:
return window->systemKeys;
case GLFW_KEY_REPEAT: case GLFW_KEY_REPEAT:
return window->keyRepeat; return window->keyRepeat;
default: default:
@ -331,9 +311,6 @@ GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value)
case GLFW_STICKY_MOUSE_BUTTONS: case GLFW_STICKY_MOUSE_BUTTONS:
setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE); setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE);
break; break;
case GLFW_SYSTEM_KEYS:
setSystemKeys(window, value ? GL_TRUE : GL_FALSE);
break;
case GLFW_KEY_REPEAT: case GLFW_KEY_REPEAT:
setKeyRepeat(window, value ? GL_TRUE : GL_FALSE); setKeyRepeat(window, value ? GL_TRUE : GL_FALSE);
break; break;

View File

@ -186,7 +186,6 @@ struct _GLFWwindow
GLboolean stickyKeys; GLboolean stickyKeys;
GLboolean stickyMouseButtons; GLboolean stickyMouseButtons;
GLboolean keyRepeat; GLboolean keyRepeat;
GLboolean systemKeys; // system keys enabled flag
int cursorPosX, cursorPosY; int cursorPosX, cursorPosY;
int cursorMode; int cursorMode;
double scrollX, scrollY; double scrollX, scrollY;

View File

@ -1,132 +0,0 @@
//========================================================================
// GLFW - An OpenGL library
// Platform: Win32
// API version: 3.0
// WWW: http://www.glfw.org/
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
//========================================================================
// Low level keyboard hook (system callback) function
// Used to disable system keys under Windows NT
//========================================================================
static LRESULT CALLBACK keyboardHook(int nCode, WPARAM wParam, LPARAM lParam)
{
BOOL syskeys = FALSE;
PKBDLLHOOKSTRUCT p;
// We are only looking for keyboard events - interpret lParam as a
// pointer to a KBDLLHOOKSTRUCT
p = (PKBDLLHOOKSTRUCT) lParam;
if (nCode == HC_ACTION)
{
// We have a keyboard event
switch (wParam)
{
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
case WM_KEYUP:
case WM_SYSKEYUP:
// Detect: ALT+TAB, ALT+ESC, ALT+F4, CTRL+ESC,
// LWIN, RWIN, APPS (mysterious menu key)
syskeys = (p->vkCode == VK_TAB &&
p->flags & LLKHF_ALTDOWN) ||
(p->vkCode == VK_ESCAPE &&
p->flags & LLKHF_ALTDOWN) ||
(p->vkCode == VK_F4 &&
p->flags & LLKHF_ALTDOWN) ||
(p->vkCode == VK_ESCAPE &&
(GetKeyState(VK_CONTROL) & 0x8000)) ||
p->vkCode == VK_LWIN ||
p->vkCode == VK_RWIN ||
p->vkCode == VK_APPS;
break;
default:
break;
}
}
// Was it a system key combination (e.g. ALT+TAB)?
if (syskeys)
{
_GLFWwindow* window = _glfwLibrary.activeWindow;
// Pass the key event to our window message loop
if (window)
PostMessage(window->Win32.handle, (UINT) wParam, p->vkCode, 0);
// We've taken care of it - don't let the system know about this
// key event
return 1;
}
else
{
// It's a harmless key press, let the system deal with it
return CallNextHookEx(_glfwLibrary.Win32.keyboardHook, nCode, wParam, lParam);
}
}
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Enable system keys
//========================================================================
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
{
UNREFERENCED_PARAMETER(window);
if (_glfwLibrary.Win32.keyboardHook != NULL)
{
UnhookWindowsHookEx(_glfwLibrary.Win32.keyboardHook);
_glfwLibrary.Win32.keyboardHook = NULL;
}
}
//========================================================================
// Disable system keys
//========================================================================
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window)
{
UNREFERENCED_PARAMETER(window);
_glfwLibrary.Win32.keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL,
keyboardHook,
_glfwLibrary.Win32.instance,
0);
}

View File

@ -176,7 +176,6 @@ typedef struct _GLFWlibraryWin32
{ {
HINSTANCE instance; // Instance of the application HINSTANCE instance; // Instance of the application
ATOM classAtom; // Window class atom ATOM classAtom; // Window class atom
HHOOK keyboardHook; // Keyboard hook handle
DWORD foregroundLockTimeout; DWORD foregroundLockTimeout;
char* clipboardString; char* clipboardString;

View File

@ -297,7 +297,6 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
window->mode = mode; window->mode = mode;
window->resizable = wndconfig.resizable; window->resizable = wndconfig.resizable;
window->cursorMode = GLFW_CURSOR_NORMAL; window->cursorMode = GLFW_CURSOR_NORMAL;
window->systemKeys = GL_TRUE;
// Open the actual window and create its context // Open the actual window and create its context
if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig)) if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig))

View File

@ -1,65 +0,0 @@
//========================================================================
// GLFW - An OpenGL library
// Platform: X11
// API version: 3.0
// WWW: http://www.glfw.org/
//------------------------------------------------------------------------
// Copyright (c) 2002-2006 Marcus Geelnard
// Copyright (c) 2006-2010 Camilla Berglund <elmindreda@elmindreda.org>
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would
// be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
//========================================================================
#include "internal.h"
//////////////////////////////////////////////////////////////////////////
////// GLFW platform API //////
//////////////////////////////////////////////////////////////////////////
//========================================================================
// Enable system keys
//========================================================================
void _glfwPlatformEnableSystemKeys(_GLFWwindow* window)
{
if (window->X11.keyboardGrabbed)
{
XUngrabKeyboard(_glfwLibrary.X11.display, CurrentTime);
window->X11.keyboardGrabbed = GL_FALSE;
}
}
//========================================================================
// Disable system keys
//========================================================================
void _glfwPlatformDisableSystemKeys(_GLFWwindow* window)
{
if (XGrabKeyboard(_glfwLibrary.X11.display, window->X11.handle,
True, GrabModeAsync, GrabModeAsync, CurrentTime)
== GrabSuccess)
{
window->X11.keyboardGrabbed = GL_TRUE;
}
}

View File

@ -135,7 +135,6 @@ typedef struct _GLFWwindowX11
// Various platform specific internal variables // Various platform specific internal variables
GLboolean overrideRedirect; // True if window is OverrideRedirect GLboolean overrideRedirect; // True if window is OverrideRedirect
GLboolean keyboardGrabbed; // True if keyboard is currently grabbed
GLboolean cursorGrabbed; // True if cursor is currently grabbed GLboolean cursorGrabbed; // True if cursor is currently grabbed
GLboolean cursorHidden; // True if cursor is currently hidden GLboolean cursorHidden; // True if cursor is currently hidden
GLboolean cursorCentered; // True if cursor was moved since last poll GLboolean cursorCentered; // True if cursor was moved since last poll

View File

@ -42,7 +42,6 @@
// These must match the input mode defaults // These must match the input mode defaults
static GLboolean keyrepeat = GL_FALSE; static GLboolean keyrepeat = GL_FALSE;
static GLboolean systemkeys = GL_TRUE;
static GLboolean closeable = GL_TRUE; static GLboolean closeable = GL_TRUE;
// Event index // Event index
@ -320,15 +319,6 @@ static void key_callback(GLFWwindow window, int key, int action)
break; break;
} }
case GLFW_KEY_S:
{
systemkeys = !systemkeys;
glfwSetInputMode(window, GLFW_SYSTEM_KEYS, systemkeys);
printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled");
break;
}
case GLFW_KEY_C: case GLFW_KEY_C:
{ {
closeable = !closeable; closeable = !closeable;
@ -393,7 +383,6 @@ int main(void)
printf("Window size should be %ix%i\n", width, height); printf("Window size should be %ix%i\n", width, height);
printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled"); printf("Key repeat should be %s\n", keyrepeat ? "enabled" : "disabled");
printf("System keys should be %s\n", systemkeys ? "enabled" : "disabled");
printf("Main loop starting\n"); printf("Main loop starting\n");