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
// 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::CursorType;
use crate::Display;
use glib::translate::*;
use std::fmt;
use std::mem;

glib::wrapper! {
    /// A [`Cursor`][crate::Cursor] represents a cursor. Its contents are private.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    #[doc(alias = "GdkCursor")]
    pub struct Cursor(Object<ffi::GdkCursor>);

    match fn {
        type_ => || ffi::gdk_cursor_get_type(),
    }
}

impl Cursor {
    /// Creates a new cursor from the set of builtin cursors.
    /// ## `display`
    /// the [`Display`][crate::Display] for which the cursor will be created
    /// ## `cursor_type`
    /// cursor to create
    ///
    /// # Returns
    ///
    /// a new [`Cursor`][crate::Cursor]
    #[doc(alias = "gdk_cursor_new_for_display")]
    #[doc(alias = "new_for_display")]
    pub fn for_display(display: &Display, cursor_type: CursorType) -> Cursor {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::gdk_cursor_new_for_display(
                display.to_glib_none().0,
                cursor_type.into_glib(),
            ))
        }
    }

    /// Creates a new cursor by looking up `name` in the current cursor
    /// theme.
    ///
    /// A recommended set of cursor names that will work across different
    /// platforms can be found in the CSS specification:
    /// - "none"
    /// - ![](default_cursor.png) "default"
    /// - ![](help_cursor.png) "help"
    /// - ![](pointer_cursor.png) "pointer"
    /// - ![](context_menu_cursor.png) "context-menu"
    /// - ![](progress_cursor.png) "progress"
    /// - ![](wait_cursor.png) "wait"
    /// - ![](cell_cursor.png) "cell"
    /// - ![](crosshair_cursor.png) "crosshair"
    /// - ![](text_cursor.png) "text"
    /// - ![](vertical_text_cursor.png) "vertical-text"
    /// - ![](alias_cursor.png) "alias"
    /// - ![](copy_cursor.png) "copy"
    /// - ![](no_drop_cursor.png) "no-drop"
    /// - ![](move_cursor.png) "move"
    /// - ![](not_allowed_cursor.png) "not-allowed"
    /// - ![](grab_cursor.png) "grab"
    /// - ![](grabbing_cursor.png) "grabbing"
    /// - ![](all_scroll_cursor.png) "all-scroll"
    /// - ![](col_resize_cursor.png) "col-resize"
    /// - ![](row_resize_cursor.png) "row-resize"
    /// - ![](n_resize_cursor.png) "n-resize"
    /// - ![](e_resize_cursor.png) "e-resize"
    /// - ![](s_resize_cursor.png) "s-resize"
    /// - ![](w_resize_cursor.png) "w-resize"
    /// - ![](ne_resize_cursor.png) "ne-resize"
    /// - ![](nw_resize_cursor.png) "nw-resize"
    /// - ![](sw_resize_cursor.png) "sw-resize"
    /// - ![](se_resize_cursor.png) "se-resize"
    /// - ![](ew_resize_cursor.png) "ew-resize"
    /// - ![](ns_resize_cursor.png) "ns-resize"
    /// - ![](nesw_resize_cursor.png) "nesw-resize"
    /// - ![](nwse_resize_cursor.png) "nwse-resize"
    /// - ![](zoom_in_cursor.png) "zoom-in"
    /// - ![](zoom_out_cursor.png) "zoom-out"
    /// ## `display`
    /// the [`Display`][crate::Display] for which the cursor will be created
    /// ## `name`
    /// the name of the cursor
    ///
    /// # Returns
    ///
    /// a new [`Cursor`][crate::Cursor], or [`None`] if there is no
    ///  cursor with the given name
    #[doc(alias = "gdk_cursor_new_from_name")]
    #[doc(alias = "new_from_name")]
    pub fn from_name(display: &Display, name: &str) -> Option<Cursor> {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::gdk_cursor_new_from_name(
                display.to_glib_none().0,
                name.to_glib_none().0,
            ))
        }
    }

    /// Creates a new cursor from a pixbuf.
    ///
    /// Not all GDK backends support RGBA cursors. If they are not
    /// supported, a monochrome approximation will be displayed.
    /// The functions [`Display::supports_cursor_alpha()`][crate::Display::supports_cursor_alpha()] and
    /// [`Display::supports_cursor_color()`][crate::Display::supports_cursor_color()] can be used to determine
    /// whether RGBA cursors are supported;
    /// [`Display::default_cursor_size()`][crate::Display::default_cursor_size()] and
    /// [`Display::maximal_cursor_size()`][crate::Display::maximal_cursor_size()] give information about
    /// cursor sizes.
    ///
    /// If `x` or `y` are `-1`, the pixbuf must have
    /// options named “x_hot” and “y_hot”, resp., containing
    /// integer values between `0` and the width resp. height of
    /// the pixbuf. (Since: 3.0)
    ///
    /// On the X backend, support for RGBA cursors requires a
    /// sufficently new version of the X Render extension.
    /// ## `display`
    /// the [`Display`][crate::Display] for which the cursor will be created
    /// ## `pixbuf`
    /// the [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] containing the cursor image
    /// ## `x`
    /// the horizontal offset of the “hotspot” of the cursor.
    /// ## `y`
    /// the vertical offset of the “hotspot” of the cursor.
    ///
    /// # Returns
    ///
    /// a new [`Cursor`][crate::Cursor].
    #[doc(alias = "gdk_cursor_new_from_pixbuf")]
    #[doc(alias = "new_from_pixbuf")]
    pub fn from_pixbuf(display: &Display, pixbuf: &gdk_pixbuf::Pixbuf, x: i32, y: i32) -> Cursor {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::gdk_cursor_new_from_pixbuf(
                display.to_glib_none().0,
                pixbuf.to_glib_none().0,
                x,
                y,
            ))
        }
    }

    /// Creates a new cursor from a cairo image surface.
    ///
    /// Not all GDK backends support RGBA cursors. If they are not
    /// supported, a monochrome approximation will be displayed.
    /// The functions [`Display::supports_cursor_alpha()`][crate::Display::supports_cursor_alpha()] and
    /// [`Display::supports_cursor_color()`][crate::Display::supports_cursor_color()] can be used to determine
    /// whether RGBA cursors are supported;
    /// [`Display::default_cursor_size()`][crate::Display::default_cursor_size()] and
    /// [`Display::maximal_cursor_size()`][crate::Display::maximal_cursor_size()] give information about
    /// cursor sizes.
    ///
    /// On the X backend, support for RGBA cursors requires a
    /// sufficently new version of the X Render extension.
    /// ## `display`
    /// the [`Display`][crate::Display] for which the cursor will be created
    /// ## `surface`
    /// the cairo image surface containing the cursor pixel data
    /// ## `x`
    /// the horizontal offset of the “hotspot” of the cursor
    /// ## `y`
    /// the vertical offset of the “hotspot” of the cursor
    ///
    /// # Returns
    ///
    /// a new [`Cursor`][crate::Cursor].
    #[doc(alias = "gdk_cursor_new_from_surface")]
    #[doc(alias = "new_from_surface")]
    pub fn from_surface(display: &Display, surface: &cairo::Surface, x: f64, y: f64) -> Cursor {
        skip_assert_initialized!();
        unsafe {
            from_glib_full(ffi::gdk_cursor_new_from_surface(
                display.to_glib_none().0,
                mut_override(surface.to_glib_none().0),
                x,
                y,
            ))
        }
    }

    /// Returns the cursor type for this cursor.
    ///
    /// # Returns
    ///
    /// a [`CursorType`][crate::CursorType]
    #[doc(alias = "gdk_cursor_get_cursor_type")]
    #[doc(alias = "get_cursor_type")]
    pub fn cursor_type(&self) -> CursorType {
        unsafe { from_glib(ffi::gdk_cursor_get_cursor_type(self.to_glib_none().0)) }
    }

    /// Returns the display on which the [`Cursor`][crate::Cursor] is defined.
    ///
    /// # Returns
    ///
    /// the [`Display`][crate::Display] associated to `self`
    #[doc(alias = "gdk_cursor_get_display")]
    #[doc(alias = "get_display")]
    pub fn display(&self) -> Display {
        unsafe { from_glib_none(ffi::gdk_cursor_get_display(self.to_glib_none().0)) }
    }

    /// Returns a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] with the image used to display the cursor.
    ///
    /// Note that depending on the capabilities of the windowing system and
    /// on the cursor, GDK may not be able to obtain the image data. In this
    /// case, [`None`] is returned.
    ///
    /// # Returns
    ///
    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] representing
    ///  `self`, or [`None`]
    #[doc(alias = "gdk_cursor_get_image")]
    #[doc(alias = "get_image")]
    pub fn image(&self) -> Option<gdk_pixbuf::Pixbuf> {
        unsafe { from_glib_full(ffi::gdk_cursor_get_image(self.to_glib_none().0)) }
    }

    /// Returns a cairo image surface with the image used to display the cursor.
    ///
    /// Note that depending on the capabilities of the windowing system and
    /// on the cursor, GDK may not be able to obtain the image data. In this
    /// case, [`None`] is returned.
    ///
    /// # Returns
    ///
    /// a [`cairo::Surface`][crate::cairo::Surface]
    ///  representing `self`, or [`None`]
    ///
    /// ## `x_hot`
    /// Location to store the hotspot x position,
    ///  or [`None`]
    ///
    /// ## `y_hot`
    /// Location to store the hotspot y position,
    ///  or [`None`]
    #[doc(alias = "gdk_cursor_get_surface")]
    #[doc(alias = "get_surface")]
    pub fn surface(&self) -> (Option<cairo::Surface>, f64, f64) {
        unsafe {
            let mut x_hot = mem::MaybeUninit::uninit();
            let mut y_hot = mem::MaybeUninit::uninit();
            let ret = from_glib_full(ffi::gdk_cursor_get_surface(
                self.to_glib_none().0,
                x_hot.as_mut_ptr(),
                y_hot.as_mut_ptr(),
            ));
            let x_hot = x_hot.assume_init();
            let y_hot = y_hot.assume_init();
            (ret, x_hot, y_hot)
        }
    }
}

impl fmt::Display for Cursor {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.write_str("Cursor")
    }
}