Graphics in GNOME

What is GTK+?

GTK+ is the Gimp Toolkit. It was originally written as part of the Gimp project, but it has grown into an excellent general purpose widget set. Find out more at http://www.gtk.org

What role does GTK+ play in GNOME?

GTK+ is the interface which GNOME applications use to interact with the user. It is similar to the role of Motif in CDE, Qt in KDE or the-widget-set-which-has-no-name in Win32.

What languages does GTK+ support?

You can write GTK+ programs in tons of languages! Your humble FAQ author knows of the following bindings:

C (original)
C++
Objective C
Python
Perl 5
Scheme (Guile)
TOM
Gwydion Dylan

If there are others, then please let us know about them. (See Contact the FAQ Maintainer)

You are encouraged to add bindings to other languages should the fancy strike you. N.b., that the Scheme bindings already have a formalized representation of the API, so if you want to start working on new bindings, then you might want to start from here.

Having written that, I have to wonder if we can't somehow use CORBA to cut this Gordian knot. If the ORBit developers can get the cost of a local CORBA call down to that of a normal shared-library call, then why not CORBify GTK and work on adding bindings for new languages to ORBit? I know, the conventional wisdom is that CORBA is too heavyweight for high-volume stuff like X calls. Hey, don't blame me for throwing out crazy ideas: the reason I maintain the FAQ is that I can't program!

What is imlib?

Along with GTK, GNOME uses imlib, an image library for X which supports multiple image formats transparently to the programmer. Imlib can even use external converter programs like ImageMagick or pmbplus to convert unknown image formats to known formats, so if a converter exists for an image type, you can almost certainly use that image type in your application! Imlib also supports multiple bit-depths, from 24-bit down to 1-bit monochrome, again transparently to the programmer, and does intelligent color map allocation and automatic dithering to get the best possible performance out of your display. Anyone who has ever tried to do this in their X apps, or who has had to endure their screen flashing when apps have to allocate a private color map, you will especially like this feature.

You can find out more about imlib at http://www.labs.redhat.com/imlib.

What's the deal with themes?

Themes let you change the look and feel of GTK+ applications without recompiling them. Eventually, you should be able to change the theme of all GTK+ apps on a given display at the same time. For now, though, you can hard-code the theme at startup.

To see some examples of what themed GTK+ apps look like, take a look at: http://gtk.themes.org.

How do I get themes working?

OK, I have gotten themes working on my machine; this is roughly how I did it. First, you have to reinstall GTK. Do a "make uninstall" on your present install, and then do the following:

% cvs get -r themes-2 -d themes-gtk+ gtk+
% cd themes-gtk+
% ./autogen.sh --prefix=/opt/gnome && make && make install
% cd themes
% ./autogen.sh --prefix=/opt/gnome && make && make install

You need the new imlib installed to do this; if you get an error because of an undefined AM_PATH_GDK_IMLIB, it's because imlib.m4 is not found, either because you don't have a new imlib, or because of normal Autoconf m4 file issues. (See Autoconf)

This should give you a working, themefied version of GTK+. Now, you need to do the following. Remember, in these examples, you should replace "/opt/gnome" with wherever you have gnome installed, which might be some place different.

% cd /opt/gnome/share
% mv gtkrc gtkrc.orig
% ln -s gtk/themes/$(theme)/gtkrc gtkrc

Where $(theme) is one of the subdirectories of gtk/themes; at present there are the following:

Pixmap
Redmond95 (a Win95-like theme)
Notif (a Motif-like theme)
Metal

That's it! After you make this symbolic link, all new GTK apps will be started with that the theme. You can even have multiple apps with multiple themes running at the same time. A theme lasts for the duration of that application.

I was changing themes so often that I came up with a silly shell script to do it for me. Here it is:

#!/bin/sh

ls -l /opt/gnome/share/gtkrc

cd /opt/gnome/share/
test -f gtkrc && mv gtkrc gtkrc.orig

echo "select from the following theme choices:"
cd /opt/gnome/share/gtk/themes/
find -name gtkrc | sed 'sH^\.\/HHg;sH\/gtkrc$HHg'

cd /opt/gnome/share/
theme=
while ! test -f gtk/themes/$theme/gtkrc
do
   echo -n "Choose a theme: "
   read theme
done

rm -f gtkrc
ln -s gtk/themes/$theme/gtkrc gtkrc
ls -l /opt/gnome/share/gtkrc
        

What is OpenGL?

OpenGL is a 2D and 3D rendering API developed by Silicon Graphics that has become a de facto industry standard. Basically, it is a tool to take a viewpoint of 3D space, and produce a 2D image of it suitable for drawing on a screen. To quote SGI's FAQ:

OpenGL is a rendering only, vendor neutral API providing 2D and 3D graphics functions, including modeling, transformations, color, lighting, smooth shading, as well as advanced features like texture mapping, NURBS, fog, alpha blending and motion blur. OpenGL works in both immediate and retained (display list) graphics modes.

GNOME uses an implementation of the OpenGL API called Mesa. Mesa is not OpenGL per se, since it is a Free Software project that has not gone through the OpenGL trademark licensing process, but it is a faithful representation of the OpenGL API. Mesa is not OpenGL(tm) in precisely the same way that GNU/Linux and FreeBSD are not Unix(tm).

What about Drag and Drop support?

GNOME currently uses the Xde Drag and Drop protocol. XDE is being replaced with an implementation of the X Windows Drag-And-Drop Protocol to inter-operate with other toolkits. Find out more at http://www.cco.caltech.edu/~jafl/xdnd/.