Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements/fixes required for the gir tutorial #167

Open
GuillaumeGomez opened this issue Aug 23, 2020 · 1 comment
Open

Improvements/fixes required for the gir tutorial #167

GuillaumeGomez opened this issue Aug 23, 2020 · 1 comment

Comments

@GuillaumeGomez
Copy link
Member

Copy/paste from here:

Hi,
I am trying to generate bindings for gtk-layer-shell with a provided gir file and followed the tutorial 1 but I have a few questions. The code is available at https://github.com/grelltrier/gtk-layer-shell-gir 1

1: I got a bunch of errors when generating the Rust wrapper because of missing macro definitions. When I searched on Github, it seemed as if people just implement those macros themselves and they all looked the same so I just copied them and added the following to my lib.rs :

/// Asserts that this is the main thread and either `gdk::init` or `gtk::init` has been called.
macro_rules! assert_initialized_main_thread {
    () => {
        if !::gtk::is_initialized_main_thread() {
            if ::gtk::is_initialized() {
                panic!("GTK may only be used from the main thread.");
            } else {
                panic!("GTK has not been initialized. Call `gtk::init` first.");
            }
        }
    };
}

/// No-op.
macro_rules! skip_assert_initialized {
    () => {};
}

Is that a good idea or should I do something else?

2: When I try building the generated Rust wrapper I get two errors complaining about unresolved imports for each of the generated enums because the enums are defined in enums.rs but functions.rs tries importing them via

use Edge;
use Layer;

This fails but if I replace it with use super::enums::*; I no longer get any errors. Since I can read, I know you are not supposed to edit the generated files :stuck_out_tongue:
How can I generate correct code?

3: Additionally to enums.rs and function.rs a window.rs was generated. I don’t understand this file at all tbh. I don’t get why it is there/needed since I thought I told gir not to worry about Gtk.Window and I do not understand its code. Aside from that there is also a lot of code commented out. The tutorial said to add the types that follow the /Ignored/ to the Gir.toml under manual= []
I tried adding them but nothing changes. In case you’ll have a look at my repository, right now those types are commented out since they did not change anything anyways.

4: Since one of the needed types is Gdk.Monitor I added gdk to the dependencies in the cargo.toml and added features= [“v3_22”]. Then I added extern crate gdk;
Is that the proper way to do this?

All in all I am very impressed by gir and the generated code. Looks really nice and its a lot easier than writing it myself.
Thank you for taking the time to help 
@sdroege
Copy link
Member

sdroege commented Aug 27, 2020

There are PRs for all these now if I'm not missing anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants