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
// 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 glib::object::IsA;
use glib::translate::*;
use std::fmt;
use std::mem;
use std::ptr;

glib::wrapper! {
    ///
    ///
    /// # Implements
    ///
    /// [`trait@gdk::prelude::DisplayExt`]
    #[doc(alias = "GdkX11Display")]
    pub struct X11Display(Object<ffi::GdkX11Display, ffi::GdkX11DisplayClass>) @extends gdk::Display;

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

impl X11Display {
    //#[doc(alias = "gdk_x11_display_broadcast_startup_message")]
    //pub fn broadcast_startup_message(&self, message_type: &str, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
    //    unsafe { TODO: call ffi:gdk_x11_display_broadcast_startup_message() }
    //}

    /// Pops the error trap pushed by [`error_trap_push()`][Self::error_trap_push()].
    /// Will XSync() if necessary and will always block until
    /// the error is known to have occurred or not occurred,
    /// so the error code can be returned.
    ///
    /// If you don’t need to use the return value,
    /// [`error_trap_pop_ignored()`][Self::error_trap_pop_ignored()] would be more efficient.
    ///
    /// See `gdk_error_trap_pop()` for the all-displays-at-once
    /// equivalent.
    ///
    /// # Returns
    ///
    /// X error code or 0 on success
    #[doc(alias = "gdk_x11_display_error_trap_pop")]
    pub fn error_trap_pop(&self) -> i32 {
        unsafe { ffi::gdk_x11_display_error_trap_pop(self.to_glib_none().0) }
    }

    /// Pops the error trap pushed by [`error_trap_push()`][Self::error_trap_push()].
    /// Does not block to see if an error occurred; merely records the
    /// range of requests to ignore errors for, and ignores those errors
    /// if they arrive asynchronously.
    ///
    /// See `gdk_error_trap_pop_ignored()` for the all-displays-at-once
    /// equivalent.
    #[doc(alias = "gdk_x11_display_error_trap_pop_ignored")]
    pub fn error_trap_pop_ignored(&self) {
        unsafe {
            ffi::gdk_x11_display_error_trap_pop_ignored(self.to_glib_none().0);
        }
    }

    /// Begins a range of X requests on `self` for which X error events
    /// will be ignored. Unignored errors (when no trap is pushed) will abort
    /// the application. Use [`error_trap_pop()`][Self::error_trap_pop()] or
    /// [`error_trap_pop_ignored()`][Self::error_trap_pop_ignored()]to lift a trap pushed
    /// with this function.
    ///
    /// See also `gdk_error_trap_push()` to push a trap on all displays.
    #[doc(alias = "gdk_x11_display_error_trap_push")]
    pub fn error_trap_push(&self) {
        unsafe {
            ffi::gdk_x11_display_error_trap_push(self.to_glib_none().0);
        }
    }

    /// Gets the startup notification ID for a display.
    ///
    /// # Returns
    ///
    /// the startup notification ID for `self`
    #[doc(alias = "gdk_x11_display_get_startup_notification_id")]
    #[doc(alias = "get_startup_notification_id")]
    pub fn startup_notification_id(&self) -> Option<glib::GString> {
        unsafe {
            from_glib_none(ffi::gdk_x11_display_get_startup_notification_id(
                self.to_glib_none().0,
            ))
        }
    }

    /// Returns the timestamp of the last user interaction on
    /// `self`. The timestamp is taken from events caused
    /// by user interaction such as key presses or pointer
    /// movements. See [`X11Window::set_user_time()`][crate::X11Window::set_user_time()].
    ///
    /// # Returns
    ///
    /// the timestamp of the last user interaction
    #[doc(alias = "gdk_x11_display_get_user_time")]
    #[doc(alias = "get_user_time")]
    pub fn user_time(&self) -> u32 {
        unsafe { ffi::gdk_x11_display_get_user_time(self.to_glib_none().0) }
    }

    /// Call XGrabServer() on `self`.
    /// To ungrab the display again, use [`ungrab()`][Self::ungrab()].
    ///
    /// [`grab()`][Self::grab()]/[`ungrab()`][Self::ungrab()] calls can be nested.
    #[doc(alias = "gdk_x11_display_grab")]
    pub fn grab(&self) {
        unsafe {
            ffi::gdk_x11_display_grab(self.to_glib_none().0);
        }
    }

    /// Sets the cursor theme from which the images for cursor
    /// should be taken.
    ///
    /// If the windowing system supports it, existing cursors created
    /// with `gdk_cursor_new()`, [`gdk::Cursor::for_display()`][crate::gdk::Cursor::for_display()] and
    /// [`gdk::Cursor::from_name()`][crate::gdk::Cursor::from_name()] are updated to reflect the theme
    /// change. Custom cursors constructed with
    /// [`gdk::Cursor::from_pixbuf()`][crate::gdk::Cursor::from_pixbuf()] will have to be handled
    /// by the application (GTK+ applications can learn about
    /// cursor theme changes by listening for change notification
    /// for the corresponding `GtkSetting`).
    /// ## `theme`
    /// the name of the cursor theme to use, or [`None`] to unset
    ///  a previously set value
    /// ## `size`
    /// the cursor size to use, or 0 to keep the previous size
    #[doc(alias = "gdk_x11_display_set_cursor_theme")]
    pub fn set_cursor_theme(&self, theme: Option<&str>, size: i32) {
        unsafe {
            ffi::gdk_x11_display_set_cursor_theme(
                self.to_glib_none().0,
                theme.to_glib_none().0,
                size,
            );
        }
    }

    /// Sets the startup notification ID for a display.
    ///
    /// This is usually taken from the value of the DESKTOP_STARTUP_ID
    /// environment variable, but in some cases (such as the application not
    /// being launched using `exec()`) it can come from other sources.
    ///
    /// If the ID contains the string "_TIME" then the portion following that
    /// string is taken to be the X11 timestamp of the event that triggered
    /// the application to be launched and the GDK current event time is set
    /// accordingly.
    ///
    /// The startup ID is also what is used to signal that the startup is
    /// complete (for example, when opening a window or when calling
    /// `gdk_notify_startup_complete()`).
    /// ## `startup_id`
    /// the startup notification ID (must be valid utf8)
    #[doc(alias = "gdk_x11_display_set_startup_notification_id")]
    pub fn set_startup_notification_id(&self, startup_id: &str) {
        unsafe {
            ffi::gdk_x11_display_set_startup_notification_id(
                self.to_glib_none().0,
                startup_id.to_glib_none().0,
            );
        }
    }

    /// Forces a specific window scale for all windows on this display,
    /// instead of using the default or user configured scale. This
    /// is can be used to disable scaling support by setting `scale` to
    /// 1, or to programmatically set the window scale.
    ///
    /// Once the scale is set by this call it will not change in response
    /// to later user configuration changes.
    /// ## `scale`
    /// The new scale value
    #[doc(alias = "gdk_x11_display_set_window_scale")]
    pub fn set_window_scale(&self, scale: i32) {
        unsafe {
            ffi::gdk_x11_display_set_window_scale(self.to_glib_none().0, scale);
        }
    }

    /// Convert a string from the encoding of the current
    /// locale into a form suitable for storing in a window property.
    /// ## `str`
    /// a nul-terminated string
    ///
    /// # Returns
    ///
    /// 0 upon success, non-zero upon failure
    ///
    /// ## `encoding`
    /// location to store the encoding atom
    ///  (to be used as the type for the property)
    ///
    /// ## `format`
    /// location to store the format of the property
    ///
    /// ## `ctext`
    /// location to store newly
    ///  allocated data for the property
    #[doc(alias = "gdk_x11_display_string_to_compound_text")]
    pub fn string_to_compound_text(&self, str: &str) -> (i32, gdk::Atom, i32, Vec<u8>) {
        unsafe {
            let mut encoding = gdk::Atom::uninitialized();
            let mut format = mem::MaybeUninit::uninit();
            let mut ctext = ptr::null_mut();
            let mut length = mem::MaybeUninit::uninit();
            let ret = ffi::gdk_x11_display_string_to_compound_text(
                self.to_glib_none().0,
                str.to_glib_none().0,
                encoding.to_glib_none_mut().0,
                format.as_mut_ptr(),
                &mut ctext,
                length.as_mut_ptr(),
            );
            (
                ret,
                encoding,
                format.assume_init(),
                FromGlibContainer::from_glib_full_num(ctext, length.assume_init() as usize),
            )
        }
    }

    /// Ungrab `self` after it has been grabbed with
    /// [`grab()`][Self::grab()].
    #[doc(alias = "gdk_x11_display_ungrab")]
    pub fn ungrab(&self) {
        unsafe {
            ffi::gdk_x11_display_ungrab(self.to_glib_none().0);
        }
    }

    /// Converts from UTF-8 to compound text.
    /// ## `str`
    /// a UTF-8 string
    ///
    /// # Returns
    ///
    /// [`true`] if the conversion succeeded,
    ///  otherwise [`false`]
    ///
    /// ## `encoding`
    /// location to store resulting encoding
    ///
    /// ## `format`
    /// location to store format of the result
    ///
    /// ## `ctext`
    /// location to store the data of the result
    #[doc(alias = "gdk_x11_display_utf8_to_compound_text")]
    pub fn utf8_to_compound_text(&self, str: &str) -> Option<(gdk::Atom, i32, Vec<u8>)> {
        unsafe {
            let mut encoding = gdk::Atom::uninitialized();
            let mut format = mem::MaybeUninit::uninit();
            let mut ctext = ptr::null_mut();
            let mut length = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gdk_x11_display_utf8_to_compound_text(
                self.to_glib_none().0,
                str.to_glib_none().0,
                encoding.to_glib_none_mut().0,
                format.as_mut_ptr(),
                &mut ctext,
                length.as_mut_ptr(),
            ));
            if ret {
                Some((
                    encoding,
                    format.assume_init(),
                    FromGlibContainer::from_glib_full_num(ctext, length.assume_init() as usize),
                ))
            } else {
                None
            }
        }
    }

    /// Retrieves the version of the GLX implementation.
    /// ## `display`
    /// a [`gdk::Display`][crate::gdk::Display]
    ///
    /// # Returns
    ///
    /// [`true`] if GLX is available
    ///
    /// ## `major`
    /// return location for the GLX major version
    ///
    /// ## `minor`
    /// return location for the GLX minor version
    #[doc(alias = "gdk_x11_display_get_glx_version")]
    #[doc(alias = "get_glx_version")]
    pub fn glx_version(display: &impl IsA<gdk::Display>) -> Option<(i32, i32)> {
        assert_initialized_main_thread!();
        unsafe {
            let mut major = mem::MaybeUninit::uninit();
            let mut minor = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gdk_x11_display_get_glx_version(
                display.as_ref().to_glib_none().0,
                major.as_mut_ptr(),
                minor.as_mut_ptr(),
            ));
            if ret {
                Some((major.assume_init(), minor.assume_init()))
            } else {
                None
            }
        }
    }
}

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