Skip to content

Commit

Permalink
Allow pressing esc in keyboard mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kivutar committed Sep 28, 2021
1 parent b71f02f commit 36e45db
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions video.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 36e45db

Please sign in to comment.