Mercurial > touhou
comparison pytouhou/lib/glfw.pyx @ 729:f953ae5b3732
PyTouhou: Fix GLFW callbacks to be nogil
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 08 Dec 2019 20:13:01 +0100 |
parents | 4fa0a8e7d941 |
children |
comparison
equal
deleted
inserted
replaced
728:414f8611f344 | 729:f953ae5b3732 |
---|---|
25 | 25 |
26 OPENGL_API = GLFW_OPENGL_API | 26 OPENGL_API = GLFW_OPENGL_API |
27 OPENGL_ES_API = GLFW_OPENGL_ES_API | 27 OPENGL_ES_API = GLFW_OPENGL_ES_API |
28 OPENGL_CORE_PROFILE = GLFW_OPENGL_CORE_PROFILE | 28 OPENGL_CORE_PROFILE = GLFW_OPENGL_CORE_PROFILE |
29 | 29 |
30 cdef void error_callback(int a, const char* b): | 30 cdef void error_callback(int a, const char* b) nogil: |
31 print('GLFW error 0x%x: %s' % (a, b.decode('utf-8'))) | 31 with gil: |
32 print('GLFW error 0x%x: %s' % (a, b.decode('utf-8'))) | |
32 | 33 |
33 cdef list _global_events = [] | 34 cdef list _global_events = [] |
34 | 35 |
35 cdef void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods): | 36 cdef void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) nogil: |
36 if action != GLFW_PRESS: | 37 with gil: |
37 return | 38 if action != GLFW_PRESS: |
38 if key == GLFW_KEY_ESCAPE: | 39 return |
39 _global_events.append((gui.PAUSE, None)) | 40 if key == GLFW_KEY_ESCAPE: |
40 elif key in (GLFW_KEY_P, GLFW_KEY_HOME): | 41 _global_events.append((gui.PAUSE, None)) |
41 _global_events.append((gui.SCREENSHOT, None)) | 42 elif key in (GLFW_KEY_P, GLFW_KEY_HOME): |
42 elif key == GLFW_KEY_DOWN: | 43 _global_events.append((gui.SCREENSHOT, None)) |
43 _global_events.append((gui.DOWN, None)) | 44 elif key == GLFW_KEY_DOWN: |
44 elif key == GLFW_KEY_F11: | 45 _global_events.append((gui.DOWN, None)) |
45 _global_events.append((gui.FULLSCREEN, None)) | 46 elif key == GLFW_KEY_F11: |
46 elif key == GLFW_KEY_ENTER: | |
47 if mods & GLFW_MOD_ALT: | |
48 _global_events.append((gui.FULLSCREEN, None)) | 47 _global_events.append((gui.FULLSCREEN, None)) |
48 elif key == GLFW_KEY_ENTER: | |
49 if mods & GLFW_MOD_ALT: | |
50 _global_events.append((gui.FULLSCREEN, None)) | |
49 | 51 |
50 cdef void size_callback(GLFWwindow* window, int width, int height): | 52 cdef void size_callback(GLFWwindow* window, int width, int height) nogil: |
51 _global_events.append((gui.RESIZE, (width, height))) | 53 with gil: |
54 _global_events.append((gui.RESIZE, (width, height))) | |
52 | 55 |
53 cdef void close_callback(GLFWwindow* window): | 56 cdef void close_callback(GLFWwindow* window) nogil: |
54 _global_events.append((gui.EXIT, None)) | 57 with gil: |
58 _global_events.append((gui.EXIT, None)) | |
55 | 59 |
56 cdef void init() except *: | 60 cdef void init() except *: |
57 glfwSetErrorCallback(<GLFWerrorfun>error_callback) | 61 glfwSetErrorCallback(<GLFWerrorfun>error_callback) |
58 ret = glfwInit() | 62 ret = glfwInit() |
59 if not ret: | 63 if not ret: |