1use gdk_sys;
6use glib::object::IsA;
7use glib::object::ObjectType as ObjectType_;
8use glib::signal::connect_raw;
9use glib::signal::SignalHandlerId;
10use glib::translate::*;
11use glib::GString;
12use glib_sys;
13use std::boxed::Box as Box_;
14use std::fmt;
15use std::mem;
16use std::mem::transmute;
17use AppLaunchContext;
18use Atom;
19use Device;
20use DeviceManager;
21use Event;
22#[cfg(any(feature = "v3_22", feature = "dox"))]
23use Monitor;
24use Screen;
25#[cfg(any(feature = "v3_20", feature = "dox"))]
26use Seat;
27use Window;
28
29glib_wrapper! {
30 pub struct Display(Object<gdk_sys::GdkDisplay, DisplayClass>);
31
32 match fn {
33 get_type => || gdk_sys::gdk_display_get_type(),
34 }
35}
36
37impl Display {
38 pub fn beep(&self) {
39 unsafe {
40 gdk_sys::gdk_display_beep(self.to_glib_none().0);
41 }
42 }
43
44 pub fn close(&self) {
45 unsafe {
46 gdk_sys::gdk_display_close(self.to_glib_none().0);
47 }
48 }
49
50 pub fn device_is_grabbed(&self, device: &Device) -> bool {
51 unsafe {
52 from_glib(gdk_sys::gdk_display_device_is_grabbed(
53 self.to_glib_none().0,
54 device.to_glib_none().0,
55 ))
56 }
57 }
58
59 pub fn flush(&self) {
60 unsafe {
61 gdk_sys::gdk_display_flush(self.to_glib_none().0);
62 }
63 }
64
65 pub fn get_app_launch_context(&self) -> Option<AppLaunchContext> {
66 unsafe {
67 from_glib_full(gdk_sys::gdk_display_get_app_launch_context(
68 self.to_glib_none().0,
69 ))
70 }
71 }
72
73 pub fn get_default_cursor_size(&self) -> u32 {
74 unsafe { gdk_sys::gdk_display_get_default_cursor_size(self.to_glib_none().0) }
75 }
76
77 pub fn get_default_group(&self) -> Window {
78 unsafe {
79 from_glib_none(gdk_sys::gdk_display_get_default_group(
80 self.to_glib_none().0,
81 ))
82 }
83 }
84
85 pub fn get_default_screen(&self) -> Screen {
86 unsafe {
87 from_glib_none(gdk_sys::gdk_display_get_default_screen(
88 self.to_glib_none().0,
89 ))
90 }
91 }
92
93 #[cfg(any(feature = "v3_20", feature = "dox"))]
94 pub fn get_default_seat(&self) -> Option<Seat> {
95 unsafe { from_glib_none(gdk_sys::gdk_display_get_default_seat(self.to_glib_none().0)) }
96 }
97
98 #[cfg_attr(feature = "v3_20", deprecated)]
99 pub fn get_device_manager(&self) -> Option<DeviceManager> {
100 unsafe {
101 from_glib_none(gdk_sys::gdk_display_get_device_manager(
102 self.to_glib_none().0,
103 ))
104 }
105 }
106
107 pub fn get_event(&self) -> Option<Event> {
108 unsafe { from_glib_full(gdk_sys::gdk_display_get_event(self.to_glib_none().0)) }
109 }
110
111 pub fn get_maximal_cursor_size(&self) -> (u32, u32) {
112 unsafe {
113 let mut width = mem::uninitialized();
114 let mut height = mem::uninitialized();
115 gdk_sys::gdk_display_get_maximal_cursor_size(
116 self.to_glib_none().0,
117 &mut width,
118 &mut height,
119 );
120 (width, height)
121 }
122 }
123
124 #[cfg(any(feature = "v3_22", feature = "dox"))]
125 pub fn get_monitor(&self, monitor_num: i32) -> Option<Monitor> {
126 unsafe {
127 from_glib_none(gdk_sys::gdk_display_get_monitor(
128 self.to_glib_none().0,
129 monitor_num,
130 ))
131 }
132 }
133
134 #[cfg(any(feature = "v3_22", feature = "dox"))]
135 pub fn get_monitor_at_point(&self, x: i32, y: i32) -> Option<Monitor> {
136 unsafe {
137 from_glib_none(gdk_sys::gdk_display_get_monitor_at_point(
138 self.to_glib_none().0,
139 x,
140 y,
141 ))
142 }
143 }
144
145 #[cfg(any(feature = "v3_22", feature = "dox"))]
146 pub fn get_monitor_at_window<P: IsA<Window>>(&self, window: &P) -> Option<Monitor> {
147 unsafe {
148 from_glib_none(gdk_sys::gdk_display_get_monitor_at_window(
149 self.to_glib_none().0,
150 window.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 #[cfg(any(feature = "v3_22", feature = "dox"))]
156 pub fn get_n_monitors(&self) -> i32 {
157 unsafe { gdk_sys::gdk_display_get_n_monitors(self.to_glib_none().0) }
158 }
159
160 pub fn get_name(&self) -> GString {
161 unsafe { from_glib_none(gdk_sys::gdk_display_get_name(self.to_glib_none().0)) }
162 }
163
164 #[cfg(any(feature = "v3_22", feature = "dox"))]
165 pub fn get_primary_monitor(&self) -> Option<Monitor> {
166 unsafe {
167 from_glib_none(gdk_sys::gdk_display_get_primary_monitor(
168 self.to_glib_none().0,
169 ))
170 }
171 }
172
173 #[cfg_attr(feature = "v3_20", deprecated)]
174 pub fn get_screen(&self, screen_num: i32) -> Screen {
175 unsafe {
176 from_glib_none(gdk_sys::gdk_display_get_screen(
177 self.to_glib_none().0,
178 screen_num,
179 ))
180 }
181 }
182
183 pub fn has_pending(&self) -> bool {
184 unsafe { from_glib(gdk_sys::gdk_display_has_pending(self.to_glib_none().0)) }
185 }
186
187 pub fn is_closed(&self) -> bool {
188 unsafe { from_glib(gdk_sys::gdk_display_is_closed(self.to_glib_none().0)) }
189 }
190
191 #[cfg(any(feature = "v3_20", feature = "dox"))]
192 pub fn list_seats(&self) -> Vec<Seat> {
193 unsafe {
194 FromGlibPtrContainer::from_glib_container(gdk_sys::gdk_display_list_seats(
195 self.to_glib_none().0,
196 ))
197 }
198 }
199
200 pub fn notify_startup_complete(&self, startup_id: &str) {
201 unsafe {
202 gdk_sys::gdk_display_notify_startup_complete(
203 self.to_glib_none().0,
204 startup_id.to_glib_none().0,
205 );
206 }
207 }
208
209 pub fn peek_event(&self) -> Option<Event> {
210 unsafe { from_glib_full(gdk_sys::gdk_display_peek_event(self.to_glib_none().0)) }
211 }
212
213 pub fn put_event(&self, event: &Event) {
214 unsafe {
215 gdk_sys::gdk_display_put_event(self.to_glib_none().0, event.to_glib_none().0);
216 }
217 }
218
219 pub fn request_selection_notification(&self, selection: &Atom) -> bool {
220 unsafe {
221 from_glib(gdk_sys::gdk_display_request_selection_notification(
222 self.to_glib_none().0,
223 selection.to_glib_none().0,
224 ))
225 }
226 }
227
228 pub fn set_double_click_distance(&self, distance: u32) {
229 unsafe {
230 gdk_sys::gdk_display_set_double_click_distance(self.to_glib_none().0, distance);
231 }
232 }
233
234 pub fn set_double_click_time(&self, msec: u32) {
235 unsafe {
236 gdk_sys::gdk_display_set_double_click_time(self.to_glib_none().0, msec);
237 }
238 }
239
240 pub fn store_clipboard<P: IsA<Window>>(
241 &self,
242 clipboard_window: &P,
243 time_: u32,
244 targets: &[&Atom],
245 ) {
246 let n_targets = targets.len() as i32;
247 unsafe {
248 gdk_sys::gdk_display_store_clipboard(
249 self.to_glib_none().0,
250 clipboard_window.as_ref().to_glib_none().0,
251 time_,
252 targets.to_glib_none().0,
253 n_targets,
254 );
255 }
256 }
257
258 pub fn supports_clipboard_persistence(&self) -> bool {
259 unsafe {
260 from_glib(gdk_sys::gdk_display_supports_clipboard_persistence(
261 self.to_glib_none().0,
262 ))
263 }
264 }
265
266 #[cfg_attr(feature = "v3_16", deprecated)]
267 pub fn supports_composite(&self) -> bool {
268 unsafe {
269 from_glib(gdk_sys::gdk_display_supports_composite(
270 self.to_glib_none().0,
271 ))
272 }
273 }
274
275 pub fn supports_cursor_alpha(&self) -> bool {
276 unsafe {
277 from_glib(gdk_sys::gdk_display_supports_cursor_alpha(
278 self.to_glib_none().0,
279 ))
280 }
281 }
282
283 pub fn supports_cursor_color(&self) -> bool {
284 unsafe {
285 from_glib(gdk_sys::gdk_display_supports_cursor_color(
286 self.to_glib_none().0,
287 ))
288 }
289 }
290
291 pub fn supports_input_shapes(&self) -> bool {
292 unsafe {
293 from_glib(gdk_sys::gdk_display_supports_input_shapes(
294 self.to_glib_none().0,
295 ))
296 }
297 }
298
299 pub fn supports_selection_notification(&self) -> bool {
300 unsafe {
301 from_glib(gdk_sys::gdk_display_supports_selection_notification(
302 self.to_glib_none().0,
303 ))
304 }
305 }
306
307 pub fn supports_shapes(&self) -> bool {
308 unsafe { from_glib(gdk_sys::gdk_display_supports_shapes(self.to_glib_none().0)) }
309 }
310
311 pub fn sync(&self) {
312 unsafe {
313 gdk_sys::gdk_display_sync(self.to_glib_none().0);
314 }
315 }
316
317 pub fn get_default() -> Option<Display> {
318 assert_initialized_main_thread!();
319 unsafe { from_glib_none(gdk_sys::gdk_display_get_default()) }
320 }
321
322 pub fn open(display_name: &str) -> Option<Display> {
323 assert_initialized_main_thread!();
324 unsafe { from_glib_none(gdk_sys::gdk_display_open(display_name.to_glib_none().0)) }
325 }
326
327 #[cfg_attr(feature = "v3_16", deprecated)]
328 pub fn open_default_libgtk_only() -> Option<Display> {
329 assert_initialized_main_thread!();
330 unsafe { from_glib_none(gdk_sys::gdk_display_open_default_libgtk_only()) }
331 }
332
333 pub fn connect_closed<F: Fn(&Display, bool) + 'static>(&self, f: F) -> SignalHandlerId {
334 unsafe extern "C" fn closed_trampoline<F: Fn(&Display, bool) + 'static>(
335 this: *mut gdk_sys::GdkDisplay,
336 is_error: glib_sys::gboolean,
337 f: glib_sys::gpointer,
338 ) {
339 let f: &F = &*(f as *const F);
340 f(&from_glib_borrow(this), from_glib(is_error))
341 }
342 unsafe {
343 let f: Box_<F> = Box_::new(f);
344 connect_raw(
345 self.as_ptr() as *mut _,
346 b"closed\0".as_ptr() as *const _,
347 Some(transmute(closed_trampoline::<F> as usize)),
348 Box_::into_raw(f),
349 )
350 }
351 }
352
353 #[cfg(any(feature = "v3_22", feature = "dox"))]
354 pub fn connect_monitor_added<F: Fn(&Display, &Monitor) + 'static>(
355 &self,
356 f: F,
357 ) -> SignalHandlerId {
358 unsafe extern "C" fn monitor_added_trampoline<F: Fn(&Display, &Monitor) + 'static>(
359 this: *mut gdk_sys::GdkDisplay,
360 monitor: *mut gdk_sys::GdkMonitor,
361 f: glib_sys::gpointer,
362 ) {
363 let f: &F = &*(f as *const F);
364 f(&from_glib_borrow(this), &from_glib_borrow(monitor))
365 }
366 unsafe {
367 let f: Box_<F> = Box_::new(f);
368 connect_raw(
369 self.as_ptr() as *mut _,
370 b"monitor-added\0".as_ptr() as *const _,
371 Some(transmute(monitor_added_trampoline::<F> as usize)),
372 Box_::into_raw(f),
373 )
374 }
375 }
376
377 #[cfg(any(feature = "v3_22", feature = "dox"))]
378 pub fn connect_monitor_removed<F: Fn(&Display, &Monitor) + 'static>(
379 &self,
380 f: F,
381 ) -> SignalHandlerId {
382 unsafe extern "C" fn monitor_removed_trampoline<F: Fn(&Display, &Monitor) + 'static>(
383 this: *mut gdk_sys::GdkDisplay,
384 monitor: *mut gdk_sys::GdkMonitor,
385 f: glib_sys::gpointer,
386 ) {
387 let f: &F = &*(f as *const F);
388 f(&from_glib_borrow(this), &from_glib_borrow(monitor))
389 }
390 unsafe {
391 let f: Box_<F> = Box_::new(f);
392 connect_raw(
393 self.as_ptr() as *mut _,
394 b"monitor-removed\0".as_ptr() as *const _,
395 Some(transmute(monitor_removed_trampoline::<F> as usize)),
396 Box_::into_raw(f),
397 )
398 }
399 }
400
401 pub fn connect_opened<F: Fn(&Display) + 'static>(&self, f: F) -> SignalHandlerId {
402 unsafe extern "C" fn opened_trampoline<F: Fn(&Display) + 'static>(
403 this: *mut gdk_sys::GdkDisplay,
404 f: glib_sys::gpointer,
405 ) {
406 let f: &F = &*(f as *const F);
407 f(&from_glib_borrow(this))
408 }
409 unsafe {
410 let f: Box_<F> = Box_::new(f);
411 connect_raw(
412 self.as_ptr() as *mut _,
413 b"opened\0".as_ptr() as *const _,
414 Some(transmute(opened_trampoline::<F> as usize)),
415 Box_::into_raw(f),
416 )
417 }
418 }
419
420 #[cfg(any(feature = "v3_20", feature = "dox"))]
421 pub fn connect_seat_added<F: Fn(&Display, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
422 unsafe extern "C" fn seat_added_trampoline<F: Fn(&Display, &Seat) + 'static>(
423 this: *mut gdk_sys::GdkDisplay,
424 seat: *mut gdk_sys::GdkSeat,
425 f: glib_sys::gpointer,
426 ) {
427 let f: &F = &*(f as *const F);
428 f(&from_glib_borrow(this), &from_glib_borrow(seat))
429 }
430 unsafe {
431 let f: Box_<F> = Box_::new(f);
432 connect_raw(
433 self.as_ptr() as *mut _,
434 b"seat-added\0".as_ptr() as *const _,
435 Some(transmute(seat_added_trampoline::<F> as usize)),
436 Box_::into_raw(f),
437 )
438 }
439 }
440
441 #[cfg(any(feature = "v3_20", feature = "dox"))]
442 pub fn connect_seat_removed<F: Fn(&Display, &Seat) + 'static>(&self, f: F) -> SignalHandlerId {
443 unsafe extern "C" fn seat_removed_trampoline<F: Fn(&Display, &Seat) + 'static>(
444 this: *mut gdk_sys::GdkDisplay,
445 seat: *mut gdk_sys::GdkSeat,
446 f: glib_sys::gpointer,
447 ) {
448 let f: &F = &*(f as *const F);
449 f(&from_glib_borrow(this), &from_glib_borrow(seat))
450 }
451 unsafe {
452 let f: Box_<F> = Box_::new(f);
453 connect_raw(
454 self.as_ptr() as *mut _,
455 b"seat-removed\0".as_ptr() as *const _,
456 Some(transmute(seat_removed_trampoline::<F> as usize)),
457 Box_::into_raw(f),
458 )
459 }
460 }
461}
462
463impl fmt::Display for Display {
464 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
465 write!(f, "Display")
466 }
467}