Commits

Marcus von Appen committed 03c0926

- added new sdl2.hints.SDL_AddHintCallback() and
sdl2.hints.SDL_DelHintCallback() functions

Comments (0)

Files changed (3)

-from ctypes import c_int, c_char_p
+from ctypes import CFUNCTYPE, c_int, c_char_p, c_void_p
 from .dll import _bind
 from .stdinc import SDL_bool
 
 SDL_HINT_GAMECONTROLLERCONFIG = b"SDL_GAMECONTROLLERCONFIG"
 SDL_HINT_ALLOW_TOPMOST = b"SDL_ALLOW_TOPMOST"
 SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS = b"SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS"
+SDL_HINT_TIMER_RESOLUTION = b"SDL_TIMER_RESOLUTION"
 
 SDL_HINT_DEFAULT = 0
 SDL_HINT_NORMAL = 1
 SDL_SetHint = _bind("SDL_SetHint", [c_char_p, c_char_p], SDL_bool)
 SDL_GetHint = _bind("SDL_GetHint", [c_char_p], c_char_p)
 SDL_ClearHints = _bind("SDL_ClearHints")
+SDL_HintCallback = CFUNCTYPE(None, c_void_p, c_char_p, c_char_p, c_char_p)
+SDL_AddHintCallback = _bind("SDL_AddHintCallback", [c_char_p, SDL_HintCallback, c_void_p])
+SDL_DelHintCallback = _bind("SDL_DelHintCallback",[c_char_p, SDL_HintCallback, c_void_p])

sdl2/test/hints_test.py

 import sys
 import unittest
+from ctypes import cast, c_char_p
 from .. import SDL_Init, SDL_Quit, SDL_QuitSubSystem, SDL_INIT_EVERYTHING
 from .. import hints
 
         # self.assertRaises(ValueError, hints.SDL_SetHintWithPriority,
         #                  "TEST", "123456789", "bananas")
 
+    def test_SDL_AddDelHintCallback(self):
+        calls = []
+        def callback(userdata, name, oldval, newval):
+            data = cast(userdata, c_char_p)
+            calls.append((data.value, name, oldval, newval))
+        hintcb = hints.SDL_HintCallback(callback)
+        hints.SDL_AddHintCallback(hints.SDL_HINT_ALLOW_TOPMOST, hintcb,
+                                  b"banana")
+        # SDL_AddHintCallback invokes the callback once.
+        self.assertEqual(len(calls), 1)
+        self.assertEqual(calls[0], (b"banana", hints.SDL_HINT_ALLOW_TOPMOST,
+                                    None, None))
+        hints.SDL_SetHint(hints.SDL_HINT_ALLOW_TOPMOST, b"true")
+        self.assertEqual(len(calls), 2)
+        self.assertEqual(calls[1], (b"banana", hints.SDL_HINT_ALLOW_TOPMOST,
+                                    None, b"true"))
+        hints.SDL_DelHintCallback(hints.SDL_HINT_ALLOW_TOPMOST, hintcb,
+                                  b"banana")
+        hints.SDL_SetHint(hints.SDL_HINT_ALLOW_TOPMOST, b"false")
+        self.assertEqual(len(calls), 2)
+
 
 if __name__ == '__main__':
     sys.exit(unittest.main())

sdl2/test/video_test.py

                                               dmode.refresh_rate)
                 closest = video.SDL_DisplayMode()
                 video.SDL_GetClosestDisplayMode(index, cmode, byref(closest))
-                # TODO: refresh_rate not correctly set anymore
-                # http://bugzilla.libsdl.org/show_bug.cgi?id=1956
-                # self.assertEqual(closest, dmode)
-                self.assertEqual(closest.format, dmode.format)
-                self.assertEqual(closest.w, dmode.w)
-                self.assertEqual(closest.h, dmode.h)
-
+                self.assertEqual(closest, dmode)
 
     def test_SDL_VideoInit(self):
         video.SDL_VideoInit(None)