glib/auto/
main_loop.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use crate::{ffi, translate::*, MainContext};

crate::wrapper! {
    /// The `GMainLoop` struct is an opaque data type
    /// representing the main event loop of a GLib or GTK application.
    // rustdoc-stripper-ignore-next-stop
    /// The `GMainLoop` struct is an opaque data type
    /// representing the main event loop of a GLib or GTK application.
    #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
    pub struct MainLoop(Shared<ffi::GMainLoop>);

    match fn {
        ref => |ptr| ffi::g_main_loop_ref(ptr),
        unref => |ptr| ffi::g_main_loop_unref(ptr),
        type_ => || ffi::g_main_loop_get_type(),
    }
}

impl MainLoop {
    /// Creates a new [`MainLoop`][crate::MainLoop] structure.
    /// ## `context`
    /// a #GMainContext  (if [`None`], the global-default
    ///   main context will be used).
    /// ## `is_running`
    /// set to [`true`] to indicate that the loop is running. This
    /// is not very important since calling [`run()`][Self::run()] will set this
    /// to [`true`] anyway.
    ///
    /// # Returns
    ///
    /// a new #GMainLoop.
    // rustdoc-stripper-ignore-next-stop
    /// Creates a new [`MainLoop`][crate::MainLoop] structure.
    /// ## `context`
    /// a #GMainContext  (if [`None`], the global-default
    ///   main context will be used).
    /// ## `is_running`
    /// set to [`true`] to indicate that the loop is running. This
    /// is not very important since calling [`run()`][Self::run()] will set this
    /// to [`true`] anyway.
    ///
    /// # Returns
    ///
    /// a new #GMainLoop.
    #[doc(alias = "g_main_loop_new")]
    pub fn new(context: Option<&MainContext>, is_running: bool) -> MainLoop {
        unsafe {
            from_glib_full(ffi::g_main_loop_new(
                context.to_glib_none().0,
                is_running.into_glib(),
            ))
        }
    }

    /// Returns the [`MainContext`][crate::MainContext] of @self.
    ///
    /// # Returns
    ///
    /// the [`MainContext`][crate::MainContext] of @self
    // rustdoc-stripper-ignore-next-stop
    /// Returns the [`MainContext`][crate::MainContext] of @self.
    ///
    /// # Returns
    ///
    /// the [`MainContext`][crate::MainContext] of @self
    #[doc(alias = "g_main_loop_get_context")]
    #[doc(alias = "get_context")]
    pub fn context(&self) -> MainContext {
        unsafe { from_glib_none(ffi::g_main_loop_get_context(self.to_glib_none().0)) }
    }

    /// Checks to see if the main loop is currently being run via
    /// [`run()`][Self::run()].
    ///
    /// # Returns
    ///
    /// [`true`] if the mainloop is currently being run.
    // rustdoc-stripper-ignore-next-stop
    /// Checks to see if the main loop is currently being run via
    /// [`run()`][Self::run()].
    ///
    /// # Returns
    ///
    /// [`true`] if the mainloop is currently being run.
    #[doc(alias = "g_main_loop_is_running")]
    pub fn is_running(&self) -> bool {
        unsafe { from_glib(ffi::g_main_loop_is_running(self.to_glib_none().0)) }
    }

    /// Stops a [`MainLoop`][crate::MainLoop] from running. Any calls to
    /// [`run()`][Self::run()] for the loop will return.
    ///
    /// Note that sources that have already been dispatched when
    /// [`quit()`][Self::quit()] is called will still be executed.
    // rustdoc-stripper-ignore-next-stop
    /// Stops a [`MainLoop`][crate::MainLoop] from running. Any calls to
    /// [`run()`][Self::run()] for the loop will return.
    ///
    /// Note that sources that have already been dispatched when
    /// [`quit()`][Self::quit()] is called will still be executed.
    #[doc(alias = "g_main_loop_quit")]
    pub fn quit(&self) {
        unsafe {
            ffi::g_main_loop_quit(self.to_glib_none().0);
        }
    }

    /// Runs a main loop until [`quit()`][Self::quit()] is called on the loop.
    /// If this is called for the thread of the loop's #GMainContext,
    /// it will process events from the loop, otherwise it will
    /// simply wait.
    // rustdoc-stripper-ignore-next-stop
    /// Runs a main loop until [`quit()`][Self::quit()] is called on the loop.
    /// If this is called for the thread of the loop's #GMainContext,
    /// it will process events from the loop, otherwise it will
    /// simply wait.
    #[doc(alias = "g_main_loop_run")]
    pub fn run(&self) {
        unsafe {
            ffi::g_main_loop_run(self.to_glib_none().0);
        }
    }
}

unsafe impl Send for MainLoop {}
unsafe impl Sync for MainLoop {}