Skip to content

Commit

Permalink
Fix IsWindowFocused() on web. (#4640)
Browse files Browse the repository at this point in the history
  • Loading branch information
marionauta authored Dec 26, 2024
1 parent 4758867 commit 7ecc47d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/platforms/rcore_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static void CursorEnterCallback(GLFWwindow *window, int enter);
static EM_BOOL EmscriptenFullscreenChangeCallback(int eventType, const EmscriptenFullscreenChangeEvent *event, void *userData);
// static EM_BOOL EmscriptenWindowResizedCallback(int eventType, const EmscriptenUiEvent *event, void *userData);
static EM_BOOL EmscriptenResizeCallback(int eventType, const EmscriptenUiEvent *event, void *userData);
static EM_BOOL EmscriptenFocusCallback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData);

// Emscripten input callback events
static EM_BOOL EmscriptenMouseMoveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);
Expand Down Expand Up @@ -1369,6 +1370,10 @@ int InitPlatform(void)
// Support gamepad events (not provided by GLFW3 on emscripten)
emscripten_set_gamepadconnected_callback(NULL, 1, EmscriptenGamepadCallback);
emscripten_set_gamepaddisconnected_callback(NULL, 1, EmscriptenGamepadCallback);

// Support focus events
emscripten_set_blur_callback("#canvas", platform.handle, 1, EmscriptenFocusCallback);
emscripten_set_focus_callback("#canvas", platform.handle, 1, EmscriptenFocusCallback);
//----------------------------------------------------------------------------

// Initialize timing system
Expand Down Expand Up @@ -1732,6 +1737,18 @@ static EM_BOOL EmscriptenGamepadCallback(int eventType, const EmscriptenGamepadE
return 1; // The event was consumed by the callback handler
}

static EM_BOOL EmscriptenFocusCallback(int eventType, const EmscriptenFocusEvent *focusEvent, void *userData)
{
EM_BOOL consumed = 1;
switch (eventType)
{
case EMSCRIPTEN_EVENT_BLUR: WindowFocusCallback(userData, 0); break;
case EMSCRIPTEN_EVENT_FOCUS: WindowFocusCallback(userData, 1); break;
default: consumed = 0; break;
}
return consumed;
}

// Register touch input events
static EM_BOOL EmscriptenTouchCallback(int eventType, const EmscriptenTouchEvent *touchEvent, void *userData)
{
Expand Down

0 comments on commit 7ecc47d

Please sign in to comment.