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

Don't care about focus when processing events / updating #227

Closed
wants to merge 1 commit into from

Conversation

eliasdaler
Copy link
Contributor

Fixes #212, #206, #88
Now the user has to not call Update/ProcessEvent on lost focus manually.
Might break some things (e.g. trigger some asserts if the user didn't call NewFrame/Render on focus lost).

@oprypin @ChrisThrasher, please review

@oprypin
Copy link
Member

oprypin commented Nov 30, 2022

Thanks. But sadly, this does not work well 😞

Consider the situation when another window (ideally a translucent one) is active and is partially covering the imgui window.
The behavior of hover events over menu items is as follows:

  • Without this change: no hover events, ever

  • imgui SDL backend: hover events happen only on the unobscured part of the window

  • With this change: hover and click events happen even on the obscured part of the window

@eliasdaler
Copy link
Contributor Author

How does SDL backend manage it? Does it keep track of which window is active?

And can’t it be left to the user? E.g. making sure to only call ProcessEvent of the currently focused window, but not others?

@JonnyPtn
Copy link
Contributor

JonnyPtn commented Feb 1, 2023

SDL backend uses a combination of SDL_GetMouseFocus() + SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH to check whether a window is hovered without focus, but this isn't something SFML supports so I don't think there's anything you can do about it

To me this change seems sensible - windows don't get events anyway when they aren't focussed so adding extra checks in your code is redundant and just adds risk of issues (as reported)

@oprypin
Copy link
Member

oprypin commented Feb 1, 2023

I don't think it's OK that clicking on an unrelated application will send clicks to an imgui-sfml application that happens to be hidden behind it.

@JonnyPtn
Copy link
Contributor

JonnyPtn commented Feb 1, 2023

I don't think it's OK that clicking on an unrelated application will send clicks to an imgui-sfml application that happens to be hidden behind it.

How does this happen? SFML only receives events if the window has focus

@oprypin
Copy link
Member

oprypin commented Feb 1, 2023

Just run it and see for yourself if you don't believe

for (unsigned int i = 0; i < 3; i++) {
io.MouseDown[i] = s_currWindowCtx->touchDown[i] || sf::Touch::isDown(i) ||
s_currWindowCtx->mousePressed[i] ||
sf::Mouse::isButtonPressed((sf::Mouse::Button)i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oprypin I see what you're saying now - it's because this directly queries the mouse state here which bypasses the event queue.

Ideally think this should use events instead?

Copy link
Contributor Author

@eliasdaler eliasdaler Feb 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it looks like this is what causes problems, thanks.
I guess I should really rework how ProcessEvent/Update/Render etc. work and not use any direct queries since they don't respect window focus.

Of course, maybe if I check s_currWindowCtx.window->hasFocus(), it might solve the problem, but it feels somewhat hacky.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, this doesn't solve the problem for hover events... Sad.

@eliasdaler
Copy link
Contributor Author

I guess hover events happen because we're changing io.MouseDown - we can just not do that when window has no focus (same with io.MouseDown, gamepad etc.)
But it looks like it lands us at square one. 🤔

@JonnyPtn
Copy link
Contributor

JonnyPtn commented Feb 2, 2023

Yeah I don’t think you can do anything about hovering on partially visible windows unless you write the platform implementations for it yourself.

If you just change to use events then users would still be able to implement this themselves if desired

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 this pull request may close these issues.

Events not handled when apps start without focus
3 participants