Skip to content

Commit dc393c3

Browse files
authored
Merge pull request #1027 from melix99/signal-group-connect-notify
glib: Add connect_notify* methods to SignalGroup
2 parents 5501aa4 + d71c109 commit dc393c3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

glib/src/gobject/signal_group.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,50 @@ impl SignalGroup {
4242
self.connect_closure(signal_name, after, RustClosure::new_local(callback));
4343
}
4444

45+
#[inline]
46+
pub fn connect_notify<F>(&self, name: Option<&str>, callback: F)
47+
where
48+
F: Fn(&crate::Object, &crate::ParamSpec) + Send + Sync + 'static,
49+
{
50+
let signal_name = if let Some(name) = name {
51+
format!("notify::{name}")
52+
} else {
53+
"notify".into()
54+
};
55+
56+
let closure = crate::RustClosure::new(move |values| {
57+
let obj = values[0].get().unwrap();
58+
let pspec = values[1].get().unwrap();
59+
callback(obj, pspec);
60+
61+
None
62+
});
63+
64+
self.connect_closure(&signal_name, false, closure);
65+
}
66+
67+
#[inline]
68+
pub fn connect_notify_local<F>(&self, name: Option<&str>, callback: F)
69+
where
70+
F: Fn(&crate::Object, &crate::ParamSpec) + 'static,
71+
{
72+
let signal_name = if let Some(name) = name {
73+
format!("notify::{name}")
74+
} else {
75+
"notify".into()
76+
};
77+
78+
let closure = crate::RustClosure::new_local(move |values| {
79+
let obj = values[0].get().unwrap();
80+
let pspec = values[1].get().unwrap();
81+
callback(obj, pspec);
82+
83+
None
84+
});
85+
86+
self.connect_closure(&signal_name, false, closure);
87+
}
88+
4589
unsafe fn connect_bind_unsafe<F: Fn(&Self, &Object)>(&self, f: F) -> SignalHandlerId {
4690
unsafe extern "C" fn bind_trampoline<F: Fn(&SignalGroup, &Object)>(
4791
this: *mut crate::gobject_ffi::GSignalGroup,

0 commit comments

Comments
 (0)