GTK (program library)

from Wikipedia, the free encyclopedia
GTK

GTK logo
Gtk3 demo
gtk3-demo shows controls
Basic data

developer The GTK team
Publishing year 1998
Current  version 3.24.21
( June 28, 2020 )
operating system Unix , Linux , macOS (beta), Windows
programming language C.
category GUI toolkit
License LGPL ( free software )
German speaking Yes
www.gtk.org
GTK3 Widget Factory

GTK (formerly GTK + , GIMP Toolkit ) is a free GUI toolkit under the LGPL . GTK contains many controls that can be used to create graphical user interfaces (GUI) for software.

The library was initially developed by Peter Mattis, Spencer Kimball and Josh MacDonald to create a user interface for the graphics program GIMP apart from Motif . GTK is now used by the desktop environments Gnome , Xfce , LXDE , Cinnamon , Pantheon and Budgie as well as by a large number of other applications and is therefore, alongside Qt , one of the most successful GUI toolkits for the X Window System .

History and Development

Old logo

GTK is written in the C programming language. The first version of GTK + appeared in April 1998. GTK + contained a number of auxiliary routines for solving basic programming tasks, for example for storing various data. These are very time-consuming for the programmer, especially with the repeated development of programs. The first versions of GTK + contained data structures for linked lists , binary trees or "growing" strings. In addition, a system was developed with GTK + to program in C object-oriented . These aids also proved useful for programs without a graphical user interface and were therefore later moved to a separate library, the GLib library of C functions . The object-oriented system has been outsourced to the GObject library, and low-level drawing methods to the GDK library (GTK + Drawing Kit). The latter enables GTK + to run identically across platforms, including Windows , X Window System and macOS .

The GTK + 2 version received new, improved functions for rendering text with the help of the Pango library, a new theme engine, a more flexible API and a new type of library ( ATK ) to improve the accessibility of the toolkit for disabled people, with the Reading software, magnification tools and alternative input devices can be addressed. GTK + 2 is not compatible with GTK + 1, so existing applications had to be ported.

From version 2.8 GTK + uses the vector-based library Cairo , which uses hardware acceleration for rendering whenever possible . GTK + 2.24 is the last version of the 2.x series.

Version 3.0 was released on February 10, 2011. Many functions classified as obsolete have been removed and existing interfaces have been improved. GTK + 3 is not backwards compatible with GTK + 2.x. However, libraries of both versions can be installed in parallel.

GTK + 3.0 contains, among other things, a new interface for drawing widgets, which is now completely based on Cairo , a CSS -based theming engine that also allows animated state transitions, improved layout options, a new slide switch widget , an application class , support for multiple pointing devices (multi-pointers) and symbolic icons that can change their color according to their status. Internal structures have been separated from the public interface and hidden, so that it will be easier in the future to make changes without having to break the interface. Furthermore, several GDK backends are supported simultaneously within the same library. So far, different libraries were necessary for this.

GTK + 3.2 introduced two new backends: one for the Wayland display server and an HTML5 backend called Broadway , with which GTK + applications can be operated remotely in the browser via the network.

GTK + 3.4 supports multi-touch and smooth scrolling and is also available for Windows.

GTK + 3.6 supports CSS animation and blurs shadows. Version 3.6.4 is the last official version for Windows 32-bit and 64-bit.

GTK + 3.8 natively supports Wayland in important parts.

GTK + 3.10 supports Wayland experimentally and improves the display for high-resolution monitors.

GTK + 3.12 introduces popover. These comic speech bubbles can be used as an aid. Wayland support has been improved.

GTK + 3.14 supports multi-touch gestures.

GTK + 3.16 supports rendering of windows through OpenGL . The new control element GtkGLArea also made it possible to integrate 3D objects directly into program interfaces.

GTK + 3.18 officially supports Wayland, the successor to the X Window System, as the basis of Gnome 3.18.

GTK + 3.20 integrates the spell check with gspell and improves the CSS theming.

GTK + 3.22 is the last stable version of GTK + 3 and will be maintained as an LTS version for three years. The main features of this version are the new Flatpak portals for simple software installations.

GTK 4.0 is being prepared with the unstable series 3.9x. In March 2017 the Scene Graph Kit (GSK) was added with version 3.90 . It implements a scene graph and takes care of the image synthesis. In February 2019 it was announced that GTK 4.0 will remove the plus sign ("+") from the name.

macOS

GTK can be used on macOS via the Quartz backend, a port of the X Window System .

Windows

  • After GTK 2.24.10 and 3.6.4, Windows development with installer at Gnome was discontinued. It is recommended to install the MSYS2 package system from Gnome on Windows.
  • GTK 2.24.10 and 3.6.4 are still available in the network, but are much more buggy than the current versions in Linux.
  • For Windows 64-bit (as of June 2018) 2.24.32 (currently like Linux) and 3.22.30 (currently like Linux) is now available through the work of Tom Schoonjans.
  • With Windows 10 Fall Creators Update , GTK 3 is now also available in the WSL. Instructions for installing programs with windows are available in the GTK Community.

Programming example

The classic way to program with GTK is to first define the properties of the graphic elements used, then to group them and link them to specific event handlers (one possible event would be the click of a button , for example ). However, there are also graphic design tools for GTK surfaces such as Glade or the Stetic contained in MonoDevelop , which can save you the first two steps, expand GTK with prototyping capabilities and make it possible to make changes to the surface of a program without the Having to change the source code of the software.

The presentation of this program

A typical hello world program that displays the window on the right could look something like this:

#include <gtk/gtk.h>

/* Rückruffunktion - aufgerufen, wenn die Schaltfläche geklickt wurde */
void on_button_clicked (GtkButton *button, gpointer data)
{
  g_print ("Knopf '%s' geklickt!\n", gtk_button_get_label (button));
  gtk_main_quit (); /* Beendet das Programm */
}

int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *button;

  /* GTK+ initialisieren */
  gtk_init (&argc, &argv);

  /* Hauptfenster erstellen, Titel setzen, Rahmenabstand setzen */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Hallo Welt!");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  /* Schaltfläche erstellen und dem Fenster hinzufügen */
  button = gtk_button_new_with_label ("Hallo Wikipedia!");
  gtk_container_add (GTK_CONTAINER (window), button);

  /* Signale mit Rückruffunktionen verbinden */
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  g_signal_connect (button, "clicked", G_CALLBACK (on_button_clicked), NULL);

  /* Fenster und all seine Unterelemente anzeigen */
  gtk_widget_show_all (window);

  /* Haupt-Ereignisschleife starten */
  gtk_main ();

  return 0;
}


First a new window is created in the main routine and its title and the frame distance to the inner elements are set. Then a button with the appropriate label is created and inserted into the window. A window is always also a container , i.e. an element that can contain other control elements ( widgets ).

Which is subsequently destroy - signal , which, for the window widget. B. generated when you click on its "Close" button, linked to the GTK function gtk_main_quit , which terminates the program. The previously created button is also connected to a callback function called on_button_clicked , which is implemented above. For the connection of signals with callback functions, GLib functions are used directly whose name prefix is g_ instead of gtk_ .

Since all controls are initially invisible, they must be made visible, either individually or all together, by calling gtk_widget_show_all . When gtk_main is called, the main event loop is finally started, which waits for events and then distributes them to the corresponding signals.

The function that is executed when the button is clicked exemplarily shows how the calling control element can be accessed by reading the button label and outputting it in the standard output. The program is then ended. The second parameter data of the callback function can contain any data that was specified when connecting. In this example, however, only the value NULL , i.e. nothing, is passed there.

The sample program is gcc gtkhello.c -o gtkhello `pkg-config gtk+-3.0 --cflags --libs`compiled when called from within the folder in which the file is located.

Connections to other programming languages

Since GTK is a pure C library, it can be easily linked to many other programming languages. With object-oriented programming languages, the GObjects are not used ; GTK objects can usually be used there like native objects of the programming language. The programming language Vala uses GObject directly as an object system and therefore does not require a runtime library for the language connection.

Hello world in Perl
programming language Name of the connection Program examples
C ++ gtkmm Inkscape , Solang, GParted , GNote
python PyGTK (up to GTK 2.24.0) OpenShot, gPodder, Ubuntu Tweak
PyGObject (from GTK 3.0.0) Pitivi, Lollypop, GNOME Music, Meld
C # ( mono ) GTK # Tomboy , F-Spot , Banshee , Pinta , MonoDevelop , gbrainy
Vala - Shotwell , Geary, Corebird, Elementary OS , libunity
JavaScript Gjs Gnome Shell , GNOME Maps, Polari
Available, but used less often:
Ada GtkAda
Common Lisp cl-gtk2
D. gtkD Tilix
FreeBASIC GladeToBac Data2App, GTK + tobac
Fortran gtk-fortran
Go Go-GTK
Haskell Gtk2Hs
Java java-gnome GNOME split
Julia Gtk.jl
Objective-C CoreGTK
OCaml LablGTK
Pascal LCL Lazarus
Pearl gtk2-pearl slimrat, odot, shutter
PHP PHP-GTK Phoronix Test Suite
Ruby Ruby-GNOME2 Alexandria
Rust Gtk-rs systemd-manager
Tcl Gnocl

Graphic style

The appearance of the toolkit is largely user-configurable. There are various themes to choose from.

Clearlooks

Example for Clearlooks 2.20

From 2005 to 2014 GTK used Clearlooks as a theme.

Adwaita

Example for Adwaita

Adwaita has been GTK's new standard topic since mid-2014 .

Environments that use GTK

The desktop environments Gnome , Cinnamon , MATE , Xfce , LXDE , Pantheon from Elementary OS and the ROX desktop are themselves based on GTK, which means that their window managers use GTK when drawing the window elements and the associated programs were developed with GTK.

GTK isn't just limited to these desktops; any GTK program can be run in any other desktop environment, such as KDE or CDE , as long as the GTK libraries are installed on the system. To improve the optical integration in Qt-based desktops (e.g. KDE), there are a. gtk-qt. GTK is also available for Windows and OS X (native / X11), making it possible to write applications that can be ported between Unix, Windows and Mac OS X with relative ease .

See also

literature

Web links

Wikibooks: GTK with Builder  - learning and teaching materials

Individual evidence

  1. ^ The GTK + Project: Team. Retrieved October 16, 2011 .
  2. a b Index of /Public/gimp/gtk/v1.0. Retrieved August 11, 2014 .
  3. history . (accessed on July 5, 2020).
  4. ^ A b Emmanuele Bassi: Project rename to "GTK". In: Gnome mailing list . February 6, 2019, accessed February 7, 2019 .
  5. GTK + 3.0.0 released. Retrieved October 16, 2011 .
  6. Multiple backends for GTK +. Retrieved October 16, 2011 .
  7. Demonstration of the HTML5 Broadway backend. Retrieved October 16, 2011 .
  8. https://www.heise.de/newsticker/meldung/GTK-3-4-mit-Multitouch-und-Windows-Unterstuetzung-1484971.html
  9. https://www.heise.de/newsticker/meldung/Neue-Versionen-von-GTK-GLib-und-Clutter-1716414.html
  10. https://www.heise.de/newsticker/meldung/Gtk-3-8-bringt-Wayland-Support-1831487.html
  11. https://www.heise.de/newsticker/meldung/Gtk-3-10-mit-verbesserter-Wayland-Unterstuetzung-1965546.html
  12. https://www.heise.de/ct/artikel/Ansehen-Gnome-3-12-2155474.html
  13. https://www.heise.de/ct/ausgabe/2014-22-aktuell-Linux-2405721.html
  14. https://www.heise.de/newsticker/meldung/GUADEC-Wayland-Support-fuer-Gnome-1929406.html
  15. Release Notes 3.16
  16. https://www.heise.de/newsticker/meldung/Linux-Desktop-Neues-Gnome- sucht-Nachrichten-oben- 2584020.html
  17. https://www.heise.de/newsticker/meldung/Linux-Desktop-Gnome-3-18-mit-Google-Drive-Support-freighaben-2824084.html
  18. https://www.heise.de/developer/meldung/GUI-Toolkit-GTK-3-20-verbessert-das-CSS-Theming-3147275.html
  19. https://www.heise.de/developer/meldung/GUI-Toolkit-GTK-3-22-bringt-Flatpak-Portale-3327937.html
  20. https://wiki.gnome.org/Projects/GTK+/OSX
  21. https://www.gtk.org/download/macos.php
  22. https://www.gtk.org/download/windows.php
  23. https://sourceforge.net/projects/gtk-win/
  24. http://www.tarnyko.net/dl/gtk.htm
  25. https://github.com/tschoonj/GTK-for-Windows-Runtime-Environment-Installer
  26. https://www.administrator.de/wissen/windows-subsystem-linux-installation-wsl-konfiguration-gnome-10-362919.html
  27. a b [ANNOUNCE] PyGTK 2.24.0. April 8, 2011, accessed October 15, 2011 .
  28. cl-gtk2 in the CLiki. Accessed April 1, 2015 .
  29. gtkD. Retrieved October 15, 2011 .
  30. GladeToBac. Retrieved October 15, 2011 .
  31. Data2App. Retrieved October 15, 2011 .
  32. GTK + tobac. Retrieved October 15, 2011 .
  33. gtk-fortran. Retrieved October 15, 2011 .
  34. ^ Go-GTK. Retrieved April 6, 2012 .
  35. CoreGTK. Accessed March 27, 2020 (English).
  36. gtk-perl. Accessed July 1, 2017 .
  37. Gtk-rs. Accessed December 20, 2016 .
  38. Default Theme Progress , February 28, 2005
  39. A new default theme for GTK + , June 13, 2014
  40. gtk-qt-engine. Retrieved November 17, 2012 .