imgui-sfml icon indicating copy to clipboard operation
imgui-sfml copied to clipboard

Events not handled when apps start without focus

Open ilyasturki opened this issue 3 years ago • 11 comments

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.

ilyasturki avatar Jun 10 '22 21:06 ilyasturki

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.

ilyasturki avatar Jun 13 '22 12:06 ilyasturki

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

danieljpetersen avatar Jun 13 '22 18:06 danieljpetersen

Yep, looks similar. I'll get to it some day (maybe on weekends?), kinda busy with real life stuff, unfortunately.

eliasdaler avatar Jun 14 '22 21:06 eliasdaler

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

celonymire avatar Jun 16 '22 01:06 celonymire

@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

danieljpetersen avatar Jun 16 '22 01:06 danieljpetersen

Thanks a lot for your answers and solutions !

ilyasturki avatar Jun 16 '22 12:06 ilyasturki

Sorry, this is a pretty big change to old behaviour so I can't promise a quick fix.

eliasdaler avatar Jun 17 '22 14:06 eliasdaler

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-sfml static instance s_currWindowCtx->windowHasFocus is 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 GainedFocus event, so imgui-sfml is never being able to set s_currWindowCtx->windowHasFocus back 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)

Bambo-Borris avatar Jun 18 '22 14:06 Bambo-Borris

I applied the same change @Bambo-Borris mentioned to fix the issue, for me and the users of my engine it happened very often

Nightmare82 avatar Aug 28 '22 21:08 Nightmare82

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

ahrbe1 avatar May 20 '23 23:05 ahrbe1

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!

eliasdaler avatar May 27 '23 11:05 eliasdaler