Skip to content

Conversation

@maxded
Copy link
Contributor

@maxded maxded commented May 18, 2021

Fixes #1750

Window::focus_window brings the window to the front and sets input focus to that window. As described in the documentation, this method steals focus from other applications and should be used with care. Even though this method can cause quite a disruptive user experience I do believe winit should provide the option to users of this crate as valid use cases exist. Once #1764 has been merged, documentation could be expanded to redirect users to request_user_attention for a less disruptive way of getting attention to a window.

Decided to call it focus_window but the name could be changed for more clarity. Some APIs, like set_minimized, have a boolean parameter for toggling the, in this case, "minimized" state. For focus_window I decided not to do that as "unfocusing" is quite strange, like, where does the focus go? Also deliberately made the choice to "ignore" focus_window on minimized and not visible windows for improved user experience.

Don't have a Linux X11 machine at my disposal so the implementation might/is probably incorrect.

  • Tested on Windows
  • Tested on macOS
  • Tested on X11
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior

@maxded
Copy link
Contributor Author

maxded commented May 18, 2021

This is a continuation on #1767, which I've accidentally removed and was unable to recover. @ArturKovacs, you should be able to push your changes now. Sorry for the delay!

@ArturKovacs
Copy link
Contributor

Not a problem, these things happen especially with PRs that are left open for long. I'll fix the conflicts as well while I'm at it

#[derive(Default)]
pub struct SharedState {
pub resizable: bool,
pub visible: bool,
Copy link
Member

Choose a reason for hiding this comment

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

this gets default initialized to false it seems

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes you are right! After fixing this, it works for me! I just jumped to assuming that it was my system at fault after the fact that the other PR didn't work either.

Copy link
Contributor

Choose a reason for hiding this comment

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

I just pushed the fix; it seemed easiest to do so.

@ArturKovacs
Copy link
Contributor

Actually I gave it another thought and realized that it's probably best if the visibility is queried through a system API instead of trying to keep track of it ourselves.

There are basically two things that free CI services struggle with:
1, Cryptocurrency mining
2, My committing habits

Copy link
Contributor

@ArturKovacs ArturKovacs left a comment

Choose a reason for hiding this comment

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

Approving for macOS and X11

Copy link
Member

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

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

Thanks! Works fine on Windows as well 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Feature: bring window to top

3 participants