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