Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds: [Feature Request] Pause on focus loss #191 #408

Open
wants to merge 2 commits into
base: nightly
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/game/level_update.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct CreditsEntry sCreditsSequence[] = {
{ LEVEL_CASTLE_GROUNDS, 1, 1, -128, { 0, 906, -1200 }, NULL },
{ LEVEL_NONE, 0, 1, 0, { 0, 0, 0 }, NULL },
};

extern bool focus_Lost;
struct MarioState gMarioStates[1];
struct HudDisplay gHudDisplay;
s16 sCurrPlayMode;
Expand Down Expand Up @@ -961,6 +961,7 @@ void basic_update(UNUSED s16 *arg) {
int gPressedStart = 0;

s32 play_mode_normal(void) {

if (gCurrDemoInput != NULL) {
print_intro_text();
if (gPlayer1Controller->buttonPressed & END_DEMO) {
Expand Down Expand Up @@ -997,11 +998,12 @@ s32 play_mode_normal(void) {
set_play_mode(PLAY_MODE_CHANGE_LEVEL);
} else if (sTransitionTimer != 0) {
set_play_mode(PLAY_MODE_CHANGE_AREA);
} else if (pressed_pause()) {
} else if (pressed_pause() || focus_Lost) {
lower_background_noise(1);
cancel_rumble();
gCameraMovementFlags |= CAM_MOVE_PAUSE_SCREEN;
set_play_mode(PLAY_MODE_PAUSED);
focus_Lost = FALSE;
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/pc/gfx/gfx_sdl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#else
# define FRAMERATE 30
#endif

bool focus_Lost = FALSE;
static int inverted_scancode_table[512];

static kb_callback_t kb_key_down = NULL;
Expand Down Expand Up @@ -202,6 +202,11 @@ static void gfx_sdl_onkeyup(int scancode) {
static void gfx_sdl_handle_events(void) {
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type.event = SDL_WINDOWEVENT_FOCUS_LOST)
{
focus_Lost = TRUE;
}

switch (event.type) {
#ifndef TARGET_WEB
// Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259
Expand All @@ -222,6 +227,7 @@ static void gfx_sdl_handle_events(void) {
case SDL_QUIT:
game_exit();
break;

}
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/pc/gfx/gfx_sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#else
# define FRAMERATE 30
#endif

bool focus_Lost = FALSE;
static SDL_Window *wnd;
static SDL_GLContext ctx = NULL;
static int inverted_scancode_table[512];
Expand Down Expand Up @@ -282,11 +282,13 @@ static void gfx_sdl_handle_events(void) {
// Scancodes are broken in Emscripten SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=3259
case SDL_KEYDOWN:
gfx_sdl_onkeydown(event.key.keysym.scancode);

break;
case SDL_KEYUP:
gfx_sdl_onkeyup(event.key.keysym.scancode);
break;
#endif

case SDL_WINDOWEVENT: // TODO: Check if this makes sense to be included in the Web build
if (!IS_FULLSCREEN()) {
switch (event.window.event) {
Expand All @@ -300,12 +302,16 @@ static void gfx_sdl_handle_events(void) {
configWindow.w = event.window.data1;
configWindow.h = event.window.data2;
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
focus_Lost = TRUE;
break;
}
}
break;
case SDL_QUIT:
game_exit();
break;

}
}

Expand Down