@@ -212,11 +212,6 @@ static Uint64 Wayland_GetKeyboardTimestamp(struct SDL_WaylandInput *input, Uint3
212
212
return 0 ;
213
213
}
214
214
215
- static Uint64 Wayland_GetKeyboardTimestampRaw (struct SDL_WaylandInput * input , Uint32 wl_timestamp_ms )
216
- {
217
- return input -> keyboard_timestamp_ns ? input -> keyboard_timestamp_ns : Wayland_EventTimestampMSToNS (wl_timestamp_ms );
218
- }
219
-
220
215
static Uint64 Wayland_GetPointerTimestamp (struct SDL_WaylandInput * input , Uint32 wl_timestamp_ms )
221
216
{
222
217
if (wl_timestamp_ms ) {
@@ -273,18 +268,10 @@ static bool keyboard_repeat_handle(SDL_WaylandKeyboardRepeat *repeat_info, Uint6
273
268
{
274
269
bool ret = false;
275
270
276
- /* Cap the elapsed time to something sane in case the compositor sends a bad timestamp,
277
- * which can result it in it looking like the key has been pressed for a *very* long time,
278
- * bringing everything to a halt while it tries to enqueue all the repeat events.
279
- *
280
- * 3 seconds seems reasonable.
281
- */
282
- elapsed = SDL_min (elapsed , SDL_MS_TO_NS (3000 ));
283
-
284
271
while (elapsed >= repeat_info -> next_repeat_ns ) {
285
272
if (repeat_info -> scancode != SDL_SCANCODE_UNKNOWN ) {
286
- const Uint64 timestamp = repeat_info -> wl_press_time_ns + repeat_info -> next_repeat_ns ;
287
- SDL_SendKeyboardKeyIgnoreModifiers (Wayland_GetEventTimestamp ( timestamp ) , repeat_info -> keyboard_id , repeat_info -> key , repeat_info -> scancode , true);
273
+ const Uint64 timestamp = repeat_info -> base_time_ns + repeat_info -> next_repeat_ns ;
274
+ SDL_SendKeyboardKeyIgnoreModifiers (timestamp , repeat_info -> keyboard_id , repeat_info -> key , repeat_info -> scancode , true);
288
275
}
289
276
if (repeat_info -> text [0 ]) {
290
277
SDL_SendKeyboardText (repeat_info -> text );
@@ -303,16 +290,17 @@ static void keyboard_repeat_clear(SDL_WaylandKeyboardRepeat *repeat_info)
303
290
repeat_info -> is_key_down = false;
304
291
}
305
292
306
- static void keyboard_repeat_set (SDL_WaylandKeyboardRepeat * repeat_info , Uint32 keyboard_id , uint32_t key , Uint64 wl_press_time_ns ,
307
- uint32_t scancode , bool has_text , char text [8 ])
293
+ static void keyboard_repeat_set (SDL_WaylandKeyboardRepeat * repeat_info , Uint32 keyboard_id , uint32_t key , Uint32 wl_press_time_ms ,
294
+ Uint64 base_time_ns , uint32_t scancode , bool has_text , char text [8 ])
308
295
{
309
296
if (!repeat_info -> is_initialized || !repeat_info -> repeat_rate ) {
310
297
return ;
311
298
}
312
299
repeat_info -> is_key_down = true;
313
300
repeat_info -> keyboard_id = keyboard_id ;
314
301
repeat_info -> key = key ;
315
- repeat_info -> wl_press_time_ns = wl_press_time_ns ;
302
+ repeat_info -> wl_press_time_ms = wl_press_time_ms ;
303
+ repeat_info -> base_time_ns = base_time_ns ;
316
304
repeat_info -> sdl_press_time_ns = SDL_GetTicksNS ();
317
305
repeat_info -> next_repeat_ns = SDL_MS_TO_NS (repeat_info -> repeat_delay_ms );
318
306
repeat_info -> scancode = scancode ;
@@ -1867,7 +1855,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
1867
1855
char text [8 ];
1868
1856
bool has_text = false;
1869
1857
bool handled_by_ime = false;
1870
- const Uint64 timestamp_raw_ns = Wayland_GetKeyboardTimestampRaw (input , time );
1858
+ const Uint64 timestamp_ns = Wayland_GetKeyboardTimestamp (input , time );
1871
1859
1872
1860
Wayland_UpdateImplicitGrabSerial (input , serial );
1873
1861
@@ -1883,17 +1871,17 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
1883
1871
* Using SDL_GetTicks would be wrong, as it would report when the release event is processed,
1884
1872
* which may be off if the application hasn't pumped events for a while.
1885
1873
*/
1886
- keyboard_repeat_handle (& input -> keyboard_repeat , timestamp_raw_ns - input -> keyboard_repeat .wl_press_time_ns );
1874
+ const Uint64 elapsed = SDL_MS_TO_NS (time - input -> keyboard_repeat .wl_press_time_ms );
1875
+ keyboard_repeat_handle (& input -> keyboard_repeat , elapsed );
1887
1876
keyboard_repeat_clear (& input -> keyboard_repeat );
1888
1877
}
1889
1878
keyboard_input_get_text (text , input , key , false, & handled_by_ime );
1890
1879
}
1891
1880
1892
1881
const SDL_Scancode scancode = Wayland_GetScancodeForKey (input , key );
1893
1882
Wayland_HandleModifierKeys (input , scancode , state == WL_KEYBOARD_KEY_STATE_PRESSED );
1894
- Uint64 timestamp = Wayland_GetKeyboardTimestamp (input , time );
1895
1883
1896
- SDL_SendKeyboardKeyIgnoreModifiers (timestamp , input -> keyboard_id , key , scancode , state == WL_KEYBOARD_KEY_STATE_PRESSED );
1884
+ SDL_SendKeyboardKeyIgnoreModifiers (timestamp_ns , input -> keyboard_id , key , scancode , state == WL_KEYBOARD_KEY_STATE_PRESSED );
1897
1885
1898
1886
if (state == WL_KEYBOARD_KEY_STATE_PRESSED ) {
1899
1887
if (has_text && !(SDL_GetModState () & (SDL_KMOD_CTRL | SDL_KMOD_ALT ))) {
@@ -1902,7 +1890,7 @@ static void keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
1902
1890
}
1903
1891
}
1904
1892
if (input -> xkb .keymap && WAYLAND_xkb_keymap_key_repeats (input -> xkb .keymap , key + 8 )) {
1905
- keyboard_repeat_set (& input -> keyboard_repeat , input -> keyboard_id , key , timestamp_raw_ns , scancode , has_text , text );
1893
+ keyboard_repeat_set (& input -> keyboard_repeat , input -> keyboard_id , key , time , timestamp_ns , scancode , has_text , text );
1906
1894
}
1907
1895
}
1908
1896
}
0 commit comments