@@ -470,19 +470,40 @@ _pg_pgevent_deproxify(Uint32 type)
470
470
return _pg_pgevent_proxify_helper (type , 0 );
471
471
}
472
472
473
+ /* Get type of an event, handling WINDOWEVENT translation on SDL2.
474
+ * On SDL3 this function is trivial */
475
+ static Uint32
476
+ _pg_pgevent_type (SDL_Event * event )
477
+ {
473
478
#if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
474
- /* We don't need to do window event translation because in SDL3 each window
475
- * event is its own thing anyways */
476
- static int
477
- _pg_translate_windowevent (void * _ , SDL_Event * event )
479
+ if (event -> type == SDL_WINDOWEVENT ) {
480
+ return PGE_WINDOWSHOWN + event -> window .event - 1 ;
481
+ }
482
+ #endif
483
+ return event -> type ;
484
+ }
485
+
486
+ /* Handle blocking of pseudo-blocked events.
487
+ * Currently this only includes WINDOWEVENT, but can be expanded in the
488
+ * future.
489
+ */
490
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
491
+ static bool SDLCALL
492
+ #else
493
+ static int SDLCALL
494
+ #endif
495
+ _pg_filter_blocked_events (void * _ , SDL_Event * event )
478
496
{
497
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
498
+ if (event -> type >= SDL_EVENT_WINDOW_FIRST &&
499
+ event -> type <= SDL_EVENT_WINDOW_LAST ) {
500
+ #else
479
501
if (event -> type == SDL_WINDOWEVENT ) {
480
- event -> type = PGE_WINDOWSHOWN + event -> window . event - 1 ;
481
- return PG_EventEnabled (_pg_pgevent_proxify (event -> type ));
502
+ #endif
503
+ return PG_EventEnabled (_pg_pgevent_proxify (_pg_pgevent_type ( event ) ));
482
504
}
483
505
return 1 ;
484
506
}
485
- #endif
486
507
487
508
#if SDL_VERSION_ATLEAST (3 , 0 , 0 )
488
509
static bool SDLCALL
@@ -709,6 +730,14 @@ pg_event_filter(void *_, SDL_Event *event)
709
730
return RAISE(pgExc_SDLError, SDL_GetError()), 0;
710
731
*/
711
732
}
733
+ /* TODO:
734
+ * Any event that gets blocked here will not be visible to the event
735
+ * watchers. So things like WINDOWEVENT should never be blocked here.
736
+ * This is taken care of in SDL2 codepaths already but needs to also
737
+ * be verified in SDL3 porting.
738
+ * If the user requests a block on WINDOWEVENTs we are going to handle
739
+ * it specially and call it a "pseudo-block", where the filtering will
740
+ * happen in a _pg_filter_blocked_events call. */
712
741
return PG_EventEnabled (_pg_pgevent_proxify (event -> type ));
713
742
}
714
743
@@ -1747,7 +1776,7 @@ pgEvent_New(SDL_Event *event)
1747
1776
}
1748
1777
1749
1778
if (event ) {
1750
- e -> type = _pg_pgevent_deproxify (event -> type );
1779
+ e -> type = _pg_pgevent_deproxify (_pg_pgevent_type ( event ) );
1751
1780
e -> dict = dict_from_event (event );
1752
1781
}
1753
1782
else {
@@ -1846,14 +1875,7 @@ _pg_event_pump(int dopump)
1846
1875
SDL_PumpEvents ();
1847
1876
}
1848
1877
1849
- /* WINDOWEVENT translation needed only on SDL2 */
1850
- #if !SDL_VERSION_ATLEAST (3 , 0 , 0 )
1851
- /* We need to translate WINDOWEVENTS. But if we do that from the
1852
- * from event filter, internal SDL stuff that rely on WINDOWEVENT
1853
- * might break. So after every event pump, we translate events from
1854
- * here */
1855
- SDL_FilterEvents (_pg_translate_windowevent , NULL );
1856
- #endif
1878
+ SDL_FilterEvents (_pg_filter_blocked_events , NULL );
1857
1879
}
1858
1880
1859
1881
static int
0 commit comments