From 36e45dbc405147b1ee4c4d9d806b46e1393fe265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 28 Sep 2021 10:43:15 +0700 Subject: [PATCH] Allow pressing esc in keyboard mode --- core.c | 4 ++++ input.c | 6 +++--- video.c | 7 +++++++ video.h | 1 + 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core.c b/core.c index 9d0e4f5..64e10bc 100644 --- a/core.c +++ b/core.c @@ -106,6 +106,10 @@ static bool core_environment(unsigned cmd, void *data) *(bool*)data = false; } break; + case RETRO_ENVIRONMENT_SHUTDOWN: { + video_should_close(1); + } + break; case RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE: { *(int*)data = 1 << 0 | 1 << 1; } diff --git a/input.c b/input.c index f61b6c7..a34fcf6 100644 --- a/input.c +++ b/input.c @@ -216,6 +216,9 @@ void input_poll(void) { { for (i = 0; kbd2joy_binds[i].k || kbd2joy_binds[i].rk; ++i) state[0][kbd2joy_binds[i].rk] = glfwGetKey(window, kbd2joy_binds[i].k) == GLFW_PRESS; + + if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) + glfwSetWindowShouldClose(window, true); } int port; @@ -243,9 +246,6 @@ void input_poll(void) { state[port][RETRO_DEVICE_ID_JOYPAD_L2] = axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER] > 0.5; state[port][RETRO_DEVICE_ID_JOYPAD_R2] = axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER] > 0.5; } - - if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) - glfwSetWindowShouldClose(window, true); } void input_set_keyboard_callback(retro_keyboard_event_t e) diff --git a/video.c b/video.c index dbaf85d..0f34cbb 100644 --- a/video.c +++ b/video.c @@ -269,6 +269,13 @@ void create_window(int width, int height) glEnable(GL_TEXTURE_2D); } +void video_should_close(int v) +{ + if (!window) + return; + glfwSetWindowShouldClose(window, v); +} + static void init_framebuffer(int width, int height) { glGenFramebuffers(1, &video.fbo_id); diff --git a/video.h b/video.h index ac6cdc4..8fcbfc1 100644 --- a/video.h +++ b/video.h @@ -5,6 +5,7 @@ void video_configure(const struct retro_game_geometry *geom); bool video_set_pixel_format(unsigned format); void video_set_geometry(const struct retro_game_geometry *geom); void video_set_hw(struct retro_hw_render_callback); +void video_should_close(int v); void video_refresh(const void *data, unsigned width, unsigned height, size_t pitch); uintptr_t video_get_current_framebuffer(); void video_render();