tags:

views:

414

answers:

3

I'm attempting to capture an event on a GTK window when the window is moved. I'm doing so with something that looks like this:

void mycallback(GtkWindow* parentWindow, GdkEvent* event, gpointer data)
{
    // do something...
}

...
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);    

gtk_widget_add_events(GTK_WIDGET(window), GDK_CONFIGURE);
g_signal_connect_(G_OBJECT(window), "configure-event", G_CALLBACK(mycallback), NULL);
...

This works- the event is properly called when the window is moved... but it's also called when the window is resized. This has the side effect of not resizing the window's sub-elements as they would if I didn't connect the event.

According to this table in the GTK docs, the GDK_CONFIGURE event does not propagate. If the event does not propagate, how can I still detect the window's movement while allowing it to resize properly?

note: I'm using GTK version 2.12.9

A: 

Well, I mainly use gtkmm (C++ wrapper of GTK). But if I recall correctly, if you want to propagate the signal to the parent, your handler should return TRUE (gint). So I think that if you return (gint)TRUE in mycallback, it should work.

my 2 cents

neuro
A: 

Neuro- I didn't believe that would work because the function signature returned void rather than gboolean. For grins, I changed:

void mycallback(GtkWindow* parentWindow, GdkEvent* event, gpointer data)

to

gboolean mycallback(GtkWindow* parentWindow, GdkEvent* event, gpointer data)

I would have thought this would cause a type-mismatch with the callback types, but it does not. Returning TRUE like you suggested doesn't work... but strangely returning FALSE does. This being the case, it appears that the event can propagate.


Edit:

According to the GTK tutorial (thanks Matt):

The value returned from this function indicates whether the event should be propagated further by the GTK event handling mechanism. Returning TRUE indicates that the event has been handled, and that it should not propagate further. Returning FALSE continues the normal event handling.

luke
+1  A: 

Luke, as you have discovered, returning FALSE allows the event to propagate. This is explained in the gtk tutorial here

Matthew Talbert