Skip to content

Fix IsWindowFocused() on web.#4640

Merged
raysan5 merged 1 commit into
raysan5:masterfrom
marionauta:platform-web-window-focus
Dec 26, 2024
Merged

Fix IsWindowFocused() on web.#4640
raysan5 merged 1 commit into
raysan5:masterfrom
marionauta:platform-web-window-focus

Conversation

@marionauta

@marionauta marionauta commented Dec 26, 2024

Copy link
Copy Markdown
Contributor

Currently the web platform uses glfwSetWindowFocusCallback which seems to do nothing regarding the game canvas' focus. This PR adds emscripten focus/blur callbacks targeting the canvas.

Sample project focus.zip

#include <raylib.h>
#include <emscripten/emscripten.h>

void gameupdate(void) {
    BeginDrawing();
    ClearBackground(WHITE);
    if (IsWindowFocused()) {
        DrawText("Focused", 10, 10, 50, BLACK);
    } else {
        DrawText("Unfocused", 10, 10, 50, BLACK);
    }
    EndDrawing();
}

int main(void) {
  InitWindow(400, 400, "focus events");
  emscripten_set_main_loop(gameupdate, 0, 1);
  CloseWindow();
  return 0;
}
Screen.Recording.2024-12-26.at.19.08.47.mov

@raysan5 raysan5 merged commit 7ecc47d into raysan5:master Dec 26, 2024
@raysan5

raysan5 commented Dec 26, 2024

Copy link
Copy Markdown
Owner

@marionauta Thanks for the improvement! As per the sources, it seems the function is set but I can't see how it is used...

@marionauta marionauta deleted the platform-web-window-focus branch February 24, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants