How to detect, if the user left the application?

I would like to implement a feature, that shuts down the app, when the user leaves it, i.e. clicks somewhere outside the app. Is there a way to implement this?

I tried to use GtkWindow::focus-out signal (call gtk_widget_destroy (mainwindow) inside), but that would also destroy the window if…

  • A combo box dropdown would be opened (dealbreaker)
  • The window is moved (no dealbreaker)

You want GtkWindow:is-active (and connect to notify::is-active to get notified about state changes)

is-active will also change to 0, if a ComboBox was expanded or the window gets moved. So it essentially brings no more value than focus-out.