Search code examples
gtkocamllablgtk

Difference between Gdk.Window, GtkWindow and GWindow in lablgtk


In Lablgtk, there are (at least) three types of window-named modules:

  • Gdk.Window
  • GtkWindow
  • GWindow

What's the difference between them, and how can I go from one to another?


Solution

  • GTK was originally for X11 systems. In X11, a "window" is a rectangular area that you can draw on and select events from. They can be nested in a tree, with the "root window" at the top for the whole screen. A Gdk.window is a thin wrapper around an X11 window, but is abstract enough to support non-X11 backends.

    A GTK window is what a user would think of as a window - a resizable area of the screen with a title, border, etc. In fact, this is probably an X11 window provided by the window manager containing the title and border and another X11 window for the content area. This inner window might then contain sub-windows, e.g. one for each button. However, I think modern GTK usually doesn't bother with sub-windows and manages everything itself to avoid flickering.

    A Gtk.window Gtk.obj represents the C object provided by the GTK C library. The functions exposed by the C library are available in GtkWindow.Window.

    However, the C object is usually wrapped by the GWindow.window class to provide an OO OCaml API to it.

    Use gtk_window#misc#window to get the GDK window from a GWindow.window.