gdk4/auto/functions.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
5use crate::{ffi, Texture};
6use glib::{prelude::*, translate::*};
7
8/// Canonicalizes the given mime type and interns the result.
9///
10/// If @string is not a valid mime type, [`None`] is returned instead.
11/// See RFC 2048 for the syntax if mime types.
12/// ## `string`
13/// string of a potential mime type
14///
15/// # Returns
16///
17/// An interned string for the canonicalized
18/// mime type or [`None`] if the string wasn't a valid mime type
19#[doc(alias = "gdk_intern_mime_type")]
20pub fn intern_mime_type(string: &str) -> Option<glib::GString> {
21 assert_initialized_main_thread!();
22 unsafe { from_glib_none(ffi::gdk_intern_mime_type(string.to_glib_none().0)) }
23}
24
25/// Transfers image data from a [`cairo::Surface`][crate::cairo::Surface] and converts it
26/// to a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
27///
28/// This allows you to efficiently read individual pixels from cairo surfaces.
29///
30/// This function will create an RGB pixbuf with 8 bits per channel.
31/// The pixbuf will contain an alpha channel if the @surface contains one.
32///
33/// # Deprecated since 4.12
34///
35/// Use [`Texture`][crate::Texture] and subclasses instead
36/// cairo surfaces and pixbufs
37/// ## `surface`
38/// surface to copy from
39/// ## `src_x`
40/// Source X coordinate within @surface
41/// ## `src_y`
42/// Source Y coordinate within @surface
43/// ## `width`
44/// Width in pixels of region to get
45/// ## `height`
46/// Height in pixels of region to get
47///
48/// # Returns
49///
50/// A newly-created pixbuf with a
51/// reference count of 1
52#[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
53#[allow(deprecated)]
54#[doc(alias = "gdk_pixbuf_get_from_surface")]
55pub fn pixbuf_get_from_surface(
56 surface: &cairo::Surface,
57 src_x: i32,
58 src_y: i32,
59 width: i32,
60 height: i32,
61) -> Option<gdk_pixbuf::Pixbuf> {
62 assert_initialized_main_thread!();
63 unsafe {
64 from_glib_full(ffi::gdk_pixbuf_get_from_surface(
65 mut_override(surface.to_glib_none().0),
66 src_x,
67 src_y,
68 width,
69 height,
70 ))
71 }
72}
73
74/// Creates a new pixbuf from @texture.
75///
76/// This should generally not be used in newly written code as later
77/// stages will almost certainly convert the pixbuf back into a texture
78/// to draw it on screen.
79///
80/// # Deprecated since 4.12
81///
82/// Use [`Texture`][crate::Texture] and subclasses instead
83/// cairo surfaces and pixbufs
84/// ## `texture`
85/// a [`Texture`][crate::Texture]
86///
87/// # Returns
88///
89/// a new [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
90#[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
91#[allow(deprecated)]
92#[doc(alias = "gdk_pixbuf_get_from_texture")]
93pub fn pixbuf_get_from_texture(texture: &impl IsA<Texture>) -> Option<gdk_pixbuf::Pixbuf> {
94 skip_assert_initialized!();
95 unsafe {
96 from_glib_full(ffi::gdk_pixbuf_get_from_texture(
97 texture.as_ref().to_glib_none().0,
98 ))
99 }
100}
101
102/// Sets a list of backends that GDK should try to use.
103///
104/// This can be useful if your application does not
105/// work with certain GDK backends.
106///
107/// By default, GDK tries all included backends.
108///
109/// For example:
110///
111/// **⚠️ The following code is in c ⚠️**
112///
113/// ```c
114/// gdk_set_allowed_backends ("wayland,macos,*");
115/// ```
116///
117/// instructs GDK to try the Wayland backend first, followed by the
118/// MacOs backend, and then all others.
119///
120/// If the `GDK_BACKEND` environment variable is set, it determines
121/// what backends are tried in what order, while still respecting the
122/// set of allowed backends that are specified by this function.
123///
124/// The possible backend names are:
125///
126/// - `broadway`
127/// - `macos`
128/// - `wayland`.
129/// - `win32`
130/// - `x11`
131///
132/// You can also include a `*` in the list to try all remaining backends.
133///
134/// This call must happen prior to functions that open a display, such
135/// as [`Display::open()`][crate::Display::open()], `gtk_init()`, or `gtk_init_check()`
136/// in order to take effect.
137/// ## `backends`
138/// a comma-separated list of backends
139#[doc(alias = "gdk_set_allowed_backends")]
140pub fn set_allowed_backends(backends: &str) {
141 skip_assert_initialized!();
142 unsafe {
143 ffi::gdk_set_allowed_backends(backends.to_glib_none().0);
144 }
145}
146
147/// Convert from a Unicode character to a key symbol.
148/// ## `wc`
149/// a Unicode character
150///
151/// # Returns
152///
153/// the corresponding GDK key symbol, if one exists.
154/// or, if there is no corresponding symbol, wc | 0x01000000
155#[doc(alias = "gdk_unicode_to_keyval")]
156pub fn unicode_to_keyval(wc: u32) -> u32 {
157 assert_initialized_main_thread!();
158 unsafe { ffi::gdk_unicode_to_keyval(wc) }
159}