gdk4/auto/
surface.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4#![allow(deprecated)]
5
6use crate::{
7    ffi, CairoContext, Cursor, Device, Display, Event, FrameClock, GLContext, ModifierType,
8    Monitor, VulkanContext,
9};
10use glib::{
11    object::ObjectType as _,
12    prelude::*,
13    signal::{connect_raw, SignalHandlerId},
14    translate::*,
15};
16use std::boxed::Box as Box_;
17
18glib::wrapper! {
19    /// Represents a rectangular region on the screen.
20    ///
21    /// It’s a low-level object, used to implement high-level objects
22    /// such as [GtkWindow](../gtk4/class.Window.html).
23    ///
24    /// The surfaces you see in practice are either [`Toplevel`][crate::Toplevel] or
25    /// [`Popup`][crate::Popup], and those interfaces provide much of the required
26    /// API to interact with these surfaces. Other, more specialized surface
27    /// types exist, but you will rarely interact with them directly.
28    ///
29    /// This is an Abstract Base Class, you cannot instantiate it.
30    ///
31    /// ## Properties
32    ///
33    ///
34    /// #### `cursor`
35    ///  The mouse pointer for the [`Surface`][crate::Surface].
36    ///
37    /// Readable | Writeable
38    ///
39    ///
40    /// #### `display`
41    ///  The [`Display`][crate::Display] connection of the surface.
42    ///
43    /// Readable | Writeable | Construct Only
44    ///
45    ///
46    /// #### `frame-clock`
47    ///  The [`FrameClock`][crate::FrameClock] of the surface.
48    ///
49    /// Readable | Writeable | Construct Only
50    ///
51    ///
52    /// #### `height`
53    ///  The height of the surface, in pixels.
54    ///
55    /// Readable
56    ///
57    ///
58    /// #### `mapped`
59    ///  Whether the surface is mapped.
60    ///
61    /// Readable
62    ///
63    ///
64    /// #### `scale`
65    ///  The scale of the surface.
66    ///
67    /// Readable
68    ///
69    ///
70    /// #### `scale-factor`
71    ///  The scale factor of the surface.
72    ///
73    /// The scale factor is the next larger integer,
74    /// compared to [`scale`][struct@crate::Surface#scale].
75    ///
76    /// Readable
77    ///
78    ///
79    /// #### `width`
80    ///  The width of the surface in pixels.
81    ///
82    /// Readable
83    ///
84    /// ## Signals
85    ///
86    ///
87    /// #### `enter-monitor`
88    ///  Emitted when @surface starts being present on the monitor.
89    ///
90    ///
91    ///
92    ///
93    /// #### `event`
94    ///  Emitted when GDK receives an input event for @surface.
95    ///
96    ///
97    ///
98    ///
99    /// #### `layout`
100    ///  Emitted when the size of @surface is changed, or when relayout should
101    /// be performed.
102    ///
103    /// Surface size is reported in ”application pixels”, not
104    /// ”device pixels” (see gdk_surface_get_scale_factor()).
105    ///
106    ///
107    ///
108    ///
109    /// #### `leave-monitor`
110    ///  Emitted when @surface stops being present on the monitor.
111    ///
112    ///
113    ///
114    ///
115    /// #### `render`
116    ///  Emitted when part of the surface needs to be redrawn.
117    ///
118    ///
119    ///
120    /// # Implements
121    ///
122    /// [`SurfaceExt`][trait@crate::prelude::SurfaceExt], [`SurfaceExtManual`][trait@crate::prelude::SurfaceExtManual]
123    #[doc(alias = "GdkSurface")]
124    pub struct Surface(Object<ffi::GdkSurface, ffi::GdkSurfaceClass>);
125
126    match fn {
127        type_ => || ffi::gdk_surface_get_type(),
128    }
129}
130
131impl Surface {
132    pub const NONE: Option<&'static Surface> = None;
133
134    /// Create a new popup surface.
135    ///
136    /// The surface will be attached to @parent and can be positioned
137    /// relative to it using [`PopupExt::present()`][crate::prelude::PopupExt::present()].
138    /// ## `parent`
139    /// the parent surface to attach the surface to
140    /// ## `autohide`
141    /// whether to hide the surface on outside clicks
142    ///
143    /// # Returns
144    ///
145    /// a new [`Surface`][crate::Surface]
146    #[doc(alias = "gdk_surface_new_popup")]
147    pub fn new_popup(parent: &impl IsA<Surface>, autohide: bool) -> Surface {
148        skip_assert_initialized!();
149        unsafe {
150            from_glib_full(ffi::gdk_surface_new_popup(
151                parent.as_ref().to_glib_none().0,
152                autohide.into_glib(),
153            ))
154        }
155    }
156
157    /// Creates a new toplevel surface.
158    /// ## `display`
159    /// the display to create the surface on
160    ///
161    /// # Returns
162    ///
163    /// the new [`Surface`][crate::Surface]
164    #[doc(alias = "gdk_surface_new_toplevel")]
165    pub fn new_toplevel(display: &impl IsA<Display>) -> Surface {
166        skip_assert_initialized!();
167        unsafe {
168            from_glib_full(ffi::gdk_surface_new_toplevel(
169                display.as_ref().to_glib_none().0,
170            ))
171        }
172    }
173}
174
175/// Trait containing all [`struct@Surface`] methods.
176///
177/// # Implementors
178///
179/// [`DragSurface`][struct@crate::DragSurface], [`Popup`][struct@crate::Popup], [`Surface`][struct@crate::Surface], [`Toplevel`][struct@crate::Toplevel]
180pub trait SurfaceExt: IsA<Surface> + 'static {
181    /// Emits a short beep associated to @self.
182    ///
183    /// If the display of @self does not support per-surface beeps,
184    /// emits a short beep on the display just as [`DisplayExt::beep()`][crate::prelude::DisplayExt::beep()].
185    #[doc(alias = "gdk_surface_beep")]
186    fn beep(&self) {
187        unsafe {
188            ffi::gdk_surface_beep(self.as_ref().to_glib_none().0);
189        }
190    }
191
192    /// Creates a new [`CairoContext`][crate::CairoContext] for rendering on @self.
193    ///
194    /// # Deprecated since 4.18
195    ///
196    /// Drawing content with Cairo should be done via
197    ///   Cairo rendernodes, not by using the Cairo renderer.
198    ///
199    /// # Returns
200    ///
201    /// the newly created [`CairoContext`][crate::CairoContext]
202    #[cfg_attr(feature = "v4_18", deprecated = "Since 4.18")]
203    #[allow(deprecated)]
204    #[doc(alias = "gdk_surface_create_cairo_context")]
205    fn create_cairo_context(&self) -> CairoContext {
206        unsafe {
207            from_glib_full(ffi::gdk_surface_create_cairo_context(
208                self.as_ref().to_glib_none().0,
209            ))
210        }
211    }
212
213    /// Creates a new [`GLContext`][crate::GLContext] for the [`Surface`][crate::Surface].
214    ///
215    /// The context is disconnected from any particular surface or surface.
216    /// If the creation of the [`GLContext`][crate::GLContext] failed, @error will be set.
217    /// Before using the returned [`GLContext`][crate::GLContext], you will need to
218    /// call [`GLContextExt::make_current()`][crate::prelude::GLContextExt::make_current()] or [`GLContextExt::realize()`][crate::prelude::GLContextExt::realize()].
219    ///
220    /// # Returns
221    ///
222    /// the newly created [`GLContext`][crate::GLContext]
223    #[doc(alias = "gdk_surface_create_gl_context")]
224    fn create_gl_context(&self) -> Result<GLContext, glib::Error> {
225        unsafe {
226            let mut error = std::ptr::null_mut();
227            let ret =
228                ffi::gdk_surface_create_gl_context(self.as_ref().to_glib_none().0, &mut error);
229            if error.is_null() {
230                Ok(from_glib_full(ret))
231            } else {
232                Err(from_glib_full(error))
233            }
234        }
235    }
236
237    /// Sets an error and returns [`None`].
238    ///
239    /// # Deprecated since 4.14
240    ///
241    /// GTK does not expose any Vulkan internals. This
242    ///   function is a leftover that was accidentally exposed.
243    ///
244    /// # Returns
245    ///
246    /// [`None`]
247    #[cfg_attr(feature = "v4_14", deprecated = "Since 4.14")]
248    #[allow(deprecated)]
249    #[doc(alias = "gdk_surface_create_vulkan_context")]
250    fn create_vulkan_context(&self) -> Result<VulkanContext, glib::Error> {
251        unsafe {
252            let mut error = std::ptr::null_mut();
253            let ret =
254                ffi::gdk_surface_create_vulkan_context(self.as_ref().to_glib_none().0, &mut error);
255            if error.is_null() {
256                Ok(from_glib_full(ret))
257            } else {
258                Err(from_glib_full(error))
259            }
260        }
261    }
262
263    #[doc(alias = "gdk_surface_destroy")]
264    fn destroy(&self) {
265        unsafe {
266            ffi::gdk_surface_destroy(self.as_ref().to_glib_none().0);
267        }
268    }
269
270    /// Retrieves a [`Cursor`][crate::Cursor] pointer for the cursor currently set on the
271    /// [`Surface`][crate::Surface].
272    ///
273    /// If the return value is [`None`] then there is no custom cursor set on
274    /// the surface, and it is using the cursor for its parent surface.
275    ///
276    /// Use [`set_cursor()`][Self::set_cursor()] to unset the cursor of the surface.
277    ///
278    /// # Returns
279    ///
280    /// a [`Cursor`][crate::Cursor]
281    #[doc(alias = "gdk_surface_get_cursor")]
282    #[doc(alias = "get_cursor")]
283    fn cursor(&self) -> Option<Cursor> {
284        unsafe { from_glib_none(ffi::gdk_surface_get_cursor(self.as_ref().to_glib_none().0)) }
285    }
286
287    /// Retrieves a [`Cursor`][crate::Cursor] pointer for the @device currently set on the
288    /// specified [`Surface`][crate::Surface].
289    ///
290    /// If the return value is [`None`] then there is no custom cursor set on the
291    /// specified surface, and it is using the cursor for its parent surface.
292    ///
293    /// Use [`set_cursor()`][Self::set_cursor()] to unset the cursor of the surface.
294    /// ## `device`
295    /// a pointer [`Device`][crate::Device]
296    ///
297    /// # Returns
298    ///
299    /// a [`Cursor`][crate::Cursor]
300    #[doc(alias = "gdk_surface_get_device_cursor")]
301    #[doc(alias = "get_device_cursor")]
302    fn device_cursor(&self, device: &impl IsA<Device>) -> Option<Cursor> {
303        unsafe {
304            from_glib_none(ffi::gdk_surface_get_device_cursor(
305                self.as_ref().to_glib_none().0,
306                device.as_ref().to_glib_none().0,
307            ))
308        }
309    }
310
311    /// Obtains the current device position and modifier state.
312    ///
313    /// The position is given in coordinates relative to the upper
314    /// left corner of @self.
315    /// ## `device`
316    /// pointer [`Device`][crate::Device] to query to
317    ///
318    /// # Returns
319    ///
320    /// [`true`] if the device is over the surface
321    ///
322    /// ## `x`
323    /// return location for the X coordinate of @device
324    ///
325    /// ## `y`
326    /// return location for the Y coordinate of @device
327    ///
328    /// ## `mask`
329    /// return location for the modifier mask
330    #[doc(alias = "gdk_surface_get_device_position")]
331    #[doc(alias = "get_device_position")]
332    fn device_position(&self, device: &impl IsA<Device>) -> Option<(f64, f64, ModifierType)> {
333        unsafe {
334            let mut x = std::mem::MaybeUninit::uninit();
335            let mut y = std::mem::MaybeUninit::uninit();
336            let mut mask = std::mem::MaybeUninit::uninit();
337            let ret = from_glib(ffi::gdk_surface_get_device_position(
338                self.as_ref().to_glib_none().0,
339                device.as_ref().to_glib_none().0,
340                x.as_mut_ptr(),
341                y.as_mut_ptr(),
342                mask.as_mut_ptr(),
343            ));
344            if ret {
345                Some((
346                    x.assume_init(),
347                    y.assume_init(),
348                    from_glib(mask.assume_init()),
349                ))
350            } else {
351                None
352            }
353        }
354    }
355
356    /// Gets the [`Display`][crate::Display] associated with a [`Surface`][crate::Surface].
357    ///
358    /// # Returns
359    ///
360    /// the [`Display`][crate::Display] associated with @self
361    #[doc(alias = "gdk_surface_get_display")]
362    #[doc(alias = "get_display")]
363    fn display(&self) -> Display {
364        unsafe { from_glib_none(ffi::gdk_surface_get_display(self.as_ref().to_glib_none().0)) }
365    }
366
367    /// Gets the frame clock for the surface.
368    ///
369    /// The frame clock for a surface never changes unless the surface is
370    /// reparented to a new toplevel surface.
371    ///
372    /// # Returns
373    ///
374    /// the frame clock
375    #[doc(alias = "gdk_surface_get_frame_clock")]
376    #[doc(alias = "get_frame_clock")]
377    #[doc(alias = "frame-clock")]
378    fn frame_clock(&self) -> FrameClock {
379        unsafe {
380            from_glib_none(ffi::gdk_surface_get_frame_clock(
381                self.as_ref().to_glib_none().0,
382            ))
383        }
384    }
385
386    /// Returns the height of the given @self.
387    ///
388    /// Surface size is reported in ”application pixels”, not
389    /// ”device pixels” (see [`scale_factor()`][Self::scale_factor()]).
390    ///
391    /// # Returns
392    ///
393    /// The height of @self
394    #[doc(alias = "gdk_surface_get_height")]
395    #[doc(alias = "get_height")]
396    fn height(&self) -> i32 {
397        unsafe { ffi::gdk_surface_get_height(self.as_ref().to_glib_none().0) }
398    }
399
400    /// Checks whether the surface has been mapped.
401    ///
402    /// A surface is mapped with [`ToplevelExt::present()`][crate::prelude::ToplevelExt::present()]
403    /// or [`PopupExt::present()`][crate::prelude::PopupExt::present()].
404    ///
405    /// # Returns
406    ///
407    /// [`true`] if the surface is mapped
408    #[doc(alias = "gdk_surface_get_mapped")]
409    #[doc(alias = "get_mapped")]
410    #[doc(alias = "mapped")]
411    fn is_mapped(&self) -> bool {
412        unsafe { from_glib(ffi::gdk_surface_get_mapped(self.as_ref().to_glib_none().0)) }
413    }
414
415    /// Returns the internal scale that maps from surface coordinates
416    /// to the actual device pixels.
417    ///
418    /// When the scale is bigger than 1, the windowing system prefers to get
419    /// buffers with a resolution that is bigger than the surface size (e.g.
420    /// to show the surface on a high-resolution display, or in a magnifier).
421    ///
422    /// Compare with [`scale_factor()`][Self::scale_factor()], which returns the
423    /// next larger integer.
424    ///
425    /// The scale may change during the lifetime of the surface.
426    ///
427    /// # Returns
428    ///
429    /// the scale
430    #[cfg(feature = "v4_12")]
431    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
432    #[doc(alias = "gdk_surface_get_scale")]
433    #[doc(alias = "get_scale")]
434    fn scale(&self) -> f64 {
435        unsafe { ffi::gdk_surface_get_scale(self.as_ref().to_glib_none().0) }
436    }
437
438    /// Returns the internal scale factor that maps from surface coordinates
439    /// to the actual device pixels.
440    ///
441    /// On traditional systems this is 1, but on very high density outputs
442    /// this can be a higher value (often 2). A higher value means that drawing
443    /// is automatically scaled up to a higher resolution, so any code doing
444    /// drawing will automatically look nicer. However, if you are supplying
445    /// pixel-based data the scale value can be used to determine whether to
446    /// use a pixel resource with higher resolution data.
447    ///
448    /// The scale factor may change during the lifetime of the surface.
449    ///
450    /// # Returns
451    ///
452    /// the scale factor
453    #[doc(alias = "gdk_surface_get_scale_factor")]
454    #[doc(alias = "get_scale_factor")]
455    #[doc(alias = "scale-factor")]
456    fn scale_factor(&self) -> i32 {
457        unsafe { ffi::gdk_surface_get_scale_factor(self.as_ref().to_glib_none().0) }
458    }
459
460    /// Returns the width of the given @self.
461    ///
462    /// Surface size is reported in ”application pixels”, not
463    /// ”device pixels” (see [`scale_factor()`][Self::scale_factor()]).
464    ///
465    /// # Returns
466    ///
467    /// The width of @self
468    #[doc(alias = "gdk_surface_get_width")]
469    #[doc(alias = "get_width")]
470    fn width(&self) -> i32 {
471        unsafe { ffi::gdk_surface_get_width(self.as_ref().to_glib_none().0) }
472    }
473
474    /// Hide the surface.
475    ///
476    /// For toplevel surfaces, withdraws them, so they will no longer be
477    /// known to the window manager; for all surfaces, unmaps them, so
478    /// they won’t be displayed. Normally done automatically as
479    /// part of [gtk_widget_hide()](../gtk4/method.Widget.hide.html).
480    #[doc(alias = "gdk_surface_hide")]
481    fn hide(&self) {
482        unsafe {
483            ffi::gdk_surface_hide(self.as_ref().to_glib_none().0);
484        }
485    }
486
487    /// Check to see if a surface is destroyed.
488    ///
489    /// # Returns
490    ///
491    /// [`true`] if the surface is destroyed
492    #[doc(alias = "gdk_surface_is_destroyed")]
493    fn is_destroyed(&self) -> bool {
494        unsafe {
495            from_glib(ffi::gdk_surface_is_destroyed(
496                self.as_ref().to_glib_none().0,
497            ))
498        }
499    }
500
501    /// Forces a [`render`][struct@crate::Surface#render] signal emission for @self
502    /// to be scheduled.
503    ///
504    /// This function is useful for implementations that track invalid
505    /// regions on their own.
506    #[doc(alias = "gdk_surface_queue_render")]
507    fn queue_render(&self) {
508        unsafe {
509            ffi::gdk_surface_queue_render(self.as_ref().to_glib_none().0);
510        }
511    }
512
513    /// Request a layout phase from the surface's frame clock.
514    ///
515    /// See [`FrameClock::request_phase()`][crate::FrameClock::request_phase()].
516    #[doc(alias = "gdk_surface_request_layout")]
517    fn request_layout(&self) {
518        unsafe {
519            ffi::gdk_surface_request_layout(self.as_ref().to_glib_none().0);
520        }
521    }
522
523    /// Sets the default mouse pointer for a [`Surface`][crate::Surface].
524    ///
525    /// Passing [`None`] for the @cursor argument means that @self will use
526    /// the cursor of its parent surface. Most surfaces should use this default.
527    /// Note that @cursor must be for the same display as @self.
528    ///
529    /// Use [`Cursor::from_name()`][crate::Cursor::from_name()] or [`Cursor::from_texture()`][crate::Cursor::from_texture()]
530    /// to create the cursor. To make the cursor invisible, use `GDK_BLANK_CURSOR`.
531    /// ## `cursor`
532    /// a [`Cursor`][crate::Cursor]
533    #[doc(alias = "gdk_surface_set_cursor")]
534    #[doc(alias = "cursor")]
535    fn set_cursor(&self, cursor: Option<&Cursor>) {
536        unsafe {
537            ffi::gdk_surface_set_cursor(self.as_ref().to_glib_none().0, cursor.to_glib_none().0);
538        }
539    }
540
541    /// Sets a specific [`Cursor`][crate::Cursor] for a given device when it gets inside @self.
542    ///
543    /// Passing [`None`] for the @cursor argument means that @self will use the
544    /// cursor of its parent surface. Most surfaces should use this default.
545    ///
546    /// Use [`Cursor::from_name()`][crate::Cursor::from_name()] or [`Cursor::from_texture()`][crate::Cursor::from_texture()]
547    /// to create the cursor. To make the cursor invisible, use `GDK_BLANK_CURSOR`.
548    /// ## `device`
549    /// a pointer [`Device`][crate::Device]
550    /// ## `cursor`
551    /// a [`Cursor`][crate::Cursor]
552    #[doc(alias = "gdk_surface_set_device_cursor")]
553    fn set_device_cursor(&self, device: &impl IsA<Device>, cursor: &Cursor) {
554        unsafe {
555            ffi::gdk_surface_set_device_cursor(
556                self.as_ref().to_glib_none().0,
557                device.as_ref().to_glib_none().0,
558                cursor.to_glib_none().0,
559            );
560        }
561    }
562
563    /// Apply the region to the surface for the purpose of event
564    /// handling.
565    ///
566    /// Mouse events which happen while the pointer position corresponds
567    /// to an unset bit in the mask will be passed on the surface below
568    /// @self.
569    ///
570    /// An input region is typically used with RGBA surfaces. The alpha
571    /// channel of the surface defines which pixels are invisible and
572    /// allows for nicely antialiased borders, and the input region
573    /// controls where the surface is “clickable”.
574    ///
575    /// Use [`DisplayExt::supports_input_shapes()`][crate::prelude::DisplayExt::supports_input_shapes()] to find out if
576    /// a particular backend supports input regions.
577    /// ## `region`
578    /// region of surface to be reactive,
579    ///   or [`None`] to make the entire surface reactive
580    #[doc(alias = "gdk_surface_set_input_region")]
581    fn set_input_region(&self, region: Option<&cairo::Region>) {
582        unsafe {
583            ffi::gdk_surface_set_input_region(
584                self.as_ref().to_glib_none().0,
585                mut_override(region.to_glib_none().0),
586            );
587        }
588    }
589
590    /// Marks a region of the [`Surface`][crate::Surface] as opaque.
591    ///
592    /// For optimisation purposes, compositing window managers may
593    /// like to not draw obscured regions of surfaces, or turn off blending
594    /// during for these regions. With RGB windows with no transparency,
595    /// this is just the shape of the window, but with ARGB32 windows, the
596    /// compositor does not know what regions of the window are transparent
597    /// or not.
598    ///
599    /// This function only works for toplevel surfaces.
600    ///
601    /// GTK will update this property automatically if the @self background
602    /// is opaque, as we know where the opaque regions are. If your surface
603    /// background is not opaque, please update this property in your
604    /// [GtkWidgetClass.css_changed](../gtk4/vfunc.Widget.css_changed.html) handler.
605    ///
606    /// # Deprecated since 4.16
607    ///
608    /// GDK can figure out the opaque parts of a window itself
609    ///   by inspecting the contents that are drawn.
610    /// ## `region`
611    /// a region, or [`None`] to make the entire
612    ///   surface opaque
613    #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
614    #[allow(deprecated)]
615    #[doc(alias = "gdk_surface_set_opaque_region")]
616    fn set_opaque_region(&self, region: Option<&cairo::Region>) {
617        unsafe {
618            ffi::gdk_surface_set_opaque_region(
619                self.as_ref().to_glib_none().0,
620                mut_override(region.to_glib_none().0),
621            );
622        }
623    }
624
625    /// Emitted when @surface starts being present on the monitor.
626    /// ## `monitor`
627    /// the monitor
628    #[doc(alias = "enter-monitor")]
629    fn connect_enter_monitor<F: Fn(&Self, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
630        unsafe extern "C" fn enter_monitor_trampoline<
631            P: IsA<Surface>,
632            F: Fn(&P, &Monitor) + 'static,
633        >(
634            this: *mut ffi::GdkSurface,
635            monitor: *mut ffi::GdkMonitor,
636            f: glib::ffi::gpointer,
637        ) {
638            let f: &F = &*(f as *const F);
639            f(
640                Surface::from_glib_borrow(this).unsafe_cast_ref(),
641                &from_glib_borrow(monitor),
642            )
643        }
644        unsafe {
645            let f: Box_<F> = Box_::new(f);
646            connect_raw(
647                self.as_ptr() as *mut _,
648                c"enter-monitor".as_ptr() as *const _,
649                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
650                    enter_monitor_trampoline::<Self, F> as *const (),
651                )),
652                Box_::into_raw(f),
653            )
654        }
655    }
656
657    /// Emitted when GDK receives an input event for @surface.
658    /// ## `event`
659    /// an input event
660    ///
661    /// # Returns
662    ///
663    /// [`true`] to indicate that the event has been handled
664    #[doc(alias = "event")]
665    fn connect_event<F: Fn(&Self, &Event) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
666        unsafe extern "C" fn event_trampoline<
667            P: IsA<Surface>,
668            F: Fn(&P, &Event) -> bool + 'static,
669        >(
670            this: *mut ffi::GdkSurface,
671            event: *mut ffi::GdkEvent,
672            f: glib::ffi::gpointer,
673        ) -> glib::ffi::gboolean {
674            let f: &F = &*(f as *const F);
675            f(
676                Surface::from_glib_borrow(this).unsafe_cast_ref(),
677                &from_glib_borrow(event),
678            )
679            .into_glib()
680        }
681        unsafe {
682            let f: Box_<F> = Box_::new(f);
683            connect_raw(
684                self.as_ptr() as *mut _,
685                c"event".as_ptr() as *const _,
686                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
687                    event_trampoline::<Self, F> as *const (),
688                )),
689                Box_::into_raw(f),
690            )
691        }
692    }
693
694    /// Emitted when the size of @surface is changed, or when relayout should
695    /// be performed.
696    ///
697    /// Surface size is reported in ”application pixels”, not
698    /// ”device pixels” (see gdk_surface_get_scale_factor()).
699    /// ## `width`
700    /// the current width
701    /// ## `height`
702    /// the current height
703    #[doc(alias = "layout")]
704    fn connect_layout<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
705        unsafe extern "C" fn layout_trampoline<P: IsA<Surface>, F: Fn(&P, i32, i32) + 'static>(
706            this: *mut ffi::GdkSurface,
707            width: std::ffi::c_int,
708            height: std::ffi::c_int,
709            f: glib::ffi::gpointer,
710        ) {
711            let f: &F = &*(f as *const F);
712            f(
713                Surface::from_glib_borrow(this).unsafe_cast_ref(),
714                width,
715                height,
716            )
717        }
718        unsafe {
719            let f: Box_<F> = Box_::new(f);
720            connect_raw(
721                self.as_ptr() as *mut _,
722                c"layout".as_ptr() as *const _,
723                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
724                    layout_trampoline::<Self, F> as *const (),
725                )),
726                Box_::into_raw(f),
727            )
728        }
729    }
730
731    /// Emitted when @surface stops being present on the monitor.
732    /// ## `monitor`
733    /// the monitor
734    #[doc(alias = "leave-monitor")]
735    fn connect_leave_monitor<F: Fn(&Self, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
736        unsafe extern "C" fn leave_monitor_trampoline<
737            P: IsA<Surface>,
738            F: Fn(&P, &Monitor) + 'static,
739        >(
740            this: *mut ffi::GdkSurface,
741            monitor: *mut ffi::GdkMonitor,
742            f: glib::ffi::gpointer,
743        ) {
744            let f: &F = &*(f as *const F);
745            f(
746                Surface::from_glib_borrow(this).unsafe_cast_ref(),
747                &from_glib_borrow(monitor),
748            )
749        }
750        unsafe {
751            let f: Box_<F> = Box_::new(f);
752            connect_raw(
753                self.as_ptr() as *mut _,
754                c"leave-monitor".as_ptr() as *const _,
755                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
756                    leave_monitor_trampoline::<Self, F> as *const (),
757                )),
758                Box_::into_raw(f),
759            )
760        }
761    }
762
763    /// Emitted when part of the surface needs to be redrawn.
764    /// ## `region`
765    /// the region that needs to be redrawn
766    ///
767    /// # Returns
768    ///
769    /// [`true`] to indicate that the signal has been handled
770    #[doc(alias = "render")]
771    fn connect_render<F: Fn(&Self, &cairo::Region) -> bool + 'static>(
772        &self,
773        f: F,
774    ) -> SignalHandlerId {
775        unsafe extern "C" fn render_trampoline<
776            P: IsA<Surface>,
777            F: Fn(&P, &cairo::Region) -> bool + 'static,
778        >(
779            this: *mut ffi::GdkSurface,
780            region: *mut cairo::ffi::cairo_region_t,
781            f: glib::ffi::gpointer,
782        ) -> glib::ffi::gboolean {
783            let f: &F = &*(f as *const F);
784            f(
785                Surface::from_glib_borrow(this).unsafe_cast_ref(),
786                &from_glib_borrow(region),
787            )
788            .into_glib()
789        }
790        unsafe {
791            let f: Box_<F> = Box_::new(f);
792            connect_raw(
793                self.as_ptr() as *mut _,
794                c"render".as_ptr() as *const _,
795                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
796                    render_trampoline::<Self, F> as *const (),
797                )),
798                Box_::into_raw(f),
799            )
800        }
801    }
802
803    #[doc(alias = "cursor")]
804    fn connect_cursor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
805        unsafe extern "C" fn notify_cursor_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
806            this: *mut ffi::GdkSurface,
807            _param_spec: glib::ffi::gpointer,
808            f: glib::ffi::gpointer,
809        ) {
810            let f: &F = &*(f as *const F);
811            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
812        }
813        unsafe {
814            let f: Box_<F> = Box_::new(f);
815            connect_raw(
816                self.as_ptr() as *mut _,
817                c"notify::cursor".as_ptr() as *const _,
818                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
819                    notify_cursor_trampoline::<Self, F> as *const (),
820                )),
821                Box_::into_raw(f),
822            )
823        }
824    }
825
826    #[doc(alias = "height")]
827    fn connect_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
828        unsafe extern "C" fn notify_height_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
829            this: *mut ffi::GdkSurface,
830            _param_spec: glib::ffi::gpointer,
831            f: glib::ffi::gpointer,
832        ) {
833            let f: &F = &*(f as *const F);
834            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
835        }
836        unsafe {
837            let f: Box_<F> = Box_::new(f);
838            connect_raw(
839                self.as_ptr() as *mut _,
840                c"notify::height".as_ptr() as *const _,
841                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
842                    notify_height_trampoline::<Self, F> as *const (),
843                )),
844                Box_::into_raw(f),
845            )
846        }
847    }
848
849    #[doc(alias = "mapped")]
850    fn connect_mapped_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
851        unsafe extern "C" fn notify_mapped_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
852            this: *mut ffi::GdkSurface,
853            _param_spec: glib::ffi::gpointer,
854            f: glib::ffi::gpointer,
855        ) {
856            let f: &F = &*(f as *const F);
857            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
858        }
859        unsafe {
860            let f: Box_<F> = Box_::new(f);
861            connect_raw(
862                self.as_ptr() as *mut _,
863                c"notify::mapped".as_ptr() as *const _,
864                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
865                    notify_mapped_trampoline::<Self, F> as *const (),
866                )),
867                Box_::into_raw(f),
868            )
869        }
870    }
871
872    #[cfg(feature = "v4_12")]
873    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
874    #[doc(alias = "scale")]
875    fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
876        unsafe extern "C" fn notify_scale_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
877            this: *mut ffi::GdkSurface,
878            _param_spec: glib::ffi::gpointer,
879            f: glib::ffi::gpointer,
880        ) {
881            let f: &F = &*(f as *const F);
882            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
883        }
884        unsafe {
885            let f: Box_<F> = Box_::new(f);
886            connect_raw(
887                self.as_ptr() as *mut _,
888                c"notify::scale".as_ptr() as *const _,
889                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
890                    notify_scale_trampoline::<Self, F> as *const (),
891                )),
892                Box_::into_raw(f),
893            )
894        }
895    }
896
897    #[doc(alias = "scale-factor")]
898    fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
899        unsafe extern "C" fn notify_scale_factor_trampoline<
900            P: IsA<Surface>,
901            F: Fn(&P) + 'static,
902        >(
903            this: *mut ffi::GdkSurface,
904            _param_spec: glib::ffi::gpointer,
905            f: glib::ffi::gpointer,
906        ) {
907            let f: &F = &*(f as *const F);
908            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
909        }
910        unsafe {
911            let f: Box_<F> = Box_::new(f);
912            connect_raw(
913                self.as_ptr() as *mut _,
914                c"notify::scale-factor".as_ptr() as *const _,
915                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
916                    notify_scale_factor_trampoline::<Self, F> as *const (),
917                )),
918                Box_::into_raw(f),
919            )
920        }
921    }
922
923    #[doc(alias = "width")]
924    fn connect_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
925        unsafe extern "C" fn notify_width_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
926            this: *mut ffi::GdkSurface,
927            _param_spec: glib::ffi::gpointer,
928            f: glib::ffi::gpointer,
929        ) {
930            let f: &F = &*(f as *const F);
931            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
932        }
933        unsafe {
934            let f: Box_<F> = Box_::new(f);
935            connect_raw(
936                self.as_ptr() as *mut _,
937                c"notify::width".as_ptr() as *const _,
938                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
939                    notify_width_trampoline::<Self, F> as *const (),
940                )),
941                Box_::into_raw(f),
942            )
943        }
944    }
945}
946
947impl<O: IsA<Surface>> SurfaceExt for O {}