Skip to main content

gdk/auto/
functions.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{Atom, Display, Event, EventType, ModifierType, Screen, Window, WindowState, ffi};
6use glib::translate::*;
7
8/// Emits a short beep on the default display.
9#[doc(alias = "gdk_beep")]
10pub fn beep() {
11    assert_initialized_main_thread!();
12    unsafe {
13        ffi::gdk_beep();
14    }
15}
16
17/// Removes an error trap pushed with [`error_trap_push()`][crate::error_trap_push()].
18/// May block until an error has been definitively received
19/// or not received from the X server. [`error_trap_pop_ignored()`][crate::error_trap_pop_ignored()]
20/// is preferred if you don’t need to know whether an error
21/// occurred, because it never has to block. If you don't
22/// need the return value of [`error_trap_pop()`][crate::error_trap_pop()], use
23/// [`error_trap_pop_ignored()`][crate::error_trap_pop_ignored()].
24///
25/// Prior to GDK 3.0, this function would not automatically
26/// sync for you, so you had to [`flush()`][crate::flush()] if your last
27/// call to Xlib was not a blocking round trip.
28///
29/// # Returns
30///
31/// X error code or 0 on success
32#[doc(alias = "gdk_error_trap_pop")]
33pub fn error_trap_pop() -> i32 {
34    assert_initialized_main_thread!();
35    unsafe { ffi::gdk_error_trap_pop() }
36}
37
38/// Removes an error trap pushed with [`error_trap_push()`][crate::error_trap_push()], but
39/// without bothering to wait and see whether an error occurred. If an
40/// error arrives later asynchronously that was triggered while the
41/// trap was pushed, that error will be ignored.
42#[doc(alias = "gdk_error_trap_pop_ignored")]
43pub fn error_trap_pop_ignored() {
44    assert_initialized_main_thread!();
45    unsafe {
46        ffi::gdk_error_trap_pop_ignored();
47    }
48}
49
50///
51/// gdk_error_trap_push ();
52///
53///  // ... Call the X function which may cause an error here ...
54///
55///
56/// if (gdk_error_trap_pop ())
57///  {
58///  // ... Handle the error here ...
59///  }
60/// ]|
61#[doc(alias = "gdk_error_trap_push")]
62pub fn error_trap_push() {
63    assert_initialized_main_thread!();
64    unsafe {
65        ffi::gdk_error_trap_push();
66    }
67}
68
69/// If both events contain X/Y information, this function will return [`true`]
70/// and return in `angle` the relative angle from `event1` to `event2`. The rotation
71/// direction for positive angles is from the positive X axis towards the positive
72/// Y axis.
73/// ## `event1`
74/// first `GdkEvent`
75/// ## `event2`
76/// second `GdkEvent`
77///
78/// # Returns
79///
80/// [`true`] if the angle could be calculated.
81///
82/// ## `angle`
83/// return location for the relative angle between both events
84#[doc(alias = "gdk_events_get_angle")]
85pub fn events_get_angle(event1: &mut Event, event2: &mut Event) -> Option<f64> {
86    assert_initialized_main_thread!();
87    unsafe {
88        let mut angle = std::mem::MaybeUninit::uninit();
89        let ret = from_glib(ffi::gdk_events_get_angle(
90            event1.to_glib_none_mut().0,
91            event2.to_glib_none_mut().0,
92            angle.as_mut_ptr(),
93        ));
94        if ret { Some(angle.assume_init()) } else { None }
95    }
96}
97
98/// If both events contain X/Y information, the center of both coordinates
99/// will be returned in `x` and `y`.
100/// ## `event1`
101/// first `GdkEvent`
102/// ## `event2`
103/// second `GdkEvent`
104///
105/// # Returns
106///
107/// [`true`] if the center could be calculated.
108///
109/// ## `x`
110/// return location for the X coordinate of the center
111///
112/// ## `y`
113/// return location for the Y coordinate of the center
114#[doc(alias = "gdk_events_get_center")]
115pub fn events_get_center(event1: &mut Event, event2: &mut Event) -> Option<(f64, f64)> {
116    assert_initialized_main_thread!();
117    unsafe {
118        let mut x = std::mem::MaybeUninit::uninit();
119        let mut y = std::mem::MaybeUninit::uninit();
120        let ret = from_glib(ffi::gdk_events_get_center(
121            event1.to_glib_none_mut().0,
122            event2.to_glib_none_mut().0,
123            x.as_mut_ptr(),
124            y.as_mut_ptr(),
125        ));
126        if ret {
127            Some((x.assume_init(), y.assume_init()))
128        } else {
129            None
130        }
131    }
132}
133
134/// If both events have X/Y information, the distance between both coordinates
135/// (as in a straight line going from `event1` to `event2`) will be returned.
136/// ## `event1`
137/// first `GdkEvent`
138/// ## `event2`
139/// second `GdkEvent`
140///
141/// # Returns
142///
143/// [`true`] if the distance could be calculated.
144///
145/// ## `distance`
146/// return location for the distance
147#[doc(alias = "gdk_events_get_distance")]
148pub fn events_get_distance(event1: &mut Event, event2: &mut Event) -> Option<f64> {
149    assert_initialized_main_thread!();
150    unsafe {
151        let mut distance = std::mem::MaybeUninit::uninit();
152        let ret = from_glib(ffi::gdk_events_get_distance(
153            event1.to_glib_none_mut().0,
154            event2.to_glib_none_mut().0,
155            distance.as_mut_ptr(),
156        ));
157        if ret {
158            Some(distance.assume_init())
159        } else {
160            None
161        }
162    }
163}
164
165/// Checks if any events are ready to be processed for any display.
166///
167/// # Returns
168///
169/// [`true`] if any events are pending.
170#[doc(alias = "gdk_events_pending")]
171pub fn events_pending() -> bool {
172    assert_initialized_main_thread!();
173    unsafe { from_glib(ffi::gdk_events_pending()) }
174}
175
176/// Flushes the output buffers of all display connections and waits
177/// until all requests have been processed.
178/// This is rarely needed by applications.
179#[doc(alias = "gdk_flush")]
180pub fn flush() {
181    assert_initialized_main_thread!();
182    unsafe {
183        ffi::gdk_flush();
184    }
185}
186
187/// Gets the display name specified in the command line arguments passed
188/// to `gdk_init()` or `gdk_parse_args()`, if any.
189///
190/// # Returns
191///
192/// the display name, if specified explicitly,
193///  otherwise [`None`] this string is owned by GTK+ and must not be
194///  modified or freed.
195#[doc(alias = "gdk_get_display_arg_name")]
196#[doc(alias = "get_display_arg_name")]
197pub fn display_arg_name() -> Option<glib::GString> {
198    assert_initialized_main_thread!();
199    unsafe { from_glib_none(ffi::gdk_get_display_arg_name()) }
200}
201
202/// Gets the program class. Unless the program class has explicitly
203/// been set with [`set_program_class()`][crate::set_program_class()] or with the `--class`
204/// commandline option, the default value is the program name (determined
205/// with `g_get_prgname()`) with the first character converted to uppercase.
206///
207/// # Returns
208///
209/// the program class.
210#[doc(alias = "gdk_get_program_class")]
211#[doc(alias = "get_program_class")]
212pub fn program_class() -> Option<glib::GString> {
213    assert_initialized_main_thread!();
214    unsafe { from_glib_none(ffi::gdk_get_program_class()) }
215}
216
217/// Gets whether event debugging output is enabled.
218///
219/// # Returns
220///
221/// [`true`] if event debugging output is enabled.
222#[doc(alias = "gdk_get_show_events")]
223#[doc(alias = "get_show_events")]
224pub fn shows_events() -> bool {
225    assert_initialized_main_thread!();
226    unsafe { from_glib(ffi::gdk_get_show_events()) }
227}
228
229/// Indicates to the GUI environment that the application has finished
230/// loading. If the applications opens windows, this function is
231/// normally called after opening the application’s initial set of
232/// windows.
233///
234/// GTK+ will call this function automatically after opening the first
235/// `GtkWindow` unless `gtk_window_set_auto_startup_notification()` is called
236/// to disable that feature.
237#[doc(alias = "gdk_notify_startup_complete")]
238pub fn notify_startup_complete() {
239    assert_initialized_main_thread!();
240    unsafe {
241        ffi::gdk_notify_startup_complete();
242    }
243}
244
245/// Indicates to the GUI environment that the application has
246/// finished loading, using a given identifier.
247///
248/// GTK+ will call this function automatically for `GtkWindow`
249/// with custom startup-notification identifier unless
250/// `gtk_window_set_auto_startup_notification()` is called to
251/// disable that feature.
252/// ## `startup_id`
253/// a startup-notification identifier, for which
254///  notification process should be completed
255#[doc(alias = "gdk_notify_startup_complete_with_id")]
256pub fn notify_startup_complete_with_id(startup_id: &str) {
257    assert_initialized_main_thread!();
258    unsafe {
259        ffi::gdk_notify_startup_complete_with_id(startup_id.to_glib_none().0);
260    }
261}
262
263/// Creates a [`pango::Context`][crate::pango::Context] for the default GDK screen.
264///
265/// The context must be freed when you’re finished with it.
266///
267/// When using GTK+, normally you should use `gtk_widget_get_pango_context()`
268/// instead of this function, to get the appropriate context for
269/// the widget you intend to render text onto.
270///
271/// The newly created context will have the default font options (see
272/// [`cairo::FontOptions`][crate::cairo::FontOptions]) for the default screen; if these options
273/// change it will not be updated. Using `gtk_widget_get_pango_context()`
274/// is more convenient if you want to keep a context around and track
275/// changes to the screen’s font rendering settings.
276///
277/// # Returns
278///
279/// a new [`pango::Context`][crate::pango::Context] for the default display
280#[doc(alias = "gdk_pango_context_get")]
281pub fn pango_context_get() -> Option<pango::Context> {
282    assert_initialized_main_thread!();
283    unsafe { from_glib_full(ffi::gdk_pango_context_get()) }
284}
285
286/// Creates a [`pango::Context`][crate::pango::Context] for `display`.
287///
288/// The context must be freed when you’re finished with it.
289///
290/// When using GTK+, normally you should use `gtk_widget_get_pango_context()`
291/// instead of this function, to get the appropriate context for
292/// the widget you intend to render text onto.
293///
294/// The newly created context will have the default font options
295/// (see [`cairo::FontOptions`][crate::cairo::FontOptions]) for the display; if these options
296/// change it will not be updated. Using `gtk_widget_get_pango_context()`
297/// is more convenient if you want to keep a context around and track
298/// changes to the font rendering settings.
299/// ## `display`
300/// the [`Display`][crate::Display] for which the context is to be created
301///
302/// # Returns
303///
304/// a new [`pango::Context`][crate::pango::Context] for `display`
305#[doc(alias = "gdk_pango_context_get_for_display")]
306pub fn pango_context_get_for_display(display: &Display) -> Option<pango::Context> {
307    skip_assert_initialized!();
308    unsafe {
309        from_glib_full(ffi::gdk_pango_context_get_for_display(
310            display.to_glib_none().0,
311        ))
312    }
313}
314
315/// Creates a [`pango::Context`][crate::pango::Context] for `screen`.
316///
317/// The context must be freed when you’re finished with it.
318///
319/// When using GTK+, normally you should use `gtk_widget_get_pango_context()`
320/// instead of this function, to get the appropriate context for
321/// the widget you intend to render text onto.
322///
323/// The newly created context will have the default font options
324/// (see [`cairo::FontOptions`][crate::cairo::FontOptions]) for the screen; if these options
325/// change it will not be updated. Using `gtk_widget_get_pango_context()`
326/// is more convenient if you want to keep a context around and track
327/// changes to the screen’s font rendering settings.
328/// ## `screen`
329/// the [`Screen`][crate::Screen] for which the context is to be created.
330///
331/// # Returns
332///
333/// a new [`pango::Context`][crate::pango::Context] for `screen`
334#[doc(alias = "gdk_pango_context_get_for_screen")]
335pub fn pango_context_get_for_screen(screen: &Screen) -> Option<pango::Context> {
336    skip_assert_initialized!();
337    unsafe {
338        from_glib_full(ffi::gdk_pango_context_get_for_screen(
339            screen.to_glib_none().0,
340        ))
341    }
342}
343
344//#[doc(alias = "gdk_pango_layout_line_get_clip_region")]
345//pub fn pango_layout_line_get_clip_region(line: &pango::LayoutLine, x_origin: i32, y_origin: i32, index_ranges: &[i32], n_ranges: i32) -> Option<cairo::Region> {
346//    unsafe { TODO: call ffi:gdk_pango_layout_line_get_clip_region() }
347//}
348
349/// Transfers image data from a [`cairo::Surface`][crate::cairo::Surface] and converts it to an RGB(A)
350/// representation inside a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]. This allows you to efficiently read
351/// individual pixels from cairo surfaces. For `GdkWindows`, use
352/// `gdk_pixbuf_get_from_window()` instead.
353///
354/// This function will create an RGB pixbuf with 8 bits per channel.
355/// The pixbuf will contain an alpha channel if the `surface` contains one.
356/// ## `surface`
357/// surface to copy from
358/// ## `src_x`
359/// Source X coordinate within `surface`
360/// ## `src_y`
361/// Source Y coordinate within `surface`
362/// ## `width`
363/// Width in pixels of region to get
364/// ## `height`
365/// Height in pixels of region to get
366///
367/// # Returns
368///
369/// A newly-created pixbuf with a
370///  reference count of 1, or [`None`] on error
371#[doc(alias = "gdk_pixbuf_get_from_surface")]
372pub fn pixbuf_get_from_surface(
373    surface: &cairo::Surface,
374    src_x: i32,
375    src_y: i32,
376    width: i32,
377    height: i32,
378) -> Option<gdk_pixbuf::Pixbuf> {
379    assert_initialized_main_thread!();
380    unsafe {
381        from_glib_full(ffi::gdk_pixbuf_get_from_surface(
382            mut_override(surface.to_glib_none().0),
383            src_x,
384            src_y,
385            width,
386            height,
387        ))
388    }
389}
390
391/// Deletes a property from a window.
392/// ## `window`
393/// a [`Window`][crate::Window]
394/// ## `property`
395/// the property to delete
396#[doc(alias = "gdk_property_delete")]
397pub fn property_delete(window: &Window, property: &Atom) {
398    skip_assert_initialized!();
399    unsafe {
400        ffi::gdk_property_delete(window.to_glib_none().0, property.to_glib_none().0);
401    }
402}
403
404/// Retrieves a portion of the contents of a property. If the
405/// property does not exist, then the function returns [`false`],
406/// and `GDK_NONE` will be stored in `actual_property_type`.
407///
408/// The XGetWindowProperty() function that [`property_get()`][crate::property_get()]
409/// uses has a very confusing and complicated set of semantics.
410/// Unfortunately, [`property_get()`][crate::property_get()] makes the situation
411/// worse instead of better (the semantics should be considered
412/// undefined), and also prints warnings to stderr in cases where it
413/// should return a useful error to the program. You are advised to use
414/// XGetWindowProperty() directly until a replacement function for
415/// [`property_get()`][crate::property_get()] is provided.
416/// ## `window`
417/// a [`Window`][crate::Window]
418/// ## `property`
419/// the property to retrieve
420/// ## `type_`
421/// the desired property type, or `GDK_NONE`, if any type of data
422///  is acceptable. If this does not match the actual
423///  type, then `actual_format` and `actual_length` will
424///  be filled in, a warning will be printed to stderr
425///  and no data will be returned.
426/// ## `offset`
427/// the offset into the property at which to begin
428///  retrieving data, in 4 byte units.
429/// ## `length`
430/// the length of the data to retrieve in bytes. Data is
431///  considered to be retrieved in 4 byte chunks, so `length`
432///  will be rounded up to the next highest 4 byte boundary
433///  (so be careful not to pass a value that might overflow
434///  when rounded up).
435/// ## `pdelete`
436/// if [`true`], delete the property after retrieving the
437///  data.
438///
439/// # Returns
440///
441/// [`true`] if data was successfully received and stored
442///  in `data`, otherwise [`false`].
443///
444/// ## `actual_property_type`
445/// location to store the
446///  actual type of the property.
447///
448/// ## `actual_format`
449/// location to store the actual return format of the
450///  data; either 8, 16 or 32 bits.
451///
452/// ## `data`
453/// location
454///  to store a pointer to the data. The retrieved data should be
455///  freed with `g_free()` when you are finished using it.
456#[doc(alias = "gdk_property_get")]
457pub fn property_get(
458    window: &Window,
459    property: &Atom,
460    type_: &Atom,
461    offset: libc::c_ulong,
462    length: libc::c_ulong,
463    pdelete: i32,
464) -> Option<(Atom, i32, Vec<u8>)> {
465    skip_assert_initialized!();
466    unsafe {
467        let mut actual_property_type = Atom::uninitialized();
468        let mut actual_format = std::mem::MaybeUninit::uninit();
469        let mut actual_length = std::mem::MaybeUninit::uninit();
470        let mut data = std::ptr::null_mut();
471        let ret = from_glib(ffi::gdk_property_get(
472            window.to_glib_none().0,
473            property.to_glib_none().0,
474            type_.to_glib_none().0,
475            offset,
476            length,
477            pdelete,
478            actual_property_type.to_glib_none_mut().0,
479            actual_format.as_mut_ptr(),
480            actual_length.as_mut_ptr(),
481            &mut data,
482        ));
483        if ret {
484            Some((
485                actual_property_type,
486                actual_format.assume_init(),
487                FromGlibContainer::from_glib_full_num(data, actual_length.assume_init() as _),
488            ))
489        } else {
490            None
491        }
492    }
493}
494
495/// Retrieves the contents of a selection in a given
496/// form.
497/// ## `requestor`
498/// a [`Window`][crate::Window].
499/// ## `selection`
500/// an atom identifying the selection to get the
501///  contents of.
502/// ## `target`
503/// the form in which to retrieve the selection.
504/// ## `time_`
505/// the timestamp to use when retrieving the
506///  selection. The selection owner may refuse the
507///  request if it did not own the selection at
508///  the time indicated by the timestamp.
509#[doc(alias = "gdk_selection_convert")]
510pub fn selection_convert(requestor: &Window, selection: &Atom, target: &Atom, time_: u32) {
511    skip_assert_initialized!();
512    unsafe {
513        ffi::gdk_selection_convert(
514            requestor.to_glib_none().0,
515            selection.to_glib_none().0,
516            target.to_glib_none().0,
517            time_,
518        );
519    }
520}
521
522/// Determines the owner of the given selection.
523/// ## `selection`
524/// an atom indentifying a selection.
525///
526/// # Returns
527///
528/// if there is a selection owner
529///  for this window, and it is a window known to the current process,
530///  the [`Window`][crate::Window] that owns the selection, otherwise [`None`]. Note
531///  that the return value may be owned by a different process if a
532///  foreign window was previously created for that window, but a new
533///  foreign window will never be created by this call.
534#[doc(alias = "gdk_selection_owner_get")]
535pub fn selection_owner_get(selection: &Atom) -> Option<Window> {
536    assert_initialized_main_thread!();
537    unsafe { from_glib_none(ffi::gdk_selection_owner_get(selection.to_glib_none().0)) }
538}
539
540/// Determine the owner of the given selection.
541///
542/// Note that the return value may be owned by a different
543/// process if a foreign window was previously created for that
544/// window, but a new foreign window will never be created by this call.
545/// ## `display`
546/// a [`Display`][crate::Display]
547/// ## `selection`
548/// an atom indentifying a selection
549///
550/// # Returns
551///
552/// if there is a selection owner
553///  for this window, and it is a window known to the current
554///  process, the [`Window`][crate::Window] that owns the selection, otherwise
555///  [`None`].
556#[doc(alias = "gdk_selection_owner_get_for_display")]
557pub fn selection_owner_get_for_display(display: &Display, selection: &Atom) -> Option<Window> {
558    skip_assert_initialized!();
559    unsafe {
560        from_glib_none(ffi::gdk_selection_owner_get_for_display(
561            display.to_glib_none().0,
562            selection.to_glib_none().0,
563        ))
564    }
565}
566
567/// Sets the owner of the given selection.
568/// ## `owner`
569/// a [`Window`][crate::Window] or [`None`] to indicate that the
570///  the owner for the given should be unset.
571/// ## `selection`
572/// an atom identifying a selection.
573/// ## `time_`
574/// timestamp to use when setting the selection.
575///  If this is older than the timestamp given last
576///  time the owner was set for the given selection, the
577///  request will be ignored.
578/// ## `send_event`
579/// if [`true`], and the new owner is different
580///  from the current owner, the current owner
581///  will be sent a SelectionClear event.
582///
583/// # Returns
584///
585/// [`true`] if the selection owner was successfully
586///  changed to `owner`, otherwise [`false`].
587#[doc(alias = "gdk_selection_owner_set")]
588pub fn selection_owner_set(
589    owner: Option<&Window>,
590    selection: &Atom,
591    time_: u32,
592    send_event: bool,
593) -> bool {
594    assert_initialized_main_thread!();
595    unsafe {
596        from_glib(ffi::gdk_selection_owner_set(
597            owner.to_glib_none().0,
598            selection.to_glib_none().0,
599            time_,
600            send_event.into_glib(),
601        ))
602    }
603}
604
605/// Sets the [`Window`][crate::Window] `owner` as the current owner of the selection `selection`.
606/// ## `display`
607/// the [`Display`][crate::Display]
608/// ## `owner`
609/// a [`Window`][crate::Window] or [`None`] to indicate that the owner for
610///  the given should be unset
611/// ## `selection`
612/// an atom identifying a selection
613/// ## `time_`
614/// timestamp to use when setting the selection
615///  If this is older than the timestamp given last time the owner was
616///  set for the given selection, the request will be ignored
617/// ## `send_event`
618/// if [`true`], and the new owner is different from the current
619///  owner, the current owner will be sent a SelectionClear event
620///
621/// # Returns
622///
623/// [`true`] if the selection owner was successfully changed to owner,
624///  otherwise [`false`].
625#[doc(alias = "gdk_selection_owner_set_for_display")]
626pub fn selection_owner_set_for_display(
627    display: &Display,
628    owner: Option<&Window>,
629    selection: &Atom,
630    time_: u32,
631    send_event: bool,
632) -> bool {
633    skip_assert_initialized!();
634    unsafe {
635        from_glib(ffi::gdk_selection_owner_set_for_display(
636            display.to_glib_none().0,
637            owner.to_glib_none().0,
638            selection.to_glib_none().0,
639            time_,
640            send_event.into_glib(),
641        ))
642    }
643}
644
645/// Sends a response to SelectionRequest event.
646/// ## `requestor`
647/// window to which to deliver response.
648/// ## `selection`
649/// selection that was requested.
650/// ## `target`
651/// target that was selected.
652/// ## `property`
653/// property in which the selection owner stored the
654///  data, or `GDK_NONE` to indicate that the request
655///  was rejected.
656/// ## `time_`
657/// timestamp.
658#[doc(alias = "gdk_selection_send_notify")]
659pub fn selection_send_notify(
660    requestor: &Window,
661    selection: &Atom,
662    target: &Atom,
663    property: &Atom,
664    time_: u32,
665) {
666    skip_assert_initialized!();
667    unsafe {
668        ffi::gdk_selection_send_notify(
669            requestor.to_glib_none().0,
670            selection.to_glib_none().0,
671            target.to_glib_none().0,
672            property.to_glib_none().0,
673            time_,
674        );
675    }
676}
677
678/// Send a response to SelectionRequest event.
679/// ## `display`
680/// the [`Display`][crate::Display] where `requestor` is realized
681/// ## `requestor`
682/// window to which to deliver response
683/// ## `selection`
684/// selection that was requested
685/// ## `target`
686/// target that was selected
687/// ## `property`
688/// property in which the selection owner stored the data,
689///  or `GDK_NONE` to indicate that the request was rejected
690/// ## `time_`
691/// timestamp
692#[doc(alias = "gdk_selection_send_notify_for_display")]
693pub fn selection_send_notify_for_display(
694    display: &Display,
695    requestor: &Window,
696    selection: &Atom,
697    target: &Atom,
698    property: &Atom,
699    time_: u32,
700) {
701    skip_assert_initialized!();
702    unsafe {
703        ffi::gdk_selection_send_notify_for_display(
704            display.to_glib_none().0,
705            requestor.to_glib_none().0,
706            selection.to_glib_none().0,
707            target.to_glib_none().0,
708            property.to_glib_none().0,
709            time_,
710        );
711    }
712}
713
714///
715/// gdk_set_allowed_backends ("wayland,quartz,*");
716/// ]|
717/// instructs GDK to try the Wayland backend first,
718/// followed by the Quartz backend, and then all
719/// others.
720///
721/// If the `GDK_BACKEND` environment variable
722/// is set, it determines what backends are tried in what
723/// order, while still respecting the set of allowed backends
724/// that are specified by this function.
725///
726/// The possible backend names are x11, win32, quartz,
727/// broadway, wayland. You can also include a * in the
728/// list to try all remaining backends.
729///
730/// This call must happen prior to [`Display::open()`][crate::Display::open()],
731/// `gtk_init()`, `gtk_init_with_args()` or `gtk_init_check()`
732/// in order to take effect.
733/// ## `backends`
734/// a comma-separated list of backends
735#[doc(alias = "gdk_set_allowed_backends")]
736pub fn set_allowed_backends(backends: &str) {
737    skip_assert_initialized!();
738    unsafe {
739        ffi::gdk_set_allowed_backends(backends.to_glib_none().0);
740    }
741}
742
743/// Set the double click time for the default display. See
744/// [`Display::set_double_click_time()`][crate::Display::set_double_click_time()].
745/// See also [`Display::set_double_click_distance()`][crate::Display::set_double_click_distance()].
746/// Applications should not set this, it is a
747/// global user-configured setting.
748/// ## `msec`
749/// double click time in milliseconds (thousandths of a second)
750#[doc(alias = "gdk_set_double_click_time")]
751pub fn set_double_click_time(msec: u32) {
752    assert_initialized_main_thread!();
753    unsafe {
754        ffi::gdk_set_double_click_time(msec);
755    }
756}
757
758/// Sets the program class. The X11 backend uses the program class to set
759/// the class name part of the `WM_CLASS` property on
760/// toplevel windows; see the ICCCM.
761///
762/// The program class can still be overridden with the --class command
763/// line option.
764/// ## `program_class`
765/// a string.
766#[doc(alias = "gdk_set_program_class")]
767pub fn set_program_class(program_class: &str) {
768    assert_initialized_main_thread!();
769    unsafe {
770        ffi::gdk_set_program_class(program_class.to_glib_none().0);
771    }
772}
773
774/// Sets whether a trace of received events is output.
775/// Note that GTK+ must be compiled with debugging (that is,
776/// configured using the `--enable-debug` option)
777/// to use this option.
778/// ## `show_events`
779/// [`true`] to output event debugging information.
780#[doc(alias = "gdk_set_show_events")]
781pub fn set_show_events(show_events: bool) {
782    assert_initialized_main_thread!();
783    unsafe {
784        ffi::gdk_set_show_events(show_events.into_glib());
785    }
786}
787
788#[doc(alias = "gdk_synthesize_window_state")]
789pub fn synthesize_window_state(window: &Window, unset_flags: WindowState, set_flags: WindowState) {
790    skip_assert_initialized!();
791    unsafe {
792        ffi::gdk_synthesize_window_state(
793            window.to_glib_none().0,
794            unset_flags.into_glib(),
795            set_flags.into_glib(),
796        );
797    }
798}
799
800/// Retrieves a pixel from `window` to force the windowing
801/// system to carry out any pending rendering commands.
802///
803/// This function is intended to be used to synchronize with rendering
804/// pipelines, to benchmark windowing system rendering operations.
805/// ## `window`
806/// a mapped [`Window`][crate::Window]
807#[doc(alias = "gdk_test_render_sync")]
808pub fn test_render_sync(window: &Window) {
809    skip_assert_initialized!();
810    unsafe {
811        ffi::gdk_test_render_sync(window.to_glib_none().0);
812    }
813}
814
815/// This function is intended to be used in GTK+ test programs.
816/// It will warp the mouse pointer to the given (`x`,`y`) coordinates
817/// within `window` and simulate a button press or release event.
818/// Because the mouse pointer needs to be warped to the target
819/// location, use of this function outside of test programs that
820/// run in their own virtual windowing system (e.g. Xvfb) is not
821/// recommended.
822///
823/// Also, [`test_simulate_button()`][crate::test_simulate_button()] is a fairly low level function,
824/// for most testing purposes, `gtk_test_widget_click()` is the right
825/// function to call which will generate a button press event followed
826/// by its accompanying button release event.
827/// ## `window`
828/// a [`Window`][crate::Window] to simulate a button event for
829/// ## `x`
830/// x coordinate within `window` for the button event
831/// ## `y`
832/// y coordinate within `window` for the button event
833/// ## `button`
834/// Number of the pointer button for the event, usually 1, 2 or 3
835/// ## `modifiers`
836/// Keyboard modifiers the event is setup with
837/// ## `button_pressrelease`
838/// either [`EventType::ButtonPress`][crate::EventType::ButtonPress] or [`EventType::ButtonRelease`][crate::EventType::ButtonRelease]
839///
840/// # Returns
841///
842/// whether all actions necessary for a button event simulation
843///  were carried out successfully
844#[doc(alias = "gdk_test_simulate_button")]
845pub fn test_simulate_button(
846    window: &Window,
847    x: i32,
848    y: i32,
849    button: u32,
850    modifiers: ModifierType,
851    button_pressrelease: EventType,
852) -> bool {
853    skip_assert_initialized!();
854    unsafe {
855        from_glib(ffi::gdk_test_simulate_button(
856            window.to_glib_none().0,
857            x,
858            y,
859            button,
860            modifiers.into_glib(),
861            button_pressrelease.into_glib(),
862        ))
863    }
864}
865
866///  (-1,-1), it will warp the mouse pointer to
867/// the given (`x`,`y`) coordinates within `window` and simulate a
868/// key press or release event.
869///
870/// When the mouse pointer is warped to the target location, use
871/// of this function outside of test programs that run in their
872/// own virtual windowing system (e.g. Xvfb) is not recommended.
873/// If (`x`,`y`) are passed as (-1,-1), the mouse pointer will not
874/// be warped and `window` origin will be used as mouse pointer
875/// location for the event.
876///
877/// Also, [`test_simulate_key()`][crate::test_simulate_key()] is a fairly low level function,
878/// for most testing purposes, `gtk_test_widget_send_key()` is the
879/// right function to call which will generate a key press event
880/// followed by its accompanying key release event.
881/// ## `window`
882/// a [`Window`][crate::Window] to simulate a key event for
883/// ## `x`
884/// x coordinate within `window` for the key event
885/// ## `y`
886/// y coordinate within `window` for the key event
887/// ## `keyval`
888/// A GDK keyboard value
889/// ## `modifiers`
890/// Keyboard modifiers the event is setup with
891/// ## `key_pressrelease`
892/// either [`EventType::KeyPress`][crate::EventType::KeyPress] or [`EventType::KeyRelease`][crate::EventType::KeyRelease]
893///
894/// # Returns
895///
896/// whether all actions necessary for a key event simulation
897///  were carried out successfully
898#[doc(alias = "gdk_test_simulate_key")]
899pub fn test_simulate_key(
900    window: &Window,
901    x: i32,
902    y: i32,
903    keyval: u32,
904    modifiers: ModifierType,
905    key_pressrelease: EventType,
906) -> bool {
907    skip_assert_initialized!();
908    unsafe {
909        from_glib(ffi::gdk_test_simulate_key(
910            window.to_glib_none().0,
911            x,
912            y,
913            keyval,
914            modifiers.into_glib(),
915            key_pressrelease.into_glib(),
916        ))
917    }
918}
919
920/// Converts a text property in the given encoding to
921/// a list of UTF-8 strings.
922/// ## `display`
923/// a [`Display`][crate::Display]
924/// ## `encoding`
925/// an atom representing the encoding of the text
926/// ## `format`
927/// the format of the property
928/// ## `text`
929/// the text to convert
930///
931/// # Returns
932///
933/// the number of strings in the resulting list
934///
935/// ## `list`
936/// location to store the list
937///  of strings or [`None`]. The list should be freed with
938///  `g_strfreev()`.
939#[doc(alias = "gdk_text_property_to_utf8_list_for_display")]
940pub fn text_property_to_utf8_list_for_display(
941    display: &Display,
942    encoding: &Atom,
943    format: i32,
944    text: &[u8],
945) -> (i32, Vec<glib::GString>) {
946    skip_assert_initialized!();
947    let length = text.len() as _;
948    unsafe {
949        let mut list = std::ptr::null_mut();
950        let ret = ffi::gdk_text_property_to_utf8_list_for_display(
951            display.to_glib_none().0,
952            encoding.to_glib_none().0,
953            format,
954            text.to_glib_none().0,
955            length,
956            &mut list,
957        );
958        (ret, FromGlibPtrContainer::from_glib_full(list))
959    }
960}
961
962/// Converts an UTF-8 string into the best possible representation
963/// as a STRING. The representation of characters not in STRING
964/// is not specified; it may be as pseudo-escape sequences
965/// \x{ABCD}, or it may be in some other form of approximation.
966/// ## `str`
967/// a UTF-8 string
968///
969/// # Returns
970///
971/// the newly-allocated string, or [`None`] if the
972///  conversion failed. (It should not fail for any properly
973///  formed UTF-8 string unless system limits like memory or
974///  file descriptors are exceeded.)
975#[doc(alias = "gdk_utf8_to_string_target")]
976pub fn utf8_to_string_target(str: &str) -> Option<glib::GString> {
977    assert_initialized_main_thread!();
978    unsafe { from_glib_full(ffi::gdk_utf8_to_string_target(str.to_glib_none().0)) }
979}