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")]
15 pub struct EventController(Object<ffi::GtkEventController, ffi::GtkEventControllerClass>);
16
17 match fn {
18 type_ => || ffi::gtk_event_controller_get_type(),
19 }
20}
21
22impl EventController {
23 pub const NONE: Option<&'static EventController> = None;
24}
25
26pub trait EventControllerExt: IsA<EventController> + 'static {
27 #[doc(alias = "gtk_event_controller_get_current_event")]
28 #[doc(alias = "get_current_event")]
29 fn current_event(&self) -> Option<gdk::Event> {
30 unsafe {
31 from_glib_none(ffi::gtk_event_controller_get_current_event(
32 self.as_ref().to_glib_none().0,
33 ))
34 }
35 }
36
37 #[doc(alias = "gtk_event_controller_get_current_event_device")]
38 #[doc(alias = "get_current_event_device")]
39 fn current_event_device(&self) -> Option<gdk::Device> {
40 unsafe {
41 from_glib_none(ffi::gtk_event_controller_get_current_event_device(
42 self.as_ref().to_glib_none().0,
43 ))
44 }
45 }
46
47 #[doc(alias = "gtk_event_controller_get_current_event_state")]
48 #[doc(alias = "get_current_event_state")]
49 fn current_event_state(&self) -> gdk::ModifierType {
50 unsafe {
51 from_glib(ffi::gtk_event_controller_get_current_event_state(
52 self.as_ref().to_glib_none().0,
53 ))
54 }
55 }
56
57 #[doc(alias = "gtk_event_controller_get_current_event_time")]
58 #[doc(alias = "get_current_event_time")]
59 fn current_event_time(&self) -> u32 {
60 unsafe { ffi::gtk_event_controller_get_current_event_time(self.as_ref().to_glib_none().0) }
61 }
62
63 #[doc(alias = "gtk_event_controller_get_name")]
64 #[doc(alias = "get_name")]
65 fn name(&self) -> Option<glib::GString> {
66 unsafe {
67 from_glib_none(ffi::gtk_event_controller_get_name(
68 self.as_ref().to_glib_none().0,
69 ))
70 }
71 }
72
73 #[doc(alias = "gtk_event_controller_get_propagation_limit")]
74 #[doc(alias = "get_propagation_limit")]
75 #[doc(alias = "propagation-limit")]
76 fn propagation_limit(&self) -> PropagationLimit {
77 unsafe {
78 from_glib(ffi::gtk_event_controller_get_propagation_limit(
79 self.as_ref().to_glib_none().0,
80 ))
81 }
82 }
83
84 #[doc(alias = "gtk_event_controller_get_propagation_phase")]
85 #[doc(alias = "get_propagation_phase")]
86 #[doc(alias = "propagation-phase")]
87 fn propagation_phase(&self) -> PropagationPhase {
88 unsafe {
89 from_glib(ffi::gtk_event_controller_get_propagation_phase(
90 self.as_ref().to_glib_none().0,
91 ))
92 }
93 }
94
95 #[doc(alias = "gtk_event_controller_get_widget")]
96 #[doc(alias = "get_widget")]
97 fn widget(&self) -> Option<Widget> {
98 unsafe {
99 from_glib_none(ffi::gtk_event_controller_get_widget(
100 self.as_ref().to_glib_none().0,
101 ))
102 }
103 }
104
105 #[doc(alias = "gtk_event_controller_reset")]
106 fn reset(&self) {
107 unsafe {
108 ffi::gtk_event_controller_reset(self.as_ref().to_glib_none().0);
109 }
110 }
111
112 #[doc(alias = "gtk_event_controller_set_name")]
113 #[doc(alias = "name")]
114 fn set_name(&self, name: Option<&str>) {
115 unsafe {
116 ffi::gtk_event_controller_set_name(
117 self.as_ref().to_glib_none().0,
118 name.to_glib_none().0,
119 );
120 }
121 }
122
123 #[doc(alias = "gtk_event_controller_set_propagation_limit")]
124 #[doc(alias = "propagation-limit")]
125 fn set_propagation_limit(&self, limit: PropagationLimit) {
126 unsafe {
127 ffi::gtk_event_controller_set_propagation_limit(
128 self.as_ref().to_glib_none().0,
129 limit.into_glib(),
130 );
131 }
132 }
133
134 #[doc(alias = "gtk_event_controller_set_propagation_phase")]
135 #[doc(alias = "propagation-phase")]
136 fn set_propagation_phase(&self, phase: PropagationPhase) {
137 unsafe {
138 ffi::gtk_event_controller_set_propagation_phase(
139 self.as_ref().to_glib_none().0,
140 phase.into_glib(),
141 );
142 }
143 }
144
145 #[doc(alias = "name")]
146 fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
147 unsafe extern "C" fn notify_name_trampoline<
148 P: IsA<EventController>,
149 F: Fn(&P) + 'static,
150 >(
151 this: *mut ffi::GtkEventController,
152 _param_spec: glib::ffi::gpointer,
153 f: glib::ffi::gpointer,
154 ) {
155 let f: &F = &*(f as *const F);
156 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
157 }
158 unsafe {
159 let f: Box_<F> = Box_::new(f);
160 connect_raw(
161 self.as_ptr() as *mut _,
162 c"notify::name".as_ptr() as *const _,
163 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
164 notify_name_trampoline::<Self, F> as *const (),
165 )),
166 Box_::into_raw(f),
167 )
168 }
169 }
170
171 #[doc(alias = "propagation-limit")]
172 fn connect_propagation_limit_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
173 unsafe extern "C" fn notify_propagation_limit_trampoline<
174 P: IsA<EventController>,
175 F: Fn(&P) + 'static,
176 >(
177 this: *mut ffi::GtkEventController,
178 _param_spec: glib::ffi::gpointer,
179 f: glib::ffi::gpointer,
180 ) {
181 let f: &F = &*(f as *const F);
182 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
183 }
184 unsafe {
185 let f: Box_<F> = Box_::new(f);
186 connect_raw(
187 self.as_ptr() as *mut _,
188 c"notify::propagation-limit".as_ptr() as *const _,
189 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
190 notify_propagation_limit_trampoline::<Self, F> as *const (),
191 )),
192 Box_::into_raw(f),
193 )
194 }
195 }
196
197 #[doc(alias = "propagation-phase")]
198 fn connect_propagation_phase_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
199 unsafe extern "C" fn notify_propagation_phase_trampoline<
200 P: IsA<EventController>,
201 F: Fn(&P) + 'static,
202 >(
203 this: *mut ffi::GtkEventController,
204 _param_spec: glib::ffi::gpointer,
205 f: glib::ffi::gpointer,
206 ) {
207 let f: &F = &*(f as *const F);
208 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
209 }
210 unsafe {
211 let f: Box_<F> = Box_::new(f);
212 connect_raw(
213 self.as_ptr() as *mut _,
214 c"notify::propagation-phase".as_ptr() as *const _,
215 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
216 notify_propagation_phase_trampoline::<Self, F> as *const (),
217 )),
218 Box_::into_raw(f),
219 )
220 }
221 }
222
223 #[doc(alias = "widget")]
224 fn connect_widget_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225 unsafe extern "C" fn notify_widget_trampoline<
226 P: IsA<EventController>,
227 F: Fn(&P) + 'static,
228 >(
229 this: *mut ffi::GtkEventController,
230 _param_spec: glib::ffi::gpointer,
231 f: glib::ffi::gpointer,
232 ) {
233 let f: &F = &*(f as *const F);
234 f(EventController::from_glib_borrow(this).unsafe_cast_ref())
235 }
236 unsafe {
237 let f: Box_<F> = Box_::new(f);
238 connect_raw(
239 self.as_ptr() as *mut _,
240 c"notify::widget".as_ptr() as *const _,
241 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
242 notify_widget_trampoline::<Self, F> as *const (),
243 )),
244 Box_::into_raw(f),
245 )
246 }
247 }
248}
249
250impl<O: IsA<EventController>> EventControllerExt for O {}