-
-
Notifications
You must be signed in to change notification settings - Fork 60
Initial GMainLoop/GMainContext bindings #194
Conversation
| /// | ||
| /// `func` will be called repeatedly until it returns `Continue(false)`. | ||
| pub fn idle_source_new<'a, N: Into<Option<&'a str>>, F>(name: N, priority: Priority, func: F) -> Source | ||
| where F: FnMut() -> Continue + Send + 'static { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question here is mostly whether we want single functions for creating Sources, or create something with a builder pattern here. Single functions seems more simple to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way seems fine to me so do whatever seems better to you.
|
For MainContext::invoke() this could in theory be this, but I'm not sure how to handle impl MainContext {
pub fn invoke<F>(&self, func: F)
where F: FnOnce() + Send + 'static {
unsafe {
glib_ffi::g_main_context_invoke_full(self.to_glib_none().0, glib_ffi::G_PRIORITY_DEFAULT_IDLE, Some(trampoline),
into_raw(func), Some(destroy_closure))
}
}
pub fn invoke_with_priority<F>(&self, priority: Priority, func: F)
where F: FnOnce() + Send + 'static {
unsafe {
glib_ffi::g_main_context_invoke_full(self.to_glib_none().0, priority.to_glib(), Some(trampoline),
into_raw(func), Some(destroy_closure))
}
}
}
unsafe extern "C" fn trampoline(func: gpointer) -> gboolean {
let _guard = CallbackGuard::new();
let func: &RefCell<Option<Box<FnOnce() + Send + 'static>>> = transmute(func);
if let Some(func) = func.borrow_mut().take() {
func();
}
glib_ffi::G_SOURCE_REMOVE
}
unsafe extern "C" fn destroy_closure(ptr: gpointer) {
let _guard = CallbackGuard::new();
Box::<RefCell<Option<Box<FnOnce() + Send + 'static>>>>::from_raw(ptr as *mut _);
}
fn into_raw<F: FnOnce() + Send + 'static>(func: F) -> gpointer {
let func: Box<RefCell<Option<Box<FnOnce() + Send + 'static>>>> =
Box::new(RefCell::new(Some(Box::new(func))));
Box::into_raw(func) as gpointer
} |
|
Problem is that we need something like |
|
Good for review then IMHO, @GuillaumeGomez @EPashkin :) No further additions planned to this pull request |
| glib_ffi::g_main_context_invoke_full(self.to_glib_none().0, glib_ffi::G_PRIORITY_DEFAULT_IDLE, Some(trampoline), | ||
| into_raw(func), Some(destroy_closure)) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We always pass to FFI boxed closure. And destroy_closure working with boxed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Missed that you added your version destory_closure
| pub mod prelude; | ||
| pub mod signal; | ||
| mod source; | ||
| pub mod source; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of source reexported, while part is not.
Not better do pub use source::*; ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your call :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No preference for me so do whatever you want.
|
Code looks good to me, but PR missing update Gir submodule and regen to correct version. |
| // unsafe { TODO: call ffi::g_idle_remove_by_data() } | ||
| //} | ||
|
|
||
| //pub fn idle_source_new() -> /*Ignored*/Option<Source> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we bound Source, why is this ignored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nevermind...
|
Looks good to me as well. Fix @EPashkin's issues and let's merge! |
|
@EPashkin What do you want to have fixed? Should source::* be re-exported at the crate level? |
|
@sdroege Yes + gir submodule update + regen |
|
OK, will do in an hour or two |
|
Done :) |
|
Ah I guess that's the reason for not re-exporting source::*. source::Id should be re-exported as SourceId. What do you suggest? Rename Id to SourceId? |
|
Let's try that... |
…e of SourceId newtype
|
👍 |
|
The "changes PR" is getting really huge. Next release will be certainly a worldwide ovation. People will throw money at us. Gods will sing our names and we'll be taken as examples by future generations. Can't wait to be at the release. 😭 |
|
I'd like to get some more things into the next release though, most importantly removing generic impls for the various conversions traits (and move them into the macros) and implement them for enums/flags/boxed/etc types (which is not possible right now. so we can have those in GValues, for example) |
|
I don't intend to make the release before at least another month. I still need to work on gtk-rs/release anyway. (my comment was super ironic: it'll be hellish for me to make this release unless I end my automatic releaser) |
|
CI passed |
|
🎉 |
|
Thanks a lot! |
#168