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

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

Open
ypujante opened this issue Jun 24, 2024 · 3 comments
Open

Comments

@ypujante
Copy link

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),

  • navigate to "Inputs & Focus"
  • Press and hold the Meta key (also called Super) => Keys Down: "LeftSuper" 530 "ModSuper" 665
  • Press the "V" key (or any other key...) => Keys Down: "LeftSuper" 530 "V" 567 "ModSuper" 665
  • Release the "V" key => Keys Down: "LeftSuper" 530 "V" 567 "ModSuper" 665 (this is wrong)
  • Release the "Meta" key => Keys Down: "V" 567 (this is wrong)
@ypujante
Copy link
Author

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
Copy link
Author

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.

sbc100 pushed a commit to emscripten-core/emscripten that referenced this issue Jun 25, 2024
I released a new version of contrib.glfw3 with a workaround/bug fix. I
wanted to point out that there is the same issue that was
[created](#18089) on
10/22 for the built-in implementation. That was never addressed. I also
wanted to point out that SDL2 also suffers from the same issue...

I found [this issue](ocornut/imgui#7732) while
working on a project using ImGui.


![Meta_V](https://github.com/ocornut/imgui/assets/357116/0cec5893-d146-40fe-ae15-2fd00e7bd319)

Release notes:
- Implemented workaround for
[#4](pongasoft/emscripten-glfw#4): _Using
Super + "Key" on macOS results in "Key" not being released_.
Due to the [broken
state](https://stackoverflow.com/questions/11818637/why-does-javascript-drop-keyup-events-when-the-metakey-is-pressed-on-mac-browser)
of javascript handling the `Super/Meta` key, there is no good solution.
The workaround implemented, releases all keys when `Super` is released.
Although not a perfect solution, it guarantees that the state is
_eventually_ consistent:
- if "Key" was released while "Super" was held, then when "Super" gets
released, "Key" is released (later than when actually released, final
state is consistent: "Key" in `Release` state)
- if "Key" is still held when "Super" is released, "Key" is released
when "Super" gets released, but immediately gets a down event (Up/Down
event, final state is consistent": "Key" in `Pressed` state)
@ocornut
Copy link
Owner

ocornut commented Jun 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants