gtk4/auto/
event_controller.rs
1use 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
70pub trait EventControllerExt: IsA<EventController> + 'static {
76 #[doc(alias = "gtk_event_controller_get_current_event")]
85 #[doc(alias = "get_current_event")]
86 fn current_event(&self) -> Option<gdk::Event> {
87 unsafe {
88 from_glib_none(ffi::gtk_event_controller_get_current_event(
89 self.as_ref().to_glib_none().0,
90 ))
91 }
92 }
93
94 #[doc(alias = "gtk_event_controller_get_current_event_device")]
104 #[doc(alias = "get_current_event_device")]
105 fn current_event_device(&self) -> Option<gdk::Device> {
106 unsafe {
107 from_glib_none(ffi::gtk_event_controller_get_current_event_device(
108 self.as_ref().to_glib_none().0,
109 ))
110 }
111 }
112
113 #[doc(alias = "gtk_event_controller_get_current_event_state")]
122 #[doc(alias = "get_current_event_state")]
123 fn current_event_state(&self) -> gdk::ModifierType {
124 unsafe {
125 from_glib(ffi::gtk_event_controller_get_current_event_state(
126 self.as_ref().to_glib_none().0,
127 ))
128 }
129 }
130
131 #[doc(alias = "gtk_event_controller_get_current_event_time")]
140 #[doc(alias = "get_current_event_time")]
141 fn current_event_time(&self) -> u32 {
142 unsafe { ffi::gtk_event_controller_get_current_event_time(self.as_ref().to_glib_none().0) }
143 }
144
145 #[doc(alias = "gtk_event_controller_get_name")]
151 #[doc(alias = "get_name")]
152 fn name(&self) -> Option<glib::GString> {
153 unsafe {
154 from_glib_none(ffi::gtk_event_controller_get_name(
155 self.as_ref().to_glib_none().0,
156 ))
157 }
158 }
159
160 #[doc(alias = "gtk_event_controller_get_propagation_limit")]
166 #[doc(alias = "get_propagation_limit")]
167 #[doc(alias = "propagation-limit")]
168 fn propagation_limit(&self) -> PropagationLimit {
169 unsafe {
170 from_glib(ffi::gtk_event_controller_get_propagation_limit(
171 self.as_ref().to_glib_none().0,
172 ))
173 }
174 }
175
176 #[doc(alias = "gtk_event_controller_get_propagation_phase")]
182 #[doc(alias = "get_propagation_phase")]
183 #[doc(alias = "propagation-phase")]
184 fn propagation_phase(&self) -> PropagationPhase {
185 unsafe {
186 from_glib(ffi::gtk_event_controller_get_propagation_phase(
187 self.as_ref().to_glib_none().0,
188 ))
189 }
190 }
191
192 #[doc(alias = "gtk_event_controller_get_widget")]
198 #[doc(alias = "get_widget")]
199 fn widget(&self) -> Option<Widget> {
200 unsafe {
201 from_glib_none(ffi::gtk_event_controller_get_widget(
202 self.as_ref().to_glib_none().0,
203 ))
204 }
205 }
206
207 #[doc(alias = "gtk_event_controller_reset")]
209 fn reset(&self) {
210 unsafe {
211 ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
212 }
213 }
214
215 #[doc(alias = "gtk_event_controller_set_name")]
219 #[doc(alias = "name")]
220 fn set_name(&self, name: Option<&str>) {
221 unsafe {
222 ffi::gtk_event_controller_set_name(
223 self.as_ref().to_glib_none().0,
224 name.to_glib_none().0,
225 );
226 }
227 }
228
229 #[doc(alias = "gtk_event_controller_set_propagation_limit")]
237 #[doc(alias = "propagation-limit")]
238 fn set_propagation_limit(&self, limit: PropagationLimit) {
239 unsafe {
240 ffi::gtk_event_controller_set_propagation_limit(
241 self.as_ref().to_glib_none().0,
242 limit.into_glib(),
243 );
244 }
245 }
246
247 #[doc(alias = "gtk_event_controller_set_propagation_phase")]
254 #[doc(alias = "propagation-phase")]
255 fn set_propagation_phase(&self, phase: PropagationPhase) {
256 unsafe {
257 ffi::gtk_event_controller_set_propagation_phase(
258 self.as_ref().to_glib_none().0,
259 phase.into_glib(),
260 );
261 }
262 }
263
264 #[cfg(feature = "v4_8")]
268 #[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
269 #[doc(alias = "gtk_event_controller_set_static_name")]
270 fn set_static_name(&self, name: Option<&str>) {
271 unsafe {
272 ffi::gtk_event_controller_set_static_name(
273 self.as_ref().to_glib_none().0,
274 name.to_glib_none().0,
275 );
276 }
277 }
278
279 #[doc(alias = "name")]
280 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
281 unsafe extern "C" fn notify_name_trampoline<
282 P: IsA<EventController>,
283 F: Fn(&P) + 'static,
284 >(
285 this: *mut ffi::GtkEventController,
286 _param_spec: glib::ffi::gpointer,
287 f: glib::ffi::gpointer,
288 ) {
289 let f: &F = &*(f as *const F);
290 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
291 }
292 unsafe {
293 let f: Box_<F> = Box_::new(f);
294 connect_raw(
295 self.as_ptr() as *mut _,
296 c"notify::name".as_ptr() as *const _,
297 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
298 notify_name_trampoline::<Self, F> as *const (),
299 )),
300 Box_::into_raw(f),
301 )
302 }
303 }
304
305 #[doc(alias = "propagation-limit")]
306 fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
307 unsafe extern "C" fn notify_propagation_limit_trampoline<
308 P: IsA<EventController>,
309 F: Fn(&P) + 'static,
310 >(
311 this: *mut ffi::GtkEventController,
312 _param_spec: glib::ffi::gpointer,
313 f: glib::ffi::gpointer,
314 ) {
315 let f: &F = &*(f as *const F);
316 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
317 }
318 unsafe {
319 let f: Box_<F> = Box_::new(f);
320 connect_raw(
321 self.as_ptr() as *mut _,
322 c"notify::propagation-limit".as_ptr() as *const _,
323 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324 notify_propagation_limit_trampoline::<Self, F> as *const (),
325 )),
326 Box_::into_raw(f),
327 )
328 }
329 }
330
331 #[doc(alias = "propagation-phase")]
332 fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
333 unsafe extern "C" fn notify_propagation_phase_trampoline<
334 P: IsA<EventController>,
335 F: Fn(&P) + 'static,
336 >(
337 this: *mut ffi::GtkEventController,
338 _param_spec: glib::ffi::gpointer,
339 f: glib::ffi::gpointer,
340 ) {
341 let f: &F = &*(f as *const F);
342 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
343 }
344 unsafe {
345 let f: Box_<F> = Box_::new(f);
346 connect_raw(
347 self.as_ptr() as *mut _,
348 c"notify::propagation-phase".as_ptr() as *const _,
349 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
350 notify_propagation_phase_trampoline::<Self, F> as *const (),
351 )),
352 Box_::into_raw(f),
353 )
354 }
355 }
356
357 #[doc(alias = "widget")]
358 fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
359 unsafe extern "C" fn notify_widget_trampoline<
360 P: IsA<EventController>,
361 F: Fn(&P) + 'static,
362 >(
363 this: *mut ffi::GtkEventController,
364 _param_spec: glib::ffi::gpointer,
365 f: glib::ffi::gpointer,
366 ) {
367 let f: &F = &*(f as *const F);
368 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
369 }
370 unsafe {
371 let f: Box_<F> = Box_::new(f);
372 connect_raw(
373 self.as_ptr() as *mut _,
374 c"notify::widget".as_ptr() as *const _,
375 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
376 notify_widget_trampoline::<Self, F> as *const (),
377 )),
378 Box_::into_raw(f),
379 )
380 }
381 }
382}
383
384impl<O: IsA<EventController>> EventControllerExt for O {}