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
// 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 AppLaunchContext;
use Atom;
use Device;
use DeviceManager;
use Event;
#[cfg(any(feature = "v3_22", feature = "dox"))]
use Monitor;
use Screen;
#[cfg(any(feature = "v3_20", feature = "dox"))]
use Seat;
use Window;
use ffi;
use glib::GString;
use glib::object::IsA;
use glib::object::ObjectType;
use glib::signal::SignalHandlerId;
use glib::signal::connect_raw;
use glib::translate::*;
use glib_ffi;
use std::boxed::Box as Box_;
use std::fmt;
use std::mem;
use std::mem::transmute;

glib_wrapper! {
    pub struct Display(Object<ffi::GdkDisplay, DisplayClass>);

    match fn {
        get_type => || ffi::gdk_display_get_type(),
    }
}

impl Display {
    pub fn beep(&self) {
        unsafe {
            ffi::gdk_display_beep(self.to_glib_none().0);
        }
    }

    pub fn close(&self) {
        unsafe {
            ffi::gdk_display_close(self.to_glib_none().0);
        }
    }

    pub fn device_is_grabbed(&self, device: &Device) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_device_is_grabbed(self.to_glib_none().0, device.to_glib_none().0))
        }
    }

    pub fn flush(&self) {
        unsafe {
            ffi::gdk_display_flush(self.to_glib_none().0);
        }
    }

    pub fn get_app_launch_context(&self) -> Option<AppLaunchContext> {
        unsafe {
            from_glib_full(ffi::gdk_display_get_app_launch_context(self.to_glib_none().0))
        }
    }

    pub fn get_default_cursor_size(&self) -> u32 {
        unsafe {
            ffi::gdk_display_get_default_cursor_size(self.to_glib_none().0)
        }
    }

    pub fn get_default_group(&self) -> Window {
        unsafe {
            from_glib_none(ffi::gdk_display_get_default_group(self.to_glib_none().0))
        }
    }

    pub fn get_default_screen(&self) -> Screen {
        unsafe {
            from_glib_none(ffi::gdk_display_get_default_screen(self.to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn get_default_seat(&self) -> Option<Seat> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_default_seat(self.to_glib_none().0))
        }
    }

    #[cfg_attr(feature = "v3_20", deprecated)]
    pub fn get_device_manager(&self) -> Option<DeviceManager> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_device_manager(self.to_glib_none().0))
        }
    }

    pub fn get_event(&self) -> Option<Event> {
        unsafe {
            from_glib_full(ffi::gdk_display_get_event(self.to_glib_none().0))
        }
    }

    pub fn get_maximal_cursor_size(&self) -> (u32, u32) {
        unsafe {
            let mut width = mem::uninitialized();
            let mut height = mem::uninitialized();
            ffi::gdk_display_get_maximal_cursor_size(self.to_glib_none().0, &mut width, &mut height);
            (width, height)
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_monitor(&self, monitor_num: i32) -> Option<Monitor> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_monitor(self.to_glib_none().0, monitor_num))
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<Monitor> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_monitor_at_point(self.to_glib_none().0, x, y))
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_monitor_at_window<P: IsA<Window>>(&self, window: &P) -> Option<Monitor> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_monitor_at_window(self.to_glib_none().0, window.as_ref().to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_n_monitors(&self) -> i32 {
        unsafe {
            ffi::gdk_display_get_n_monitors(self.to_glib_none().0)
        }
    }

    pub fn get_name(&self) -> GString {
        unsafe {
            from_glib_none(ffi::gdk_display_get_name(self.to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn get_primary_monitor(&self) -> Option<Monitor> {
        unsafe {
            from_glib_none(ffi::gdk_display_get_primary_monitor(self.to_glib_none().0))
        }
    }

    #[cfg_attr(feature = "v3_20", deprecated)]
    pub fn get_screen(&self, screen_num: i32) -> Screen {
        unsafe {
            from_glib_none(ffi::gdk_display_get_screen(self.to_glib_none().0, screen_num))
        }
    }

    pub fn has_pending(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_has_pending(self.to_glib_none().0))
        }
    }

    pub fn is_closed(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_is_closed(self.to_glib_none().0))
        }
    }

    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn list_seats(&self) -> Vec<Seat> {
        unsafe {
            FromGlibPtrContainer::from_glib_container(ffi::gdk_display_list_seats(self.to_glib_none().0))
        }
    }

    pub fn notify_startup_complete(&self, startup_id: &str) {
        unsafe {
            ffi::gdk_display_notify_startup_complete(self.to_glib_none().0, startup_id.to_glib_none().0);
        }
    }

    pub fn peek_event(&self) -> Option<Event> {
        unsafe {
            from_glib_full(ffi::gdk_display_peek_event(self.to_glib_none().0))
        }
    }

    pub fn put_event(&self, event: &Event) {
        unsafe {
            ffi::gdk_display_put_event(self.to_glib_none().0, event.to_glib_none().0);
        }
    }

    pub fn request_selection_notification(&self, selection: &Atom) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_request_selection_notification(self.to_glib_none().0, selection.to_glib_none().0))
        }
    }

    pub fn set_double_click_distance(&self, distance: u32) {
        unsafe {
            ffi::gdk_display_set_double_click_distance(self.to_glib_none().0, distance);
        }
    }

    pub fn set_double_click_time(&self, msec: u32) {
        unsafe {
            ffi::gdk_display_set_double_click_time(self.to_glib_none().0, msec);
        }
    }

    pub fn store_clipboard<P: IsA<Window>>(&self, clipboard_window: &P, time_: u32, targets: &[&Atom]) {
        let n_targets = targets.len() as i32;
        unsafe {
            ffi::gdk_display_store_clipboard(self.to_glib_none().0, clipboard_window.as_ref().to_glib_none().0, time_, targets.to_glib_none().0, n_targets);
        }
    }

    pub fn supports_clipboard_persistence(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_clipboard_persistence(self.to_glib_none().0))
        }
    }

    #[cfg_attr(feature = "v3_16", deprecated)]
    pub fn supports_composite(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_composite(self.to_glib_none().0))
        }
    }

    pub fn supports_cursor_alpha(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_cursor_alpha(self.to_glib_none().0))
        }
    }

    pub fn supports_cursor_color(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_cursor_color(self.to_glib_none().0))
        }
    }

    pub fn supports_input_shapes(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_input_shapes(self.to_glib_none().0))
        }
    }

    pub fn supports_selection_notification(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_selection_notification(self.to_glib_none().0))
        }
    }

    pub fn supports_shapes(&self) -> bool {
        unsafe {
            from_glib(ffi::gdk_display_supports_shapes(self.to_glib_none().0))
        }
    }

    pub fn sync(&self) {
        unsafe {
            ffi::gdk_display_sync(self.to_glib_none().0);
        }
    }

    pub fn get_default() -> Option<Display> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(ffi::gdk_display_get_default())
        }
    }

    pub fn open(display_name: &str) -> Option<Display> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(ffi::gdk_display_open(display_name.to_glib_none().0))
        }
    }

    #[cfg_attr(feature = "v3_16", deprecated)]
    pub fn open_default_libgtk_only() -> Option<Display> {
        assert_initialized_main_thread!();
        unsafe {
            from_glib_none(ffi::gdk_display_open_default_libgtk_only())
        }
    }

    pub fn connect_closed<F: Fn(&Display, bool) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"closed\0".as_ptr() as *const _,
                Some(transmute(closed_trampoline::<F> as usize)), Box_::into_raw(f))
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn connect_monitor_added<F: Fn(&Display, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"monitor-added\0".as_ptr() as *const _,
                Some(transmute(monitor_added_trampoline::<F> as usize)), Box_::into_raw(f))
        }
    }

    #[cfg(any(feature = "v3_22", feature = "dox"))]
    pub fn connect_monitor_removed<F: Fn(&Display, &Monitor) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"monitor-removed\0".as_ptr() as *const _,
                Some(transmute(monitor_removed_trampoline::<F> as usize)), Box_::into_raw(f))
        }
    }

    pub fn connect_opened<F: Fn(&Display) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"opened\0".as_ptr() as *const _,
                Some(transmute(opened_trampoline::<F> as usize)), Box_::into_raw(f))
        }
    }

    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn connect_seat_added<F: Fn(&Display, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"seat-added\0".as_ptr() as *const _,
                Some(transmute(seat_added_trampoline::<F> as usize)), Box_::into_raw(f))
        }
    }

    #[cfg(any(feature = "v3_20", feature = "dox"))]
    pub fn connect_seat_removed<F: Fn(&Display, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(self.as_ptr() as *mut _, b"seat-removed\0".as_ptr() as *const _,
                Some(transmute(seat_removed_trampoline::<F> as usize)), Box_::into_raw(f))
        }
    }
}

unsafe extern "C" fn closed_trampoline<F: Fn(&Display, bool) + 'static>(this: *mut ffi::GdkDisplay, is_error: glib_ffi::gboolean, f: glib_ffi::gpointer) {
    let f: &F = transmute(f);
    f(&from_glib_borrow(this), from_glib(is_error))
}

#[cfg(any(feature = "v3_22", feature = "dox"))]
unsafe extern "C" fn monitor_added_trampoline<F: Fn(&Display, &Monitor) + 'static>(this: *mut ffi::GdkDisplay, monitor: *mut ffi::GdkMonitor, f: glib_ffi::gpointer) {
    let f: &F = transmute(f);
    f(&from_glib_borrow(this), &from_glib_borrow(monitor))
}

#[cfg(any(feature = "v3_22", feature = "dox"))]
unsafe extern "C" fn monitor_removed_trampoline<F: Fn(&Display, &Monitor) + 'static>(this: *mut ffi::GdkDisplay, monitor: *mut ffi::GdkMonitor, f: glib_ffi::gpointer) {
    let f: &F = transmute(f);
    f(&from_glib_borrow(this), &from_glib_borrow(monitor))
}

unsafe extern "C" fn opened_trampoline<F: Fn(&Display) + 'static>(this: *mut ffi::GdkDisplay, f: glib_ffi::gpointer) {
    let f: &F = transmute(f);
    f(&from_glib_borrow(this))
}

#[cfg(any(feature = "v3_20", feature = "dox"))]
unsafe extern "C" fn seat_added_trampoline<F: Fn(&Display, &Seat) + 'static>(this: *mut ffi::GdkDisplay, seat: *mut ffi::GdkSeat, f: glib_ffi::gpointer) {
    let f: &F = transmute(f);
    f(&from_glib_borrow(this), &from_glib_borrow(seat))
}

#[cfg(any(feature = "v3_20", feature = "dox"))]
unsafe extern "C" fn seat_removed_trampoline<F: Fn(&Display, &Seat) + 'static>(this: *mut ffi::GdkDisplay, seat: *mut ffi::GdkSeat, f: glib_ffi::gpointer) {
    let f: &F = transmute(f);
    f(&from_glib_borrow(this), &from_glib_borrow(seat))
}

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