gtk4/auto/
event_controller.rs1use crate::{PropagationLimit, PropagationPhase, Widget, ffi};
6use glib::{
7 prelude::*,
8 signal::{SignalHandlerId, connect_raw},
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 #[doc(alias = "name")]
265 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
266 unsafe extern "C" fn notify_name_trampoline<
267 P: IsA<EventController>,
268 F: Fn(&P) + 'static,
269 >(
270 this: *mut ffi::GtkEventController,
271 _param_spec: glib::ffi::gpointer,
272 f: glib::ffi::gpointer,
273 ) {
274 unsafe {
275 let f: &F = &*(f as *const F);
276 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
277 }
278 }
279 unsafe {
280 let f: Box_<F> = Box_::new(f);
281 connect_raw(
282 self.as_ptr() as *mut _,
283 c"notify::name".as_ptr() as *const _,
284 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
285 notify_name_trampoline::<Self, F> as *const (),
286 )),
287 Box_::into_raw(f),
288 )
289 }
290 }
291
292 #[doc(alias = "propagation-limit")]
293 fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
294 unsafe extern "C" fn notify_propagation_limit_trampoline<
295 P: IsA<EventController>,
296 F: Fn(&P) + 'static,
297 >(
298 this: *mut ffi::GtkEventController,
299 _param_spec: glib::ffi::gpointer,
300 f: glib::ffi::gpointer,
301 ) {
302 unsafe {
303 let f: &F = &*(f as *const F);
304 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
305 }
306 }
307 unsafe {
308 let f: Box_<F> = Box_::new(f);
309 connect_raw(
310 self.as_ptr() as *mut _,
311 c"notify::propagation-limit".as_ptr() as *const _,
312 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
313 notify_propagation_limit_trampoline::<Self, F> as *const (),
314 )),
315 Box_::into_raw(f),
316 )
317 }
318 }
319
320 #[doc(alias = "propagation-phase")]
321 fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
322 unsafe extern "C" fn notify_propagation_phase_trampoline<
323 P: IsA<EventController>,
324 F: Fn(&P) + 'static,
325 >(
326 this: *mut ffi::GtkEventController,
327 _param_spec: glib::ffi::gpointer,
328 f: glib::ffi::gpointer,
329 ) {
330 unsafe {
331 let f: &F = &*(f as *const F);
332 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
333 }
334 }
335 unsafe {
336 let f: Box_<F> = Box_::new(f);
337 connect_raw(
338 self.as_ptr() as *mut _,
339 c"notify::propagation-phase".as_ptr() as *const _,
340 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
341 notify_propagation_phase_trampoline::<Self, F> as *const (),
342 )),
343 Box_::into_raw(f),
344 )
345 }
346 }
347
348 #[doc(alias = "widget")]
349 fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
350 unsafe extern "C" fn notify_widget_trampoline<
351 P: IsA<EventController>,
352 F: Fn(&P) + 'static,
353 >(
354 this: *mut ffi::GtkEventController,
355 _param_spec: glib::ffi::gpointer,
356 f: glib::ffi::gpointer,
357 ) {
358 unsafe {
359 let f: &F = &*(f as *const F);
360 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
361 }
362 }
363 unsafe {
364 let f: Box_<F> = Box_::new(f);
365 connect_raw(
366 self.as_ptr() as *mut _,
367 c"notify::widget".as_ptr() as *const _,
368 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
369 notify_widget_trampoline::<Self, F> as *const (),
370 )),
371 Box_::into_raw(f),
372 )
373 }
374 }
375}
376
377impl<O: IsA<EventController>> EventControllerExt for O {}