diff --git a/README.md b/README.md index 3f5cc1f10..7cbda2dd7 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ GLFW bundles a number of dependencies in the `deps/` directory. ## Changelog + - Added `mods` parameter to character callback - Added `GLFWcursor` custom system cursor handle - Added `glfwCreateCursor`, `glfwDestroyCursor` and `glfwSetCursor` for managing custom system cursors diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 51743c90b..d58383578 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -781,12 +781,14 @@ typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int); * * @param[in] window The window that received the event. * @param[in] codepoint The Unicode code point of the character. + * @param[in] mods Bit field describing which [modifier keys](@ref mods) were + * held down. * * @sa glfwSetCharCallback * * @ingroup input */ -typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int); +typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int,int); /*! @brief The function signature for file drop callbacks. * diff --git a/src/cocoa_window.m b/src/cocoa_window.m index b7fbde973..679e94373 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -611,7 +611,7 @@ static int translateKey(unsigned int key) NSUInteger i, length = [characters length]; for (i = 0; i < length; i++) - _glfwInputChar(window, [characters characterAtIndex:i]); + _glfwInputChar(window, [characters characterAtIndex:i], mods); } - (void)flagsChanged:(NSEvent *)event diff --git a/src/input.c b/src/input.c index 4aa6b23d4..4a6f32bdb 100644 --- a/src/input.c +++ b/src/input.c @@ -153,13 +153,13 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m window->callbacks.key((GLFWwindow*) window, key, scancode, action, mods); } -void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint) +void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods) { if (codepoint < 32 || (codepoint > 126 && codepoint < 160)) return; if (window->callbacks.character) - window->callbacks.character((GLFWwindow*) window, codepoint); + window->callbacks.character((GLFWwindow*) window, codepoint, mods); } void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset) diff --git a/src/internal.h b/src/internal.h index ddf6f24a7..66764d518 100644 --- a/src/internal.h +++ b/src/internal.h @@ -700,9 +700,10 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m /*! @brief Notifies shared code of a Unicode character input event. * @param[in] window The window that received the event. * @param[in] codepoint The Unicode code point of the input character. + * @param[in] mods The modifiers pressed when the event was generated. * @ingroup event */ -void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint); +void _glfwInputChar(_GLFWwindow* window, unsigned int codepoint, int mods); /*! @brief Notifies shared code of a scroll event. * @param[in] window The window that received the event. diff --git a/src/win32_window.c b/src/win32_window.c index 2818ed81b..fa3049dae 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -528,7 +528,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_CHAR: case WM_SYSCHAR: { - _glfwInputChar(window, (unsigned int) wParam); + _glfwInputChar(window, (unsigned int) wParam, getKeyMods()); return 0; } @@ -543,7 +543,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, return TRUE; } - _glfwInputChar(window, (unsigned int) wParam); + _glfwInputChar(window, (unsigned int) wParam, getKeyMods()); return FALSE; } diff --git a/src/x11_window.c b/src/x11_window.c index 0c41303f9..5fcd8febe 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -609,7 +609,7 @@ static void processEvent(XEvent *event) _glfwInputKey(window, key, event->xkey.keycode, GLFW_PRESS, mods); if (character != -1) - _glfwInputChar(window, character); + _glfwInputChar(window, character, mods); break; } diff --git a/tests/events.c b/tests/events.c index 234a0a058..56524a46a 100644 --- a/tests/events.c +++ b/tests/events.c @@ -388,12 +388,18 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action, } } -static void char_callback(GLFWwindow* window, unsigned int codepoint) +static void char_callback(GLFWwindow* window, unsigned int codepoint, int mods) { Slot* slot = glfwGetWindowUserPointer(window); - printf("%08x to %i at %0.3f: Character 0x%08x (%s) input\n", + + printf("%08x to %i at %0.3f: Character 0x%08x (%s)", counter++, slot->number, glfwGetTime(), codepoint, get_character_string(codepoint)); + + if (mods) + printf(" (with%s)", get_mods_name(mods)); + + printf(" input\n"); } static void drop_callback(GLFWwindow* window, int count, const char** names)