-
Couldn't load subscription status.
- Fork 5.7k
Description
To reproduce, run the following code:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <GLFW/glfw3.h>
int polln = 0;
void keyCall(GLFWwindow *win, int key, int scancode, int action, int mods) {
printf("[%d] key: key=%d, sc=%d, act=%d, mod=%d\n", polln, key, scancode, action, mods);
}
void charCall(GLFWwindow *win, unsigned int codepoint) {
printf("[%d] char: code=%u\n", polln, codepoint);
}
int main(int argc, char **argv) {
assert(glfwInit());
GLFWwindow *win = glfwCreateWindow(640, 480, "key test", NULL, NULL);
assert(win);
glfwSetKeyCallback(win, keyCall);
glfwSetCharModsCallback(win, charCall);
glfwMakeContextCurrent(win);
while (!glfwWindowShouldClose(win)) {
glfwSwapBuffers(win);
glfwPollEvents();
polln++;
}
glfwTerminate();
return 0;
}The code polls events and displays output in the key callback and char callback. The number in the brackets is the poll number (i.e. n-th poll)
Actual behaviour
On some Linux machines, the key callback is called on one poll, and the char callback is called on the next poll:
[156] key: key=65, sc=38, act=1, mod=0
[157] char: code=97
[163] key: key=65, sc=38, act=0, mod=0
This behaviour seems to happen on GNOME but not KDE. On an affected machine, this happens consistently. This is what causes the Minecraft bug MC-122477.
My machine is affected: Pop!_OS 20.10. See the above Minecraft bug report for other users who have reported experiencing this issue.
Expected behaviour
The key callback and char callback are called during the same poll:
[13659] key: key=65, sc=38, act=1, mod=0
[13659] char: code=97
[14837] key: key=65, sc=38, act=0, mod=0
Indeed, this is the behaviour on Linux machines running KDE (and probably on Windows and macOS too, but I haven't tested).