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

Events not handled when apps start without focus #212

Open
Yasso9 opened this issue Jun 10, 2022 · 11 comments
Open

Events not handled when apps start without focus #212

Yasso9 opened this issue Jun 10, 2022 · 11 comments

Comments

@Yasso9
Copy link

Yasso9 commented Jun 10, 2022

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.

@Yasso9
Copy link
Author

Yasso9 commented Jun 13, 2022

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.

@danieljpetersen
Copy link

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, #206

@eliasdaler
Copy link
Contributor

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

@sam20908
Copy link

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

@danieljpetersen
Copy link

@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

@Yasso9
Copy link
Author

Yasso9 commented Jun 16, 2022

Thanks a lot for your answers and solutions !

@eliasdaler
Copy link
Contributor

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

@Bambo-Borris
Copy link
Contributor

Bambo-Borris commented Jun 18, 2022

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)

@Nightmare82
Copy link

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

@ahrbe1
Copy link

ahrbe1 commented May 20, 2023

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

@eliasdaler
Copy link
Contributor

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!

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

Successfully merging a pull request may close this issue.

7 participants