Using libhandy with vala

I want to play with vala and libhandy, I followed firstly this way (which for python)

It didnt work, so I downloaded gnome clocks source whiche used libhandy and I did these steps:

  1. add these lines to main meson.build

    # add these after project(...) lines
    
    libhandy = dependency ('libhandy-1', version: '>= 0.80.0', required: false)
    
    if not libhandy.found()
      libhandy_subproj = subproject(
        'libhandy',
        default_options: [
          'examples=false',
          'glade_catalog=disabled',
          'tests=false',
        ]
      )
    
      libhandy = declare_dependency(
        dependencies: [
          libhandy_subproj.get_variable('libhandy_dep'),
          libhandy_subproj.get_variable('libhandy_vapi'),
        ]
      )
    endif
    
  2. add folder with name subprojects and inside it add file libhandy.wrap with this content

    [wrap-git]
    directory=libhandy
    url=https://gitlab.gnome.org/GNOME/libhandy.git
    revision=origin/master
    
  3. to add libhandy for your flatpak build, add these lines in your me.rush.Rush.json file

    "modules" : [
            // add from here
            {
                "name": "libhandy",
                "buildsystem": "meson",
                "config-opts": [
                    "-Dtests=false",
                    "-Dexamples=false",
                    "-Dglade_catalog=disabled"
                ],
                "sources": [
                    {
                        "type": "git",
                        "url": "https://gitlab.gnome.org/GNOME/libhandy.git"
                    }
                ]
            }, // to here
    	    {
                "name" : "rush",
                "builddir" : true,
                "buildsystem" : "meson",
                "sources" : [
                    {
                        "type" : "git",
                        "url" : "file:///home/rush/Projects/Rush"
                    }
                ]
            }
        ]
    
  4. sure to add this line for your ui files

    <requires lib="gtk+" version="3.24"/>
    <requires lib="libhandy" version="0.0"/>

so after that I started by replace GtkApplicationWindow by HdyApplicationWindow in window.ui and replacing Gtk.ApplicationWindow by Hdy.ApplicationWindow in window.vala

but it doesnt work also, but that what I noticed if any one can help

  1. in gnome clocks (also other projects like gnome calculator and gnome contacts) they doesnt use
using Gtk;
using Handy; // I also tried `Hdy` and `libhandy`

in main.vala , I get error when I use it (by the way I tried to dont use it but also I get error coz class Hdy.ApplicationWindow seems like doesnt exist)

  1. when I build my project it make directory in subprojects with name libhandy and download library to it, but when I build gnome clocks it does not make this

I assume you are actually adding handy to the executable’s dependencies?

For Handy 1 the namespace should be Handy

please if you can explain that

Somewhere you must have something like

executable('gnome-clocks', clocks_sources,
  dependencies: clocks_dependencies,
  install: true
)

The list of dependencies should include the handy object

1 Like
  1. Unless you absolutely have to use subproject (if you don’t know, then you don’t need it), just do:
handy_dep = dependency ('libhandy-1', version: '>= 0.81.0')

in meson.build. and then mention the handy_dep in the list of dependencies like Zander mentioned.

  1. Not needed if you don’t use subproject

  2. Correct

  3. Not needed, those lines are ignored.

n gnome clocks (also other projects like gnome calculator and gnome contacts) they doesnt use

Hdy. But you don’t have to do that, that would just allow you to use ApplicationWindow instead of Hdy.ApplicationWindow.

  1. when I build my project it make directory in subprojects with name libhandy and download library to it, but when I build gnome clocks it does not make this

Then there’s a problem with the flatpak manifest. Maybe a typo somewhere, e.g. a missing comma?

1 Like

Then what you also do need in meson.build is:

add_project_arguments (
  '-DHANDY_USE_UNSTABLE_API',
  language: 'c'
)

# FIXME Disable --disable-since-check after libhandy 1.0 is released
add_project_arguments (
  '--disable-since-check',
  language: 'vala'
)
1 Like

https://gitlab.gnome.org/exalm/libhandy-vala-demo here’s a working example. See the commit history for what I changed compared to a default project Builder creates.

1 Like

thanks for all of you, and this example on gitlab was very helpful and I learnd another things from example coz using of headerbar in libhandy has a little diffrence on gtk

The headerbar usage difference is just a thing specific to HdyWindow/HdyApplicationWindow. Basically, it has no separate titlebar and you just pack a headerbar inside, which is its main feature compared to GtkWindow really :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.