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