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