Johannes Braun
Johannes Braun

Reputation: 115

Vala generates deprecated warnings for higher GTK/GDK Versions

I am compiling some Vala code on ElementaryOS Loki, which ships with GTK Version 3.18. Now I get (a lot of) deprecated warnings like:

src/ScreenGrabber.vala:64.55-64.94: warning: Gdk.Display.get_device_manager has been deprecated since 3.20.
src/ScreenGrabber.vala:64.55-64.115: warning: Gdk.DeviceManager.get_client_pointer has been deprecated since 3.20
src/ScreenGrabber.vala:85.19-85.50: warning: Gdk.Screen.get_active_window has been deprecated since 3.22

But the recommended alternative methods that should be used in favor of the "deprecated" ones simply dont't exist in 3.18 yet, so I cannot use them.

How can I make valac giving me correct warnings for the given GTK Version? I tend to switch off warnings completely which I would rather like to avoid, if possible. valac has a switch --target-glib, but there is no equivalent "--target-gtk"

--

EDIT: e.g. this little program demonstrates the problem if compiled with valac -o test test.vala --pkg=gtk+-3.0 (on ElementaryOS Loki, with GTK 3.18)

using Gtk;
public class Test {

    public Test() {
        var manager = Gdk.Display.get_default().get_device_manager();
    }

    public static int main(string[] args) {
        var test = new Test();
        return 0;
    }   
}   

Upvotes: 3

Views: 460

Answers (1)

AlThomas
AlThomas

Reputation: 4289

Probably the best solution is to use the --enable-deprecated switch when compiling with valac. You could also try --disable-since-check if that doesn't work. The --disable-since-check was introduced in Vala 0.32 with the new [Version] attribute.

In an ideal world a library would also distribute its binding for Vala. This would mean the binding is kept in sync with the library. See Vala Bindings Upstream guide.

Both GTK+ and Vala are GNOME hosted projects. Although Vala carries the GTK+ bindings, both projects are kept in sync and should work well together. Specifically relating to your question, GTK+ 3.18 was released 22 September 2015 and Vala 0.30 on the 18 September 2015. Both of these were in time for the GNOME 3.18 release on 23 September 2015.

What has happened with Loki is, according to the Loki beta release blog post, GTK+3.18 and Vala 0.32 have been bundled together. Vala 0.32 carries bindings for GTK+3.20.

So you could download the gtk+-3.0.vapi and gdk-3.0.vapi from the Vala 0.30.0 release and use that instead. This, unfortunately, will show a lot of different warnings because of the way version information is noted in VAPIs has recently changed. Vala now uses [Version] instead of [Deprecated]. These different warnings can be suppressed with --enable-deprecated.

If you contribute to a distribution then there is no fundamental reason why distributions need to bundle the Vala compiler with the bindings that come with the compiler. So they could have two, or more, packages. One for the compiler, one for the non-upstreamed bindings, e.g. vala-0.30 and vala-non-upstreamed-bindings-0.30. Although that is a bit of a simplification, for example Vala will continue to carry a binding some time after it has been generated upstream.

Upvotes: 4

Related Questions