Wayland: Clean up key event handler

Adapt style and naming to match the rest of the project.
This commit is contained in:
Camilla Löwy 2021-12-30 21:06:22 +01:00
parent 293d19a153
commit bf99587005

View File

@ -559,42 +559,40 @@ static void keyboardHandleKey(void* data,
struct wl_keyboard* keyboard, struct wl_keyboard* keyboard,
uint32_t serial, uint32_t serial,
uint32_t time, uint32_t time,
uint32_t key, uint32_t scancode,
uint32_t state) uint32_t state)
{ {
int keyCode;
int action;
_GLFWwindow* window = _glfw.wl.keyboardFocus; _GLFWwindow* window = _glfw.wl.keyboardFocus;
GLFWbool shouldRepeat;
struct itimerspec timer = {};
if (!window) if (!window)
return; return;
keyCode = toGLFWKeyCode(key); const int key = toGLFWKeyCode(scancode);
action = state == WL_KEYBOARD_KEY_STATE_PRESSED const int action =
? GLFW_PRESS : GLFW_RELEASE; state == WL_KEYBOARD_KEY_STATE_PRESSED ? GLFW_PRESS : GLFW_RELEASE;
_glfw.wl.serial = serial; _glfw.wl.serial = serial;
_glfwInputKey(window, keyCode, key, action, _glfwInputKey(window, key, scancode, action, _glfw.wl.xkb.modifiers);
_glfw.wl.xkb.modifiers);
struct itimerspec timer = {};
if (action == GLFW_PRESS) if (action == GLFW_PRESS)
{ {
shouldRepeat = inputChar(window, key); const GLFWbool shouldRepeat = inputChar(window, scancode);
if (shouldRepeat && _glfw.wl.keyboardRepeatRate > 0) if (shouldRepeat && _glfw.wl.keyboardRepeatRate > 0)
{ {
_glfw.wl.keyboardLastKey = keyCode; _glfw.wl.keyboardLastKey = key;
_glfw.wl.keyboardLastScancode = key; _glfw.wl.keyboardLastScancode = scancode;
if (_glfw.wl.keyboardRepeatRate > 1) if (_glfw.wl.keyboardRepeatRate > 1)
timer.it_interval.tv_nsec = 1000000000 / _glfw.wl.keyboardRepeatRate; timer.it_interval.tv_nsec = 1000000000 / _glfw.wl.keyboardRepeatRate;
else else
timer.it_interval.tv_sec = 1; timer.it_interval.tv_sec = 1;
timer.it_value.tv_sec = _glfw.wl.keyboardRepeatDelay / 1000; timer.it_value.tv_sec = _glfw.wl.keyboardRepeatDelay / 1000;
timer.it_value.tv_nsec = (_glfw.wl.keyboardRepeatDelay % 1000) * 1000000; timer.it_value.tv_nsec = (_glfw.wl.keyboardRepeatDelay % 1000) * 1000000;
} }
} }
timerfd_settime(_glfw.wl.timerfd, 0, &timer, NULL); timerfd_settime(_glfw.wl.timerfd, 0, &timer, NULL);
} }