Skip to content

Mac: Bring focused windows to the foreground - #2964

Open
Descolada wants to merge 1 commit into
picoe:developfrom
keysharp-org:fix/mac-window-focus
Open

Mac: Bring focused windows to the foreground#2964
Descolada wants to merge 1 commit into
picoe:developfrom
keysharp-org:fix/mac-window-focus

Conversation

@Descolada

Copy link
Copy Markdown
Contributor

MakeKeyAndOrderFront does not activate a background macOS application, so Window.Focus() may fail to foreground the requested window. Activate the application first, then make the window key and bring it forward.

@cwensley

cwensley commented Jul 3, 2026

Copy link
Copy Markdown
Member

Hey @Descolada, so I've thought about this one, and I think I'd like to see an Application.Instance.Activate() API instead of making macOS try to activate every time you focus a window. Thoughts?

@Descolada

Copy link
Copy Markdown
Contributor Author

@cwensley interesting idea. As far as I understand, currently only macOS distinguishes active app (the overarching currently used program, claims the global menu bar at the top of the screen, owns the Dock icon indicator etc) vs focused window (where keyboard focus is). It's possible to activate an app without focusing a window, but not focusing a window without activating the app (and a window can't have keyboard focus without also being the active app). So, I think Application.Instance.Activate() would have a place to activate the app, but that would likely be a macOS-only feature (I'm not sure how that would work on other platforms - on Windows/Linux what would it activate?). Also, if Window.Focus() didn't automatically call it then the semantics of Window.Focus() would remain incorrect, because it sometimes won't bring the window to focus due to app-level activation status being wrong.

On further thought, it could perhaps be a property instead Application.Instance.Active:

  • on macOS the getter would return application-level focus status (supposing it's possible to query it, I haven't looked into it), the setter would set the app-level focus
  • on Windows/Linux it could answer the question whether the currently focused window belongs to our Application.Instance, but I don't think the setter would have an use

What do you think? If you think this is worth implementing then I can attempt it + change the current PR to do if (!Application.Instance.Active) Application.Instance.Active = true before attempting window focusing.

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.

2 participants