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

glib: Add connect_notify* methods to SignalGroup #1027

Merged
merged 1 commit into from Feb 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 44 additions & 0 deletions glib/src/gobject/signal_group.rs
Expand Up @@ -42,6 +42,50 @@ impl SignalGroup {
self.connect_closure(signal_name, after, RustClosure::new_local(callback));
}

#[inline]
pub fn connect_notify<F>(&self, name: Option<&str>, callback: F)
sdroege marked this conversation as resolved.
Show resolved Hide resolved
where
F: Fn(&crate::Object, &crate::ParamSpec) + Send + Sync + 'static,
{
let signal_name = if let Some(name) = name {
format!("notify::{name}")
} else {
"notify".into()
};

let closure = crate::RustClosure::new(move |values| {
let obj = values[0].get().unwrap();
sdroege marked this conversation as resolved.
Show resolved Hide resolved
let pspec = values[1].get().unwrap();
callback(obj, pspec);

None
});

self.connect_closure(&signal_name, false, closure);
}

#[inline]
pub fn connect_notify_local<F>(&self, name: Option<&str>, callback: F)
where
F: Fn(&crate::Object, &crate::ParamSpec) + 'static,
{
let signal_name = if let Some(name) = name {
format!("notify::{name}")
} else {
"notify".into()
};

let closure = crate::RustClosure::new_local(move |values| {
let obj = values[0].get().unwrap();
let pspec = values[1].get().unwrap();
callback(obj, pspec);

None
});

self.connect_closure(&signal_name, false, closure);
}

unsafe fn connect_bind_unsafe<F: Fn(&Self, &Object)>(&self, f: F) -> SignalHandlerId {
unsafe extern "C" fn bind_trampoline<F: Fn(&SignalGroup, &Object)>(
this: *mut crate::gobject_ffi::GSignalGroup,
Expand Down