mirror of
https://github.com/glfw/glfw.git
synced 2024-11-10 00:51:47 +00:00
Wayland: Clean up key repeat logic
This commit is contained in:
parent
a1a73ee862
commit
9180923ea0
@ -478,7 +478,7 @@ int _glfwInitWayland(void)
|
|||||||
int cursorSize;
|
int cursorSize;
|
||||||
|
|
||||||
// These must be set before any failure checks
|
// These must be set before any failure checks
|
||||||
_glfw.wl.timerfd = -1;
|
_glfw.wl.keyRepeatTimerfd = -1;
|
||||||
_glfw.wl.cursorTimerfd = -1;
|
_glfw.wl.cursorTimerfd = -1;
|
||||||
|
|
||||||
_glfw.wl.client.display_flush = (PFN_wl_display_flush)
|
_glfw.wl.client.display_flush = (PFN_wl_display_flush)
|
||||||
@ -639,7 +639,10 @@ int _glfwInitWayland(void)
|
|||||||
|
|
||||||
#ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION
|
#ifdef WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION
|
||||||
if (_glfw.wl.seatVersion >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION)
|
if (_glfw.wl.seatVersion >= WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION)
|
||||||
_glfw.wl.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
{
|
||||||
|
_glfw.wl.keyRepeatTimerfd =
|
||||||
|
timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!_glfw.wl.wmBase)
|
if (!_glfw.wl.wmBase)
|
||||||
@ -772,8 +775,8 @@ void _glfwTerminateWayland(void)
|
|||||||
wl_display_disconnect(_glfw.wl.display);
|
wl_display_disconnect(_glfw.wl.display);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_glfw.wl.timerfd >= 0)
|
if (_glfw.wl.keyRepeatTimerfd >= 0)
|
||||||
close(_glfw.wl.timerfd);
|
close(_glfw.wl.keyRepeatTimerfd);
|
||||||
if (_glfw.wl.cursorTimerfd >= 0)
|
if (_glfw.wl.cursorTimerfd >= 0)
|
||||||
close(_glfw.wl.cursorTimerfd);
|
close(_glfw.wl.cursorTimerfd);
|
||||||
|
|
||||||
|
@ -322,12 +322,12 @@ typedef struct _GLFWlibraryWayland
|
|||||||
uint32_t serial;
|
uint32_t serial;
|
||||||
uint32_t pointerEnterSerial;
|
uint32_t pointerEnterSerial;
|
||||||
|
|
||||||
int32_t keyboardRepeatRate;
|
int keyRepeatTimerfd;
|
||||||
int32_t keyboardRepeatDelay;
|
int32_t keyRepeatRate;
|
||||||
int keyboardLastKey;
|
int32_t keyRepeatDelay;
|
||||||
int keyboardLastScancode;
|
int keyRepeatScancode;
|
||||||
|
|
||||||
char* clipboardString;
|
char* clipboardString;
|
||||||
int timerfd;
|
|
||||||
short int keycodes[256];
|
short int keycodes[256];
|
||||||
short int scancodes[GLFW_KEY_LAST + 1];
|
short int scancodes[GLFW_KEY_LAST + 1];
|
||||||
char keynames[GLFW_KEY_LAST + 1][5];
|
char keynames[GLFW_KEY_LAST + 1][5];
|
||||||
|
@ -849,7 +849,7 @@ static xkb_keysym_t composeSymbol(xkb_keysym_t sym)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWbool inputText(_GLFWwindow* window, uint32_t scancode)
|
void inputText(_GLFWwindow* window, uint32_t scancode)
|
||||||
{
|
{
|
||||||
const xkb_keysym_t* keysyms;
|
const xkb_keysym_t* keysyms;
|
||||||
const xkb_keycode_t keycode = scancode + 8;
|
const xkb_keycode_t keycode = scancode + 8;
|
||||||
@ -865,8 +865,6 @@ GLFWbool inputText(_GLFWwindow* window, uint32_t scancode)
|
|||||||
_glfwInputChar(window, codepoint, mods, plain);
|
_glfwInputChar(window, codepoint, mods, plain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return xkb_keymap_key_repeats(_glfw.wl.xkb.keymap, keycode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleEvents(double* timeout)
|
static void handleEvents(double* timeout)
|
||||||
@ -875,7 +873,7 @@ static void handleEvents(double* timeout)
|
|||||||
struct pollfd fds[] =
|
struct pollfd fds[] =
|
||||||
{
|
{
|
||||||
{ wl_display_get_fd(_glfw.wl.display), POLLIN },
|
{ wl_display_get_fd(_glfw.wl.display), POLLIN },
|
||||||
{ _glfw.wl.timerfd, POLLIN },
|
{ _glfw.wl.keyRepeatTimerfd, POLLIN },
|
||||||
{ _glfw.wl.cursorTimerfd, POLLIN },
|
{ _glfw.wl.cursorTimerfd, POLLIN },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -919,16 +917,16 @@ static void handleEvents(double* timeout)
|
|||||||
{
|
{
|
||||||
uint64_t repeats;
|
uint64_t repeats;
|
||||||
|
|
||||||
if (read(_glfw.wl.timerfd, &repeats, sizeof(repeats)) == 8)
|
if (read(_glfw.wl.keyRepeatTimerfd, &repeats, sizeof(repeats)) == 8)
|
||||||
{
|
{
|
||||||
for (uint64_t i = 0; i < repeats; i++)
|
for (uint64_t i = 0; i < repeats; i++)
|
||||||
{
|
{
|
||||||
_glfwInputKey(_glfw.wl.keyboardFocus,
|
_glfwInputKey(_glfw.wl.keyboardFocus,
|
||||||
_glfw.wl.keyboardLastKey,
|
translateKey(_glfw.wl.keyRepeatScancode),
|
||||||
_glfw.wl.keyboardLastScancode,
|
_glfw.wl.keyRepeatScancode,
|
||||||
GLFW_PRESS,
|
GLFW_PRESS,
|
||||||
_glfw.wl.xkb.modifiers);
|
_glfw.wl.xkb.modifiers);
|
||||||
inputText(_glfw.wl.keyboardFocus, _glfw.wl.keyboardLastScancode);
|
inputText(_glfw.wl.keyboardFocus, _glfw.wl.keyRepeatScancode);
|
||||||
}
|
}
|
||||||
|
|
||||||
event = GLFW_TRUE;
|
event = GLFW_TRUE;
|
||||||
@ -1445,7 +1443,7 @@ static void keyboardHandleLeave(void* userData,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
struct itimerspec timer = {0};
|
struct itimerspec timer = {0};
|
||||||
timerfd_settime(_glfw.wl.timerfd, 0, &timer, NULL);
|
timerfd_settime(_glfw.wl.keyRepeatTimerfd, 0, &timer, NULL);
|
||||||
|
|
||||||
_glfw.wl.serial = serial;
|
_glfw.wl.serial = serial;
|
||||||
_glfw.wl.keyboardFocus = NULL;
|
_glfw.wl.keyboardFocus = NULL;
|
||||||
@ -1474,23 +1472,25 @@ static void keyboardHandleKey(void* userData,
|
|||||||
|
|
||||||
if (action == GLFW_PRESS)
|
if (action == GLFW_PRESS)
|
||||||
{
|
{
|
||||||
const GLFWbool shouldRepeat = inputText(window, scancode);
|
inputText(window, scancode);
|
||||||
|
|
||||||
if (shouldRepeat && _glfw.wl.keyboardRepeatRate > 0)
|
const xkb_keycode_t keycode = scancode + 8;
|
||||||
|
|
||||||
|
if (xkb_keymap_key_repeats(_glfw.wl.xkb.keymap, keycode) &&
|
||||||
|
_glfw.wl.keyRepeatRate > 0)
|
||||||
{
|
{
|
||||||
_glfw.wl.keyboardLastKey = key;
|
_glfw.wl.keyRepeatScancode = scancode;
|
||||||
_glfw.wl.keyboardLastScancode = scancode;
|
if (_glfw.wl.keyRepeatRate > 1)
|
||||||
if (_glfw.wl.keyboardRepeatRate > 1)
|
timer.it_interval.tv_nsec = 1000000000 / _glfw.wl.keyRepeatRate;
|
||||||
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.keyRepeatDelay / 1000;
|
||||||
timer.it_value.tv_nsec = (_glfw.wl.keyboardRepeatDelay % 1000) * 1000000;
|
timer.it_value.tv_nsec = (_glfw.wl.keyRepeatDelay % 1000) * 1000000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timerfd_settime(_glfw.wl.timerfd, 0, &timer, NULL);
|
timerfd_settime(_glfw.wl.keyRepeatTimerfd, 0, &timer, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void keyboardHandleModifiers(void* userData,
|
static void keyboardHandleModifiers(void* userData,
|
||||||
@ -1550,8 +1550,8 @@ static void keyboardHandleRepeatInfo(void* userData,
|
|||||||
if (keyboard != _glfw.wl.keyboard)
|
if (keyboard != _glfw.wl.keyboard)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_glfw.wl.keyboardRepeatRate = rate;
|
_glfw.wl.keyRepeatRate = rate;
|
||||||
_glfw.wl.keyboardRepeatDelay = delay;
|
_glfw.wl.keyRepeatDelay = delay;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user