1use cairo;
6use gdk_pixbuf;
7use gdk_sys;
8use glib::object::IsA;
9use glib::translate::*;
10use glib::GString;
11use libc;
12use pango;
13use std::boxed::Box as Box_;
14use std::mem;
15use std::ptr;
16use Atom;
17use Display;
18use Event;
19use EventType;
20use ModifierType;
21use Screen;
22use Visual;
23use Window;
24use WindowState;
25
26pub fn beep() {
32 assert_initialized_main_thread!();
33 unsafe {
34 gdk_sys::gdk_beep();
35 }
36}
37
38pub fn error_trap_pop() -> i32 {
39 assert_initialized_main_thread!();
40 unsafe { gdk_sys::gdk_error_trap_pop() }
41}
42
43pub fn error_trap_pop_ignored() {
44 assert_initialized_main_thread!();
45 unsafe {
46 gdk_sys::gdk_error_trap_pop_ignored();
47 }
48}
49
50pub fn error_trap_push() {
51 assert_initialized_main_thread!();
52 unsafe {
53 gdk_sys::gdk_error_trap_push();
54 }
55}
56
57pub fn events_get_angle(event1: &mut Event, event2: &mut Event) -> Option<f64> {
58 assert_initialized_main_thread!();
59 unsafe {
60 let mut angle = mem::uninitialized();
61 let ret = from_glib(gdk_sys::gdk_events_get_angle(
62 event1.to_glib_none_mut().0,
63 event2.to_glib_none_mut().0,
64 &mut angle,
65 ));
66 if ret {
67 Some(angle)
68 } else {
69 None
70 }
71 }
72}
73
74pub fn events_get_center(event1: &mut Event, event2: &mut Event) -> Option<(f64, f64)> {
75 assert_initialized_main_thread!();
76 unsafe {
77 let mut x = mem::uninitialized();
78 let mut y = mem::uninitialized();
79 let ret = from_glib(gdk_sys::gdk_events_get_center(
80 event1.to_glib_none_mut().0,
81 event2.to_glib_none_mut().0,
82 &mut x,
83 &mut y,
84 ));
85 if ret {
86 Some((x, y))
87 } else {
88 None
89 }
90 }
91}
92
93pub fn events_get_distance(event1: &mut Event, event2: &mut Event) -> Option<f64> {
94 assert_initialized_main_thread!();
95 unsafe {
96 let mut distance = mem::uninitialized();
97 let ret = from_glib(gdk_sys::gdk_events_get_distance(
98 event1.to_glib_none_mut().0,
99 event2.to_glib_none_mut().0,
100 &mut distance,
101 ));
102 if ret {
103 Some(distance)
104 } else {
105 None
106 }
107 }
108}
109
110pub fn events_pending() -> bool {
111 assert_initialized_main_thread!();
112 unsafe { from_glib(gdk_sys::gdk_events_pending()) }
113}
114
115pub fn flush() {
116 assert_initialized_main_thread!();
117 unsafe {
118 gdk_sys::gdk_flush();
119 }
120}
121
122pub fn get_display_arg_name() -> Option<GString> {
123 assert_initialized_main_thread!();
124 unsafe { from_glib_none(gdk_sys::gdk_get_display_arg_name()) }
125}
126
127pub fn get_program_class() -> Option<GString> {
128 assert_initialized_main_thread!();
129 unsafe { from_glib_none(gdk_sys::gdk_get_program_class()) }
130}
131
132pub fn get_show_events() -> bool {
133 assert_initialized_main_thread!();
134 unsafe { from_glib(gdk_sys::gdk_get_show_events()) }
135}
136
137pub fn keyval_convert_case(symbol: u32) -> (u32, u32) {
142 assert_initialized_main_thread!();
143 unsafe {
144 let mut lower = mem::uninitialized();
145 let mut upper = mem::uninitialized();
146 gdk_sys::gdk_keyval_convert_case(symbol, &mut lower, &mut upper);
147 (lower, upper)
148 }
149}
150
151pub fn keyval_from_name(keyval_name: &str) -> u32 {
152 assert_initialized_main_thread!();
153 unsafe { gdk_sys::gdk_keyval_from_name(keyval_name.to_glib_none().0) }
154}
155
156pub fn keyval_is_lower(keyval: u32) -> bool {
157 assert_initialized_main_thread!();
158 unsafe { from_glib(gdk_sys::gdk_keyval_is_lower(keyval)) }
159}
160
161pub fn keyval_is_upper(keyval: u32) -> bool {
162 assert_initialized_main_thread!();
163 unsafe { from_glib(gdk_sys::gdk_keyval_is_upper(keyval)) }
164}
165
166pub fn keyval_to_lower(keyval: u32) -> u32 {
167 assert_initialized_main_thread!();
168 unsafe { gdk_sys::gdk_keyval_to_lower(keyval) }
169}
170
171pub fn keyval_to_upper(keyval: u32) -> u32 {
172 assert_initialized_main_thread!();
173 unsafe { gdk_sys::gdk_keyval_to_upper(keyval) }
174}
175
176#[cfg_attr(feature = "v3_22", deprecated)]
177pub fn list_visuals() -> Vec<Visual> {
178 assert_initialized_main_thread!();
179 unsafe { FromGlibPtrContainer::from_glib_container(gdk_sys::gdk_list_visuals()) }
180}
181
182pub fn notify_startup_complete() {
183 assert_initialized_main_thread!();
184 unsafe {
185 gdk_sys::gdk_notify_startup_complete();
186 }
187}
188
189pub fn notify_startup_complete_with_id(startup_id: &str) {
190 assert_initialized_main_thread!();
191 unsafe {
192 gdk_sys::gdk_notify_startup_complete_with_id(startup_id.to_glib_none().0);
193 }
194}
195
196pub fn pango_context_get() -> Option<pango::Context> {
197 assert_initialized_main_thread!();
198 unsafe { from_glib_full(gdk_sys::gdk_pango_context_get()) }
199}
200
201#[cfg(any(feature = "v3_22", feature = "dox"))]
202pub fn pango_context_get_for_display(display: &Display) -> Option<pango::Context> {
203 skip_assert_initialized!();
204 unsafe {
205 from_glib_full(gdk_sys::gdk_pango_context_get_for_display(
206 display.to_glib_none().0,
207 ))
208 }
209}
210
211pub fn pango_context_get_for_screen(screen: &Screen) -> Option<pango::Context> {
212 skip_assert_initialized!();
213 unsafe {
214 from_glib_full(gdk_sys::gdk_pango_context_get_for_screen(
215 screen.to_glib_none().0,
216 ))
217 }
218}
219
220pub fn pixbuf_get_from_surface(
229 surface: &cairo::Surface,
230 src_x: i32,
231 src_y: i32,
232 width: i32,
233 height: i32,
234) -> Option<gdk_pixbuf::Pixbuf> {
235 assert_initialized_main_thread!();
236 unsafe {
237 from_glib_full(gdk_sys::gdk_pixbuf_get_from_surface(
238 mut_override(surface.to_glib_none().0),
239 src_x,
240 src_y,
241 width,
242 height,
243 ))
244 }
245}
246
247#[cfg_attr(feature = "v3_16", deprecated)]
248pub fn pre_parse_libgtk_only() {
249 assert_initialized_main_thread!();
250 unsafe {
251 gdk_sys::gdk_pre_parse_libgtk_only();
252 }
253}
254
255pub fn property_delete<P: IsA<Window>>(window: &P, property: &Atom) {
256 skip_assert_initialized!();
257 unsafe {
258 gdk_sys::gdk_property_delete(window.as_ref().to_glib_none().0, property.to_glib_none().0);
259 }
260}
261
262pub fn property_get<P: IsA<Window>>(
263 window: &P,
264 property: &Atom,
265 type_: &Atom,
266 offset: libc::c_ulong,
267 length: libc::c_ulong,
268 pdelete: i32,
269) -> Option<(Atom, i32, Vec<u8>)> {
270 skip_assert_initialized!();
271 unsafe {
272 let mut actual_property_type = Atom::uninitialized();
273 let mut actual_format = mem::uninitialized();
274 let mut actual_length = mem::uninitialized();
275 let mut data = ptr::null_mut();
276 let ret = from_glib(gdk_sys::gdk_property_get(
277 window.as_ref().to_glib_none().0,
278 property.to_glib_none().0,
279 type_.to_glib_none().0,
280 offset,
281 length,
282 pdelete,
283 actual_property_type.to_glib_none_mut().0,
284 &mut actual_format,
285 &mut actual_length,
286 &mut data,
287 ));
288 if ret {
289 Some((
290 actual_property_type,
291 actual_format,
292 FromGlibContainer::from_glib_full_num(data, actual_length as usize),
293 ))
294 } else {
295 None
296 }
297 }
298}
299
300#[cfg_attr(feature = "v3_22", deprecated)]
301pub fn query_depths() -> Vec<i32> {
302 assert_initialized_main_thread!();
303 unsafe {
304 let mut depths = ptr::null_mut();
305 let mut count = mem::uninitialized();
306 gdk_sys::gdk_query_depths(&mut depths, &mut count);
307 FromGlibContainer::from_glib_none_num(depths, count as usize)
308 }
309}
310
311pub fn selection_convert<P: IsA<Window>>(
317 requestor: &P,
318 selection: &Atom,
319 target: &Atom,
320 time_: u32,
321) {
322 skip_assert_initialized!();
323 unsafe {
324 gdk_sys::gdk_selection_convert(
325 requestor.as_ref().to_glib_none().0,
326 selection.to_glib_none().0,
327 target.to_glib_none().0,
328 time_,
329 );
330 }
331}
332
333pub fn selection_owner_get(selection: &Atom) -> Option<Window> {
334 assert_initialized_main_thread!();
335 unsafe { from_glib_none(gdk_sys::gdk_selection_owner_get(selection.to_glib_none().0)) }
336}
337
338pub fn selection_owner_get_for_display(display: &Display, selection: &Atom) -> Option<Window> {
339 skip_assert_initialized!();
340 unsafe {
341 from_glib_none(gdk_sys::gdk_selection_owner_get_for_display(
342 display.to_glib_none().0,
343 selection.to_glib_none().0,
344 ))
345 }
346}
347
348pub fn selection_owner_set<P: IsA<Window>>(
349 owner: Option<&P>,
350 selection: &Atom,
351 time_: u32,
352 send_event: bool,
353) -> bool {
354 assert_initialized_main_thread!();
355 unsafe {
356 from_glib(gdk_sys::gdk_selection_owner_set(
357 owner.map(|p| p.as_ref()).to_glib_none().0,
358 selection.to_glib_none().0,
359 time_,
360 send_event.to_glib(),
361 ))
362 }
363}
364
365pub fn selection_owner_set_for_display<P: IsA<Window>>(
366 display: &Display,
367 owner: Option<&P>,
368 selection: &Atom,
369 time_: u32,
370 send_event: bool,
371) -> bool {
372 skip_assert_initialized!();
373 unsafe {
374 from_glib(gdk_sys::gdk_selection_owner_set_for_display(
375 display.to_glib_none().0,
376 owner.map(|p| p.as_ref()).to_glib_none().0,
377 selection.to_glib_none().0,
378 time_,
379 send_event.to_glib(),
380 ))
381 }
382}
383
384pub fn selection_send_notify<P: IsA<Window>>(
385 requestor: &P,
386 selection: &Atom,
387 target: &Atom,
388 property: &Atom,
389 time_: u32,
390) {
391 skip_assert_initialized!();
392 unsafe {
393 gdk_sys::gdk_selection_send_notify(
394 requestor.as_ref().to_glib_none().0,
395 selection.to_glib_none().0,
396 target.to_glib_none().0,
397 property.to_glib_none().0,
398 time_,
399 );
400 }
401}
402
403pub fn selection_send_notify_for_display<P: IsA<Window>>(
404 display: &Display,
405 requestor: &P,
406 selection: &Atom,
407 target: &Atom,
408 property: &Atom,
409 time_: u32,
410) {
411 skip_assert_initialized!();
412 unsafe {
413 gdk_sys::gdk_selection_send_notify_for_display(
414 display.to_glib_none().0,
415 requestor.as_ref().to_glib_none().0,
416 selection.to_glib_none().0,
417 target.to_glib_none().0,
418 property.to_glib_none().0,
419 time_,
420 );
421 }
422}
423
424pub fn set_allowed_backends(backends: &str) {
425 assert_initialized_main_thread!();
426 unsafe {
427 gdk_sys::gdk_set_allowed_backends(backends.to_glib_none().0);
428 }
429}
430
431pub fn set_double_click_time(msec: u32) {
432 assert_initialized_main_thread!();
433 unsafe {
434 gdk_sys::gdk_set_double_click_time(msec);
435 }
436}
437
438pub fn set_program_class(program_class: &str) {
439 assert_initialized_main_thread!();
440 unsafe {
441 gdk_sys::gdk_set_program_class(program_class.to_glib_none().0);
442 }
443}
444
445pub fn set_show_events(show_events: bool) {
446 assert_initialized_main_thread!();
447 unsafe {
448 gdk_sys::gdk_set_show_events(show_events.to_glib());
449 }
450}
451
452pub fn synthesize_window_state<P: IsA<Window>>(
453 window: &P,
454 unset_flags: WindowState,
455 set_flags: WindowState,
456) {
457 skip_assert_initialized!();
458 unsafe {
459 gdk_sys::gdk_synthesize_window_state(
460 window.as_ref().to_glib_none().0,
461 unset_flags.to_glib(),
462 set_flags.to_glib(),
463 );
464 }
465}
466
467pub fn test_render_sync<P: IsA<Window>>(window: &P) {
468 skip_assert_initialized!();
469 unsafe {
470 gdk_sys::gdk_test_render_sync(window.as_ref().to_glib_none().0);
471 }
472}
473
474pub fn test_simulate_button<P: IsA<Window>>(
475 window: &P,
476 x: i32,
477 y: i32,
478 button: u32,
479 modifiers: ModifierType,
480 button_pressrelease: EventType,
481) -> bool {
482 skip_assert_initialized!();
483 unsafe {
484 from_glib(gdk_sys::gdk_test_simulate_button(
485 window.as_ref().to_glib_none().0,
486 x,
487 y,
488 button,
489 modifiers.to_glib(),
490 button_pressrelease.to_glib(),
491 ))
492 }
493}
494
495pub fn test_simulate_key<P: IsA<Window>>(
496 window: &P,
497 x: i32,
498 y: i32,
499 keyval: u32,
500 modifiers: ModifierType,
501 key_pressrelease: EventType,
502) -> bool {
503 skip_assert_initialized!();
504 unsafe {
505 from_glib(gdk_sys::gdk_test_simulate_key(
506 window.as_ref().to_glib_none().0,
507 x,
508 y,
509 keyval,
510 modifiers.to_glib(),
511 key_pressrelease.to_glib(),
512 ))
513 }
514}
515
516pub fn text_property_to_utf8_list_for_display(
517 display: &Display,
518 encoding: &Atom,
519 format: i32,
520 text: &[u8],
521) -> (i32, Vec<GString>) {
522 skip_assert_initialized!();
523 let length = text.len() as i32;
524 unsafe {
525 let mut list = ptr::null_mut();
526 let ret = gdk_sys::gdk_text_property_to_utf8_list_for_display(
527 display.to_glib_none().0,
528 encoding.to_glib_none().0,
529 format,
530 text.to_glib_none().0,
531 length,
532 &mut list,
533 );
534 (ret, FromGlibPtrContainer::from_glib_full(list))
535 }
536}
537
538pub fn threads_add_idle<P: Fn() -> bool + Send + Sync + 'static>(function: P) -> u32 {
539 assert_initialized_main_thread!();
540 let function_data: Box_<P> = Box::new(function);
541 unsafe extern "C" fn function_func<P: Fn() -> bool + Send + Sync + 'static>(
542 user_data: glib_sys::gpointer,
543 ) -> glib_sys::gboolean {
544 let callback: &P = &*(user_data as *mut _);
545 let res = (*callback)();
546 res.to_glib()
547 }
548 let function = Some(function_func::<P> as _);
549 let super_callback0: Box_<P> = function_data;
550 unsafe { gdk_sys::gdk_threads_add_idle(function, Box::into_raw(super_callback0) as *mut _) }
551}
552
553pub fn threads_add_idle_full<P: Fn() -> bool + Send + Sync + 'static>(
554 priority: i32,
555 function: P,
556) -> u32 {
557 assert_initialized_main_thread!();
558 let function_data: Box_<P> = Box::new(function);
559 unsafe extern "C" fn function_func<P: Fn() -> bool + Send + Sync + 'static>(
560 user_data: glib_sys::gpointer,
561 ) -> glib_sys::gboolean {
562 let callback: &P = &*(user_data as *mut _);
563 let res = (*callback)();
564 res.to_glib()
565 }
566 let function = Some(function_func::<P> as _);
567 unsafe extern "C" fn notify_func<P: Fn() -> bool + Send + Sync + 'static>(
568 data: glib_sys::gpointer,
569 ) {
570 let _callback: Box_<P> = Box_::from_raw(data as *mut _);
571 }
572 let destroy_call3 = Some(notify_func::<P> as _);
573 let super_callback0: Box_<P> = function_data;
574 unsafe {
575 gdk_sys::gdk_threads_add_idle_full(
576 priority,
577 function,
578 Box::into_raw(super_callback0) as *mut _,
579 destroy_call3,
580 )
581 }
582}
583
584pub fn threads_add_timeout<P: Fn() -> bool + Send + Sync + 'static>(
585 interval: u32,
586 function: P,
587) -> u32 {
588 assert_initialized_main_thread!();
589 let function_data: Box_<P> = Box::new(function);
590 unsafe extern "C" fn function_func<P: Fn() -> bool + Send + Sync + 'static>(
591 user_data: glib_sys::gpointer,
592 ) -> glib_sys::gboolean {
593 let callback: &P = &*(user_data as *mut _);
594 let res = (*callback)();
595 res.to_glib()
596 }
597 let function = Some(function_func::<P> as _);
598 let super_callback0: Box_<P> = function_data;
599 unsafe {
600 gdk_sys::gdk_threads_add_timeout(
601 interval,
602 function,
603 Box::into_raw(super_callback0) as *mut _,
604 )
605 }
606}
607
608pub fn threads_add_timeout_full<P: Fn() -> bool + Send + Sync + 'static>(
609 priority: i32,
610 interval: u32,
611 function: P,
612) -> u32 {
613 assert_initialized_main_thread!();
614 let function_data: Box_<P> = Box::new(function);
615 unsafe extern "C" fn function_func<P: Fn() -> bool + Send + Sync + 'static>(
616 user_data: glib_sys::gpointer,
617 ) -> glib_sys::gboolean {
618 let callback: &P = &*(user_data as *mut _);
619 let res = (*callback)();
620 res.to_glib()
621 }
622 let function = Some(function_func::<P> as _);
623 unsafe extern "C" fn notify_func<P: Fn() -> bool + Send + Sync + 'static>(
624 data: glib_sys::gpointer,
625 ) {
626 let _callback: Box_<P> = Box_::from_raw(data as *mut _);
627 }
628 let destroy_call4 = Some(notify_func::<P> as _);
629 let super_callback0: Box_<P> = function_data;
630 unsafe {
631 gdk_sys::gdk_threads_add_timeout_full(
632 priority,
633 interval,
634 function,
635 Box::into_raw(super_callback0) as *mut _,
636 destroy_call4,
637 )
638 }
639}
640
641pub fn threads_add_timeout_seconds<P: Fn() -> bool + Send + Sync + 'static>(
642 interval: u32,
643 function: P,
644) -> u32 {
645 assert_initialized_main_thread!();
646 let function_data: Box_<P> = Box::new(function);
647 unsafe extern "C" fn function_func<P: Fn() -> bool + Send + Sync + 'static>(
648 user_data: glib_sys::gpointer,
649 ) -> glib_sys::gboolean {
650 let callback: &P = &*(user_data as *mut _);
651 let res = (*callback)();
652 res.to_glib()
653 }
654 let function = Some(function_func::<P> as _);
655 let super_callback0: Box_<P> = function_data;
656 unsafe {
657 gdk_sys::gdk_threads_add_timeout_seconds(
658 interval,
659 function,
660 Box::into_raw(super_callback0) as *mut _,
661 )
662 }
663}
664
665pub fn threads_add_timeout_seconds_full<P: Fn() -> bool + Send + Sync + 'static>(
666 priority: i32,
667 interval: u32,
668 function: P,
669) -> u32 {
670 assert_initialized_main_thread!();
671 let function_data: Box_<P> = Box::new(function);
672 unsafe extern "C" fn function_func<P: Fn() -> bool + Send + Sync + 'static>(
673 user_data: glib_sys::gpointer,
674 ) -> glib_sys::gboolean {
675 let callback: &P = &*(user_data as *mut _);
676 let res = (*callback)();
677 res.to_glib()
678 }
679 let function = Some(function_func::<P> as _);
680 unsafe extern "C" fn notify_func<P: Fn() -> bool + Send + Sync + 'static>(
681 data: glib_sys::gpointer,
682 ) {
683 let _callback: Box_<P> = Box_::from_raw(data as *mut _);
684 }
685 let destroy_call4 = Some(notify_func::<P> as _);
686 let super_callback0: Box_<P> = function_data;
687 unsafe {
688 gdk_sys::gdk_threads_add_timeout_seconds_full(
689 priority,
690 interval,
691 function,
692 Box::into_raw(super_callback0) as *mut _,
693 destroy_call4,
694 )
695 }
696}
697
698pub fn unicode_to_keyval(wc: u32) -> u32 {
699 assert_initialized_main_thread!();
700 unsafe { gdk_sys::gdk_unicode_to_keyval(wc) }
701}
702
703pub fn utf8_to_string_target(str: &str) -> Option<GString> {
704 assert_initialized_main_thread!();
705 unsafe { from_glib_full(gdk_sys::gdk_utf8_to_string_target(str.to_glib_none().0)) }
706}