imgui-sfml
imgui-sfml copied to clipboard
Events not handled when apps start without focus
Hello,
When I start the app without focus (e.g. when I click anywhere in my screen before the window to show) I cannot drag window, click on buttons and all imgui events aren't available.
I can reproduce the error with the basic example given in the readme.md. I am on windows and the error happen with both g++ 11.2.0 and clang++ 13.0.0. I haven't tested with other compilers.
I don't know if it's the right place to tell that or if I must say it on the general imgui repository.
Besides that everything works perfectly.
Little Update on this issue.
I have tested my program on linux and this problem doesn't happen. I think it's because no matter what I do, the window of my program always shows on top of my desktop when it start.
Hi Yasso9. Thanks for reporting this. It is indeed an issue specific to imgui-sfml and not imgui in general. There's another issue for it here, https://github.com/eliasdaler/imgui-sfml/issues/206
Yep, looks similar. I'll get to it some day (maybe on weekends?), kinda busy with real life stuff, unfortunately.
It'd be great if this can be fixed relatively soon. We use this library (and a very good one!) for our project and we were having the issue of imgui not "receiving" any events when we launch our app from time to time. It's good that we finally found the cause :)
@sam20908 If you want a quick fix before a better one comes along, just change line 217 of this file to
windowHasFocus = true;
https://github.com/eliasdaler/imgui-sfml/blob/master/imgui-SFML.cpp#L217
Thanks a lot for your answers and solutions !
Sorry, this is a pretty big change to old behaviour so I can't promise a quick fix.
On Windows I noticed the following when getting this issue constantly. Firstly it the window always launches without focus, then when I click into it there's no input on my imgui-sfml windows.
- The
imgui-sfmlstatic instances_currWindowCtx->windowHasFocusis correct when my Window launches. The window launches and is set to no focus. - When you click back into the window SFML doesn't seem to send a
GainedFocusevent, soimgui-sfmlis never being able to sets_currWindowCtx->windowHasFocusback to true.
I was wondering would it be worth to add a backup check into Update() which just checks this:
if (s_currWindowCtx->windowHasFocus != window.hasFocus())
s_currWindowCtx->windowHasFocus = window.hasFocus();
(Edit: This does actually resolve the issue well enough for me to not have to worry about it while working on my project)
I applied the same change @Bambo-Borris mentioned to fix the issue, for me and the users of my engine it happened very often
Any chance of an update for this? I'm running into the same issue constantly. For now I'm patching locally as suggested by @Bambo-Borris
I guess it would be better to stop caching window's focus in windowHasFocus variable and instead call Window::hasFocus where needed. PRs are welcome!