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
// 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

use crate::Texture;
use glib::object::IsA;
use glib::translate::*;

/// Canonicalizes the given mime type and interns the result.
///
/// If @string is not a valid mime type, [`None`] is returned instead.
/// See RFC 2048 for the syntax if mime types.
/// ## `string`
/// string of a potential mime type
///
/// # Returns
///
/// An interned string for the canonicalized
///   mime type or [`None`] if the string wasn't a valid mime type
#[doc(alias = "gdk_intern_mime_type")]
pub fn intern_mime_type(string: &str) -> Option<glib::GString> {
    assert_initialized_main_thread!();
    unsafe { from_glib_none(ffi::gdk_intern_mime_type(string.to_glib_none().0)) }
}

/// Transfers image data from a [`cairo::Surface`][crate::cairo::Surface] and converts it
/// to a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
///
/// This allows you to efficiently read individual pixels from cairo surfaces.
///
/// This function will create an RGB pixbuf with 8 bits per channel.
/// The pixbuf will contain an alpha channel if the @surface contains one.
/// ## `surface`
/// surface to copy from
/// ## `src_x`
/// Source X coordinate within @surface
/// ## `src_y`
/// Source Y coordinate within @surface
/// ## `width`
/// Width in pixels of region to get
/// ## `height`
/// Height in pixels of region to get
///
/// # Returns
///
/// A newly-created pixbuf with a
///   reference count of 1
#[doc(alias = "gdk_pixbuf_get_from_surface")]
pub fn pixbuf_get_from_surface(
    surface: &cairo::Surface,
    src_x: i32,
    src_y: i32,
    width: i32,
    height: i32,
) -> Option<gdk_pixbuf::Pixbuf> {
    assert_initialized_main_thread!();
    unsafe {
        from_glib_full(ffi::gdk_pixbuf_get_from_surface(
            mut_override(surface.to_glib_none().0),
            src_x,
            src_y,
            width,
            height,
        ))
    }
}

/// Creates a new pixbuf from @texture.
///
/// This should generally not be used in newly written code as later
/// stages will almost certainly convert the pixbuf back into a texture
/// to draw it on screen.
/// ## `texture`
/// a [`Texture`][crate::Texture]
///
/// # Returns
///
/// a new [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
#[doc(alias = "gdk_pixbuf_get_from_texture")]
pub fn pixbuf_get_from_texture(texture: &impl IsA<Texture>) -> Option<gdk_pixbuf::Pixbuf> {
    skip_assert_initialized!();
    unsafe {
        from_glib_full(ffi::gdk_pixbuf_get_from_texture(
            texture.as_ref().to_glib_none().0,
        ))
    }
}

/// Sets a list of backends that GDK should try to use.
///
/// This can be useful if your application does not
/// work with certain GDK backends.
///
/// By default, GDK tries all included backends.
///
/// For example:
///
/// **⚠️ The following code is in c ⚠️**
///
/// ```c
/// gdk_set_allowed_backends ("wayland,macos,*");
/// ```
///
/// instructs GDK to try the Wayland backend first, followed by the
/// MacOs backend, and then all others.
///
/// If the `GDK_BACKEND` environment variable is set, it determines
/// what backends are tried in what order, while still respecting the
/// set of allowed backends that are specified by this function.
///
/// The possible backend names are:
///
///   - `broadway`
///   - `macos`
///   - `wayland`.
///   - `win32`
///   - `x11`
///
/// You can also include a `*` in the list to try all remaining backends.
///
/// This call must happen prior to functions that open a display, such
/// as [`Display::open()`][crate::Display::open()], `gtk_init()`, or `gtk_init_check()`
/// in order to take effect.
/// ## `backends`
/// a comma-separated list of backends
#[doc(alias = "gdk_set_allowed_backends")]
pub fn set_allowed_backends(backends: &str) {
    skip_assert_initialized!();
    unsafe {
        ffi::gdk_set_allowed_backends(backends.to_glib_none().0);
    }
}

/// Convert from a Unicode character to a key symbol.
/// ## `wc`
/// a Unicode character
///
/// # Returns
///
/// the corresponding GDK key symbol, if one exists.
///   or, if there is no corresponding symbol, wc | 0x01000000
#[doc(alias = "gdk_unicode_to_keyval")]
pub fn unicode_to_keyval(wc: u32) -> u32 {
    assert_initialized_main_thread!();
    unsafe { ffi::gdk_unicode_to_keyval(wc) }
}