Algram
Algram

Reputation: 84

How can your gnome-shell-extension grab key focus?

I have a BoxLayout with multiple actors in it. One of the actors is a St.Entry. I want this Entry to have keyboard-focus, so when the window is created, I can start typing right away.

I already found the "grab_key_focus()" method, but if I call that on my Entry it does nothing.

I am thankful for any help you can give me, since this has a really scarce documentation..

Upvotes: 2

Views: 323

Answers (1)

Daniel Landau
Daniel Landau

Reputation: 2314

The trick is

global.stage.set_key_focus(entry);

I found this by reading the source of an existing extension (Project Hamster extension), the exact line is here: https://github.com/projecthamster/shell-extension/blob/c99fb165430d12ff7e6e9b4c5a20f43eb56b810d/extension.js#L149

I use this extension and it has a text entry with initial focus which made me look in this extension for the functionality. How the author of that extension figured it out, I do not know.

Upvotes: 1

Related Questions