Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 137eedd

Browse files
committed
Add support for passing the SignalInvocationHint to signal accumulators
1 parent b0f0c15 commit 137eedd

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

src/subclass/interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub trait ObjectInterfaceExt: ObjectInterface {
196196
ret_type: Type,
197197
accumulator: F,
198198
) where
199-
F: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
199+
F: Fn(&super::SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
200200
{
201201
unsafe {
202202
super::types::add_signal_with_accumulator(
@@ -231,7 +231,7 @@ pub trait ObjectInterfaceExt: ObjectInterface {
231231
accumulator: G,
232232
) where
233233
F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,
234-
G: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
234+
G: Fn(&super::SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
235235
{
236236
unsafe {
237237
super::types::add_signal_with_class_handler_and_accumulator(

src/subclass/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,4 @@ pub mod prelude {
195195
pub use self::boxed::register_boxed_type;
196196
pub use self::interface::register_interface;
197197
pub use self::object::Property;
198-
pub use self::types::{register_type, InitializingType, TypeData};
198+
pub use self::types::{register_type, InitializingType, SignalInvocationHint, TypeData};

src/subclass/object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ pub unsafe trait ObjectClassSubclassExt: Sized + 'static {
233233
ret_type: Type,
234234
accumulator: F,
235235
) where
236-
F: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
236+
F: Fn(&super::SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
237237
{
238238
unsafe {
239239
super::types::add_signal_with_accumulator(
@@ -268,7 +268,7 @@ pub unsafe trait ObjectClassSubclassExt: Sized + 'static {
268268
accumulator: G,
269269
) where
270270
F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,
271-
G: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
271+
G: Fn(&super::SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
272272
{
273273
unsafe {
274274
super::types::add_signal_with_class_handler_and_accumulator(

src/subclass/types.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,19 @@ pub(crate) unsafe fn add_signal(
522522
);
523523
}
524524

525+
#[repr(C)]
526+
pub struct SignalInvocationHint(gobject_ffi::GSignalInvocationHint);
527+
528+
impl SignalInvocationHint {
529+
pub fn detail(&self) -> ::Quark {
530+
from_glib(self.0.detail)
531+
}
532+
533+
pub fn run_type(&self) -> SignalFlags {
534+
from_glib(self.0.run_type)
535+
}
536+
}
537+
525538
pub(crate) unsafe fn add_signal_with_accumulator<F>(
526539
type_: ffi::GType,
527540
name: &str,
@@ -530,22 +543,23 @@ pub(crate) unsafe fn add_signal_with_accumulator<F>(
530543
ret_type: Type,
531544
accumulator: F,
532545
) where
533-
F: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
546+
F: Fn(&SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
534547
{
535548
let arg_types = arg_types.iter().map(|t| t.to_glib()).collect::<Vec<_>>();
536549

537550
let accumulator: Box<F> = Box::new(accumulator);
538551

539552
unsafe extern "C" fn accumulator_trampoline<
540-
F: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
553+
F: Fn(&SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
541554
>(
542-
_ihint: *mut gobject_ffi::GSignalInvocationHint,
555+
ihint: *mut gobject_ffi::GSignalInvocationHint,
543556
return_accu: *mut gobject_ffi::GValue,
544557
handler_return: *const gobject_ffi::GValue,
545558
data: ffi::gpointer,
546559
) -> ffi::gboolean {
547560
let accumulator: &F = &*(data as *const &F);
548561
accumulator(
562+
&SignalInvocationHint(*ihint),
549563
&mut *(return_accu as *mut Value),
550564
&*(handler_return as *const Value),
551565
)
@@ -603,23 +617,24 @@ pub(crate) unsafe fn add_signal_with_class_handler_and_accumulator<F, G>(
603617
accumulator: G,
604618
) where
605619
F: Fn(&[Value]) -> Option<Value> + Send + Sync + 'static,
606-
G: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
620+
G: Fn(&SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
607621
{
608622
let arg_types = arg_types.iter().map(|t| t.to_glib()).collect::<Vec<_>>();
609623

610624
let class_handler = Closure::new(class_handler);
611625
let accumulator: Box<G> = Box::new(accumulator);
612626

613627
unsafe extern "C" fn accumulator_trampoline<
614-
G: Fn(&mut Value, &Value) -> bool + Send + Sync + 'static,
628+
G: Fn(&SignalInvocationHint, &mut Value, &Value) -> bool + Send + Sync + 'static,
615629
>(
616-
_ihint: *mut gobject_ffi::GSignalInvocationHint,
630+
ihint: *mut gobject_ffi::GSignalInvocationHint,
617631
return_accu: *mut gobject_ffi::GValue,
618632
handler_return: *const gobject_ffi::GValue,
619633
data: ffi::gpointer,
620634
) -> ffi::gboolean {
621635
let accumulator: &G = &*(data as *const &G);
622636
accumulator(
637+
&SignalInvocationHint(*ihint),
623638
&mut *(return_accu as *mut Value),
624639
&*(handler_return as *const Value),
625640
)

0 commit comments

Comments
 (0)