Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EventState SDL3 compat #2940

Merged
merged 1 commit into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src_c/_pygame.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ PG_UnlockMutex(SDL_mutex *mutex)
/* Mask to test if surface flags are in a fullscreen window. */
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN

#define PG_SetEventEnabled(type, enabled) SDL_SetEventEnabled(type, enabled)
#define PG_EventEnabled(type) SDL_EventEnabled(type)
#define PG_SetJoystickEventsEnabled(enabled) \
SDL_SetJoystickEventsEnabled(enabled)

#else /* ~SDL_VERSION_ATLEAST(3, 0, 0)*/
#define PG_ShowCursor() SDL_ShowCursor(SDL_ENABLE)
#define PG_HideCursor() SDL_ShowCursor(SDL_DISABLE)
Expand Down Expand Up @@ -155,6 +160,13 @@ PG_UnlockMutex(SDL_mutex *mutex)
* SDL_WINDOW_FULLSCREEN. */
#define PG_WINDOW_FULLSCREEN_INCLUSIVE SDL_WINDOW_FULLSCREEN_DESKTOP

/* SDL_EventState is meant to take SDL_IGNORE or SDL_ENABLE, but it also
* works identically with SDL_FALSE and SDL_TRUE, because they evaluate to
* the same values, respectively. */
#define PG_SetEventEnabled(type, enabled) SDL_EventState(type, enabled)
#define PG_EventEnabled(type) SDL_EventState(type, SDL_QUERY)
#define PG_SetJoystickEventsEnabled(enabled) SDL_JoystickEventState(enabled)

#if SDL_VERSION_ATLEAST(2, 0, 14)
#define PG_SurfaceHasRLE SDL_HasSurfaceRLE
#else
Expand Down
19 changes: 9 additions & 10 deletions src_c/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ _pg_translate_windowevent(void *_, SDL_Event *event)
{
if (event->type == SDL_WINDOWEVENT) {
event->type = PGE_WINDOWSHOWN + event->window.event - 1;
return SDL_EventState(_pg_pgevent_proxify(event->type), SDL_QUERY);
return PG_EventEnabled(_pg_pgevent_proxify(event->type));
}
return 1;
}
Expand Down Expand Up @@ -599,7 +599,7 @@ pg_event_filter(void *_, SDL_Event *event)
return RAISE(pgExc_SDLError, SDL_GetError()), 0;
*/
}
return SDL_EventState(_pg_pgevent_proxify(event->type), SDL_QUERY);
return PG_EventEnabled(_pg_pgevent_proxify(event->type));
}

/* The two keyrepeat functions below modify state accessed by the event filter,
Expand Down Expand Up @@ -2142,7 +2142,7 @@ pg_event_set_allowed(PyObject *self, PyObject *obj)
if (obj == Py_None) {
int i;
for (i = SDL_FIRSTEVENT; i < SDL_LASTEVENT; i++) {
SDL_EventState(i, SDL_ENABLE);
PG_SetEventEnabled(i, SDL_TRUE);
}
}
else {
Expand All @@ -2156,7 +2156,7 @@ pg_event_set_allowed(PyObject *self, PyObject *obj)
Py_DECREF(seq);
return NULL;
}
SDL_EventState(_pg_pgevent_proxify(type), SDL_ENABLE);
PG_SetEventEnabled(_pg_pgevent_proxify(type), SDL_TRUE);
}
Py_DECREF(seq);
}
Expand All @@ -2175,7 +2175,7 @@ pg_event_set_blocked(PyObject *self, PyObject *obj)
int i;
/* Start at PGPOST_EVENTBEGIN */
for (i = PGPOST_EVENTBEGIN; i < SDL_LASTEVENT; i++) {
SDL_EventState(i, SDL_IGNORE);
PG_SetEventEnabled(i, SDL_FALSE);
}
}
else {
Expand All @@ -2189,14 +2189,14 @@ pg_event_set_blocked(PyObject *self, PyObject *obj)
Py_DECREF(seq);
return NULL;
}
SDL_EventState(_pg_pgevent_proxify(type), SDL_IGNORE);
PG_SetEventEnabled(_pg_pgevent_proxify(type), SDL_FALSE);
}
Py_DECREF(seq);
}
/* Never block SDL_WINDOWEVENT, we need them for translation */
SDL_EventState(SDL_WINDOWEVENT, SDL_ENABLE);
PG_SetEventEnabled(SDL_WINDOWEVENT, SDL_TRUE);
/* Never block PGE_KEYREPEAT too, its needed for pygame internal use */
SDL_EventState(PGE_KEYREPEAT, SDL_ENABLE);
PG_SetEventEnabled(PGE_KEYREPEAT, SDL_TRUE);
Py_RETURN_NONE;
}

Expand All @@ -2219,8 +2219,7 @@ pg_event_get_blocked(PyObject *self, PyObject *obj)
Py_DECREF(seq);
return NULL;
}
if (SDL_EventState(_pg_pgevent_proxify(type), SDL_QUERY) ==
SDL_IGNORE) {
if (PG_EventEnabled(_pg_pgevent_proxify(type)) == SDL_FALSE) {
isblocked = 1;
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src_c/joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ init(PyObject *self, PyObject *_null)
if (!SDL_WasInit(SDL_INIT_JOYSTICK)) {
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK))
return RAISE(pgExc_SDLError, SDL_GetError());
SDL_JoystickEventState(SDL_ENABLE);
PG_SetJoystickEventsEnabled(SDL_TRUE);
}
Py_RETURN_NONE;
}
Expand All @@ -60,7 +60,7 @@ quit(PyObject *self, PyObject *_null)
}

if (SDL_WasInit(SDL_INIT_JOYSTICK)) {
SDL_JoystickEventState(SDL_ENABLE);
PG_SetJoystickEventsEnabled(SDL_TRUE);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}
Py_RETURN_NONE;
Expand Down
Loading