Add mods parameter to character callback.

This is needed to correctly and _reliably_ distinguish character events
from mod+key combinations, due to the change in #40.
I am sick of improvements behind held back due to "backwards
compatibility". Why is it acceptable to do so much more work to jump
through hoops to use sub-optimal API and still suffer with sub-optimal
results, rather than doing so much less work to improve the API and
code that uses it and have correct results? -.-
This commit is contained in:
Dmitri Shuralyov 2014-06-07 16:32:14 -07:00
parent c6e02c09ff
commit b27b644610
8 changed files with 20 additions and 10 deletions

View File

@ -48,6 +48,7 @@ The following dependencies are needed by the examples and test programs:
## Changelog ## Changelog
- Added `mods` parameter to character callback
- Added `GLFWcursor` custom system cursor handle - Added `GLFWcursor` custom system cursor handle
- Added `glfwCreateCursor`, `glfwDestroyCursor` and `glfwSetCursor` for - Added `glfwCreateCursor`, `glfwDestroyCursor` and `glfwSetCursor` for
managing custom system cursors managing custom system cursors

View File

@ -776,12 +776,14 @@ typedef void (* GLFWkeyfun)(GLFWwindow*,int,int,int,int);
* *
* @param[in] window The window that received the event. * @param[in] window The window that received the event.
* @param[in] codepoint The Unicode code point of the character. * @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 * @sa glfwSetCharCallback
* *
* @ingroup input * @ingroup input
*/ */
typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int); typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int,int);
/*! @brief The function signature for file drop callbacks. /*! @brief The function signature for file drop callbacks.

View File

@ -611,7 +611,7 @@ static int translateKey(unsigned int key)
NSUInteger i, length = [characters length]; NSUInteger i, length = [characters length];
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
_glfwInputChar(window, [characters characterAtIndex:i]); _glfwInputChar(window, [characters characterAtIndex:i], mods);
} }
- (void)flagsChanged:(NSEvent *)event - (void)flagsChanged:(NSEvent *)event

View File

@ -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); 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)) if (codepoint < 32 || (codepoint > 126 && codepoint < 160))
return; return;
if (window->callbacks.character) 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) void _glfwInputScroll(_GLFWwindow* window, double xoffset, double yoffset)

View File

@ -682,9 +682,10 @@ void _glfwInputKey(_GLFWwindow* window, int key, int scancode, int action, int m
/*! @brief Notifies shared code of a Unicode character input event. /*! @brief Notifies shared code of a Unicode character input event.
* @param[in] window The window that received the event. * @param[in] window The window that received the event.
* @param[in] codepoint The Unicode code point of the input character. * @param[in] codepoint The Unicode code point of the input character.
* @param[in] mods The modifiers pressed when the event was generated.
* @ingroup event * @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. /*! @brief Notifies shared code of a scroll event.
* @param[in] window The window that received the event. * @param[in] window The window that received the event.

View File

@ -528,7 +528,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
case WM_CHAR: case WM_CHAR:
case WM_SYSCHAR: case WM_SYSCHAR:
{ {
_glfwInputChar(window, (unsigned int) wParam); _glfwInputChar(window, (unsigned int) wParam, getKeyMods());
return 0; return 0;
} }
@ -543,7 +543,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
return TRUE; return TRUE;
} }
_glfwInputChar(window, (unsigned int) wParam); _glfwInputChar(window, (unsigned int) wParam, getKeyMods());
return FALSE; return FALSE;
} }

View File

@ -605,7 +605,7 @@ static void processEvent(XEvent *event)
_glfwInputKey(window, key, event->xkey.keycode, GLFW_PRESS, mods); _glfwInputKey(window, key, event->xkey.keycode, GLFW_PRESS, mods);
if (character != -1) if (character != -1)
_glfwInputChar(window, character); _glfwInputChar(window, character, mods);
break; break;
} }

View File

@ -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); 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, counter++, slot->number, glfwGetTime(), codepoint,
get_character_string(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) static void drop_callback(GLFWwindow* window, int count, const char** names)