How to manually implement a funcion for gir generated bindings for gtk-layer-shells

Hi,
I created the bindings and the wrapper for gtk-layer-shell. In order for it to build I had to add the following to the Gir.toml file of the sys crate:

[[object]]
name = "GtkLayerShell.*"
    [[object.function]]
    name = "get_zwlr_layer_surface_v1"
    ignore = true

Otherwise I got an error

error[E0412]: cannot find type `zwlr_layer_surface_v1` in this scope
  --> src/lib.rs:87:85
   |
87 |     pub fn gtk_layer_get_zwlr_layer_surface_v1(window: *mut gtk::GtkWindow) -> *mut zwlr_layer_surface_v1;
   |                                                                                     ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0412`.

If I let gir generate the function automatically, it only adds


#[link(name = "gtk-layer-shell")]
extern "C" {
    // More automatically generated functions
    // ...
    #[cfg(any(feature = "v0_4", feature = "dox"))]
    #[cfg_attr(feature = "dox", doc(cfg(feature = "v0_4")))]
    pub fn gtk_layer_get_zwlr_layer_surface_v1(window: *mut gtk::GtkWindow) -> *mut zwlr_layer_surface_v1;
}

I’d like to not ignore that function anymore but I do not know how to fix the error. I guess I’d have to manually implement the function or work with upstream to change the .gir file?
I read the tutorial and had a look at a few other gir-generated bindings, but I still don’t know how to proceed. Can somebody please point me to the right direction? The failing code can be found in this branch. The code on main is the working code with the function ignored.
Thank you very much!

The issue is zwlr_layer_surface_v1 is an unknown type. You will have to replace it in the gir file with a gpointer then you generate the safe bindings and handle it however you think fits.

See gir-files/fix.sh at master · gtk-rs/gir-files · GitHub for example.

1 Like

Thank you, your post was enough for me to solve it. :slight_smile:

I didn’t replace the type in the gir file because I’d like to use the vanilla version so I decided to use a type alias instead. I created a file manual.rs in the sys crates src folder and added the following code:

use glib::gpointer;

pub type zwlr_layer_surface_v1 = gpointer;

This allowed the building of the crate to be successful.

For the safe wrapper, no corresponding function was automatically generated but the code for all the functions looks very similar so I created a manual.rs file for the normal crate as well, copied the code from another function and adapted it to the function I wanted to implement.
If anyone else is facing a similar issue, this is the commit that fixed it.

That is indeed a better option. I will modify gdk-wayland to do something similar

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