From c9f4dedd96ea954e88f09c81fda8ed7d912ba09b Mon Sep 17 00:00:00 2001 From: "m@bitsnbites.eu" Date: Sun, 28 Oct 2012 00:23:28 +0200 Subject: [PATCH 1/3] Introduced window positioning hints and window position properties --- include/GL/glfw3.h | 2 ++ src/cocoa_window.m | 2 +- src/internal.h | 4 ++++ src/win32_window.c | 4 ++++ src/window.c | 16 ++++++++++++++++ src/x11_platform.h | 6 ++++++ src/x11_window.c | 17 ++++++++++++++++- tests/sharing.c | 14 ++++++-------- tests/threads.c | 4 ++-- tests/windows.c | 4 ++-- 10 files changed, 59 insertions(+), 14 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 87ba9423..69fe6bfd 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -413,6 +413,8 @@ extern "C" { #define GLFW_OPENGL_ROBUSTNESS 0x00022006 #define GLFW_RESIZABLE 0x00022007 #define GLFW_VISIBLE 0x00022008 +#define GLFW_POSITION_X 0x00022009 +#define GLFW_POSITION_Y 0x0002200A /* GLFW_CLIENT_API tokens */ #define GLFW_OPENGL_API 0x00000001 diff --git a/src/cocoa_window.m b/src/cocoa_window.m index fd60d0ee..8fa1b866 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -686,7 +686,7 @@ static GLboolean createWindow(_GLFWwindow* window, styleMask = NSBorderlessWindowMask; window->NS.object = [[NSWindow alloc] - initWithContentRect:NSMakeRect(0, 0, window->width, window->height) + initWithContentRect:NSMakeRect(wndconfig->positionX, wndconfig->positionY, window->width, window->height) styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]; diff --git a/src/internal.h b/src/internal.h index bbbced89..573c9851 100644 --- a/src/internal.h +++ b/src/internal.h @@ -107,6 +107,8 @@ struct _GLFWhints GLboolean glDebug; int glProfile; int glRobustness; + int positionX; + int positionY; }; @@ -123,6 +125,8 @@ struct _GLFWwndconfig int refreshRate; GLboolean resizable; GLboolean visible; + int positionX; + int positionY; int clientAPI; int glMajor; int glMinor; diff --git a/src/win32_window.c b/src/win32_window.c index 75c8a8c1..2e6070ae 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -772,7 +772,11 @@ static int createWindow(_GLFWwindow* window, if (window->mode == GLFW_FULLSCREEN) wa.left = wa.top = 0; else + { SystemParametersInfo(SPI_GETWORKAREA, 0, &wa, 0); + wa.left += wndconfig->positionX; + wa.top += wndconfig->positionY; + } wideTitle = _glfwCreateWideStringFromUTF8(wndconfig->title); if (!wideTitle) diff --git a/src/window.c b/src/window.c index b86dcfec..bf499a0a 100644 --- a/src/window.c +++ b/src/window.c @@ -238,6 +238,8 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0); wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE; wndconfig.visible = _glfwLibrary.hints.visible ? GL_TRUE : GL_FALSE; + wndconfig.positionX = _glfwLibrary.hints.positionX; + wndconfig.positionY = _glfwLibrary.hints.positionY; wndconfig.clientAPI = _glfwLibrary.hints.clientAPI; wndconfig.glMajor = _glfwLibrary.hints.glMajor; wndconfig.glMinor = _glfwLibrary.hints.glMinor; @@ -369,6 +371,10 @@ void glfwDefaultWindowHints(void) _glfwLibrary.hints.resizable = GL_TRUE; _glfwLibrary.hints.visible = GL_TRUE; + // The default window position is the upper left corner of the screen + _glfwLibrary.hints.positionX = 0; + _glfwLibrary.hints.positionY = 0; + // The default is 24 bits of color, 24 bits of depth and 8 bits of stencil _glfwLibrary.hints.redBits = 8; _glfwLibrary.hints.greenBits = 8; @@ -437,6 +443,12 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_VISIBLE: _glfwLibrary.hints.visible = hint; break; + case GLFW_POSITION_X: + _glfwLibrary.hints.positionX = hint; + break; + case GLFW_POSITION_Y: + _glfwLibrary.hints.positionY = hint; + break; case GLFW_FSAA_SAMPLES: _glfwLibrary.hints.samples = hint; break; @@ -747,6 +759,10 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param) return window->resizable; case GLFW_VISIBLE: return window->visible; + case GLFW_POSITION_X: + return window->positionX; + case GLFW_POSITION_Y: + return window->positionY; case GLFW_CLIENT_API: return window->clientAPI; case GLFW_OPENGL_VERSION_MAJOR: diff --git a/src/x11_platform.h b/src/x11_platform.h index a6b576ed..e2897216 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -141,6 +141,12 @@ typedef struct _GLFWwindowX11 GLboolean cursorCentered; // True if cursor was moved since last poll int cursorPosX, cursorPosY; + // Window position hint (commited the first time the window is shown) + GLboolean windowPosSet; // False until the window position has + // been set + int positionX; // The window position to be set the + int positionY; // first time the window is shown + } _GLFWwindowX11; diff --git a/src/x11_window.c b/src/x11_window.c index ae920e7f..a4233f26 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -119,7 +119,7 @@ static GLboolean createWindow(_GLFWwindow* window, window->X11.handle = XCreateWindow(_glfwLibrary.X11.display, _glfwLibrary.X11.root, - 0, 0, // Position + wndconfig->positionX, wndconfig->positionY, window->width, window->height, 0, // Border width visual->depth, // Color depth @@ -136,6 +136,12 @@ static GLboolean createWindow(_GLFWwindow* window, _glfwSetError(GLFW_PLATFORM_ERROR, "X11: Failed to create window"); return GL_FALSE; } + + // Request a window position to be set once the window is shown + // (see _glfwPlatformShowWindow) + window->X11.windowPosSet = GL_FALSE; + window->X11.positionX = wndconfig->positionX; + window->X11.positionY = wndconfig->positionY; } if (window->mode == GLFW_FULLSCREEN && !_glfwLibrary.X11.hasEWMH) @@ -1060,6 +1066,15 @@ void _glfwPlatformShowWindow(_GLFWwindow* window) { XMapRaised(_glfwLibrary.X11.display, window->X11.handle); XFlush(_glfwLibrary.X11.display); + + // Set the window position the first time the window is shown + // Note: XMoveWindow has no effect before the window has been mapped. + if (!window->X11.windowPosSet) + { + XMoveWindow(_glfwLibrary.X11.display, window->X11.handle, + window->X11.positionX, window->X11.positionY); + window->X11.windowPosSet = GL_TRUE; + } } diff --git a/tests/sharing.c b/tests/sharing.c index 41ce8db5..74e11478 100644 --- a/tests/sharing.c +++ b/tests/sharing.c @@ -51,10 +51,12 @@ static int window_close_callback(GLFWwindow window) return GL_FALSE; } -static GLFWwindow open_window(const char* title, GLFWwindow share) +static GLFWwindow open_window(const char* title, GLFWwindow share, int posX, int posY) { GLFWwindow window; + glfwWindowHint(GLFW_POSITION_X, posX); + glfwWindowHint(GLFW_POSITION_Y, posY); window = glfwCreateWindow(WIDTH, HEIGHT, GLFW_WINDOWED, title, share); if (!window) return NULL; @@ -125,7 +127,6 @@ static void draw_quad(GLuint texture) int main(int argc, char** argv) { GLuint texture; - int x, y; if (!glfwInit()) { @@ -133,7 +134,7 @@ int main(int argc, char** argv) exit(EXIT_FAILURE); } - windows[0] = open_window("First", NULL); + windows[0] = open_window("First", NULL, 0, 0); if (!windows[0]) { fprintf(stderr, "Failed to open first GLFW window: %s\n", glfwErrorString(glfwGetError())); @@ -147,7 +148,8 @@ int main(int argc, char** argv) // It will then be shared with the second context, created below texture = create_texture(); - windows[1] = open_window("Second", windows[0]); + // Put the second window to the right of the first one + windows[1] = open_window("Second", windows[0], WIDTH + 50, 0); if (!windows[1]) { fprintf(stderr, "Failed to open second GLFW window: %s\n", glfwErrorString(glfwGetError())); @@ -161,10 +163,6 @@ int main(int argc, char** argv) glColor3f(0.6f, 0.f, 0.6f); glfwCopyContext(windows[0], windows[1], GL_CURRENT_BIT); - // Put the second window to the right of the first one - glfwGetWindowPos(windows[0], &x, &y); - glfwSetWindowPos(windows[1], x + WIDTH + 50, y); - while (!closed) { glfwMakeContextCurrent(windows[0]); diff --git a/tests/threads.c b/tests/threads.c index 49e3739a..8b06b1d3 100644 --- a/tests/threads.c +++ b/tests/threads.c @@ -89,6 +89,8 @@ int main(void) for (i = 0; i < count; i++) { + glfwWindowHint(GLFW_POSITION_X, 200 + 250 * i); + glfwWindowHint(GLFW_POSITION_Y, 200); threads[i].window = glfwCreateWindow(200, 200, GLFW_WINDOWED, threads[i].title, @@ -100,8 +102,6 @@ int main(void) exit(EXIT_FAILURE); } - glfwSetWindowPos(threads[i].window, 200 + 250 * i, 200); - if (thrd_create(&threads[i].id, thread_main, threads + i) != thrd_success) { diff --git a/tests/windows.c b/tests/windows.c index ddf67915..187248c2 100644 --- a/tests/windows.c +++ b/tests/windows.c @@ -55,6 +55,8 @@ int main(void) for (i = 0; i < 4; i++) { + glfwWindowHint(GLFW_POSITION_X, 100 + (i & 1) * 300); + glfwWindowHint(GLFW_POSITION_Y, 100 + (i >> 1) * 300); windows[i] = glfwCreateWindow(200, 200, GLFW_WINDOWED, titles[i], NULL); if (!windows[i]) { @@ -70,8 +72,6 @@ int main(void) (GLclampf) (i >> 1), i ? 0.f : 1.f, 0.f); - - glfwSetWindowPos(windows[i], 100 + (i & 1) * 300, 100 + (i >> 1) * 300); } while (running) From 424e7c7b5399a6caefec1bdacf28b81c58fd743f Mon Sep 17 00:00:00 2001 From: "m@bitsnbites.eu" Date: Sun, 28 Oct 2012 00:31:56 +0200 Subject: [PATCH 2/3] Removed glfwSetWindowPos and glfwGetWindowPos glfwGetWindowPos is superseded by glfwGetWindowParam() with GLFW_POSITION_X and GLFW_POSITION_Y as parameters. glfwSetWindowPos can easily lead to bad practices (moving windows around without the users consent), and has been replaced with the GLFW_POSITION_X/Y window hints that allow setting the window position for a newly created window. --- include/GL/glfw3.h | 2 -- src/cocoa_window.m | 21 --------------------- src/internal.h | 1 - src/win32_window.c | 17 ----------------- src/window.c | 46 ---------------------------------------------- src/x11_window.c | 10 ---------- 6 files changed, 97 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 69fe6bfd..191633a2 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -538,8 +538,6 @@ GLFWAPI void glfwDestroyWindow(GLFWwindow window); GLFWAPI void glfwSetWindowTitle(GLFWwindow window, const char* title); GLFWAPI void glfwGetWindowSize(GLFWwindow window, int* width, int* height); GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height); -GLFWAPI void glfwGetWindowPos(GLFWwindow window, int* xpos, int* ypos); -GLFWAPI void glfwSetWindowPos(GLFWwindow window, int xpos, int ypos); GLFWAPI void glfwIconifyWindow(GLFWwindow window); GLFWAPI void glfwRestoreWindow(GLFWwindow window); GLFWAPI void glfwShowWindow(GLFWwindow window); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 8fa1b866..5e4c7d81 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1006,27 +1006,6 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) } -//======================================================================== -// Set the window position -//======================================================================== - -void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) -{ - NSRect contentRect = - [window->NS.object contentRectForFrameRect:[window->NS.object frame]]; - - // We assume here that the client code wants to position the window within the - // screen the window currently occupies - NSRect screenRect = [[window->NS.object screen] visibleFrame]; - contentRect.origin = NSMakePoint(screenRect.origin.x + x, - screenRect.origin.y + screenRect.size.height - - y - contentRect.size.height); - - [window->NS.object setFrame:[window->NS.object frameRectForContentRect:contentRect] - display:YES]; -} - - //======================================================================== // Iconify the window //======================================================================== diff --git a/src/internal.h b/src/internal.h index 573c9851..2101ad23 100644 --- a/src/internal.h +++ b/src/internal.h @@ -294,7 +294,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, const _GLFWwndconfig* wndcon void _glfwPlatformDestroyWindow(_GLFWwindow* window); void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title); void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); -void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y); void _glfwPlatformIconifyWindow(_GLFWwindow* window); void _glfwPlatformRestoreWindow(_GLFWwindow* window); void _glfwPlatformShowWindow(_GLFWwindow* window); diff --git a/src/win32_window.c b/src/win32_window.c index 2e6070ae..fd342da6 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -1058,23 +1058,6 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) } -//======================================================================== -// Set the window position -//======================================================================== - -void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) -{ - RECT rect; - - GetClientRect(window->Win32.handle, &rect); - AdjustWindowRectEx(&rect, window->Win32.dwStyle, FALSE, window->Win32.dwExStyle); - - SetWindowPos(window->Win32.handle, HWND_TOP, - x + rect.left, y + rect.top, 0, 0, - SWP_NOOWNERZORDER | SWP_NOSIZE | SWP_NOZORDER); -} - - //======================================================================== // Window iconification //======================================================================== diff --git a/src/window.c b/src/window.c index bf499a0a..986a0cb6 100644 --- a/src/window.c +++ b/src/window.c @@ -598,52 +598,6 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow handle, int width, int height) } -//======================================================================== -// Get the window position -//======================================================================== - -GLFWAPI void glfwGetWindowPos(GLFWwindow handle, int* xpos, int* ypos) -{ - _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - if (xpos != NULL) - *xpos = window->positionX; - - if (ypos != NULL) - *ypos = window->positionY; -} - - -//======================================================================== -// Set the window position -//======================================================================== - -GLFWAPI void glfwSetWindowPos(GLFWwindow handle, int xpos, int ypos) -{ - _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - if (window->mode == GLFW_FULLSCREEN || window->iconified) - { - // TODO: Figure out if this is an error - return; - } - - _glfwPlatformSetWindowPos(window, xpos, ypos); -} - - //======================================================================== // Window iconification //======================================================================== diff --git a/src/x11_window.c b/src/x11_window.c index a4233f26..28724750 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1012,16 +1012,6 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) } -//======================================================================== -// Set the window position. -//======================================================================== - -void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y) -{ - XMoveWindow(_glfwLibrary.X11.display, window->X11.handle, x, y); -} - - //======================================================================== // Window iconification //======================================================================== From 1c21fc1383366c11488a774fe0d2d187d0c67d71 Mon Sep 17 00:00:00 2001 From: "m@bitsnbites.eu" Date: Sun, 28 Oct 2012 00:50:38 +0200 Subject: [PATCH 3/3] 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");