Sunday, January 23, 2011

Today's Lesson

Today's lessons are:

A) Not all widgets are created equal.
B) Different signals/events require different callback function prototypes to handle them properly
C) READ THE DAMNED API DOCS

So here was my problem. I assumed that every callback function would have the same prototype:

function(GtkWidget*,gpointer)

This is not true. I was trying to act on a "button_press_event" which required:

function(GtkWidget*,GdkEvent*,gpointer)

And you know what? The API was blasting this in my face the entire time:

http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-button-press-event

The scary thing is that the "destroy" event has the same prototype but my particular callback function didn't care about the values passed to it, so no problems were had even though I left something out.

I guess there isn't a way to get the compiler to warn me?

*EDIT* The vast majority of my confusion was because I found a tutorial program that did something similar. Instead of a key press in a GtkWindow widget they were clicking on a GtkButton widget. The "clicked" signal has a different prototype that just happened to be the same as the "wrong" prototype I was using for the "destroy" event in my program, which made me think that it was correct and something else was going on.

I feel like I leveled up today.

*EDIT x2*
The program.

No comments:

Post a Comment