How to detect when window focus changes?

The application I’m working on needs to act differently after a set timer depending on whether the window is focused (with keyboard) or not.

The application is using GtkEventControllerFocus for now, but this is unreliable:

  • When setting a widget to be focused, it acts as if the window got keyboard focus even when it’s not the case
  • When no specific widget is selected, events are not emitted

I looked around the documentation and obscure stackoverflow posts in order to find a solution, but I didn’t find anything that worked with Gtk4.

Is this is a limitation of the Wayland protocol, or is their a way to work around the issues I described above?

Do you mean something like Gdk.Toplevel:state ?

That’s exactly what I needed. Thanks for your help, I would never have figured this out by myself!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.