From 3386299e1fa40ae2b7a6a382404f05278deb283f Mon Sep 17 00:00:00 2001 From: Daijiro Fukuda Date: Wed, 20 Apr 2022 17:14:47 +0900 Subject: [PATCH] Apply shibukawa's fix of tests/events This fix is based on shibukawa's fix: https://github.com/glfw/glfw/pull/658 https://github.com/shibukawa/glfw-1/commit/d36a164423c933948661f3f17576e5a6388ff251 This code doesn't work because `get_character_string` is undefined. We need further work. --- tests/events.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/events.c b/tests/events.c index a9d4023d..465b5e1b 100644 --- a/tests/events.c +++ b/tests/events.c @@ -454,6 +454,45 @@ static void char_callback(GLFWwindow* window, unsigned int codepoint) counter++, slot->number, glfwGetTime(), codepoint, string); } +static void preedit_callback(GLFWwindow* window, int strLength, unsigned int* string, int blockLength, int* blocks, int focusedBlock) { + Slot* slot = glfwGetWindowUserPointer(window); + int i, blockIndex = -1, blockCount = 0; + int width, height; + printf("%08x to %i at %0.3f: Preedit text ", + counter++, slot->number, glfwGetTime()); + if (strLength == 0 || blockLength == 0) { + printf("(empty)\n"); + } else { + for (i = 0; i < strLength; i++) { + if (blockCount == 0) { + if (blockIndex == focusedBlock) { + printf("]"); + } + blockIndex++; + blockCount = blocks[blockIndex]; + printf("\n block %d: ", blockIndex); + if (blockIndex == focusedBlock) { + printf("["); + } + } + printf("%s", get_character_string(string[i])); + blockCount--; + } + if (blockIndex == focusedBlock) { + printf("]"); + } + printf("\n"); + glfwGetWindowSize(window, &width, &height); + glfwSetPreeditCursorPos(window, width/2, height/2, 20); + } +} + +static void ime_callback(GLFWwindow* window) { + Slot* slot = glfwGetWindowUserPointer(window); + printf("%08x to %i at %0.3f: IME switched\n", + counter++, slot->number, glfwGetTime()); +} + static void drop_callback(GLFWwindow* window, int count, const char* paths[]) { int i; @@ -638,6 +677,8 @@ int main(int argc, char** argv) glfwSetScrollCallback(slots[i].window, scroll_callback); glfwSetKeyCallback(slots[i].window, key_callback); glfwSetCharCallback(slots[i].window, char_callback); + glfwSetPreeditCallback(slots[i].window, preedit_callback); + glfwSetIMEStatusCallback(slots[i].window, ime_callback); glfwSetDropCallback(slots[i].window, drop_callback); glfwMakeContextCurrent(slots[i].window);