glib/auto/main_loop.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::{ffi, translate::*, MainContext};
6
7crate::wrapper! {
8 /// The `GMainLoop` struct is an opaque data type
9 /// representing the main event loop of a GLib or GTK application.
10 // rustdoc-stripper-ignore-next-stop
11 /// The `GMainLoop` struct is an opaque data type
12 /// representing the main event loop of a GLib or GTK application.
13 #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
14 pub struct MainLoop(Shared<ffi::GMainLoop>);
15
16 match fn {
17 ref => |ptr| ffi::g_main_loop_ref(ptr),
18 unref => |ptr| ffi::g_main_loop_unref(ptr),
19 type_ => || ffi::g_main_loop_get_type(),
20 }
21}
22
23impl MainLoop {
24 /// Creates a new [`MainLoop`][crate::MainLoop] structure.
25 /// ## `context`
26 /// a #GMainContext (if [`None`], the global-default
27 /// main context will be used).
28 /// ## `is_running`
29 /// set to [`true`] to indicate that the loop is running. This
30 /// is not very important since calling [`run()`][Self::run()] will set this
31 /// to [`true`] anyway.
32 ///
33 /// # Returns
34 ///
35 /// a new #GMainLoop.
36 // rustdoc-stripper-ignore-next-stop
37 /// Creates a new [`MainLoop`][crate::MainLoop] structure.
38 /// ## `context`
39 /// a #GMainContext (if [`None`], the global-default
40 /// main context will be used).
41 /// ## `is_running`
42 /// set to [`true`] to indicate that the loop is running. This
43 /// is not very important since calling [`run()`][Self::run()] will set this
44 /// to [`true`] anyway.
45 ///
46 /// # Returns
47 ///
48 /// a new #GMainLoop.
49 #[doc(alias = "g_main_loop_new")]
50 pub fn new(context: Option<&MainContext>, is_running: bool) -> MainLoop {
51 unsafe {
52 from_glib_full(ffi::g_main_loop_new(
53 context.to_glib_none().0,
54 is_running.into_glib(),
55 ))
56 }
57 }
58
59 /// Returns the [`MainContext`][crate::MainContext] of @self.
60 ///
61 /// # Returns
62 ///
63 /// the [`MainContext`][crate::MainContext] of @self
64 // rustdoc-stripper-ignore-next-stop
65 /// Returns the [`MainContext`][crate::MainContext] of @self.
66 ///
67 /// # Returns
68 ///
69 /// the [`MainContext`][crate::MainContext] of @self
70 #[doc(alias = "g_main_loop_get_context")]
71 #[doc(alias = "get_context")]
72 pub fn context(&self) -> MainContext {
73 unsafe { from_glib_none(ffi::g_main_loop_get_context(self.to_glib_none().0)) }
74 }
75
76 /// Checks to see if the main loop is currently being run via
77 /// [`run()`][Self::run()].
78 ///
79 /// # Returns
80 ///
81 /// [`true`] if the mainloop is currently being run.
82 // rustdoc-stripper-ignore-next-stop
83 /// Checks to see if the main loop is currently being run via
84 /// [`run()`][Self::run()].
85 ///
86 /// # Returns
87 ///
88 /// [`true`] if the mainloop is currently being run.
89 #[doc(alias = "g_main_loop_is_running")]
90 pub fn is_running(&self) -> bool {
91 unsafe { from_glib(ffi::g_main_loop_is_running(self.to_glib_none().0)) }
92 }
93
94 /// Stops a [`MainLoop`][crate::MainLoop] from running. Any calls to
95 /// [`run()`][Self::run()] for the loop will return.
96 ///
97 /// Note that sources that have already been dispatched when
98 /// [`quit()`][Self::quit()] is called will still be executed.
99 // rustdoc-stripper-ignore-next-stop
100 /// Stops a [`MainLoop`][crate::MainLoop] from running. Any calls to
101 /// [`run()`][Self::run()] for the loop will return.
102 ///
103 /// Note that sources that have already been dispatched when
104 /// [`quit()`][Self::quit()] is called will still be executed.
105 #[doc(alias = "g_main_loop_quit")]
106 pub fn quit(&self) {
107 unsafe {
108 ffi::g_main_loop_quit(self.to_glib_none().0);
109 }
110 }
111
112 /// Runs a main loop until [`quit()`][Self::quit()] is called on the loop.
113 /// If this is called for the thread of the loop's #GMainContext,
114 /// it will process events from the loop, otherwise it will
115 /// simply wait.
116 // rustdoc-stripper-ignore-next-stop
117 /// Runs a main loop until [`quit()`][Self::quit()] is called on the loop.
118 /// If this is called for the thread of the loop's #GMainContext,
119 /// it will process events from the loop, otherwise it will
120 /// simply wait.
121 #[doc(alias = "g_main_loop_run")]
122 pub fn run(&self) {
123 unsafe {
124 ffi::g_main_loop_run(self.to_glib_none().0);
125 }
126 }
127}
128
129unsafe impl Send for MainLoop {}
130unsafe impl Sync for MainLoop {}