1#[cfg(feature = "v4_4")]
6#[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
7use crate::TitlebarGesture;
8use crate::{
9 ffi, Device, Event, FullscreenMode, Surface, SurfaceEdge, Texture, ToplevelLayout,
10 ToplevelState,
11};
12#[cfg(feature = "v4_20")]
13#[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
14use crate::{Gravity, ToplevelCapabilities};
15use glib::{
16 prelude::*,
17 signal::{connect_raw, SignalHandlerId},
18 translate::*,
19};
20use std::boxed::Box as Box_;
21
22glib::wrapper! {
23 #[doc(alias = "GdkToplevel")]
24 pub struct Toplevel(Interface<ffi::GdkToplevel, ffi::GdkToplevelInterface>) @requires Surface;
25
26 match fn {
27 type_ => || ffi::gdk_toplevel_get_type(),
28 }
29}
30
31impl Toplevel {
32 pub const NONE: Option<&'static Toplevel> = None;
33}
34
35pub trait ToplevelExt: IsA<Toplevel> + 'static {
36 #[doc(alias = "gdk_toplevel_begin_move")]
37 fn begin_move(&self, device: &impl IsA<Device>, button: i32, x: f64, y: f64, timestamp: u32) {
38 unsafe {
39 ffi::gdk_toplevel_begin_move(
40 self.as_ref().to_glib_none().0,
41 device.as_ref().to_glib_none().0,
42 button,
43 x,
44 y,
45 timestamp,
46 );
47 }
48 }
49
50 #[doc(alias = "gdk_toplevel_begin_resize")]
51 fn begin_resize(
52 &self,
53 edge: SurfaceEdge,
54 device: Option<&impl IsA<Device>>,
55 button: i32,
56 x: f64,
57 y: f64,
58 timestamp: u32,
59 ) {
60 unsafe {
61 ffi::gdk_toplevel_begin_resize(
62 self.as_ref().to_glib_none().0,
63 edge.into_glib(),
64 device.map(|p| p.as_ref()).to_glib_none().0,
65 button,
66 x,
67 y,
68 timestamp,
69 );
70 }
71 }
72
73 #[doc(alias = "gdk_toplevel_focus")]
74 fn focus(&self, timestamp: u32) {
75 unsafe {
76 ffi::gdk_toplevel_focus(self.as_ref().to_glib_none().0, timestamp);
77 }
78 }
79
80 #[cfg(feature = "v4_20")]
81 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
82 #[doc(alias = "gdk_toplevel_get_capabilities")]
83 #[doc(alias = "get_capabilities")]
84 fn capabilities(&self) -> ToplevelCapabilities {
85 unsafe {
86 from_glib(ffi::gdk_toplevel_get_capabilities(
87 self.as_ref().to_glib_none().0,
88 ))
89 }
90 }
91
92 #[cfg(feature = "v4_20")]
93 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
94 #[doc(alias = "gdk_toplevel_get_gravity")]
95 #[doc(alias = "get_gravity")]
96 fn gravity(&self) -> Gravity {
97 unsafe {
98 from_glib(ffi::gdk_toplevel_get_gravity(
99 self.as_ref().to_glib_none().0,
100 ))
101 }
102 }
103
104 #[doc(alias = "gdk_toplevel_get_state")]
105 #[doc(alias = "get_state")]
106 fn state(&self) -> ToplevelState {
107 unsafe { from_glib(ffi::gdk_toplevel_get_state(self.as_ref().to_glib_none().0)) }
108 }
109
110 #[doc(alias = "gdk_toplevel_inhibit_system_shortcuts")]
111 fn inhibit_system_shortcuts(&self, event: Option<impl AsRef<Event>>) {
112 unsafe {
113 ffi::gdk_toplevel_inhibit_system_shortcuts(
114 self.as_ref().to_glib_none().0,
115 event.as_ref().map(|p| p.as_ref()).to_glib_none().0,
116 );
117 }
118 }
119
120 #[doc(alias = "gdk_toplevel_lower")]
121 fn lower(&self) -> bool {
122 unsafe { from_glib(ffi::gdk_toplevel_lower(self.as_ref().to_glib_none().0)) }
123 }
124
125 #[doc(alias = "gdk_toplevel_minimize")]
126 fn minimize(&self) -> bool {
127 unsafe { from_glib(ffi::gdk_toplevel_minimize(self.as_ref().to_glib_none().0)) }
128 }
129
130 #[doc(alias = "gdk_toplevel_present")]
131 fn present(&self, layout: &ToplevelLayout) {
132 unsafe {
133 ffi::gdk_toplevel_present(self.as_ref().to_glib_none().0, layout.to_glib_none().0);
134 }
135 }
136
137 #[doc(alias = "gdk_toplevel_restore_system_shortcuts")]
138 fn restore_system_shortcuts(&self) {
139 unsafe {
140 ffi::gdk_toplevel_restore_system_shortcuts(self.as_ref().to_glib_none().0);
141 }
142 }
143
144 #[doc(alias = "gdk_toplevel_set_decorated")]
145 #[doc(alias = "decorated")]
146 fn set_decorated(&self, decorated: bool) {
147 unsafe {
148 ffi::gdk_toplevel_set_decorated(self.as_ref().to_glib_none().0, decorated.into_glib());
149 }
150 }
151
152 #[doc(alias = "gdk_toplevel_set_deletable")]
153 #[doc(alias = "deletable")]
154 fn set_deletable(&self, deletable: bool) {
155 unsafe {
156 ffi::gdk_toplevel_set_deletable(self.as_ref().to_glib_none().0, deletable.into_glib());
157 }
158 }
159
160 #[cfg(feature = "v4_20")]
161 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
162 #[doc(alias = "gdk_toplevel_set_gravity")]
163 #[doc(alias = "gravity")]
164 fn set_gravity(&self, gravity: Gravity) {
165 unsafe {
166 ffi::gdk_toplevel_set_gravity(self.as_ref().to_glib_none().0, gravity.into_glib());
167 }
168 }
169
170 #[doc(alias = "gdk_toplevel_set_icon_list")]
171 #[doc(alias = "icon-list")]
172 fn set_icon_list(&self, surfaces: &[Texture]) {
173 unsafe {
174 ffi::gdk_toplevel_set_icon_list(
175 self.as_ref().to_glib_none().0,
176 surfaces.to_glib_none().0,
177 );
178 }
179 }
180
181 #[doc(alias = "gdk_toplevel_set_modal")]
182 #[doc(alias = "modal")]
183 fn set_modal(&self, modal: bool) {
184 unsafe {
185 ffi::gdk_toplevel_set_modal(self.as_ref().to_glib_none().0, modal.into_glib());
186 }
187 }
188
189 #[doc(alias = "gdk_toplevel_set_startup_id")]
190 #[doc(alias = "startup-id")]
191 fn set_startup_id(&self, startup_id: &str) {
192 unsafe {
193 ffi::gdk_toplevel_set_startup_id(
194 self.as_ref().to_glib_none().0,
195 startup_id.to_glib_none().0,
196 );
197 }
198 }
199
200 #[doc(alias = "gdk_toplevel_set_title")]
201 #[doc(alias = "title")]
202 fn set_title(&self, title: &str) {
203 unsafe {
204 ffi::gdk_toplevel_set_title(self.as_ref().to_glib_none().0, title.to_glib_none().0);
205 }
206 }
207
208 #[doc(alias = "gdk_toplevel_set_transient_for")]
209 #[doc(alias = "transient-for")]
210 fn set_transient_for(&self, parent: &impl IsA<Surface>) {
211 unsafe {
212 ffi::gdk_toplevel_set_transient_for(
213 self.as_ref().to_glib_none().0,
214 parent.as_ref().to_glib_none().0,
215 );
216 }
217 }
218
219 #[doc(alias = "gdk_toplevel_show_window_menu")]
220 fn show_window_menu(&self, event: impl AsRef<Event>) -> bool {
221 unsafe {
222 from_glib(ffi::gdk_toplevel_show_window_menu(
223 self.as_ref().to_glib_none().0,
224 event.as_ref().to_glib_none().0,
225 ))
226 }
227 }
228
229 #[doc(alias = "gdk_toplevel_supports_edge_constraints")]
230 fn supports_edge_constraints(&self) -> bool {
231 unsafe {
232 from_glib(ffi::gdk_toplevel_supports_edge_constraints(
233 self.as_ref().to_glib_none().0,
234 ))
235 }
236 }
237
238 #[cfg(feature = "v4_4")]
239 #[cfg_attr(docsrs, doc(cfg(feature = "v4_4")))]
240 #[doc(alias = "gdk_toplevel_titlebar_gesture")]
241 fn titlebar_gesture(&self, gesture: TitlebarGesture) -> bool {
242 unsafe {
243 from_glib(ffi::gdk_toplevel_titlebar_gesture(
244 self.as_ref().to_glib_none().0,
245 gesture.into_glib(),
246 ))
247 }
248 }
249
250 fn is_decorated(&self) -> bool {
251 ObjectExt::property(self.as_ref(), "decorated")
252 }
253
254 fn is_deletable(&self) -> bool {
255 ObjectExt::property(self.as_ref(), "deletable")
256 }
257
258 #[doc(alias = "fullscreen-mode")]
259 fn fullscreen_mode(&self) -> FullscreenMode {
260 ObjectExt::property(self.as_ref(), "fullscreen-mode")
261 }
262
263 #[doc(alias = "fullscreen-mode")]
264 fn set_fullscreen_mode(&self, fullscreen_mode: FullscreenMode) {
265 ObjectExt::set_property(self.as_ref(), "fullscreen-mode", fullscreen_mode)
266 }
267
268 fn is_modal(&self) -> bool {
274 ObjectExt::property(self.as_ref(), "modal")
275 }
276
277 #[doc(alias = "shortcuts-inhibited")]
278 fn is_shortcuts_inhibited(&self) -> bool {
279 ObjectExt::property(self.as_ref(), "shortcuts-inhibited")
280 }
281
282 #[doc(alias = "startup-id")]
283 fn startup_id(&self) -> Option<glib::GString> {
284 ObjectExt::property(self.as_ref(), "startup-id")
285 }
286
287 fn title(&self) -> Option<glib::GString> {
288 ObjectExt::property(self.as_ref(), "title")
289 }
290
291 #[doc(alias = "transient-for")]
292 fn transient_for(&self) -> Option<Surface> {
293 ObjectExt::property(self.as_ref(), "transient-for")
294 }
295
296 #[cfg(feature = "v4_20")]
297 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
298 #[doc(alias = "capabilities")]
299 fn connect_capabilities_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
300 unsafe extern "C" fn notify_capabilities_trampoline<
301 P: IsA<Toplevel>,
302 F: Fn(&P) + 'static,
303 >(
304 this: *mut ffi::GdkToplevel,
305 _param_spec: glib::ffi::gpointer,
306 f: glib::ffi::gpointer,
307 ) {
308 let f: &F = &*(f as *const F);
309 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
310 }
311 unsafe {
312 let f: Box_<F> = Box_::new(f);
313 connect_raw(
314 self.as_ptr() as *mut _,
315 c"notify::capabilities".as_ptr() as *const _,
316 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
317 notify_capabilities_trampoline::<Self, F> as *const (),
318 )),
319 Box_::into_raw(f),
320 )
321 }
322 }
323
324 #[doc(alias = "decorated")]
325 fn connect_decorated_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
326 unsafe extern "C" fn notify_decorated_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
327 this: *mut ffi::GdkToplevel,
328 _param_spec: glib::ffi::gpointer,
329 f: glib::ffi::gpointer,
330 ) {
331 let f: &F = &*(f as *const F);
332 f(Toplevel::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 c"notify::decorated".as_ptr() as *const _,
339 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
340 notify_decorated_trampoline::<Self, F> as *const (),
341 )),
342 Box_::into_raw(f),
343 )
344 }
345 }
346
347 #[doc(alias = "deletable")]
348 fn connect_deletable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
349 unsafe extern "C" fn notify_deletable_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
350 this: *mut ffi::GdkToplevel,
351 _param_spec: glib::ffi::gpointer,
352 f: glib::ffi::gpointer,
353 ) {
354 let f: &F = &*(f as *const F);
355 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
356 }
357 unsafe {
358 let f: Box_<F> = Box_::new(f);
359 connect_raw(
360 self.as_ptr() as *mut _,
361 c"notify::deletable".as_ptr() as *const _,
362 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
363 notify_deletable_trampoline::<Self, F> as *const (),
364 )),
365 Box_::into_raw(f),
366 )
367 }
368 }
369
370 #[doc(alias = "fullscreen-mode")]
371 fn connect_fullscreen_mode_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
372 unsafe extern "C" fn notify_fullscreen_mode_trampoline<
373 P: IsA<Toplevel>,
374 F: Fn(&P) + 'static,
375 >(
376 this: *mut ffi::GdkToplevel,
377 _param_spec: glib::ffi::gpointer,
378 f: glib::ffi::gpointer,
379 ) {
380 let f: &F = &*(f as *const F);
381 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
382 }
383 unsafe {
384 let f: Box_<F> = Box_::new(f);
385 connect_raw(
386 self.as_ptr() as *mut _,
387 c"notify::fullscreen-mode".as_ptr() as *const _,
388 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
389 notify_fullscreen_mode_trampoline::<Self, F> as *const (),
390 )),
391 Box_::into_raw(f),
392 )
393 }
394 }
395
396 #[cfg(feature = "v4_20")]
397 #[cfg_attr(docsrs, doc(cfg(feature = "v4_20")))]
398 #[doc(alias = "gravity")]
399 fn connect_gravity_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
400 unsafe extern "C" fn notify_gravity_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
401 this: *mut ffi::GdkToplevel,
402 _param_spec: glib::ffi::gpointer,
403 f: glib::ffi::gpointer,
404 ) {
405 let f: &F = &*(f as *const F);
406 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
407 }
408 unsafe {
409 let f: Box_<F> = Box_::new(f);
410 connect_raw(
411 self.as_ptr() as *mut _,
412 c"notify::gravity".as_ptr() as *const _,
413 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
414 notify_gravity_trampoline::<Self, F> as *const (),
415 )),
416 Box_::into_raw(f),
417 )
418 }
419 }
420
421 #[doc(alias = "icon-list")]
422 fn connect_icon_list_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
423 unsafe extern "C" fn notify_icon_list_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
424 this: *mut ffi::GdkToplevel,
425 _param_spec: glib::ffi::gpointer,
426 f: glib::ffi::gpointer,
427 ) {
428 let f: &F = &*(f as *const F);
429 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
430 }
431 unsafe {
432 let f: Box_<F> = Box_::new(f);
433 connect_raw(
434 self.as_ptr() as *mut _,
435 c"notify::icon-list".as_ptr() as *const _,
436 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
437 notify_icon_list_trampoline::<Self, F> as *const (),
438 )),
439 Box_::into_raw(f),
440 )
441 }
442 }
443
444 #[doc(alias = "modal")]
445 fn connect_modal_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
446 unsafe extern "C" fn notify_modal_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
447 this: *mut ffi::GdkToplevel,
448 _param_spec: glib::ffi::gpointer,
449 f: glib::ffi::gpointer,
450 ) {
451 let f: &F = &*(f as *const F);
452 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
453 }
454 unsafe {
455 let f: Box_<F> = Box_::new(f);
456 connect_raw(
457 self.as_ptr() as *mut _,
458 c"notify::modal".as_ptr() as *const _,
459 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
460 notify_modal_trampoline::<Self, F> as *const (),
461 )),
462 Box_::into_raw(f),
463 )
464 }
465 }
466
467 #[doc(alias = "shortcuts-inhibited")]
468 fn connect_shortcuts_inhibited_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
469 unsafe extern "C" fn notify_shortcuts_inhibited_trampoline<
470 P: IsA<Toplevel>,
471 F: Fn(&P) + 'static,
472 >(
473 this: *mut ffi::GdkToplevel,
474 _param_spec: glib::ffi::gpointer,
475 f: glib::ffi::gpointer,
476 ) {
477 let f: &F = &*(f as *const F);
478 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
479 }
480 unsafe {
481 let f: Box_<F> = Box_::new(f);
482 connect_raw(
483 self.as_ptr() as *mut _,
484 c"notify::shortcuts-inhibited".as_ptr() as *const _,
485 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
486 notify_shortcuts_inhibited_trampoline::<Self, F> as *const (),
487 )),
488 Box_::into_raw(f),
489 )
490 }
491 }
492
493 #[doc(alias = "startup-id")]
494 fn connect_startup_id_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
495 unsafe extern "C" fn notify_startup_id_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
496 this: *mut ffi::GdkToplevel,
497 _param_spec: glib::ffi::gpointer,
498 f: glib::ffi::gpointer,
499 ) {
500 let f: &F = &*(f as *const F);
501 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
502 }
503 unsafe {
504 let f: Box_<F> = Box_::new(f);
505 connect_raw(
506 self.as_ptr() as *mut _,
507 c"notify::startup-id".as_ptr() as *const _,
508 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
509 notify_startup_id_trampoline::<Self, F> as *const (),
510 )),
511 Box_::into_raw(f),
512 )
513 }
514 }
515
516 #[doc(alias = "state")]
517 fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
518 unsafe extern "C" fn notify_state_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
519 this: *mut ffi::GdkToplevel,
520 _param_spec: glib::ffi::gpointer,
521 f: glib::ffi::gpointer,
522 ) {
523 let f: &F = &*(f as *const F);
524 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
525 }
526 unsafe {
527 let f: Box_<F> = Box_::new(f);
528 connect_raw(
529 self.as_ptr() as *mut _,
530 c"notify::state".as_ptr() as *const _,
531 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
532 notify_state_trampoline::<Self, F> as *const (),
533 )),
534 Box_::into_raw(f),
535 )
536 }
537 }
538
539 #[doc(alias = "title")]
540 fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
541 unsafe extern "C" fn notify_title_trampoline<P: IsA<Toplevel>, F: Fn(&P) + 'static>(
542 this: *mut ffi::GdkToplevel,
543 _param_spec: glib::ffi::gpointer,
544 f: glib::ffi::gpointer,
545 ) {
546 let f: &F = &*(f as *const F);
547 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
548 }
549 unsafe {
550 let f: Box_<F> = Box_::new(f);
551 connect_raw(
552 self.as_ptr() as *mut _,
553 c"notify::title".as_ptr() as *const _,
554 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
555 notify_title_trampoline::<Self, F> as *const (),
556 )),
557 Box_::into_raw(f),
558 )
559 }
560 }
561
562 #[doc(alias = "transient-for")]
563 fn connect_transient_for_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
564 unsafe extern "C" fn notify_transient_for_trampoline<
565 P: IsA<Toplevel>,
566 F: Fn(&P) + 'static,
567 >(
568 this: *mut ffi::GdkToplevel,
569 _param_spec: glib::ffi::gpointer,
570 f: glib::ffi::gpointer,
571 ) {
572 let f: &F = &*(f as *const F);
573 f(Toplevel::from_glib_borrow(this).unsafe_cast_ref())
574 }
575 unsafe {
576 let f: Box_<F> = Box_::new(f);
577 connect_raw(
578 self.as_ptr() as *mut _,
579 c"notify::transient-for".as_ptr() as *const _,
580 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
581 notify_transient_for_trampoline::<Self, F> as *const (),
582 )),
583 Box_::into_raw(f),
584 )
585 }
586 }
587}
588
589impl<O: IsA<Toplevel>> ToplevelExt for O {}