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

Don't care about focus when processing events / updating

Open eliasdaler opened this issue 1 year ago • 8 comments

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

eliasdaler avatar Nov 30 '22 12:11 eliasdaler

Thanks. But sadly, this does not work well :disappointed:

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

oprypin avatar Nov 30 '22 19:11 oprypin

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?

eliasdaler avatar Nov 30 '22 20:11 eliasdaler

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)

JonnyPtn avatar Feb 01 '23 11:02 JonnyPtn

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.

oprypin avatar Feb 01 '23 12:02 oprypin

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

JonnyPtn avatar Feb 01 '23 12:02 JonnyPtn

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

oprypin avatar Feb 01 '23 12:02 oprypin

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. 🤔

eliasdaler avatar Feb 01 '23 18:02 eliasdaler

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

JonnyPtn avatar Feb 02 '23 07:02 JonnyPtn