The GLib/ GTK Development Platform

Recommended

1.2.1 About Rust

Some people recommend Rust for new projects.

But there is a lot of existing C/GObject code, and it’s not feasible to rewrite everything. So, some people still need to work and learn C/GObject. And, even for a full rewrite, reading and understanding C/GObject code is needed to avoid repeating history and past mistakes.

1.3 What is GLib and GTK? 

Roughly speaking, GLib is a set of libraries: GLib core, GObject and GIO. Those three libraries are developed in the same Git repository called glib, so when referring to “GLib”, it can either mean “GLib core” or the broader set including also GObject and GIO.

GLib core provides data structure handling for C (linked lists, trees, hash tables, . . . ), portability wrappers, an event loop, threads, dynamic loading of modules and lots of utility functions.

GObject – which depends on GLib core – simplifies the object-oriented pro- gramming and event-driven programming paradigms in C. Event-driven pro- gramming is not only useful for graphical user interfaces (with user events such as key presses and mouse clicks), but also for daemons that respond to hardware changes (a USB stick inserted, a second monitor connected, a printer low on paper), or software that listen to network connections or messages from other processes, and so on.

GIO – which depends on GLib core and GObject – provides high-level APIs for input/output: reading a local file, a remote file, a network stream, inter-process communication with D-Bus, and many more.

The GLib libraries can be used to write operating system services, libraries, command line utilities and such. GLib offers higher-level APIs than the POSIX standard; it is therefore more comfortable to write a C program with GLib.

GTK is a widget toolkit based on GLib that can be used to develop applications with a graphical user interface (GUI). A “widget” is a GUI element, for example a button, some text, a menu, etc. And there are some special kinds of widgets that are called “containers”, which can contain other widgets, to assemble the elements in a window. GTK provides a broad range of widgets and containers.

The first version of GTK, or the GIMP Tool Kit5, was mainly written by Peter Mattis in 1996 for the GIMP (GNU Image Manipulation Program), but has quickly become a general-purpose library. The “+” has been added later to distinguish between the original version and a new version that added object oriented features. GLib started as part of GTK, but is now a standalone library.

The GLib and GTK APIs are documented with GTK-Doc. Special comments are written in the source code, and GTK-Doc extracts those comments to generate HTML pages.

Although GLib and GTK are written in C, language bindings are available for JavaScript, Python, Perl and many other programming languages. At the beginning, manual bindings were created, which needed to be updated each time the API of the library changed. Nowadays the language bindings are generic and are thus automatically updated when, for example, new functions are added. This is thanks to GObject Introspection. Special annotations are added to the GTK-Doc comments, to expose more information than what the C syntax can provide, for example about ownership transfer of dynamically-allocated content6. Any C library with GObject Introspection support is thus available from many programming languages. In addition, the annotations are also useful to the C programmer because it’s a good and succint way to document certain recurrent API aspects.

GLib and GTK are part of the GNU Project, whose overall goal is developing a free operating system (named GNU) plus applications to go with it. GNU stands for “GNU’s Not Unix”, a humorous way of saying that the GNU operating system is Unix-compatible. You can learn more about GNU at https://www.gnu.org.

The GLib/GTK web site is: http://www.gtk.org

Attribution

Sébastien Wilmet(2022), The GLib/GTK Development Platform, URL: https://gitlab.gnome.org/swilmet/glib-gtk-book

This work is licensed under Creative Commons Attribution-ShareAlike 4.0 International License:  (https://creativecommons.org/licenses/by-sa/4.0/).

VP Flipbook Maker

Here is a book converted and displayed as digital flipbook by VP Online Flipbook Maker! We can also create our own flipbook with the tool. Try it now!