From 1c21fc1383366c11488a774fe0d2d187d0c67d71 Mon Sep 17 00:00:00 2001 From: "m@bitsnbites.eu" Date: Sun, 28 Oct 2012 00:50:38 +0200 Subject: [PATCH] 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. --- include/GL/glfw3.h | 3 +- src/CMakeLists.txt | 6 +- src/cocoa_input.m | 53 ----------------- src/cocoa_window.m | 3 +- src/input.c | 23 -------- src/internal.h | 1 - src/win32_input.c | 132 ------------------------------------------- src/win32_platform.h | 1 - src/window.c | 1 - src/x11_input.c | 65 --------------------- src/x11_platform.h | 1 - tests/events.c | 11 ---- 12 files changed, 5 insertions(+), 295 deletions(-) delete mode 100644 src/cocoa_input.m delete mode 100644 src/win32_input.c delete mode 100644 src/x11_input.c diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 191633a2..52ab1a75 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -434,8 +434,7 @@ extern "C" { #define GLFW_CURSOR_MODE 0x00030001 #define GLFW_STICKY_KEYS 0x00030002 #define GLFW_STICKY_MOUSE_BUTTONS 0x00030003 -#define GLFW_SYSTEM_KEYS 0x00030004 -#define GLFW_KEY_REPEAT 0x00030005 +#define GLFW_KEY_REPEAT 0x00030004 /* GLFW_CURSOR_MODE values */ #define GLFW_CURSOR_NORMAL 0x00040001 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d066b70..783a2c35 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -13,7 +13,7 @@ set(common_SOURCES clipboard.c fullscreen.c gamma.c init.c input.c if (_GLFW_COCOA_NSGL) set(glfw_HEADERS ${common_HEADERS} cocoa_platform.h) 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) if (GLFW_NATIVE_API) @@ -25,7 +25,7 @@ if (_GLFW_COCOA_NSGL) elseif (_GLFW_WIN32_WGL) set(glfw_HEADERS ${common_HEADERS} win32_platform.h) 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) if (GLFW_NATIVE_API) @@ -34,7 +34,7 @@ elseif (_GLFW_WIN32_WGL) elseif (_GLFW_X11_GLX) set(glfw_HEADERS ${common_HEADERS} x11_platform.h) 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) if (GLFW_NATIVE_API) diff --git a/src/cocoa_input.m b/src/cocoa_input.m deleted file mode 100644 index 11e1083b..00000000 --- a/src/cocoa_input.m +++ /dev/null @@ -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 -// -// 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. -} - diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 5e4c7d81..24ba6628 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -455,8 +455,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) if ([event modifierFlags] & NSCommandKeyMask) { - if (window->systemKeys) - [super keyDown:event]; + [super keyDown:event]; } else { diff --git a/src/input.c b/src/input.c index 701da4f0..46c9da6e 100644 --- a/src/input.c +++ b/src/input.c @@ -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 //======================================================================== @@ -295,8 +277,6 @@ GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode) return window->stickyKeys; case GLFW_STICKY_MOUSE_BUTTONS: return window->stickyMouseButtons; - case GLFW_SYSTEM_KEYS: - return window->systemKeys; case GLFW_KEY_REPEAT: return window->keyRepeat; default: @@ -331,9 +311,6 @@ GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value) case GLFW_STICKY_MOUSE_BUTTONS: setStickyMouseButtons(window, value ? GL_TRUE : GL_FALSE); break; - case GLFW_SYSTEM_KEYS: - setSystemKeys(window, value ? GL_TRUE : GL_FALSE); - break; case GLFW_KEY_REPEAT: setKeyRepeat(window, value ? GL_TRUE : GL_FALSE); break; diff --git a/src/internal.h b/src/internal.h index 2101ad23..50bfa4c6 100644 --- a/src/internal.h +++ b/src/internal.h @@ -186,7 +186,6 @@ struct _GLFWwindow GLboolean stickyKeys; GLboolean stickyMouseButtons; GLboolean keyRepeat; - GLboolean systemKeys; // system keys enabled flag int cursorPosX, cursorPosY; int cursorMode; double scrollX, scrollY; diff --git a/src/win32_input.c b/src/win32_input.c deleted file mode 100644 index 2178b145..00000000 --- a/src/win32_input.c +++ /dev/null @@ -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 -// -// 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); -} - diff --git a/src/win32_platform.h b/src/win32_platform.h index ba10039e..217fc2cf 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -176,7 +176,6 @@ typedef struct _GLFWlibraryWin32 { HINSTANCE instance; // Instance of the application ATOM classAtom; // Window class atom - HHOOK keyboardHook; // Keyboard hook handle DWORD foregroundLockTimeout; char* clipboardString; diff --git a/src/window.c b/src/window.c index 986a0cb6..73bc1698 100644 --- a/src/window.c +++ b/src/window.c @@ -297,7 +297,6 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, window->mode = mode; window->resizable = wndconfig.resizable; window->cursorMode = GLFW_CURSOR_NORMAL; - window->systemKeys = GL_TRUE; // Open the actual window and create its context if (!_glfwPlatformCreateWindow(window, &wndconfig, &fbconfig)) diff --git a/src/x11_input.c b/src/x11_input.c deleted file mode 100644 index 2ea8b8c4..00000000 --- a/src/x11_input.c +++ /dev/null @@ -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 -// -// 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; - } -} - diff --git a/src/x11_platform.h b/src/x11_platform.h index e2897216..e577c22f 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -135,7 +135,6 @@ typedef struct _GLFWwindowX11 // Various platform specific internal variables GLboolean overrideRedirect; // True if window is OverrideRedirect - GLboolean keyboardGrabbed; // True if keyboard is currently grabbed GLboolean cursorGrabbed; // True if cursor is currently grabbed GLboolean cursorHidden; // True if cursor is currently hidden GLboolean cursorCentered; // True if cursor was moved since last poll diff --git a/tests/events.c b/tests/events.c index 9379ded9..4e3002cf 100644 --- a/tests/events.c +++ b/tests/events.c @@ -42,7 +42,6 @@ // These must match the input mode defaults static GLboolean keyrepeat = GL_FALSE; -static GLboolean systemkeys = GL_TRUE; static GLboolean closeable = GL_TRUE; // Event index @@ -320,15 +319,6 @@ static void key_callback(GLFWwindow window, int key, int action) 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: { closeable = !closeable; @@ -393,7 +383,6 @@ int main(void) printf("Window size should be %ix%i\n", width, height); 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");