Search code examples
gtk3

‘GtkWidget {aka struct _GtkWidget}’ has no member named ‘window’


I have recently tried my hand at learning GTK using Andrew Krause's "Foundations of GTK+ Development" (this is the most recent - 2007 - book on GTK I could find). Thus far, about half of the programs compile & run outright and the other half have deprecated functions which I can find replacements for with a little googling. I do use some online tutorials but they don't have the detail of explanation that Mr. Krause's book has.

In a perfect world, I would like to have an up to date book to learn from but that is not available. Thus I have to go back and forth between the book (GTK2) and online sources (GTK3).

My question, when I try to compile the source code from the book, I get several errors. I have been able to update all of the code except for the issue I name in the title that I cannot get past.

From the book, chapter 3 event boxes, this line is the one I am having trouble with:

gdk_window_set_cursor (eventbox->window, gdk_cursor_new (GDK_HAND1));

I have been able to modify it to work to this point but still get the error when I compile:

gdk_window_set_cursor (eventbox->window, gdk_cursor_new_for_display   (gdk_display_get_default(), GDK_HAND1));

When I compile I get:

eventboxes.c:37:33: error: ‘GtkWidget {aka struct _GtkWidget}’ has no member named ‘window’


gdk_window_set_cursor (eventbox->window, gdk_cursor_new_for_display (gdk_display_get_default(), GDK_HAND1));

Having read some other items online such as this one "using cairo with gtk3"

I have found that changes between GTK2 and GTK3 have made members, such as window, inaccessible.

Sorry for the longwinded post by my question is: Is there a way in GTK3 to make the line of code work or I am just pursuing a fool's errand and should let this one die?


Solution

  • This exact code can be fixed the following way:

    GdkWindow * gdk_window = gtk_widget_get_window (eventbox);
    gdk_window_set_cursor (gdk_window, gdk_cursor_new (GDK_HAND1));
    

    However, I don't think it's a good idea to learn Gtk3 with Gtk2 books. You can read them to get overall view, but then switch to gtk documentation, gtk3-demo app for some recipes, gtk3-widget-factory source code and, of course, SO.