Errata - Pro PHP-GTK - pg 71/72 - Call to undefined method Gdk::screen_width()

I have been learning PHP-GTK. I was following Chapter 5 of the Pro PHP-GTK book by Scott Mattocks, published by Apress (published 2006).

In the section on Window Positioning and Sizing (getting the width and height of the user’s screen) it says:

“To get values related to the user’s screen, the code must call on GDK for a little help. Two static GDK methods return the needed information: Gdk::screen_width and Gdk::screen_height provide the size of the screen in pixels.”

Now, there are a number of things to be aware of:

  • Note that these are methods of Gdk and not Gtk - this is the first time in the book that you have to call upon the drawing class as opposed to the toolkit class.
  • Also, if you try out Listing 5-3 with PHP Version: 5.2.9 and Gtk Version: GTK 2.12.9 you will get an error along the lines of
    Fatal error: Call to undefined method Gdk::screen_width()
  • Also, if you go and check the documentation for the GDK class. As it stands, you will see the methods are still listed.

The Correction

However, Christian Weiske has kindly answered a question on the nabble mailing list and suggests using the static width() method of GdkScreen class instead.

I have also done a bit of experimentation and, sure enough, that works and so does the height() method.

So, note that the text on page 71 and the listing 5-3 on page 72 should have all occurrences of Gdk::screen_width and Gdk::screen_height replaced with the respective new methods:

GdkScreen::width()
GdkScreen::height()

Also this site suggests an alternative approach using GtkWidget::get_screen() .

Leave a Reply