This page was last updated around 1999

Buy the book from Amazon

This is the main home page for my book, GTK+/Gnome Application Development. Thanks for your interest in the book.

GTK+/Gnome Application Development is an intermediate-to-advanced GTK+/Gnome programming book. You should be comfortable with programming (data structures, algorithms, etc.) and with the C programming language before you try to read it. It's also helpful to have had some introductory exposure to GTK+, via the online tutorial or Eric Harlow's book Developing Linux Applications with GTK+ and GDK (buy from Amazon). However, if you know C and are willing to jump right in you could start with my book, perhaps in conjunction with the GTK+ reference documentation.

If you don't know how to program or you don't know C, you should probably start with a different book. If you don't know the UNIX and GNU/Linux standard interfaces, you can go ahead and read my book but you might want to get some others as well.

Beginners might also be interested in my guide to working on free software.


Sadly, people have already found errors in the book. Here are some errata...

Support the author!

If you click on the links on this page and then order the book then I get a small kickback from Amazon, which I can use to buy nicer caffeinated beverages for hacking. :-) You have to order by clicking on these links though, you can't click on this link and then later go directly to the Amazon page.

Shamelessly, I've also made links to some other books of interest to Gnome programmers.

In association with

Online Edition

I've checked the XML version of the book into the GNOME CVS server, the module is called GGAD. If you aren't a CVS kind of person, you can also look here for the HTML version.

Right now the online version isn't available in a printable format (well, other than choosing "Print" in Netscape) because I didn't have a need to write an XML-to-printable-format converter while I was writing the book. The XML-to-HTML converter is in CVS with the book itself; adding a DocBook backend is on my TODO list, but I haven't done it yet. If you want to have a go at it, please do.

Note that the online version is the final draft that I sent to the publisher; the printed copy has been edited a good bit more.

Source Code

The "GnomeHello" sample application from the book is on the Gnome CVS server under the gnome-hello module. It's also available in a tarball from The other source code is in the GGAD module along with the book itself.


This book is licensed under the Open Publication License, sans Options A and B, making it a part of the GNU Project's collection of free documentation. The GNU and GNOME projects feel that options A and B of the OPL are inappropriate for technical documentation. You can read about the importance of free documentation here.


Here's an outline of the book. As you can see, it's intended as a kind of sequel and supplement to a GTK+ tutorial or introduction. It adds a Gnome tutorial and some advanced Gtk concepts (such as the object system, and Gdk). For now GTK+/Gnome Application Development is the best source of documentation for the core GNOME libraries, GTK+ object system, GDK, and GTK+ widget system.

1 Introduction
  1.1 What is Gnome?
  1.2 The Gnome Development Framework
    1.2.1 Non-Gnome Libraries
    1.2.2 Gnome Libraries
    1.2.3 Other Libraries
    1.2.4 A Word About Header Files
  1.3 Structure of the Book

2 glib: Portability and Utility
  2.1 Basics
    2.1.1 Type Definitions
    2.1.2 Frequently Used Macros
    2.1.3 Debugging Macros
    2.1.4 Memory
    2.1.5 String Handling
  2.2 Data Structures
    2.2.1 Lists
    2.2.2 Trees
    2.2.3 Hash Tables
  2.3 Other Features

3 GTK+ Basics
  3.1 Whirlwind Tour of GTK+
    3.1.1 A Complete Hello, World
       Compiling Hello, World
    3.1.2 How It Works
       Entering the Main Loop
       More on Signals and Callbacks
  3.2 Containers And Widget Layout
    3.2.1 Size Allocation
    3.2.2 GtkBox
       GtkBox Layout Details
       Non-Homogeneous Box Packing Patterns
       Homogeneous Box Packing Patterns
       Box Packing Summary
    3.2.3 GtkTable
       GtkTable Example
       Using gtk_table_attach_defaults()
    3.2.4 Other Layout Widgets
    3.2.5 Manually Affecting Layout
  3.3 Widget Concepts
    3.3.1 Widget Life Cycle
    3.3.2 Realizing, Mapping, and Showing
    3.3.3 Other Widget Concepts
       Widget States
  3.4 The Main Loop
    3.4.1 Main Loop Basics
    3.4.2 Quit Functions
    3.4.3 Timeout Functions
    3.4.4 Idle Functions
    3.4.5 Input Functions

4 Creating Your Source Tree
  4.1 Overview of a Gnome Source Tree
  4.2 Source Tree Checklist
  4.5 Relevant GNU Documentation
  4.6 Installing Support Files
    4.6.1 Installing Datafiles: Documentation and Pixmaps
    4.6.2 .desktop Entries
    4.6.3 EXTRA_DIST

5 Gnome Application Basics
  5.1 Initializing the Libraries
  5.2 Internationalization
  5.3 Argument Parsing with popt
    5.3.1 Argument Parsing in GnomeHello
  5.4 Saving Configuration Information
    5.4.1 Reading Stored Config Data
    5.4.2 Storing Data In Configuration Files
    5.4.3 Config File Iterators
       Iteration Example from gnome-apt
       Section Iterators
       Other Config File Operations
  5.5 Session Management
    5.5.1 Using the GnomeClient Object

6 The Main Window: GnomeApp
  6.1 The GnomeApp Widget
  6.2 Menus and Toolbars with GnomeUIInfo
    6.2.1 Converting GnomeUIInfo to a Widget
    6.2.2 GnomeHello: An Example
  6.3 Adding a Status Bar
    6.3.1 GnomeAppBar
    6.3.2 GtkStatusbar
  6.4 Online Help
    6.4.1 Gnome Documentation and Help Menu Items
    6.4.2 Menu Hints
    6.4.3 Tooltips
  6.5 Finishing Touches
    6.5.1 Adapting to Screen Size
    6.5.2 Setting Window Class Hints

7 User Communication: Dialogs
  7.1 The GnomeDialog Widget
    7.1.1 Creating a Dialog
    7.1.2 Filling in the Dialog
    7.1.3 Handling GnomeDialog Signals
    7.1.4 Finishing Touches
  7.2 Modal Dialogs
  7.3 A Dialog Example
  7.4 Special Dialog Types
    7.4.1 GnomeAbout
    7.4.2 GnomePropertyBox
    7.4.3 GnomeMessageBox
  7.5 Convenience Routines

8 Gnome Application Checklist

9 The GTK+ Object and Type System
  9.1 Object and Class Structures
  9.2 Type Checking and New Types
  9.3 Initializing a New Class
  9.4 GtkArg and the Type System
  9.5 Object Arguments
    9.5.1 Setting Object Arguments
    9.5.2 Reading Object Arguments
    9.5.3 Using Object Arguments in Your Own GtkObject Subclass
    9.5.4 Discovering the Available Object Arguments
  9.6 Signals
    9.6.1 Adding a New Signal
    9.6.2 Using Existing Signals
    9.6.3 Emitting A Signal
    9.6.4 What Happens When A Signal Is Emitted
  9.7 Object Finalization
    9.7.1 Chaining Up
  9.8 Attaching Data to Objects

10 GDK Basics
  10.1 GDK and Xlib
  10.2 GdkWindow
    10.2.1 GdkWindow and GtkWidget
    10.2.2 GdkWindow Attributes
  10.3 Visuals and Colormaps
    10.3.1 GdkVisual
       Types of Visual
    10.3.2 Color and GdkColormap
       Obtaining a Colormap
  10.4 Drawables and Pixmaps
  10.5 Events
    10.5.1 Types of Event
    10.5.2 The Event Mask
    10.5.3 Receiving GDK Events in GTK+
    10.5.4 Button Events
    10.5.5 Keyboard Events
    10.5.6 Mouse Movement Events
       Keyboard Focus
    10.5.7 Focus Change Events
    10.5.8 Expose Events
    10.5.9 Window Change Events
    10.5.10 Little-used Events
       Visibility Events
       Property Events
       Selection Events
       Client Events
       Drag and Drop Events
       Proximity Events
  10.6 The Mouse Pointer
    10.6.1 Pointer Location
    10.6.2 Grabbing the Pointer
    10.6.3 Changing the Cursor
  10.7 Fonts
    10.7.1 Font Metrics
  10.8 Graphics Contexts
  10.9 Drawing
    10.9.1 Points
    10.9.2 Lines
    10.9.3 Rectangles
    10.9.4 Arcs
    10.9.5 Polygons
    10.9.6 Text
    10.9.7 Pixmaps
    10.9.8 RGB Buffers
  10.10 GDK Resource Management
  10.11 GtkStyle and Themes

11 Writing a GtkWidget
  11.1 Overview
    11.1.1 Kinds of Widget
    11.1.2 What a Widget Does
  11.2 The GtkWidget Base Class
    11.2.1 The GtkWidget Instance Struct
    11.2.2 The GtkWidget Class Struct
       Overridable Signals
  11.3 An Example: The GtkEv Widget
    11.3.1 Overview
    11.3.2 GtkObject Features
    11.3.3 Realization and Mapping
    11.3.4 Size Negotiation
    11.3.5 Drawing
    11.3.6 Handling Focus
    11.3.7 GtkEv's Functionality
  11.4 GtkWidget In Detail
    11.4.1 Destruction
    11.4.2 Showing, Hiding, and Mapping
    11.4.3 Realization
    11.4.4 Drawing
    11.4.5 Size Negotiation
    11.4.6 GtkContainer
       The GtkContainer Instance Struct
       The GtkContainer Class Struct
    11.4.7 GtkBin: Containers With One Child
       Adding and Removing Children
       Iterating Over Children
       Child Type
       Other GtkBin Functionality
  11.5 GtkVBox: A Windowless Container
    11.5.1 Coding a GTK_NO_WINDOW Widget
    11.5.2 Size Negotiation
    11.5.3 Child Arguments
  11.6 GnomeAppBar: A Trivial Composite Widget
  11.7 Other Examples

12 GnomeCanvas
  12.1 Introduction to the Canvas
  12.2 Basic Canvas Architecture
    12.2.1 GnomeCanvasGroup
    12.2.2 Coordinates
    12.2.3 Affine Transformations
  12.3 Using the Canvas
    12.3.1 Preparing the GnomeCanvas Widget
       Scroll Region
    12.3.2 Canvas Items
    12.3.3 Canvas Items and Events
    12.3.4 A Canvas Example
  12.4 Standard Canvas Item Reference
       Rectangle and Ellipse Items
       Line Item
       Polygon Item
       Image Item
       Text Item
       Widget Item

13 Writing a GnomeCanvasItem
  13.1 Overview
    13.1.1 GnomeCanvasRect
  13.2 Drawing Methods
    13.2.1 The Update Method
       Requesting Updates
    13.2.2 The Render Method (Antialiased Mode)
       Speed and RGB Rendering
    13.2.3 The Draw Method (GDK Mode)
  13.3 Other Methods
    13.3.1 Events
    13.3.2 Point
    13.3.3 Bounds
    13.3.4 Realizing and Mapping
    13.3.5 GtkObject Methods

A GTK+/Gnome Object Hierarchy
  A.1 Hierarchy Summary
  A.2 GtkObject
    A.2.1 GtkObject
       Header File
  A.3 Widgets
    A.3.1 GtkWidget
    A.3.2 GtkContainer
    A.3.3 GtkBin
    A.3.4 GtkWindow
    A.3.5 GnomeDialog
    A.3.6 GnomeAbout
    A.3.7 GnomeMessageBox
    A.3.8 GnomePropertyBox
    A.3.9 GnomeScores
    A.3.10 GnomeApp
    A.3.11 GtkDialog
    A.3.12 GnomeFontSelector
    A.3.13 GtkInputDialog
    A.3.14 GtkColorSelectionDialog
    A.3.15 GtkFileSelection
    A.3.16 GtkFontSelectionDialog
    A.3.17 GtkPlug
    A.3.18 GtkButton
    A.3.19 GnomeColorPicker
    A.3.20 GnomeFontPicker
    A.3.21 GnomeHRef
    A.3.22 GtkToggleButton
    A.3.23 GtkCheckButton
    A.3.24 GtkRadioButton
    A.3.25 GtkOptionMenu
    A.3.26 GnomeDockItem
    A.3.27 GtkAlignment
    A.3.28 GtkFrame
    A.3.29 GtkAspectFrame
    A.3.30 GtkItem
    A.3.31 GtkMenuItem
    A.3.32 GtkCheckMenuItem
    A.3.33 GtkRadioMenuItem
    A.3.34 GtkPixmapMenuItem
    A.3.35 GtkTearoffMenuItem
    A.3.36 GtkListItem
    A.3.37 GtkTreeItem
    A.3.38 GtkEventBox
    A.3.39 GtkHandleBox
    A.3.40 GtkScrolledWindow
    A.3.41 GtkViewport
    A.3.42 GtkBox
    A.3.43 GtkHBox
    A.3.44 GnomeAppBar
    A.3.45 GnomeDateEdit
    A.3.46 GtkCombo
    A.3.47 GnomeEntry
    A.3.48 GnomeFileEntry
    A.3.49 GnomeNumberEntry
    A.3.50 GnomeProcBar
    A.3.51 GtkStatusbar
    A.3.52 GtkVBox
    A.3.53 GnomeCalculator
    A.3.54 GnomeGuru
    A.3.55 GnomeIconEntry
    A.3.56 GnomeIconSelection
    A.3.57 GnomeLess
    A.3.58 GnomePaperSelector
    A.3.59 GnomePixmapEntry
    A.3.60 GnomeSpell
    A.3.61 GtkColorSelection
    A.3.62 GtkGammaCurve
    A.3.63 GtkButtonBox
    A.3.64 GtkHButtonBox
    A.3.65 GtkVButtonBox
    A.3.66 GtkLayout
    A.3.67 GnomeCanvas
    A.3.68 GnomeIconList
    A.3.69 GnomeDockBand
    A.3.70 GnomeDock
    A.3.71 GtkCList
    A.3.72 GtkCTree
    A.3.73 GtkFixed
    A.3.74 GtkNotebook
    A.3.75 GtkFontSelection
    A.3.76 GtkPaned
    A.3.77 GtkHPaned
    A.3.78 GtkVPaned
    A.3.79 GtkList
    A.3.80 GtkMenuShell
    A.3.81 GtkMenuBar
    A.3.82 GtkMenu
    A.3.83 GtkPacker
    A.3.84 GtkSocket
    A.3.85 GtkTable
    A.3.86 GtkTed
    A.3.87 GtkToolbar
    A.3.88 GtkTree
    A.3.89 GnomeAnimator
    A.3.90 GnomePixmap
    A.3.91 GnomeStock
    A.3.92 GtkMisc
    A.3.93 GtkLabel
    A.3.94 GtkAccelLabel
    A.3.95 GtkClock
    A.3.96 GtkTipsQuery
    A.3.97 GtkArrow
    A.3.98 GtkImage
    A.3.99 GtkPixmap
    A.3.100 GtkCalendar
    A.3.101 GtkDrawingArea
    A.3.102 GtkCurve
    A.3.103 GtkDial
    A.3.104 GtkEditable
    A.3.105 GtkEntry
    A.3.106 GtkSpinButton
    A.3.107 GtkText
    A.3.108 GtkRuler
    A.3.109 GtkHRuler
    A.3.110 GtkVRuler
    A.3.111 GtkRange
    A.3.112 GtkScale
    A.3.113 GtkHScale
    A.3.1A GtkVScale
    A.3.115 GtkScrollbar
    A.3.116 GtkHScrollbar
    A.3.117 GtkVScrollbar
    A.3.118 GtkSeparator
    A.3.119 GtkHSeparator
    A.3.120 GtkVSeparator
    A.3.121 GtkPreview
    A.3.122 GtkProgress
    A.3.123 GtkProgressBar
    A.3.124 ZvtTerm
  A.4 Canvas Items
    A.4.1 GnomeCanvasItem
    A.4.2 GnomeCanvasRE
    A.4.3 GnomeCanvasEllipse
    A.4.4 GnomeCanvasRect
    A.4.5 GnomeCanvasGroup
    A.4.6 GnomeCanvasImage
    A.4.7 GnomeCanvasLine
    A.4.8 GnomeCanvasPolygon
    A.4.9 GnomeCanvasText
    A.4.10 GnomeCanvasWidget
    A.4.11 GnomeCanvasTextItem
  A.5 Miscellaneous Objects
    A.5.1 GnomeClient
    A.5.2 GnomeDEntryEdit
    A.5.3 GnomeDockLayout
    A.5.4 GnomeMDIChild
    A.5.5 GnomeMDIGenericChild
    A.5.6 GnomeMDI
    A.5.7 GtkData
    A.5.8 GtkAdjustment
    A.5.9 GtkTooltips
    A.5.10 GtkItemFactory

B Table of Header Files

C Frequently Asked Questions
  C.1 Index of Questions
  C.2 Questions, with Answers
    C.2.1 How do I make my application beep?
    C.2.2 When do I need to destroy my widgets?
    C.2.3 When I turn on memory profiling in glib, my application becomes unstable. What gives?
    C.2.4 To create a custom display, I want to place widgets in arbitrary       locations, or move them around rapidly, or draw to them       directly. How?
    C.2.5 Why does my memory debugging tool show memory leaks in glib?
    C.2.6 I get a bunch of "assertion failed" warnings from GTK+. What         causes these?
    C.2.7 Why are some things in Gnome rather than GTK+?
    C.2.8 How can I center a window on the screen?
    C.2.9 Is there a widget that does printing?
    C.2.10 When I fork(), I get a bunch of warnings and     my program crashes. What's going on?
    C.2.11 When do I need to call gtk_widget_realize()     vs. gtk_widget_show()?
    C.2.12 When creating a pixmap, I get the warning: Creating pixmap from xpm with NULL window and colormap. What's wrong?
    C.2.13 How can I separate the GUI from the rest of my application?
    C.2.14 I don't like the default appearance of [some widget].  How do I change its appearance?
    C.2.15 Thanks for the lecture, but I have a really good reason to change   the appearance of a widget. How do I override the theme?
    C.2.16 Why are signals specified as strings rather than integers or some sort of macro?
    C.2.17 Why is GTK+ written in C?
    C.2.18 My motion event handler is only invoked once; why is that?
    C.2.19 Can I move the mouse pointer myself?
    C.2.20 How do I read the pixels out of a GdkPixmap?
    C.2.21 I'm drawing a lot of points to the screen with
  gdk_draw_point(), and it's unbelievably   slow. What's wrong? How
  can I render image data to the screen?
    C.2.22 I'm trying to set the background of a GtkLabel, and   it doesn't work.
    C.2.23 In the GTK+ and Gnome source code, many functions have two       variants: one called gtk_whatever_foo(),       and another called       gtk_whatever_real_foo(). What's the       difference?
    C.2.24 How do I "gray out" a widget, so the user can't select it?
    C.2.25 I'm connecting to "button_press_event" or some other event   signal, but the callback is never invoked.
    C.2.26 I want to use the arrow keys as a control in my application, but   GTK+ keeps stealing the key press events to move the focus around.
    C.2.27 Does GTK+ have multiple inheritance?
    C.2.28 I'm getting error messages from GDK. How     can I determine the cause of these?
    C.2.29 How do I update the GUI without returning control to the main   loop?
    C.2.30 How should I format code to be included in GTK+ or Gnome?
    C.2.31 Is there a GUI builder for GTK+ and Gnome?
    C.2.32 How well do GTK+ and Gnome support internationalization?

D Online Resources
  D.1 Obtaining and Compiling the Libraries
  D.2 Web sites
  D.3 Mailing Lists
  D.4 Internet Relay Chat
  D.5 This Book

E Code Listings
  E.1 The GnomeHello Application
    E.1.1 hello.c
    E.1.2 app.h
    E.1.3 app.c
    E.1.4 menus.h
    E.1.5 menus.c
  E.2 The GtkEv Widget
    E.2.1 gtkev.h
    E.2.2 gtkev.