ocornut / imgui

Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
MIT License
61.15k stars 10.3k forks source link

Meta + [key] on macOS using emscripten is broken (sdl2 + glfw backends) #7732

Open ypujante opened 4 months ago

ypujante commented 4 months ago

Version/Branch of Dear ImGui:

master

Back-ends:

example_sdl2_opengl3 / example_glfw_wgpu

Compiler, OS:

emscripten / browser

Full config/build information:

# emcc --version
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.61 (67fa4c16496b157a7fc3377afd69ee0445e8a6e3)
Copyright (C) 2014 the Emscripten authors (see AUTHORS.txt)
This is free and open source software under the MIT license.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Details:

I uncovered this issue while working on a separate project tied to the PR

Screenshots/Video:

Meta_V

Minimal, Complete and Verifiable Example code:

Using fresh imgui clone

# git rev-parse HEAD
48e7e7bfe8521af8802eda2ec26546a6069e5573

# git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

Under examples/example_sdl2_opengl3

# make -f Makefile.emscripten clean serve

Under examples/example_glfw_wgpu

# make -f Makefile.emscripten clean serve

In both builds (using sdl2 as the backend or glfw as the backend),

ypujante commented 4 months ago

I believe the issue, in both instances, is linked to this javascript problem.

Although it is not an ImGui bug per se, but more an issue in the underlying implementations/platform, I just wanted to file this bug here in case other people run into this issue and know that there is, at the moment, an issue when using ImGui in the browser... In the end, it does break ImGui since the state of keys maintained by ImGui becomes out of whack with reality which can then lead to other issues...

I am going to investigate if there is a workaround I can implement in emscripten-glfw at the minimum since I am in control of this library... I am going to report it to emscripten as well...

ypujante commented 4 months ago

The issue was actually reported for the built-in/embedded implementation of GLFW3 back on 10/2022 (and never addressed for what I can tell)

I have now implemented a workaround for emscripten-glfw and issued a PR to be merged.

ocornut commented 4 months ago

Another issue in this case, is that io.ConfigMacOSXBehaviors is not set. It would need to be set on a Mac to invert Super and Ctrl and handle behaviors such as Ctrl+LeftClick turned into RightClick.

Normally we do this:

#ifdef __APPLE__
    ConfigMacOSXBehaviors = true;  // Set Mac OS X style defaults based on __APPLE__ compile time flag
#else
    ConfigMacOSXBehaviors = false;
#endif

But of course this doesn't run on Emscripten. So we need a way to detect a Mac user on Emscripten.