Skip to content

Commit 2a019f2

Browse files
glib: Re-introduce an event propagation specific type
As the semantics of ControlFlow don't match 1:1 with the event propagations See gtk-rs/gtk4-rs#1435
1 parent 3fa1b3b commit 2a019f2

File tree

2 files changed

+79
-1
lines changed

2 files changed

+79
-1
lines changed

glib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub use self::{
2929
},
3030
signal::{
3131
signal_handler_block, signal_handler_disconnect, signal_handler_unblock,
32-
signal_stop_emission_by_name, SignalHandlerId,
32+
signal_stop_emission_by_name, Propagation, SignalHandlerId,
3333
},
3434
types::{ILong, Pointer, StaticType, StaticTypeExt, Type, ULong},
3535
value::{BoxedValue, SendValue, ToSendValue, ToValue, Value},

glib/src/signal.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,81 @@ pub fn signal_has_handler_pending<T: ObjectType>(
146146
))
147147
}
148148
}
149+
150+
// rustdoc-stripper-ignore-next
151+
/// Whether to invoke the other event handlers.
152+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
153+
pub enum Propagation {
154+
// Stop other handlers from being invoked for the event.
155+
Stop,
156+
// Propagate the event further.
157+
Proceed,
158+
}
159+
160+
impl Propagation {
161+
// rustdoc-stripper-ignore-next
162+
/// Returns `true` if this is a `Stop` variant.
163+
pub fn is_stop(&self) -> bool {
164+
matches!(self, Self::Stop)
165+
}
166+
167+
// rustdoc-stripper-ignore-next
168+
/// Returns `true` if this is a `Proceed` variant.
169+
pub fn is_proceed(&self) -> bool {
170+
matches!(self, Self::Proceed)
171+
}
172+
}
173+
174+
impl From<bool> for Propagation {
175+
fn from(value: bool) -> Self {
176+
if value {
177+
Self::Stop
178+
} else {
179+
Self::Proceed
180+
}
181+
}
182+
}
183+
184+
impl From<Propagation> for bool {
185+
fn from(c: Propagation) -> Self {
186+
match c {
187+
Propagation::Stop => true,
188+
Propagation::Proceed => false,
189+
}
190+
}
191+
}
192+
193+
#[doc(hidden)]
194+
impl IntoGlib for Propagation {
195+
type GlibType = ffi::gboolean;
196+
197+
#[inline]
198+
fn into_glib(self) -> ffi::gboolean {
199+
bool::from(self).into_glib()
200+
}
201+
}
202+
203+
#[doc(hidden)]
204+
impl FromGlib<ffi::gboolean> for Propagation {
205+
#[inline]
206+
unsafe fn from_glib(value: ffi::gboolean) -> Self {
207+
bool::from_glib(value).into()
208+
}
209+
}
210+
211+
impl crate::ToValue for Propagation {
212+
fn to_value(&self) -> crate::Value {
213+
bool::from(*self).to_value()
214+
}
215+
216+
fn value_type(&self) -> crate::Type {
217+
<bool as crate::StaticType>::static_type()
218+
}
219+
}
220+
221+
impl From<Propagation> for crate::Value {
222+
#[inline]
223+
fn from(v: Propagation) -> Self {
224+
bool::from(v).into()
225+
}
226+
}

0 commit comments

Comments
 (0)