[GTK3] Why is GtkButton implemented with a GDK_INPUT_ONLY GdkWindow?


Out of curiosity, I was looking at how some Gtk widgets were implemented (Gtk3).
I was surprised to see that GtkButton seems to use a GDK_INPUT_ONLY GdkWindow (i.e. attributes.wclass = GDK_INPUT_ONLY in function gtk_button_realize of gtkbutton.c), since the documentation states :

GDK_INPUT_ONLY windows are invisible

Maybe I am missing something here ?

In GTK3, GtkButton uses an input-only windowing system surface to receive events, but draws on the parent’s surface. This is necessary because input events in GTK3 are tied to the GdkWindow hierarchy.

Thanks for your reply. But this leads to another question : if input-only widgets are drawn directly on their parent, why are some widgets (for instance GtkListBox) not input-only ? Do they need to be input-output because they are more complex to draw ?

Containers that enact a layout policy, like GtkBox, GtkGrid, or GtkListBox, don’t typically respond to events, leaving it to their children widgets. That’s why widgets like GtkEventBox exist in the first place.

Widgets in GTK3 don’t really use input-output windows, unless they both need to draw something and respond to events. Drawing on a real GdkWindow introduces limitations, as the rendering gets clipped to the window’s region, for instance.

The typical scenarios are:

  • no window: draws on the parent’s surface, does not react to events
  • input-only window: draws on the parent’s surface, reacts to events
  • input-output window: draws on its own surface, reacts to events

Most widgets in GTK3 belong to the first two groups, and very few to the last one.

1 Like

Alright, got it. Thanks for your detailed reply.

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