Hi! Does anybody know how to focus a shown window?...
# compose-desktop
y
Hi! Does anybody know how to focus a shown window? The app is running in a tray and its window is usually
visible = false
. But a user can trigger window visibility from the tray menu. The shown window is not focused even if it is
alwaysOnTop = true
. Use of
window.requestFocus(), window.toFront()
didn’t help. What is a proper way to do that? I can’t pass a focus requester to window’s modifier, it doesn’t accept one. This is on MacOS.
a
window.toFront()
and then use
FocusRequester
to focus whatever you want to focus in the window.
y
window.toFront()
takes no effect. Window remains non-active. It is topmost, there is a caret in a text field I request focus for with
FocusRequester
, but I can’t type there as soon as I show a window. Firstly, I have to click either a window frame or a text field, and only then type there. A window frame remains grey (and not able to consume keyboard input in the focused text filed) until I click it.
a
Can you post a short reproducer?
For me
window.toFront()
does make the window active
Screen Recording 2024-02-01 at 12.10.54.mp4
y
Maybe it is because my app is a background application from the start (
Tray
+
LSUIElement = true
for MacOS). Tray menu has
Show window
item. And a user usually have another active application at the moment he/she clicks a
Show window
item from a tray menu. I will try to create a simple reproducer a bit later.
@Alexander Maryanovsky Please take a look on the reproducer. 1. Run the application, wait until the tray icon appears in the top bar. 2. Click on empty space on your Desktop to make sure the currently active app is
Finder
. 3. Go to tray icon and open a window from the tray menu. 4. Its field is not focused. When the currently active app is NOT
MainKt
, the window never gets focused on showing up. When the currently active app is
MainKt
, the window gets focused exactly half the time.
v
@Yevhenii Nadtochii I have the exact same problem as you. Did you found a solution?
v
Nice thank you 🙏