GNOME Bugzilla – Bug 601221
Gtk.Widget's can_focus binding is broken with vala-0.7.8
Last modified: 2009-11-13 18:38:22 UTC
Created attachment 147249 [details] [review] patch Hello When I updated to vala-0.7.8 my app stopped compiling the *_can_focus(bool a) function in a button. This is a function inherited from Gtk.Widget. I attached a patch to this bug report that fixes the problem in the vapi only. Regards Jörn Magens
Of course it is a property *.can_focus = true/false. But still, the patch is working.
I'm having trouble reproducing this—would you mind attaching a test case? I've tried var btn = new Gtk.Button (); btn.set_can_focus (false); and it seems to work. Maybe I'm misunderstanding the problem. Thanks.
Hi Evan It's not the method "set_can_focus", but the property or public field "can_focus". This is why I added my comment. The original bug report was a little misleading. Please have a look at the patch and you will see. Thanks and Regards Jörn Magens
Ok, more details: The following code (snippet): public class VolumeSliderButton : Gtk.VolumeButton { public VolumeSliderButton() { // in the constructor this.can_focus = false; } } ------------------------ leads to this: xnoise-main-window.o: In function `xnoise_main_window_volume_slider_button_construct': /home/xyz/xnoise/src/xnoise/xnoise-main-window.c:2920: undefined reference to `gtk_widget_set_can_focus' collect2: ld returned 1 exit status .... ------------------------ The generated ccode is (snippet): XnoiseMainWindowVolumeSliderButton* xnoise_main_window_volume_slider_button_construct (GType object_type) { XnoiseMainWindowVolumeSliderButton * self; ... gtk_widget_set_can_focus ((GtkWidget*) self, FALSE); ... return self; } ------------------------ but it should be: XnoiseMainWindowVolumeSliderButton* xnoise_main_window_volume_slider_button_construct (GType object_type) { XnoiseMainWindowVolumeSliderButton * self; ... g_object_set ((GtkWidget*) self, "can-focus", FALSE, NULL); ... return self; } The patch contains the [NoAccessorMethod] annotation for the property public bool can_focus { get; set; }. Thanks and Regards Jörn
Created attachment 147682 [details] Working test case Sorry, I should have mentioned in my previous comments that I tried that as well, and all seems well. Here is the test I was using, which works for me. That btn.can_focus = true; compiles to gtk_widget_set_can_focus ((GtkWidget*) btn, TRUE);
Jörn, ah, thanks. Looks like you replied before I hit submit :) gtk_widget_set_can_focus is works on my system--that test case output the following: ** (601221:15316): DEBUG: 601221.vala:6: get_can_focus() = false ** (601221:15316): DEBUG: 601221.vala:8: can_focus = true What version of gtk+ are you using? Mine is 2.18.3. I'll investigate and try and figure out when it was added.
Hi Evan I use still 2.16.1 (Ubuntu Jaunty). It worked until I upgraded from vala-0.7.7 to vala-0.7.8. Is this because vapi files should be distributed with their according version of librarie they belong to? If so, there is probably no fix but upgrading to a more recent distribution, is it? Regards Jörn
Yes, the GTK+ bindings were upgraded to 2.18 during the 0.7.8 development process, but you don't need to upgrade GTK+ to use them. I've gone ahead with your patch (actually, I edited the metadata file to generate the same change your patch made). The difference is transparent to vala users, so it's not a big deal to preserve compatibility here--it will just generate slightly less nice code than it could. Obviously you won't be able to make use of the new GTK+ 2.18 features, but hopefully the new bindings will continue to be useful to 2.16, and maybe even 2.14, users. Thanks for your patience regarding this bug.
commit 95889a88390af5e084bbf2330fe0d9a74c2e22ee Author: Evan Nemerson <evan@coeus-group.com> Date: Fri Nov 13 10:25:42 2009 -0800 gtk+-2.0: Mark Gtk.Widget.can_focus as not having an accessor method, to preserve compatibility with GTK+ < 2.18. Fixes bug 601221.