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