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