@@ -80,7 +80,11 @@ pg_scancodewrapper_subscript(pgScancodeWrapper *self, PyObject *item)
80
80
PyObject * adjustedvalue , * ret ;
81
81
if ((index = PyLong_AsLong (item )) == -1 && PyErr_Occurred ())
82
82
return NULL ;
83
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
84
+ index = SDL_GetScancodeFromKey (index , NULL );
85
+ #else
83
86
index = SDL_GetScancodeFromKey (index );
87
+ #endif
84
88
adjustedvalue = PyLong_FromLong (index );
85
89
ret = PyTuple_Type .tp_as_mapping -> mp_subscript ((PyObject * )self ,
86
90
adjustedvalue );
@@ -163,7 +167,11 @@ static PyObject *
163
167
key_get_pressed (PyObject * self , PyObject * _null )
164
168
{
165
169
int num_keys ;
170
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
171
+ const bool * key_state ;
172
+ #else
166
173
const Uint8 * key_state ;
174
+ #endif
167
175
PyObject * ret_obj = NULL ;
168
176
PyObject * key_tuple ;
169
177
int i ;
@@ -511,16 +519,42 @@ key_get_focused(PyObject *self, PyObject *_null)
511
519
static PyObject *
512
520
key_start_text_input (PyObject * self , PyObject * _null )
513
521
{
522
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
523
+ /* Can consider making this a method of the Window class, this function
524
+ * just does backcompat */
525
+ SDL_Window * win = pg_GetDefaultWindow ();
526
+ if (!win ) {
527
+ return RAISE (pgExc_SDLError ,
528
+ "display.set_mode has not been called yet." );
529
+ }
530
+ if (!SDL_StartTextInput (win )) {
531
+ return RAISE (pgExc_SDLError , SDL_GetError ());
532
+ }
533
+ #else
514
534
/* https://wiki.libsdl.org/SDL_StartTextInput */
515
535
SDL_StartTextInput ();
536
+ #endif
516
537
Py_RETURN_NONE ;
517
538
}
518
539
519
540
static PyObject *
520
541
key_stop_text_input (PyObject * self , PyObject * _null )
521
542
{
543
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
544
+ /* Can consider making this a method of the Window class, this function
545
+ * just does backcompat */
546
+ SDL_Window * win = pg_GetDefaultWindow ();
547
+ if (!win ) {
548
+ return RAISE (pgExc_SDLError ,
549
+ "display.set_mode has not been called yet." );
550
+ }
551
+ if (!SDL_StopTextInput (win )) {
552
+ return RAISE (pgExc_SDLError , SDL_GetError ());
553
+ }
554
+ #else
522
555
/* https://wiki.libsdl.org/SDL_StopTextInput */
523
556
SDL_StopTextInput ();
557
+ #endif
524
558
Py_RETURN_NONE ;
525
559
}
526
560
@@ -552,11 +586,23 @@ key_set_text_input_rect(PyObject *self, PyObject *obj)
552
586
rect2 .w = (int )(rect -> w * scalex );
553
587
rect2 .h = (int )(rect -> h * scaley );
554
588
589
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
590
+ /* Should consider how to expose the cursor argument to the user, maybe
591
+ * this should be new API in Window? */
592
+ SDL_SetTextInputArea (sdlWindow , & rect2 , 0 );
593
+ #else
555
594
SDL_SetTextInputRect (& rect2 );
595
+ #endif
556
596
Py_RETURN_NONE ;
557
597
}
558
598
599
+ #if SDL_VERSION_ATLEAST (3 , 0 , 0 )
600
+ /* Should consider how to expose the cursor argument to the user, maybe
601
+ * this should be new API in Window? */
602
+ SDL_SetTextInputArea (sdlWindow , rect , 0 );
603
+ #else
559
604
SDL_SetTextInputRect (rect );
605
+ #endif
560
606
561
607
Py_RETURN_NONE ;
562
608
}
0 commit comments