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