Chapter 10. Gtk2::Gdk

Objective

The Gtk2::Gdk modules are not often used, but there are places and situations where you have to use it, especially when you want to do lower level functions. To find lots of information on Gtk2::Gdk is not very easy. (This is not just Gtk2::Gdk but GDK in general, especially!).

This lesson will first look at Gtk2::Gdk in general. We will then look at two programs that will introduce the reader to more fancy tricks that will use Gtk2::Gdk classes in combination with Gtk2 classes.

10.1. Gtk2::Gdk in general

If you followed the lessons up to now, you have already used Gtk2::Gdk in a few places, although it was just for basic things. The following is a table of Gtk2::Gdk classes that we used and what we used it for.

Table 10-1. Gtk2::Gdk object classes used

Gtk2::Gdk Class NameUsed to do:
Gtk2::Gdk::WindowGetting the X-Window that a widget is displayed in.
Gtk2::Gdk::CursorSetting the cursor when the mouse hovered over a widget's Gtk2::Gdk::Window
Gtk2::Gdk::EventThe first event used was the "delete_event", which happens when the Gtk2::Window is closed.
Gtk2::Gdk::Event::ButtonThis was used to check which button was clicked. It is a sub-class of Gtk2::Gdk::Event
Gtk2::Gdk::Event::KeyThis was used to check which key was pressed. It is a sub-class of Gtk2::Gdk::Event
Gtk2::Gdk::KeysymsThis is a hash of names and key numbers. Used for lookups to catch certain key strokes

We will discuss Gtk2::Gdk::Pixbuf and Gtk2::Gdk::Pixmap here. This is done prior to discussing Gtk2::Image in depth, since Gtk2::Image can use them to create a visible image.

Gtk2::Gdk, as stated at the start of the document is an abstraction layer between the lower level windowing system of the OS and the widgets. This allows you do do things like image manipulation, event blocking and handling, the shape of your windows, the color scheme of the widgets.

Since it is an abstraction layer, it allows you to write your application once, and it will be able to run on different OS'es with different windowing systems. You will be able to do the same tricks using X's API on Linux for instance, but this will not work if you run the program on a Windows machine, since it does not use X as a graphical system.