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

Focused issue when creating multiple new windows at once. #1077

Closed
hardiesoft opened this issue Jul 29, 2019 · 8 comments
Closed

Focused issue when creating multiple new windows at once. #1077

hardiesoft opened this issue Jul 29, 2019 · 8 comments
Labels
B - bug Dang, that shouldn't have happened C - needs investigation Issue must be confirmed and researched DS - macos DS - wayland DS - windows DS - x11 S - platform parity Unintended platform differences

Comments

@hardiesoft
Copy link

I have noticed different behavior of when the WindowEvent::Focused(bool) event is dispatched, depending whether you are on Windows or MacOS.

I've modified the multiwindow example here to illustrate these differences:

On running the example on windows I get the following output:
New window WindowId(WindowId(0x40e7a))
New window WindowId(WindowId(0x30edc))
Lost focus: WindowId(WindowId(0x40e7a))

On macos, I get:
New window WindowId(Id(140494821671056))
New window WindowId(Id(140494818628096))
Got focus: WindowId(Id(140494818628096))

The windows example seems more wrong than the macos example, since we never get an event for the second window that gained focus when the first window lost it.

Depending on your point of view though, the macos example could also be wrong if we're aiming for consistency with the model that each window gains focus when it is created, and loses it when another one is created afterwards.

I'm happy to put together a PR for this issue, but I'd first like to start some discussion around what the correct behavior should be.

As an aside, I also think winit is missing an APIs to programmatically set window focus and to control stacking order of windows. If it's agreed that those pieces of functionality are in scope for winit, then I'll write up issues for them.

@goddessfreya goddessfreya added C - needs investigation Issue must be confirmed and researched B - bug Dang, that shouldn't have happened S - platform parity Unintended platform differences labels Jul 30, 2019
@goddessfreya
Copy link
Contributor

This is unfortunate. I think it would make sense if on all platforms, a lost focus on the old window then a got focus on the new window were both issued, in that order.

@murarth Do you know what's the current behavior on x11?

As an aside, I also think winit is missing an APIs to programmatically set window focus and to control stacking order of windows. If it's agreed that those pieces of functionality are in scope for winit, then I'll write up issues for them.

I think that would be in scope.

@hardiesoft
Copy link
Author

hardiesoft commented Jul 30, 2019

I've just tested on x11, and happily it does what you'd expect:

New window WindowId(X(WindowId(48234497)))
New window WindowId(X(WindowId(48234498)))
Got focus: WindowId(X(WindowId(48234497)))
Lost focus: WindowId(X(WindowId(48234497)))
Got focus: WindowId(X(WindowId(48234498)))

(although I did notice that I had to move the mouse to get the focus messages to appear?)

@goddessfreya
Copy link
Contributor

What version of winit did you test? Master might have this delay fixed.

@hardiesoft
Copy link
Author

I was building from master.

@murarth
Copy link
Contributor

murarth commented Jul 30, 2019

I'm getting the same result as @hardiesoft for window creation events. However, I'm unable to reproduce any delay in events.

Also, I'm getting another interesting thing: When switching windows using Alt-Tab, I'll get this:

Lost focus: WindowId(X(WindowId(58720258)))
Lost focus: WindowId(X(WindowId(58720258)))
Lost focus: WindowId(X(WindowId(58720258)))
Gained focus: WindowId(X(WindowId(58720257)))
Gained focus: WindowId(X(WindowId(58720257)))

@Osspial
Copy link
Contributor

Osspial commented Aug 5, 2019

From what I've seen, Winit is just reporting the focus events received from the underlying OS on all platforms. Since this seems to be consistently broken everywhere, it'd probably make sense to write some platform-agnostic code that processes the platform's focus events and makes sure Winit outputs events in a predictable way.

@elinorbgr
Copy link
Contributor

Looks like this is also related to alacritty/alacritty#3139

Basically, the main issue is that winit is not consistent on whether windows are created with the focus or not. My suggestion would be to standardize towards "By default windows are created unfocused, and winit inserts a Focused(true) on platforms where the window is focused at creation."

@kchibisov
Copy link
Member

This was fixed for a long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened C - needs investigation Issue must be confirmed and researched DS - macos DS - wayland DS - windows DS - x11 S - platform parity Unintended platform differences
Development

No branches or pull requests

7 participants