gtk4/auto/
event_controller.rs1use crate::{ffi, PropagationLimit, PropagationPhase, Widget};
6use glib::{
7 prelude::*,
8 signal::{connect_raw, SignalHandlerId},
9 translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14 #[doc(alias = "GtkEventController")]
59 pub struct EventController(Object<ffi::GtkEventController, ffi::GtkEventControllerClass>);
60
61 match fn {
62 type_ => || ffi::gtk_event_controller_get_type(),
63 }
64}
65
66impl EventController {
67 pub const NONE: Option<&'static EventController> = None;
68}
69
70mod sealed {
71 pub trait Sealed {}
72 impl<T: super::IsA<super::EventController>> Sealed for T {}
73}
74
75pub trait EventControllerExt: IsA<EventController> + sealed::Sealed + 'static {
81 #[doc(alias = "gtk_event_controller_get_current_event")]
90 #[doc(alias = "get_current_event")]
91 fn current_event(&self) -> Option<gdk::Event> {
92 unsafe {
93 from_glib_none(ffi::gtk_event_controller_get_current_event(
94 self.as_ref().to_glib_none().0,
95 ))
96 }
97 }
98
99 #[doc(alias = "gtk_event_controller_get_current_event_device")]
109 #[doc(alias = "get_current_event_device")]
110 fn current_event_device(&self) -> Option<gdk::Device> {
111 unsafe {
112 from_glib_none(ffi::gtk_event_controller_get_current_event_device(
113 self.as_ref().to_glib_none().0,
114 ))
115 }
116 }
117
118 #[doc(alias = "gtk_event_controller_get_current_event_state")]
127 #[doc(alias = "get_current_event_state")]
128 fn current_event_state(&self) -> gdk::ModifierType {
129 unsafe {
130 from_glib(ffi::gtk_event_controller_get_current_event_state(
131 self.as_ref().to_glib_none().0,
132 ))
133 }
134 }
135
136 #[doc(alias = "gtk_event_controller_get_current_event_time")]
145 #[doc(alias = "get_current_event_time")]
146 fn current_event_time(&self) -> u32 {
147 unsafe { ffi::gtk_event_controller_get_current_event_time(self.as_ref().to_glib_none().0) }
148 }
149
150 #[doc(alias = "gtk_event_controller_get_name")]
156 #[doc(alias = "get_name")]
157 fn name(&self) -> Option<glib::GString> {
158 unsafe {
159 from_glib_none(ffi::gtk_event_controller_get_name(
160 self.as_ref().to_glib_none().0,
161 ))
162 }
163 }
164
165 #[doc(alias = "gtk_event_controller_get_propagation_limit")]
171 #[doc(alias = "get_propagation_limit")]
172 #[doc(alias = "propagation-limit")]
173 fn propagation_limit(&self) -> PropagationLimit {
174 unsafe {
175 from_glib(ffi::gtk_event_controller_get_propagation_limit(
176 self.as_ref().to_glib_none().0,
177 ))
178 }
179 }
180
181 #[doc(alias = "gtk_event_controller_get_propagation_phase")]
187 #[doc(alias = "get_propagation_phase")]
188 #[doc(alias = "propagation-phase")]
189 fn propagation_phase(&self) -> PropagationPhase {
190 unsafe {
191 from_glib(ffi::gtk_event_controller_get_propagation_phase(
192 self.as_ref().to_glib_none().0,
193 ))
194 }
195 }
196
197 #[doc(alias = "gtk_event_controller_get_widget")]
203 #[doc(alias = "get_widget")]
204 fn widget(&self) -> Option<Widget> {
205 unsafe {
206 from_glib_none(ffi::gtk_event_controller_get_widget(
207 self.as_ref().to_glib_none().0,
208 ))
209 }
210 }
211
212 #[doc(alias = "gtk_event_controller_reset")]
214 fn reset(&self) {
215 unsafe {
216 ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
217 }
218 }
219
220 #[doc(alias = "gtk_event_controller_set_name")]
224 #[doc(alias = "name")]
225 fn set_name(&self, name: Option<&str>) {
226 unsafe {
227 ffi::gtk_event_controller_set_name(
228 self.as_ref().to_glib_none().0,
229 name.to_glib_none().0,
230 );
231 }
232 }
233
234 #[doc(alias = "gtk_event_controller_set_propagation_limit")]
242 #[doc(alias = "propagation-limit")]
243 fn set_propagation_limit(&self, limit: PropagationLimit) {
244 unsafe {
245 ffi::gtk_event_controller_set_propagation_limit(
246 self.as_ref().to_glib_none().0,
247 limit.into_glib(),
248 );
249 }
250 }
251
252 #[doc(alias = "gtk_event_controller_set_propagation_phase")]
259 #[doc(alias = "propagation-phase")]
260 fn set_propagation_phase(&self, phase: PropagationPhase) {
261 unsafe {
262 ffi::gtk_event_controller_set_propagation_phase(
263 self.as_ref().to_glib_none().0,
264 phase.into_glib(),
265 );
266 }
267 }
268
269 #[doc(alias = "name")]
270 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
271 unsafe extern "C" fn notify_name_trampoline<
272 P: IsA<EventController>,
273 F: Fn(&P) + 'static,
274 >(
275 this: *mut ffi::GtkEventController,
276 _param_spec: glib::ffi::gpointer,
277 f: glib::ffi::gpointer,
278 ) {
279 let f: &F = &*(f as *const F);
280 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
281 }
282 unsafe {
283 let f: Box_<F> = Box_::new(f);
284 connect_raw(
285 self.as_ptr() as *mut _,
286 b"notify::name\0".as_ptr() as *const _,
287 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
288 notify_name_trampoline::<Self, F> as *const (),
289 )),
290 Box_::into_raw(f),
291 )
292 }
293 }
294
295 #[doc(alias = "propagation-limit")]
296 fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
297 unsafe extern "C" fn notify_propagation_limit_trampoline<
298 P: IsA<EventController>,
299 F: Fn(&P) + 'static,
300 >(
301 this: *mut ffi::GtkEventController,
302 _param_spec: glib::ffi::gpointer,
303 f: glib::ffi::gpointer,
304 ) {
305 let f: &F = &*(f as *const F);
306 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
307 }
308 unsafe {
309 let f: Box_<F> = Box_::new(f);
310 connect_raw(
311 self.as_ptr() as *mut _,
312 b"notify::propagation-limit\0".as_ptr() as *const _,
313 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
314 notify_propagation_limit_trampoline::<Self, F> as *const (),
315 )),
316 Box_::into_raw(f),
317 )
318 }
319 }
320
321 #[doc(alias = "propagation-phase")]
322 fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
323 unsafe extern "C" fn notify_propagation_phase_trampoline<
324 P: IsA<EventController>,
325 F: Fn(&P) + 'static,
326 >(
327 this: *mut ffi::GtkEventController,
328 _param_spec: glib::ffi::gpointer,
329 f: glib::ffi::gpointer,
330 ) {
331 let f: &F = &*(f as *const F);
332 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
333 }
334 unsafe {
335 let f: Box_<F> = Box_::new(f);
336 connect_raw(
337 self.as_ptr() as *mut _,
338 b"notify::propagation-phase\0".as_ptr() as *const _,
339 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
340 notify_propagation_phase_trampoline::<Self, F> as *const (),
341 )),
342 Box_::into_raw(f),
343 )
344 }
345 }
346
347 #[doc(alias = "widget")]
348 fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
349 unsafe extern "C" fn notify_widget_trampoline<
350 P: IsA<EventController>,
351 F: Fn(&P) + 'static,
352 >(
353 this: *mut ffi::GtkEventController,
354 _param_spec: glib::ffi::gpointer,
355 f: glib::ffi::gpointer,
356 ) {
357 let f: &F = &*(f as *const F);
358 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
359 }
360 unsafe {
361 let f: Box_<F> = Box_::new(f);
362 connect_raw(
363 self.as_ptr() as *mut _,
364 b"notify::widget\0".as_ptr() as *const _,
365 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
366 notify_widget_trampoline::<Self, F> as *const (),
367 )),
368 Box_::into_raw(f),
369 )
370 }
371 }
372}
373
374impl<O: IsA<EventController>> EventControllerExt for O {}