2

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?

anol
  • 8,264
  • 3
  • 34
  • 78
  • Is there online documentation for labigtk? I'm not sure what GWindow is, and Google isn't helping... In the meantime [here's a discussion of the difference between GdkWindow and GtkWindow that I wrote a while ago](http://stackoverflow.com/questions/27515062/difference-between-gtkwindow-and-gdkwindow/27515738#27515738). Hopefully that clears up part of the story. – andlabs Apr 24 '15 at 13:05
  • There is [some online documentation](http://lablgtk.forge.ocamlcore.org/refdoc/GWindow.html) which is the output of Ocamldoc, but with very few comments. I'd like a more general overview of the difference between Gtk* modules and G* modules. Still, your answer about GtkWindow/GdkWindow is relevant. In particular, I believe that it is indeed the fact that from a GdkWindow it's not possible to obtain a GtkWindow, but the converse is true. Could you please confirm that? – anol Apr 24 '15 at 14:44
  • That is true, but for most things you don't want a GdkWindow in the first place. – andlabs Apr 24 '15 at 18:43
  • From that documentation, it appears that GWindow is the module that GtkWindow and its various subclasses (GtkDialog, GtkMessageDialog, GtkAssistant, etc.) are part of. – andlabs Apr 24 '15 at 18:44

1 Answers1

1

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.

Thomas Leonard
  • 7,068
  • 2
  • 36
  • 40
  • Could you please just add some extra information about going from one to another and vice-versa? E.g., from a `GWindow.window` I can use `#as_window` to obtain a `Gtk.window Gtk.obj`, but how can I get a `Gdk.window` from it? And the other way around? This is especially useful if you only have a method giving you one of these objects, but you need the other one. – anol Apr 27 '15 at 07:21
  • Added. Not sure you can go the other way (many GDK windows don't correspond to a GTK window anyway). – Thomas Leonard Apr 28 '15 at 13:03
  • Thanks a lot! Since the documentation is not always friendly, I often ask these kinds of Lablgtk questions hoping that someday there will be a `lablgtk` tag and a repository of common patterns to help future users to save time. – anol Apr 28 '15 at 13:56