-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix: OSX backend improvements #4759
Conversation
backends/imgui_impl_osx.mm
Outdated
if (key != -1) | ||
io.KeysDown[key] = true; | ||
NSString* str = [event characters]; | ||
io.AddInputCharactersUTF8(str.UTF8String); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some characters were previously intentionally filtered, why removing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, sorry. I will provide a fix for this.
I will also resolve the OpenGL build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth double checking if those checks are still valid, or if they are specific to old versions of the OS. like the 127 code test I believe is checking for the delete key, but I don't have any keyboards that generate the 127 code. And I think the 0xF700 0xFF00 range might be an old way of filtering F keys? I might be wrong on this, but I think that's what this line of code was intended for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reworked it to use macOS's NSTextInputClient
protocol, which is the same as GLFW:
and SDL2:
This means we only send characters to ImGui when macOS tells us so:
Thank you for this PR!
|
d63dca2
to
28c32a6
Compare
9a680eb
to
4fdbf46
Compare
👋🏻 hey @ocornut, I've updated this PR and expanded the description to reflect the recent changes. The OSX backend should now be ready for another review. |
git blame is your friend and this is all pretty recent. We can probably merge the gamepad stuff asap (if this is resquashed and split into two distinct commits, as well as brace styles fixed). The other inputs stuff would need more careful review and maybe more comments in the code. |
4fdbf46
to
b754802
Compare
@ocornut I have separated the commits, so that the game controller is isolated. There is also a fix for macOS 12.1 to address incorrect scrolling behaviour (which incidentally breaks a number of other macOS apps I have used) |
6c26d97
to
3a3b9ae
Compare
@ocornut FYI, io_inputqueue does have osx backend redone to handle all keys and modifiers. Maybe we could pull that into backend and cherry-pick gamepad support from this PR? |
👋🏻 hi @ocornut! I have pushed up a separate commit with the macOS keyboard fixes. It includes a number of comments and fixes the brace formatting. NOTE the resolved FIXME:
This final commit implements these recommendations and is consistent with GLFW's and SDL2's approach of using a |
@thedmd I've pushed up another commit – can you take a look at that? |
@thedmd where is |
I will let you know, when it is ready. :) |
Note the original FIXME: refered to GLFWs Cocoa implementation, which is largely what this commit provides.
b73bacd
to
0e0dfb8
Compare
@stuartcarnie I managed to pull keyboard handling out of the private branch. https://github.com/thedmd/imgui/tree/thedmd/osx-backend-keyboard It is based on "extra keys" PR. I made support for it optional, so it is easy to pull and test changes as they are. After some fiddling I tweaked examples too, to handle key event using NSView, just to get rid of this annoying 'ding' sound when typing. Feedback is welcome. |
I did some cleaning up. In order to get new improved keyboard handling, there is what need to be done:
|
@thedmd those look ok, however, I prefer to use macOS's own input manager system via I really like the idea of shortcuts and the extra keys! |
You're right, When your PR I will merged, I will rebase my commits. :) |
I've merged the game controller commit b720f1f already, thank you! |
Merged everything else now (squashed and tweaked as 1b6b860) Slightly tangential, but CI says:
Any suggestion? |
I updated it this way: -(void)reshape { [super reshape]; [[self openGLContext] update]; [self updateAndDrawDemoView]; } |
…th focusing and tweak speed. (#4759)
There was an inconsistency with gamepad mapping for navigation, fixed b6582a4 |
This PR makes changes to the macOS backend and the Apple example that uses the macOS backend.
Firstly, the PR addresses some issues and shortcomings of in
imgui_impl_osx.mm
as followskVK_
codes and keyboard modifier handling.Secondly, the
example_apple_metal.mm
example has addressed the unhandled key event chimes, which adds akeyDown:
handler.This PR does not touch the core of IMGUI.
NOTE:
There is a single breaking change to the
ImGui_ImplOSX_Init
API, which now takes the sameNSView
being used by theImGui_ImplOSX_NewFrame
. This NSView is used to attach anNSTextInputClient
to the responder chain to process key presses using the same approach as GLFW and SDL. This approach ensures the macOS ImGui backend us macOS APIs for determining characters that should be accepted as text input.