Fixed closing window issue on linux

This commit is contained in:
KiritoDv 2022-05-19 15:51:20 -05:00
commit 518373db23
2 changed files with 8 additions and 7 deletions

View file

@ -156,6 +156,7 @@ static struct {
Atom atom_wm_delete_window; Atom atom_wm_delete_window;
bool is_fullscreen; bool is_fullscreen;
bool is_running = true;
void (*on_fullscreen_changed)(bool is_now_fullscreen); void (*on_fullscreen_changed)(bool is_now_fullscreen);
int keymap[256]; int keymap[256];
@ -399,7 +400,7 @@ static void gfx_glx_set_keyboard_callbacks(bool (*on_key_down)(int scancode), bo
} }
static void gfx_glx_main_loop(void (*run_one_game_iter)(void)) { static void gfx_glx_main_loop(void (*run_one_game_iter)(void)) {
while (1) { while (glx.is_running) {
run_one_game_iter(); run_one_game_iter();
} }
} }
@ -440,7 +441,7 @@ static void gfx_glx_handle_events(void) {
} }
} }
if (xev.type == ClientMessage && (Atom)xev.xclient.data.l[0] == glx.atom_wm_delete_window) { if (xev.type == ClientMessage && (Atom)xev.xclient.data.l[0] == glx.atom_wm_delete_window) {
exit(0); glx.is_running = false;
} }
} }
} }

View file

@ -37,6 +37,7 @@ static int vsync_enabled = 0;
static unsigned int window_width = DESIRED_SCREEN_WIDTH; static unsigned int window_width = DESIRED_SCREEN_WIDTH;
static unsigned int window_height = DESIRED_SCREEN_HEIGHT; static unsigned int window_height = DESIRED_SCREEN_HEIGHT;
static bool fullscreen_state; static bool fullscreen_state;
static bool is_running = true;
static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen); static void (*on_fullscreen_changed_callback)(bool is_now_fullscreen);
static bool (*on_key_down_callback)(int scancode); static bool (*on_key_down_callback)(int scancode);
static bool (*on_key_up_callback)(int scancode); static bool (*on_key_up_callback)(int scancode);
@ -135,7 +136,7 @@ static void gfx_sdl_init(const char *game_name, bool start_in_fullscreen) {
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#ifndef __linux #ifndef __linux__
timer = CreateWaitableTimer(nullptr, false, nullptr); timer = CreateWaitableTimer(nullptr, false, nullptr);
#endif #endif
@ -194,8 +195,7 @@ static void gfx_sdl_set_keyboard_callbacks(bool (*on_key_down)(int scancode), bo
} }
static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) { static void gfx_sdl_main_loop(void (*run_one_game_iter)(void)) {
while (1) while(is_running) {
{
run_one_game_iter(); run_one_game_iter();
} }
} }
@ -250,7 +250,7 @@ static void gfx_sdl_handle_events(void) {
} }
break; break;
case SDL_QUIT: case SDL_QUIT:
exit(0); is_running = false;
} }
} }
} }