Suvarna Garge (Editor)

GTK

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Developer(s)
  
The GNOME Project

GTK+

Original author(s)
  
Spencer Kimball, Peter Mattis, eXperimental Computing Facility (XCF)

Initial release
  
April 14, 1998; 18 years ago (1998-04-14)

Stable release
  
3.22.7 (January 16, 2017; 51 days ago (2017-01-16)) [±]

Preview release
  
3.89.3 (January 17, 2017; 50 days ago (2017-01-17)) [±]

Repository
  
git.gnome.org/browse/gtk+

GTK+ (formerly GIMP Toolkit) is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU Lesser General Public License, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the Wayland and X11 windowing systems, along with Qt.

Contents

Software architecture

The GTK+ library contains a set of graphical control elements (widgets), version 3.13.3 contains 203 active and 37 deprecated widgets. GTK+ is an object-oriented widget toolkit written in the C programming language; it uses GObject, that is the GLib object system, for the object orientation. While GTK+ is primarily targeted at windowing systems based upon X11 and Wayland, it works on other platforms, including Microsoft Windows (interfaced with the Windows API), and macOS (interfaced with Quartz). There is also an HTML5 back-end called Broadway.

GTK+ can be configured to change the look of the widgets drawn; this is done using different display engines. Several display engines exist which try to emulate the look of the native widgets on the platform in use.

Starting with version 2.8, released in 2005, GTK+ began the transition to using Cairo to render the majority of its graphical control elements. Since GTK+ version 3.0, all the rendering is done using Cairo.

GTK+ Scene Graph Kit (GSK)

In June 2006 Clutter, an OpenGL-based 'interactive canvas' library, was released. Clutter has its own scene graph, and GNOME developers preferred to use Clutter's scene graph with GTK+, facilitated by a library called clutter-gtk. Clutter can be embedded into every GNOME application by using the clutter-gtk library. The clutter-gtk library provides a GtkClutterEmbed GTK+ widget which can be used to display a ClutterStage.

Some thought went into how to merge Clutter and GTK+ in a better way than the clutter-gtk library.

In 2011 Firefox introduced "Azure" and Joe Drew and Bas Schouten bothered with some explanations.

  • GTK+ Scene Graph Kit (GSK) is the forthcoming scene graph (canvas) for GTK+ in the process of being written by Emanuele Bassi.
  • There was a presentation at the 2014 Developer Experience Hackfest regarding a new scene graph for GTK+ aimed at being merged into GTK+ 3.16. Then GSK was planned to be ready and fully integrated into GTK+ version 3.20, to be released in March 2016. This was postponed to 3.22., then postponed to 3.90, and finally merged in GTK4.00

  • Graphene is a collection of geometry types — points, sizes, rectangles, vectors, quads, quaternions, matrices. It tries to optimize them so that the naive, four floats for vertex/four vertices for matrix implementation is not the only one available. Graphene's API makes it possible to avoid exposing C arrays of floating point values, or opaque memory regions, enabling the manipulation of vectors and matrices in other languages as well.
  • Having OpenGL (or OpenGL ES) support in GDK facilitates a slightly better control of the graphics pipeline; OpenGL is well suited for compositing textured data but totally unsuited for drawing.

    Before the adoption of GSK, application developers could optionally use Clutter. The way widgets were drawn in GTK+, was, that a draw function drew everything. There was no way to know, what has just been drawn. To know where the mouse pointer was currently hovering over, the current position had to be computed.

    With GSK, it should be fairly easy to write complex graphical control elements (widgets) and still track easily the whereabout of the mouse pointer. Getting more conformation with CSS should also arrive.

    The latest information about the status of GSK is from GUADEC 2016.

    GtkInspector

    GtkInspector has been introduced with version 3.14. GtkInspector can only be invoked after installing the development package libgtk-3-dev/gtk+-devel.

    GUI designers

    There are several GUI designers for GTK+. The following projects are active as of July 2011:

  • Glade, supports GtkBuilder, which is a GTK+ built-in GUI description format.
  • Gazpacho, GUI builder for the GTK+ toolkit written in Python
  • Crow Designer, relies on its own GuiXml format and GuiLoader library.
  • Stetic, part of MonoDevelop, oriented towards Gtk#.
  • GtkBuilder

    GtkBuilder allows user interfaces to be designed without writing code. The interface is described in an Extensible Markup Language (XML) file, which is then loaded at runtime and the objects created automatically. The Glade Interface Designer allows creation of the user interface in a WYSIWYG manner. The description of the user interface is independent from the programming language being used.

    Language bindings

    A library written in one programming language may be used in another language if bindings are written; GTK+ has a range of bindings for various languages.

    Gtk#

    Gtk# is a set of .NET bindings for the GTK+ GUI toolkit and assorted GNOME libraries. The library facilitates building graphical GNOME applications using Mono or any other compliant CLR. Gtk# is an event-driven system like any other modern windowing library where every widget allows you to associate handler methods, which get called when particular events happen.

    Applications built using Gtk# will run on many platforms including Linux, Windows and macOS. The Mono packages for Windows include GTK+, Gtk# and a native theme to make applications look like native Windows applications. Starting with Mono 1.9, running Gtk# applications on macOS no longer requires the user to run the X11 server.

    Glade can be used with the Glade# bindings to easily design GUI applications. A GUI designer called Stetic is integrated with the MonoDevelop IDE.

    In addition to support the standard GTK/GNOME stack of development tools, the gtk-dotnet.dll assembly provides a bridge to consume functionality available on the .NET stack. At this point this includes the functionality to use System.Drawing to draw on a widget.

    Development

    GTK+ is mainly developed by The GNOME Project, which also develops the GNOME Development Platform and the GNOME Desktop Environment.

    GTK+ development is loosely managed. Discussion chiefly occurs on a number of public mailing lists. GNOME developers and users gather at an annual GUADEC meeting to discuss the current state and the future direction of GNOME. GNOME incorporates standards and programs from freedesktop.org to better interoperate with other desktops.

    GTK+ is mainly written in C. A number of language bindings are available.

    On September 1, 2016 a post on the GTK development blog denoted, among other things, the future numbering scheme of GTK+. GTK+ version 3.22 from autumn 2016 shall be the last 3.x release. After that all resources will flow into the GTK+ 4 development series with the version names 3.90, 3.92, etc. Whether the numerous application that still use GTK+ 2.x, even the Wikipedia has a couple of articles on those, will be ported to 3.22 or not, only the future can show.

    Build automation

    In former times GTK+ (and GNOME, GLib, etc.) utilized the GNU Build System (called Autotools) as the build automation system of choice.

    The Meson build system is being prepared to be used with GTK.

    At Saturday 13. August at GUADEC2016 Nirbheek Chauhan hold a talk titled "Making your GNOME app compile 2.4x faster". The video is available on YouTube:

    Criticisms

    The most common criticism towards GTK+ is a lack of backwards-compatibility in major updates, most notably in the API and theming.

    The compatibility breaks between minor releases during the GTK+ 3.x development cycle has been explained by Benjamin Otte as due to strong pressures to innovate, such as providing the features modern users expect and supporting the increasingly influential Wayland (display server protocol). With the release of GTK+ 4, the pressure from the need to innovate will have been released and the balance between stability and innovation will tip towards stability. Similarly, recent changes to theming are specifically intended to improve and stabilise that part of the API, meaning some investment now should be rewarded later.

  • Dirk Hohndel, co-developer of Subsurface and member of Intel's Open-Source Technology Center, criticized the GTK+ developers for being abrasive and ignoring most community requests.
  • Hong Jen Yee, developer of LXDE, expressed disdain for version 3 of the GTK+ toolkit's radical API changes and increased memory usage, and ported PCManFM to Qt additionally. PCManFM is being developed with a GTK+ and with a Qt at the same time.
  • The Audacious music player plans to move back to GTK+ version 2 starting with version 3.6, with the long-term goal of migrating to Qt. The reasons stated by the developers for this include a transition to client-side window decorations, which they claim cause the application to look "GNOME-y and out of place."
  • Wireshark also is transitioning to use Qt due to not having a good experience with GTK+'s cross-platform support.
  • Applications

    Some notable applications that use or once used GTK+ as a widget toolkit include:

  • GNOME Core Applications – as part of GNOME desktop environment, developed in concert with GTK+ itself.
  • Desktop environments

    Several desktop environments utilize GTK+ as the widget toolkit.

  • GNOME, based on GTK+, meaning that programs native to GNOME use GTK+
  • Unity, the default desktop environment of Ubuntu
  • Consort, the GNOME 3.4 Fallback Mode – fork from SolusOS
  • Budgie, built from scratch the SolusOS successor, Solus
  • Cinnamon, a fork of GNOME 3 and uses GTK+ version 3
  • MATE, a fork of GNOME 2, which has been updated to support GTK+ 3
  • Xfce, currently based on GTK+ 2 with support for and eventual plans for a migration to GTK+ 3
  • LXDE (Lightweight X11 Desktop Environment) is based on GTK+ 2
  • Pantheon uses GTK+ 3 exclusively, being developed by elementary OS
  • Sugar is a desktop environment oriented towards children's education, which uses GTK+, especially PyGTK
  • ROX Desktop, a lightweight desktop, with features from the GUI of RISC OS
  • GPE, the GPE Palmtop Environment
  • Access Linux Platform (successor of the Palm OS PDA platform)
  • KDE, though based on Qt, has integration with GTK+-based programs and themes since version 4.2
  • GTK+ programs can run on top of X11-based desktop environments or window managers even those not made with GTK+, provided the required libraries are installed; this includes macOS if X11.app is installed. GTK+ can also run under Microsoft Windows, where it is used by some popular cross-platform applications like Pidgin and GIMP. wxWidgets, a cross-platform GUI toolkit, uses GTK+ for GNU/Linux operating systems. Other ports include DirectFB (used by the Debian installer, for example) and ncurses.

    Window managers

    The following window managers use GTK+:

    Example

    The following code presents a graphical GTK+ hello-world program in the C programming language. This program has a window with the title "Hello, world!" and a label with similar text.

    Needs installing the libraries first in debian or derivatives:

    $ sudo apt-get install libgtk-3-dev

    Using pkg-config in a Unix shell, this code can be compiled with the following command (assume above source has file name "helloworld.c"):

    $ cc -Wall helloworld.c -o helloworld $(pkg-config --cflags --libs gtk+-3.0)

    Invoke the program

    $ ./helloworld

    History

    GTK+ was originally designed and used in the GNU Image Manipulation Program (GIMP) as a replacement of the Motif toolkit; at some point Peter Mattis became disenchanted with Motif and began to write his own GUI toolkit called the GIMP toolkit and had successfully replaced Motif by the 0.60 release of GIMP. Finally GTK was re-written to be object-oriented and was renamed GTK+. This was first used in the 0.99 release of GIMP. GTK+ was subsequently adopted for maintenance by the GNOME Foundation, which uses it in the GNOME desktop environment.

    The GTK+ 2.0.0 release series introduced new features which include improved text rendering using Pango, a new theme engine, improved accessibility using the Accessibility Toolkit, transition to Unicode using UTF-8 strings, and a more flexible API. Starting with version 2.8, GTK+ 2 depends on the Cairo graphics library for rendering vector graphics.

    GTK+ version 3.0.0 included revised input device handling, support for themes written with CSS-like syntax, and the ability to receive information about other opened GTK+ applications.

    Releases

    The GNOME team releases new versions on a regular basis.

    References

    GTK+ Wikipedia