From ce288a893962684aaa8a4299458ff86bd2251222 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sat, 4 Feb 2012 00:51:35 +0100 Subject: [PATCH] Transformed glfwEnable/Disable/SetCursorMode into glfwGetInputMode/SetInputMode. --- examples/boing.c | 2 +- examples/gears.c | 2 +- examples/splitview.c | 4 +- examples/triangle.c | 2 +- examples/wave.c | 6 +- include/GL/glfw3.h | 12 +- readme.html | 2 +- src/CMakeLists.txt | 14 +- src/{cocoa_enable.m => cocoa_input.m} | 0 src/cocoa_window.m | 2 +- src/enable.c | 192 --------------------- src/input.c | 232 +++++++++++++++++++++----- src/internal.h | 4 +- src/{win32_enable.c => win32_input.c} | 0 src/window.c | 3 +- src/{x11_enable.c => x11_input.c} | 0 tests/events.c | 10 +- tests/fsfocus.c | 2 +- tests/peter.c | 9 +- 19 files changed, 219 insertions(+), 279 deletions(-) rename src/{cocoa_enable.m => cocoa_input.m} (100%) delete mode 100644 src/enable.c rename src/{win32_enable.c => win32_input.c} (100%) rename src/{x11_enable.c => x11_input.c} (100%) diff --git a/examples/boing.c b/examples/boing.c index 914d1291..33696e46 100644 --- a/examples/boing.c +++ b/examples/boing.c @@ -586,7 +586,7 @@ int main( void ) } glfwSetWindowSizeCallback( reshape ); - glfwEnable( window, GLFW_STICKY_KEYS ); + glfwSetInputMode( window, GLFW_STICKY_KEYS, GL_TRUE ); glfwSwapInterval( 1 ); glfwSetTime( 0.0 ); diff --git a/examples/gears.c b/examples/gears.c index cb31b1f8..53d601f3 100644 --- a/examples/gears.c +++ b/examples/gears.c @@ -339,7 +339,7 @@ int main(int argc, char *argv[]) exit( EXIT_FAILURE ); } - glfwEnable( window, GLFW_KEY_REPEAT ); + glfwSetInputMode( window, GLFW_KEY_REPEAT, GL_TRUE ); glfwSwapInterval( 1 ); // Parse command-line options diff --git a/examples/splitview.c b/examples/splitview.c index f37c4142..2cd43fdf 100644 --- a/examples/splitview.c +++ b/examples/splitview.c @@ -462,10 +462,10 @@ int main(void) glfwSwapInterval(1); // Enable sticky keys - glfwEnable(window, GLFW_STICKY_KEYS); + glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); // Enable mouse cursor (only needed for fullscreen mode) - glfwSetCursorMode(window, GLFW_CURSOR_NORMAL); + glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); // Set callback functions glfwSetWindowSizeCallback(windowSizeFun); diff --git a/examples/triangle.c b/examples/triangle.c index c61baeff..e61ea9ab 100644 --- a/examples/triangle.c +++ b/examples/triangle.c @@ -30,7 +30,7 @@ int main(void) } // Ensure we can capture the escape key being pressed below - glfwEnable(window, GLFW_STICKY_KEYS); + glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); // Enable vertical sync (on cards that support it) glfwSwapInterval(1); diff --git a/examples/wave.c b/examples/wave.c index 26a0ca1a..1eb8b855 100644 --- a/examples/wave.c +++ b/examples/wave.c @@ -309,13 +309,13 @@ void mouse_button_callback(GLFWwindow window, int button, int action) if (action == GLFW_PRESS) { - glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED); + glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED); locked = GL_TRUE; } else { locked = GL_FALSE; - glfwSetCursorMode(window, GLFW_CURSOR_NORMAL); + glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); } } @@ -396,7 +396,7 @@ int main(int argc, char* argv[]) // Keyboard handler glfwSetKeyCallback(key_callback); - glfwEnable(window, GLFW_KEY_REPEAT); + glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE); // Window resize handler glfwSetWindowSizeCallback(window_resize_callback); diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index e49654d1..6bf5f548 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -427,13 +427,14 @@ extern "C" { #define GLFW_OPENGL_COMPAT_PROFILE 0x00000002 #define GLFW_OPENGL_ES2_PROFILE 0x00000004 -/* glfwEnable/glfwDisable tokens */ +/* glfwGetInputMode/glfwSetInputMode tokens */ +#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 -/* glfwSetCursorMode tokens */ +/* GLFW_CURSOR_MODE values */ #define GLFW_CURSOR_NORMAL 0x00040001 #define GLFW_CURSOR_HIDDEN 0x00040002 #define GLFW_CURSOR_CAPTURED 0x00040003 @@ -567,7 +568,8 @@ GLFWAPI int glfwGetKey(GLFWwindow window, int key); GLFWAPI int glfwGetMouseButton(GLFWwindow window, int button); GLFWAPI void glfwGetMousePos(GLFWwindow window, int* xpos, int* ypos); GLFWAPI void glfwSetMousePos(GLFWwindow window, int xpos, int ypos); -GLFWAPI void glfwSetCursorMode(GLFWwindow window, int mode); +GLFWAPI int glfwGetInputMode(GLFWwindow window, int mode); +GLFWAPI void glfwSetInputMode(GLFWwindow window, int mode, int value); GLFWAPI void glfwGetScrollOffset(GLFWwindow window, int* xoffset, int* yoffset); GLFWAPI void glfwSetKeyCallback(GLFWkeyfun cbfun); GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); @@ -593,10 +595,6 @@ GLFWAPI int glfwExtensionSupported(const char* extension); GLFWAPI void* glfwGetProcAddress(const char* procname); GLFWAPI void glfwCopyContext(GLFWwindow src, GLFWwindow dst, unsigned long mask); -/* Enable/disable functions */ -GLFWAPI void glfwEnable(GLFWwindow window, int token); -GLFWAPI void glfwDisable(GLFWwindow window, int token); - /************************************************************************* * Global definition cleanup diff --git a/readme.html b/readme.html index 4d1f4c72..e13d8944 100644 --- a/readme.html +++ b/readme.html @@ -274,7 +274,6 @@ version of GLFW.

  • Added glfwGetCurrentContext function for retrieving the window whose OpenGL context is current
  • Added glfwInitWithModels function and GLFWallocator and GLFWthreadmodel types for pluggable memory allocation and threading models
  • Added glfwCopyContext function for copying OpenGL state categories between contexts
  • -
  • Added glfwSetCursorMode function for controlling per-window cursor mode, replacing GLFW_MOUSE_CURSOR
  • Added GLFW_OPENGL_ES2_PROFILE profile for creating OpenGL ES 2.0 contexts using the GLX_EXT_create_context_es2_profile and WGL_EXT_create_context_es2_profile extensions
  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
  • @@ -293,6 +292,7 @@ version of GLFW.

  • Replaced ad hoc build system with CMake
  • Replaced layout-dependent key codes with single, platform-independent set based on US layout
  • Replaced mouse wheel interface with two-dimensional scrolling interface
  • +
  • Replaced glfwEnable and glfwDisable with glfwGetInputMode and glfwSetInputMode
  • Made Unicode character input unaffected by GLFW_KEY_REPEAT
  • Removed event auto-polling and the GLFW_AUTO_POLL_EVENTS window enable
  • Removed the Win32 port .def files
  • diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f15089e9..31cd9fd9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -15,24 +15,24 @@ include_directories(${GLFW_SOURCE_DIR}/src ${GLFW_BINARY_DIR}/src ${GLFW_INCLUDE_DIR}) -set(common_SOURCES enable.c error.c fullscreen.c gamma.c init.c input.c +set(common_SOURCES error.c fullscreen.c gamma.c init.c input.c joystick.c opengl.c time.c window.c) if(_GLFW_COCOA_NSGL) - set(libglfw_SOURCES ${common_SOURCES} cocoa_enable.m cocoa_fullscreen.m - cocoa_gamma.m cocoa_init.m cocoa_joystick.m + set(libglfw_SOURCES ${common_SOURCES} cocoa_fullscreen.m cocoa_gamma.m + cocoa_init.m cocoa_input.m cocoa_joystick.m cocoa_opengl.m cocoa_time.m cocoa_window.m) # For some reason, CMake doesn't know about .m set_source_files_properties(${libglfw_SOURCES} PROPERTIES LANGUAGE C) elseif(_GLFW_WIN32_WGL) - set(libglfw_SOURCES ${common_SOURCES} win32_enable.c win32_fullscreen.c - win32_gamma.c win32_init.c win32_joystick.c + set(libglfw_SOURCES ${common_SOURCES} win32_fullscreen.c win32_gamma.c + win32_init.c win32_input.c win32_joystick.c win32_opengl.c win32_time.c win32_window.c win32_dllmain.c) elseif(_GLFW_X11_GLX) - set(libglfw_SOURCES ${common_SOURCES} x11_enable.c x11_fullscreen.c - x11_gamma.c x11_init.c x11_joystick.c + set(libglfw_SOURCES ${common_SOURCES} x11_fullscreen.c x11_gamma.c + x11_init.c x11_input.c x11_joystick.c x11_keysym2unicode.c x11_opengl.c x11_time.c x11_window.c) else() diff --git a/src/cocoa_enable.m b/src/cocoa_input.m similarity index 100% rename from src/cocoa_enable.m rename to src/cocoa_input.m diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 7d8cb991..3e94f541 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -393,7 +393,7 @@ static int convertMacKeyCode(unsigned int macKeyCode) if ([event modifierFlags] & NSCommandKeyMask) { - if (!window->sysKeysDisabled) + if (window->systemKeys) [super keyDown:event]; } else diff --git a/src/enable.c b/src/enable.c deleted file mode 100644 index 897f0753..00000000 --- a/src/enable.c +++ /dev/null @@ -1,192 +0,0 @@ -//======================================================================== -// GLFW - An OpenGL library -// Platform: Any -// 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" - - -//======================================================================== -// Enable and disable sticky keys mode -//======================================================================== - -static void enableStickyKeys(_GLFWwindow* window) -{ - window->stickyKeys = GL_TRUE; -} - -static void disableStickyKeys(_GLFWwindow* window) -{ - int i; - - window->stickyKeys = GL_FALSE; - - // Release all sticky keys - for (i = 0; i <= GLFW_KEY_LAST; i++) - { - if (window->key[i] == GLFW_STICK) - window->key[i] = GLFW_RELEASE; - } -} - - -//======================================================================== -// Enable and disable sticky mouse buttons mode -//======================================================================== - -static void enableStickyMouseButtons(_GLFWwindow* window) -{ - window->stickyMouseButtons = GL_TRUE; -} - -static void disableStickyMouseButtons(_GLFWwindow* window) -{ - int i; - - window->stickyMouseButtons = GL_FALSE; - - // Release all sticky mouse buttons - for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) - { - if (window->mouseButton[i] == GLFW_STICK) - window->mouseButton[i] = GLFW_RELEASE; - } -} - - -//======================================================================== -// Enable and disable system keys -//======================================================================== - -static void enableSystemKeys(_GLFWwindow* window) -{ - if (!window->sysKeysDisabled) - return; - - _glfwPlatformEnableSystemKeys(window); - - // Indicate that system keys are no longer disabled - window->sysKeysDisabled = GL_FALSE; -} - -static void disableSystemKeys(_GLFWwindow* window) -{ - if (window->sysKeysDisabled) - return; - - _glfwPlatformDisableSystemKeys(window); - - // Indicate that system keys are now disabled - window->sysKeysDisabled = GL_TRUE; -} - - -//======================================================================== -// Enable and disable key repeat -//======================================================================== - -static void enableKeyRepeat(_GLFWwindow* window) -{ - window->keyRepeat = GL_TRUE; -} - -static void disableKeyRepeat(_GLFWwindow* window) -{ - window->keyRepeat = GL_FALSE; -} - - -////////////////////////////////////////////////////////////////////////// -////// GLFW public API ////// -////////////////////////////////////////////////////////////////////////// - -//======================================================================== -// Enable certain GLFW/window/system functions -//======================================================================== - -GLFWAPI void glfwEnable(GLFWwindow window, int token) -{ - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - switch (token) - { - case GLFW_STICKY_KEYS: - enableStickyKeys(window); - break; - case GLFW_STICKY_MOUSE_BUTTONS: - enableStickyMouseButtons(window); - break; - case GLFW_SYSTEM_KEYS: - enableSystemKeys(window); - break; - case GLFW_KEY_REPEAT: - enableKeyRepeat(window); - break; - default: - _glfwSetError(GLFW_INVALID_ENUM, NULL); - break; - } -} - - -//======================================================================== -// Disable certain GLFW/window/system functions -//======================================================================== - -GLFWAPI void glfwDisable(GLFWwindow window, int token) -{ - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - switch (token) - { - case GLFW_STICKY_KEYS: - disableStickyKeys(window); - break; - case GLFW_STICKY_MOUSE_BUTTONS: - disableStickyMouseButtons(window); - break; - case GLFW_SYSTEM_KEYS: - disableSystemKeys(window); - break; - case GLFW_KEY_REPEAT: - disableKeyRepeat(window); - break; - default: - _glfwSetError(GLFW_INVALID_ENUM, NULL); - break; - } -} - diff --git a/src/input.c b/src/input.c index 531bcc7e..052034aa 100644 --- a/src/input.c +++ b/src/input.c @@ -31,6 +31,122 @@ #include "internal.h" +//======================================================================== +// Sets the cursor mode for the specified window +//======================================================================== + +static void setCursorMode(_GLFWwindow* window, int mode) +{ + int centerPosX, centerPosY; + + if (mode != GLFW_CURSOR_NORMAL && + mode != GLFW_CURSOR_HIDDEN && + mode != GLFW_CURSOR_CAPTURED) + { + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return; + } + + if (window->cursorMode == mode) + return; + + centerPosX = window->width / 2; + centerPosY = window->height / 2; + + if (mode == GLFW_CURSOR_CAPTURED) + _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); + else if (window->cursorMode == GLFW_CURSOR_CAPTURED) + { + _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); + _glfwInputCursorMotion(window, + centerPosX - window->cursorPosX, + centerPosY - window->cursorPosY); + } + + _glfwPlatformSetCursorMode(window, mode); + + window->cursorMode = mode; +} + + +//======================================================================== +// Set sticky keys mode for the specified window +//======================================================================== + +static void setStickyKeys(_GLFWwindow* window, int enabled) +{ + if (window->stickyKeys == enabled) + return; + + if (!enabled) + { + int i; + + // Release all sticky keys + for (i = 0; i <= GLFW_KEY_LAST; i++) + { + if (window->key[i] == GLFW_STICK) + window->key[i] = GLFW_RELEASE; + } + } + + window->stickyKeys = enabled; +} + + +//======================================================================== +// Set sticky mouse buttons mode for the specified window +//======================================================================== + +static void setStickyMouseButtons(_GLFWwindow* window, int enabled) +{ + if (window->stickyMouseButtons == enabled) + return; + + if (!enabled) + { + int i; + + // Release all sticky mouse buttons + for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++) + { + if (window->mouseButton[i] == GLFW_STICK) + window->mouseButton[i] = GLFW_RELEASE; + } + } + + window->stickyMouseButtons = 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 +//======================================================================== + +static void setKeyRepeat(_GLFWwindow* window, int enabled) +{ + window->keyRepeat = enabled; +} + + ////////////////////////////////////////////////////////////////////////// ////// GLFW internal API ////// ////////////////////////////////////////////////////////////////////////// @@ -278,6 +394,77 @@ GLFWAPI void glfwSetMousePos(GLFWwindow handle, int xpos, int ypos) } +//======================================================================== +// Returns the specified input mode of the specified window +//======================================================================== + +GLFWAPI int glfwGetInputMode(GLFWwindow handle, int mode) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return 0; + } + + switch (mode) + { + case GLFW_CURSOR_MODE: + return window->cursorMode; + case GLFW_STICKY_KEYS: + 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: + _glfwSetError(GLFW_INVALID_ENUM, NULL); + return 0; + } +} + + +//======================================================================== +// Sets the specified input mode of the specified window +//======================================================================== + +GLFWAPI void glfwSetInputMode(GLFWwindow handle, int mode, int value) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + switch (mode) + { + case GLFW_CURSOR_MODE: + setCursorMode(window, value); + break; + case GLFW_STICKY_KEYS: + setStickyKeys(window, value ? GL_TRUE : GL_FALSE); + break; + 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; + default: + _glfwSetError(GLFW_INVALID_ENUM, NULL); + break; + } +} + + //======================================================================== // Returns the scroll offset for the specified window //======================================================================== @@ -300,51 +487,6 @@ GLFWAPI void glfwGetScrollOffset(GLFWwindow handle, int* xoffset, int* yoffset) } -//======================================================================== -// Sets the cursor mode for the specified window -//======================================================================== - -GLFWAPI void glfwSetCursorMode(GLFWwindow handle, int mode) -{ - int centerPosX, centerPosY; - _GLFWwindow* window = (_GLFWwindow*) handle; - - if (!_glfwInitialized) - { - _glfwSetError(GLFW_NOT_INITIALIZED, NULL); - return; - } - - if (mode != GLFW_CURSOR_NORMAL && - mode != GLFW_CURSOR_HIDDEN && - mode != GLFW_CURSOR_CAPTURED) - { - _glfwSetError(GLFW_INVALID_ENUM, NULL); - return; - } - - if (window->cursorMode == mode) - return; - - centerPosX = window->width / 2; - centerPosY = window->height / 2; - - if (mode == GLFW_CURSOR_CAPTURED) - _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); - else if (window->cursorMode == GLFW_CURSOR_CAPTURED) - { - _glfwPlatformSetMouseCursorPos(window, centerPosX, centerPosY); - _glfwInputCursorMotion(window, - centerPosX - window->cursorPosX, - centerPosY - window->cursorPosY); - } - - _glfwPlatformSetCursorMode(window, mode); - - window->cursorMode = mode; -} - - //======================================================================== // Set callback function for keyboard input //======================================================================== diff --git a/src/internal.h b/src/internal.h index 10da3ee7..a78cef11 100644 --- a/src/internal.h +++ b/src/internal.h @@ -183,7 +183,7 @@ struct _GLFWwindow GLboolean stickyKeys; GLboolean stickyMouseButtons; GLboolean keyRepeat; - GLboolean sysKeysDisabled; // system keys disabled flag + GLboolean systemKeys; // system keys enabled flag int cursorPosX, cursorPosY; int cursorMode; int scrollX, scrollY; @@ -276,7 +276,7 @@ int _glfwPlatformInit(void); int _glfwPlatformTerminate(void); const char* _glfwPlatformGetVersionString(void); -// Enable/Disable +// Input void _glfwPlatformEnableSystemKeys(_GLFWwindow* window); void _glfwPlatformDisableSystemKeys(_GLFWwindow* window); diff --git a/src/win32_enable.c b/src/win32_input.c similarity index 100% rename from src/win32_enable.c rename to src/win32_input.c diff --git a/src/window.c b/src/window.c index 88b3dc18..de89b069 100644 --- a/src/window.c +++ b/src/window.c @@ -309,6 +309,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, window->height = height; window->mode = mode; window->cursorMode = GLFW_CURSOR_NORMAL; + window->systemKeys = GL_TRUE; // Open the actual window and create its context if (!_glfwPlatformOpenWindow(window, &wndconfig, &fbconfig)) @@ -330,7 +331,7 @@ GLFWAPI GLFWwindow glfwOpenWindow(int width, int height, // The GLFW specification states that fullscreen windows have the cursor // captured by default if (mode == GLFW_FULLSCREEN) - glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED); + glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED); // Clearing the front buffer to black to avoid garbage pixels left over // from previous uses of our bit of VRAM diff --git a/src/x11_enable.c b/src/x11_input.c similarity index 100% rename from src/x11_enable.c rename to src/x11_input.c diff --git a/tests/events.c b/tests/events.c index ac758100..fffd9f58 100644 --- a/tests/events.c +++ b/tests/events.c @@ -298,10 +298,7 @@ static void key_callback(GLFWwindow window, int key, int action) case GLFW_KEY_R: { keyrepeat = !keyrepeat; - if (keyrepeat) - glfwEnable(window, GLFW_KEY_REPEAT); - else - glfwDisable(window, GLFW_KEY_REPEAT); + glfwSetInputMode(window, GLFW_KEY_REPEAT, keyrepeat); printf("(( key repeat %s ))\n", keyrepeat ? "enabled" : "disabled"); break; @@ -310,10 +307,7 @@ static void key_callback(GLFWwindow window, int key, int action) case GLFW_KEY_S: { systemkeys = !systemkeys; - if (systemkeys) - glfwEnable(window, GLFW_SYSTEM_KEYS); - else - glfwDisable(window, GLFW_SYSTEM_KEYS); + glfwSetInputMode(window, GLFW_SYSTEM_KEYS, systemkeys); printf("(( system keys %s ))\n", systemkeys ? "enabled" : "disabled"); break; diff --git a/tests/fsfocus.c b/tests/fsfocus.c index 5392c5e7..951409a6 100644 --- a/tests/fsfocus.c +++ b/tests/fsfocus.c @@ -91,7 +91,7 @@ int main(void) } glfwSwapInterval(1); - glfwSetCursorMode(window, GLFW_CURSOR_NORMAL); + glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); glfwSetWindowFocusCallback(window_focus_callback); glfwSetKeyCallback(window_key_callback); diff --git a/tests/peter.c b/tests/peter.c index cefdb103..5ae7ba5d 100644 --- a/tests/peter.c +++ b/tests/peter.c @@ -35,7 +35,6 @@ #include #include -static GLboolean cursor_captured = GL_FALSE; static GLFWwindow window_handle = NULL; static int cursor_x; static int cursor_y; @@ -44,18 +43,16 @@ static GLboolean open_window(void); static void toggle_mouse_cursor(GLFWwindow window) { - if (cursor_captured) + if (glfwGetInputMode(window, GLFW_CURSOR_MODE) == GLFW_CURSOR_CAPTURED) { printf("Released cursor\n"); - glfwSetCursorMode(window, GLFW_CURSOR_NORMAL); + glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_NORMAL); } else { printf("Captured cursor\n"); - glfwSetCursorMode(window, GLFW_CURSOR_CAPTURED); + glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED); } - - cursor_captured = !cursor_captured; } static void mouse_position_callback(GLFWwindow window, int x, int y)