Skip to content

Commit b5843fc

Browse files
committed
Fix key repeat in sdl2-compat
1 parent 46edd4e commit b5843fc

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src_c/_pygame.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,6 @@ typedef enum {
403403

404404
PGE_MIDIIN,
405405
PGE_MIDIOUT,
406-
PGE_KEYREPEAT, /* Special internal pygame event, for managing key-presses
407-
*/
408406

409407
/* DO NOT CHANGE THE ORDER OF EVENTS HERE */
410408
PGE_WINDOWSHOWN,

src_c/event.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,17 @@ _pg_repeat_callback(Uint32 interval, void *param)
152152
int repeat_interval_copy = pg_key_repeat_interval;
153153
PG_UNLOCK_EVFILTER_MUTEX
154154

155-
repeat_event_copy.type = PGE_KEYREPEAT;
155+
repeat_event_copy.type = SDL_KEYDOWN;
156156
#if SDL_VERSION_ATLEAST(3, 0, 0)
157157
repeat_event_copy.key.down = true;
158158
repeat_event_copy.key.repeat = true;
159159
#else
160160
repeat_event_copy.key.state = SDL_PRESSED;
161161
repeat_event_copy.key.repeat = 1;
162162
#endif
163-
SDL_PushEvent(&repeat_event_copy);
163+
/* Use SDL_PeepEvents and not SDL_PushEvent because we don't want
164+
* this to go through our event filter */
165+
SDL_PeepEvents(&repeat_event_copy, 1, SDL_ADDEVENT, 0, 0);
164166
return repeat_interval_copy;
165167
}
166168

@@ -634,10 +636,6 @@ pg_event_filter(void *_, SDL_Event *event)
634636
PG_UNLOCK_EVFILTER_MUTEX
635637
}
636638

637-
else if (event->type == PGE_KEYREPEAT) {
638-
event->type = SDL_KEYDOWN;
639-
}
640-
641639
else if (event->type == SDL_KEYUP) {
642640
PG_LOCK_EVFILTER_MUTEX
643641
/* Actual keyup is blocked, so clear unneeded cache if it exists */
@@ -2481,8 +2479,6 @@ pg_event_set_blocked(PyObject *self, PyObject *obj)
24812479
/* Never block SDL_WINDOWEVENT on SDL2, we need them for translation */
24822480
PG_SetEventEnabled(SDL_WINDOWEVENT, SDL_TRUE);
24832481
#endif
2484-
/* Never block PGE_KEYREPEAT too, its needed for pygame internal use */
2485-
PG_SetEventEnabled(PGE_KEYREPEAT, SDL_TRUE);
24862482
Py_RETURN_NONE;
24872483
}
24882484

0 commit comments

Comments
 (0)