3

I'd like to know which signal is emitted when a Gtk.Window is fully shown, with fully shown I mean the window itself is shown and its widgets too.

I tried several signals:

  • show
  • realize
  • visibility-notify-event
  • set_focus

but none of them works properly.

The only interesting answer I found on the web is this.

1
  • If you need the proper dimensions (width, height) too, the only signal that worked for me was size_allocate. Sep 9, 2014 at 15:52

2 Answers 2

4

Connect a callback after the GtkWidget::draw signal (previously called expose in GTK+2).

Addendum

There is other stuff that comes into play: double buffering, client-side windows and (why not?) the fact that a widget can defer its drawing in an idle callback.

If you want to know when your main window appears the first time, it is far easier (and saner) add a g_idle_add after your show_all call.

6
  • I've just tried, but the draw signal is emitted when the window is showed, but before its widgets are showed
    – Irr
    Feb 3, 2013 at 9:42
  • Have you tried g_signal_connect_after instead of g_signal_connect ?
    – liberforce
    Feb 3, 2013 at 13:34
  • @liberforce: this is still not enough. For example double buffering wraps the draw signal between gdk_window_begin_paint_region and gdk_window_end_paint calls to avoid flickering.
    – ntd
    Feb 3, 2013 at 14:09
  • The g_idle_add solution seems to work, but I think it is not deterministic. In fact I think it works because up to when the window is fully shown, Gtk is busy and doesn't execute the function passed as argument to g_idle_add. But I don't know if this behavior is deterministic.
    – Irr
    Feb 5, 2013 at 11:53
  • @robbo: it is deterministic. You have one process, one thread and one event loop: how cannot be deterministic? The idle function has been implemented to do exactly what you described, that is being called after any other pending event with higher priority is executed. As you can see from developer.gnome.org/glib/stable/… event handlers have higher priority.
    – ntd
    Feb 5, 2013 at 18:57
1

It should be:

window.get_property("visible")
#Returns true if the window is visible
1
  • I think using the event VisibilityNotifyEvent then checking the property Visible is better than using the property alone
    – Galacticai
    Dec 5, 2021 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.