Friday, January 21, 2011

Hello world GTK



I'll be going over this later today. It's mostly easy to follow - the only confusing part is the existence of the delete_event function that returns FALSE. There are signals that the widgets emit that you can catch and do stuff with (like closing the window when the "X" on the top right is clicked) but BEFORE those signals are emitted the underlying system emits an event. So...if you catch and act on an event then no signal for that event is emitted.

There are two g_signal_connect calls - one for catching "destroy" and one for catching "delete_event". It's not obvious (well, maybe it is by the name) that "delete_event" happens first and would subsequently cause the "destroy" event if left alone.

My callback function for the event (again - events before signals) is confusingly called delete_event (thanks Andrew Krause) and this function is run first before the callback for the "destroy" signal. By returning FALSE in the destroy_event function I am saying "this callback function didn't really do anything important enough to block the subsequent signal that this event will cause".

In fact, changing it to TRUE makes the "X" do nothing! You have to kill the window in task manager.

So that's how you can have a "Do you really want to quit" dialog. If you want to quit then the function for the event returns FALSE and the event delete_event causes the widget to emit the "destroy" signal which runs the destroy callback function which proper kills the window.

All these signals, events, and functions having similar names makes me want to set a standard for how I write things out. Maybe signals/events in "" and every function has a () after it. Just for readability.

*EDIT*
Jeez, 4:30AM Chris is not coherent enough to make journal entries. Fixed a few incorrect statements.

No comments:

Post a Comment