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