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    #[doc(alias = "gdk_surface_set_input_region")]
580    fn set_input_region(&self, region: &cairo::Region) {
581        unsafe {
582            ffi::gdk_surface_set_input_region(
583                self.as_ref().to_glib_none().0,
584                mut_override(region.to_glib_none().0),
585            );
586        }
587    }
588
589    /// Marks a region of the [`Surface`][crate::Surface] as opaque.
590    ///
591    /// For optimisation purposes, compositing window managers may
592    /// like to not draw obscured regions of surfaces, or turn off blending
593    /// during for these regions. With RGB windows with no transparency,
594    /// this is just the shape of the window, but with ARGB32 windows, the
595    /// compositor does not know what regions of the window are transparent
596    /// or not.
597    ///
598    /// This function only works for toplevel surfaces.
599    ///
600    /// GTK will update this property automatically if the @self background
601    /// is opaque, as we know where the opaque regions are. If your surface
602    /// background is not opaque, please update this property in your
603    /// [GtkWidgetClass.css_changed](../gtk4/vfunc.Widget.css_changed.html) handler.
604    ///
605    /// # Deprecated since 4.16
606    ///
607    /// GDK can figure out the opaque parts of a window itself
608    ///   by inspecting the contents that are drawn.
609    /// ## `region`
610    /// a region, or [`None`] to make the entire
611    ///   surface opaque
612    #[cfg_attr(feature = "v4_16", deprecated = "Since 4.16")]
613    #[allow(deprecated)]
614    #[doc(alias = "gdk_surface_set_opaque_region")]
615    fn set_opaque_region(&self, region: Option<&cairo::Region>) {
616        unsafe {
617            ffi::gdk_surface_set_opaque_region(
618                self.as_ref().to_glib_none().0,
619                mut_override(region.to_glib_none().0),
620            );
621        }
622    }
623
624    /// Emitted when @surface starts being present on the monitor.
625    /// ## `monitor`
626    /// the monitor
627    #[doc(alias = "enter-monitor")]
628    fn connect_enter_monitor<F: Fn(&Self, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
629        unsafe extern "C" fn enter_monitor_trampoline<
630            P: IsA<Surface>,
631            F: Fn(&P, &Monitor) + 'static,
632        >(
633            this: *mut ffi::GdkSurface,
634            monitor: *mut ffi::GdkMonitor,
635            f: glib::ffi::gpointer,
636        ) {
637            let f: &F = &*(f as *const F);
638            f(
639                Surface::from_glib_borrow(this).unsafe_cast_ref(),
640                &from_glib_borrow(monitor),
641            )
642        }
643        unsafe {
644            let f: Box_<F> = Box_::new(f);
645            connect_raw(
646                self.as_ptr() as *mut _,
647                c"enter-monitor".as_ptr() as *const _,
648                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
649                    enter_monitor_trampoline::<Self, F> as *const (),
650                )),
651                Box_::into_raw(f),
652            )
653        }
654    }
655
656    /// Emitted when GDK receives an input event for @surface.
657    /// ## `event`
658    /// an input event
659    ///
660    /// # Returns
661    ///
662    /// [`true`] to indicate that the event has been handled
663    #[doc(alias = "event")]
664    fn connect_event<F: Fn(&Self, &Event) -> bool + 'static>(&self, f: F) -> SignalHandlerId {
665        unsafe extern "C" fn event_trampoline<
666            P: IsA<Surface>,
667            F: Fn(&P, &Event) -> bool + 'static,
668        >(
669            this: *mut ffi::GdkSurface,
670            event: *mut ffi::GdkEvent,
671            f: glib::ffi::gpointer,
672        ) -> glib::ffi::gboolean {
673            let f: &F = &*(f as *const F);
674            f(
675                Surface::from_glib_borrow(this).unsafe_cast_ref(),
676                &from_glib_borrow(event),
677            )
678            .into_glib()
679        }
680        unsafe {
681            let f: Box_<F> = Box_::new(f);
682            connect_raw(
683                self.as_ptr() as *mut _,
684                c"event".as_ptr() as *const _,
685                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
686                    event_trampoline::<Self, F> as *const (),
687                )),
688                Box_::into_raw(f),
689            )
690        }
691    }
692
693    /// Emitted when the size of @surface is changed, or when relayout should
694    /// be performed.
695    ///
696    /// Surface size is reported in ”application pixels”, not
697    /// ”device pixels” (see gdk_surface_get_scale_factor()).
698    /// ## `width`
699    /// the current width
700    /// ## `height`
701    /// the current height
702    #[doc(alias = "layout")]
703    fn connect_layout<F: Fn(&Self, i32, i32) + 'static>(&self, f: F) -> SignalHandlerId {
704        unsafe extern "C" fn layout_trampoline<P: IsA<Surface>, F: Fn(&P, i32, i32) + 'static>(
705            this: *mut ffi::GdkSurface,
706            width: std::ffi::c_int,
707            height: std::ffi::c_int,
708            f: glib::ffi::gpointer,
709        ) {
710            let f: &F = &*(f as *const F);
711            f(
712                Surface::from_glib_borrow(this).unsafe_cast_ref(),
713                width,
714                height,
715            )
716        }
717        unsafe {
718            let f: Box_<F> = Box_::new(f);
719            connect_raw(
720                self.as_ptr() as *mut _,
721                c"layout".as_ptr() as *const _,
722                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
723                    layout_trampoline::<Self, F> as *const (),
724                )),
725                Box_::into_raw(f),
726            )
727        }
728    }
729
730    /// Emitted when @surface stops being present on the monitor.
731    /// ## `monitor`
732    /// the monitor
733    #[doc(alias = "leave-monitor")]
734    fn connect_leave_monitor<F: Fn(&Self, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
735        unsafe extern "C" fn leave_monitor_trampoline<
736            P: IsA<Surface>,
737            F: Fn(&P, &Monitor) + 'static,
738        >(
739            this: *mut ffi::GdkSurface,
740            monitor: *mut ffi::GdkMonitor,
741            f: glib::ffi::gpointer,
742        ) {
743            let f: &F = &*(f as *const F);
744            f(
745                Surface::from_glib_borrow(this).unsafe_cast_ref(),
746                &from_glib_borrow(monitor),
747            )
748        }
749        unsafe {
750            let f: Box_<F> = Box_::new(f);
751            connect_raw(
752                self.as_ptr() as *mut _,
753                c"leave-monitor".as_ptr() as *const _,
754                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
755                    leave_monitor_trampoline::<Self, F> as *const (),
756                )),
757                Box_::into_raw(f),
758            )
759        }
760    }
761
762    /// Emitted when part of the surface needs to be redrawn.
763    /// ## `region`
764    /// the region that needs to be redrawn
765    ///
766    /// # Returns
767    ///
768    /// [`true`] to indicate that the signal has been handled
769    #[doc(alias = "render")]
770    fn connect_render<F: Fn(&Self, &cairo::Region) -> bool + 'static>(
771        &self,
772        f: F,
773    ) -> SignalHandlerId {
774        unsafe extern "C" fn render_trampoline<
775            P: IsA<Surface>,
776            F: Fn(&P, &cairo::Region) -> bool + 'static,
777        >(
778            this: *mut ffi::GdkSurface,
779            region: *mut cairo::ffi::cairo_region_t,
780            f: glib::ffi::gpointer,
781        ) -> glib::ffi::gboolean {
782            let f: &F = &*(f as *const F);
783            f(
784                Surface::from_glib_borrow(this).unsafe_cast_ref(),
785                &from_glib_borrow(region),
786            )
787            .into_glib()
788        }
789        unsafe {
790            let f: Box_<F> = Box_::new(f);
791            connect_raw(
792                self.as_ptr() as *mut _,
793                c"render".as_ptr() as *const _,
794                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
795                    render_trampoline::<Self, F> as *const (),
796                )),
797                Box_::into_raw(f),
798            )
799        }
800    }
801
802    #[doc(alias = "cursor")]
803    fn connect_cursor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
804        unsafe extern "C" fn notify_cursor_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
805            this: *mut ffi::GdkSurface,
806            _param_spec: glib::ffi::gpointer,
807            f: glib::ffi::gpointer,
808        ) {
809            let f: &F = &*(f as *const F);
810            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
811        }
812        unsafe {
813            let f: Box_<F> = Box_::new(f);
814            connect_raw(
815                self.as_ptr() as *mut _,
816                c"notify::cursor".as_ptr() as *const _,
817                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
818                    notify_cursor_trampoline::<Self, F> as *const (),
819                )),
820                Box_::into_raw(f),
821            )
822        }
823    }
824
825    #[doc(alias = "height")]
826    fn connect_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
827        unsafe extern "C" fn notify_height_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
828            this: *mut ffi::GdkSurface,
829            _param_spec: glib::ffi::gpointer,
830            f: glib::ffi::gpointer,
831        ) {
832            let f: &F = &*(f as *const F);
833            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
834        }
835        unsafe {
836            let f: Box_<F> = Box_::new(f);
837            connect_raw(
838                self.as_ptr() as *mut _,
839                c"notify::height".as_ptr() as *const _,
840                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
841                    notify_height_trampoline::<Self, F> as *const (),
842                )),
843                Box_::into_raw(f),
844            )
845        }
846    }
847
848    #[doc(alias = "mapped")]
849    fn connect_mapped_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
850        unsafe extern "C" fn notify_mapped_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
851            this: *mut ffi::GdkSurface,
852            _param_spec: glib::ffi::gpointer,
853            f: glib::ffi::gpointer,
854        ) {
855            let f: &F = &*(f as *const F);
856            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
857        }
858        unsafe {
859            let f: Box_<F> = Box_::new(f);
860            connect_raw(
861                self.as_ptr() as *mut _,
862                c"notify::mapped".as_ptr() as *const _,
863                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
864                    notify_mapped_trampoline::<Self, F> as *const (),
865                )),
866                Box_::into_raw(f),
867            )
868        }
869    }
870
871    #[cfg(feature = "v4_12")]
872    #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
873    #[doc(alias = "scale")]
874    fn connect_scale_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
875        unsafe extern "C" fn notify_scale_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
876            this: *mut ffi::GdkSurface,
877            _param_spec: glib::ffi::gpointer,
878            f: glib::ffi::gpointer,
879        ) {
880            let f: &F = &*(f as *const F);
881            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
882        }
883        unsafe {
884            let f: Box_<F> = Box_::new(f);
885            connect_raw(
886                self.as_ptr() as *mut _,
887                c"notify::scale".as_ptr() as *const _,
888                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
889                    notify_scale_trampoline::<Self, F> as *const (),
890                )),
891                Box_::into_raw(f),
892            )
893        }
894    }
895
896    #[doc(alias = "scale-factor")]
897    fn connect_scale_factor_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
898        unsafe extern "C" fn notify_scale_factor_trampoline<
899            P: IsA<Surface>,
900            F: Fn(&P) + 'static,
901        >(
902            this: *mut ffi::GdkSurface,
903            _param_spec: glib::ffi::gpointer,
904            f: glib::ffi::gpointer,
905        ) {
906            let f: &F = &*(f as *const F);
907            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
908        }
909        unsafe {
910            let f: Box_<F> = Box_::new(f);
911            connect_raw(
912                self.as_ptr() as *mut _,
913                c"notify::scale-factor".as_ptr() as *const _,
914                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
915                    notify_scale_factor_trampoline::<Self, F> as *const (),
916                )),
917                Box_::into_raw(f),
918            )
919        }
920    }
921
922    #[doc(alias = "width")]
923    fn connect_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
924        unsafe extern "C" fn notify_width_trampoline<P: IsA<Surface>, F: Fn(&P) + 'static>(
925            this: *mut ffi::GdkSurface,
926            _param_spec: glib::ffi::gpointer,
927            f: glib::ffi::gpointer,
928        ) {
929            let f: &F = &*(f as *const F);
930            f(Surface::from_glib_borrow(this).unsafe_cast_ref())
931        }
932        unsafe {
933            let f: Box_<F> = Box_::new(f);
934            connect_raw(
935                self.as_ptr() as *mut _,
936                c"notify::width".as_ptr() as *const _,
937                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
938                    notify_width_trampoline::<Self, F> as *const (),
939                )),
940                Box_::into_raw(f),
941            )
942        }
943    }
944}
945
946impl<O: IsA<Surface>> SurfaceExt for O {}