[BUG] Gtk2::GladeXML using signal_connect_after for everything

in #gtk-perl this evening (times are -0400):
05:16PM <Jodrell> interesting
05:17PM <Jodrell> button_release_event signals don't seem to work on glade-generated widgets
05:18PM <Jodrell> anyone care to confirm that for me?
05:20PM <Jodrell> http://jodrell.net/files/button_release_event_test.tgz

i tried it out, and indeed, the signals don't fire. they do get connected, they just never fire.

i loaded that xml file with a trivial C program that does the same thing, and the signals fire.

so, dug a little deeper.

the function signal_autoconnect_from_package() is implemented in perl, and simply calls signal_autoconnect(), which is implemented in XS, passing in _autoconnect_helper as the function to call to connect each signal. this callback is invoked by a private C function in the xs file, named connect_func_handler() (which is, in turn, called by libglade). this function passes all the arguments through the standard GPerlCallback marshaller gperl_callback_invoke(), which puts something on the stack for each item and invokes the perl subroutine. then we wind up in _autoconnect_helper(), which decides whether to call signal_connect() or signal_connect_after() based on the $after argument.

however, the logic here is broken.  it uses the code

        my $func = defined($after) ? 'signal_connect_after'
                                  : 'signal_connect';

which, since gperl_callback_invoke() always puts a defined value on the stack for a G_TYPE_BOOLEAN argument, *always* uses 'signal_connect_after'.

that means that *every* callback connected by Gtk2::GladeXML runs after the default handler.

GtkButton's default handler for button-release-event returns TRUE, which stops signal propagation; therefore, your perl-connected handler never gets called.

that line should read

        my $func = $after ? 'signal_connect_after' : 'signal_connect';

with that one-line change, the example you posted works great.

there appear to be a couple of unused functions in GladeXML.pm, as well, which have the same bug; does anybody use Gtk2::GladeXML::handler_connect() ? i think it (and its helper) should be removed.

the attached patch is against Gtk2::GladeXML 1.00 -- please test it out.

Attachment: connect_after_fix.patch
Description: Binary data

Without treatment, a common cold will last about seven days.
With treatment, it will last about a week.
  -- conventional wisdom

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]