This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 31
Generate “open” signal for g_application #31
Comments
What is the |
i32 is n_files - count of files in [File] array |
Yes, that's my point. |
Ok, but how to implement this properly? Gir generator does not support such kind of thing? Does it need to implement this manually? Or maybe some converter already exists? |
I wonder. I think we already did it but not sure if it was in gir or manually... cc @EPashkin |
Yes, this need be manual. Something like this: impl<O: IsA<Application> + IsA<glib::object::Object>> ApplicationExtManual for O {
fn connect_open<F: Fn(&Self, &[File], &str) + 'static>(&self, f: F) -> u64 {
unsafe {
let f: Box_<Box_<Fn(&Self, &[File], &str) + 'static>> = Box_::new(Box_::new(f));
connect(self.to_glib_none().0, "open",
transmute(open_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
}
}
}
unsafe extern "C" fn open_trampoline<P>(this: *mut ffi::GApplication, files: *const *mut ffi::GFile, n_files: libc::c_int, hint: *mut libc::c_char, f: glib_ffi::gpointer)
where P: IsA<Application> {
callback_guard!();
let f: &Box_<Fn(&P, &[File], &str) + 'static> = transmute(f);
let files: Vec<File> = FromGlibPtrContainer::from_glib_none_num(files, n_files as usize);
f(&Application::from_glib_none(this).downcast_unchecked(), &files[..], &String::from_glib_none(hint))
} |
Thanks, i try 😄 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I try to generate https://developer.gnome.org/gio/stable/GApplication.html#GApplication-open
When add Gio.File, Gir generate next closure:
But looks like this is wrong, because as i understand
&[File]
array can't be generated properly without n_files field, so looks like it is need to write this code manually? To make proper conversion between array of pointers to rust slice? Or any other way exists?Thanks
The text was updated successfully, but these errors were encountered: