toga icon indicating copy to clipboard operation
toga copied to clipboard

Add API to give an App focus

Open freakboy3742 opened this issue 1 year ago • 1 comments

What is the problem or limitation you are having?

When an app is currently active, it's possible to change which widget accepts input (i.e., has focus). However, it isn't possible to programmatically give an app focus if it isn't currently active.

Describe the solution you'd like

A new method App.focus() that ensures (to the extent possible) that the app is the currently active app.

Describe alternatives you've considered

Don't add the API. It's impolite for apps to change focus.

Additional context

This will be a no-op on mobile and console platforms; it will likely be ignored on GTK.

On macOS, it can be implemented with: App._impl.native.activateIgnoringOtherApps(True)

It will also be near impossible to verify in the testbed, because we can't programmatically give a different app focus. We can call the method... but only on the app that already, by definition, has focus.

Any documentation should highlight that it's really bad form for an app to bring itself into focus, so the method should be used sparingly.

freakboy3742 avatar Dec 08 '24 22:12 freakboy3742

For further discussion of whether we should add this API, see https://github.com/beeware/toga/pull/3034#issuecomment-2533140379.

mhsmith avatar Dec 11 '24 11:12 mhsmith

Based on the discussion on #3034, I'm closing this feature request. If this is a feature you're particularly interested in, let us know your use case (and examples of other apps that implement that behavior).

freakboy3742 avatar Jun 20 '25 04:06 freakboy3742