Apply shibukawa's fix of tests/events

This fix is based on shibukawa's fix:
  https://github.com/glfw/glfw/pull/658
  d36a164423

This code doesn't work because `get_character_string` is undefined.
We need further work.
This commit is contained in:
Daijiro Fukuda 2022-04-20 17:14:47 +09:00
parent 59e192be6d
commit 3386299e1f

View File

@ -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);