📄 main.sgml
字号:
</para> <figure id="mainloop-states"> <title>States of a Main Context</title> <graphic fileref="mainloop-states.gif" format="gif"></graphic> </figure> </refsect2></refsect1><refsect1><title>Details</title><refsect2><title><anchor id="GMainLoop">struct GMainLoop</title><programlisting>struct GMainLoop;</programlisting><para>The <structname>GMainLoop</structname> struct is an opaque data type representing the main event loop of a GLib or GTK+ application.</para></refsect2><refsect2><title><anchor id="g-main-loop-new">g_main_loop_new ()</title><programlisting><link linkend="GMainLoop">GMainLoop</link>* g_main_loop_new (<link linkend="GMainContext">GMainContext</link> *context, <link linkend="gboolean">gboolean</link> is_running);</programlisting><para>Creates a new <link linkend="GMainLoop">GMainLoop</link> structure.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>context</parameter> :</entry><entry> a <link linkend="GMainContext">GMainContext</link> (if <literal>NULL</literal>, the default context will be used).</entry></row><row><entry align="right"><parameter>is_running</parameter> :</entry><entry> set to <literal>TRUE</literal> to indicate that the loop is running. Thisis not very important since calling <link linkend="g-main-loop-run">g_main_loop_run</link>() will set this to<literal>TRUE</literal> anyway.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> a new <link linkend="GMainLoop">GMainLoop</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-loop-ref">g_main_loop_ref ()</title><programlisting><link linkend="GMainLoop">GMainLoop</link>* g_main_loop_ref (<link linkend="GMainLoop">GMainLoop</link> *loop);</programlisting><para>Increases the reference count on a <link linkend="GMainLoop">GMainLoop</link> object by one.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry> a <link linkend="GMainLoop">GMainLoop</link></entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> <parameter>loop</parameter></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-loop-unref">g_main_loop_unref ()</title><programlisting>void g_main_loop_unref (<link linkend="GMainLoop">GMainLoop</link> *loop);</programlisting><para>Decreases the reference count on a <link linkend="GMainLoop">GMainLoop</link> object by one. Ifthe result is zero, free the loop and free all associated memory.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry> a <link linkend="GMainLoop">GMainLoop</link></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-loop-run">g_main_loop_run ()</title><programlisting>void g_main_loop_run (<link linkend="GMainLoop">GMainLoop</link> *loop);</programlisting><para>Runs a main loop until <link linkend="g-main-loop-quit">g_main_loop_quit</link>() is called on the loop.If this is called for the thread of the loop's <link linkend="GMainContext">GMainContext</link>,it will process events from the loop, otherwise it willsimply wait.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry> a <link linkend="GMainLoop">GMainLoop</link></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-loop-quit">g_main_loop_quit ()</title><programlisting>void g_main_loop_quit (<link linkend="GMainLoop">GMainLoop</link> *loop);</programlisting><para>Stops a <link linkend="GMainLoop">GMainLoop</link> from running. Any calls to <link linkend="g-main-loop-run">g_main_loop_run</link>()for the loop will return.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry> a <link linkend="GMainLoop">GMainLoop</link></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-loop-is-running">g_main_loop_is_running ()</title><programlisting><link linkend="gboolean">gboolean</link> g_main_loop_is_running (<link linkend="GMainLoop">GMainLoop</link> *loop);</programlisting><para>Checks to see if the main loop is currently being run via <link linkend="g-main-loop-run">g_main_loop_run</link>().</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry> a <link linkend="GMainLoop">GMainLoop</link>.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> <literal>TRUE</literal> if the mainloop is currently being run.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-loop-get-context">g_main_loop_get_context ()</title><programlisting><link linkend="GMainContext">GMainContext</link>* g_main_loop_get_context (<link linkend="GMainLoop">GMainLoop</link> *loop);</programlisting><para>Returns the <link linkend="GMainContext">GMainContext</link> of <parameter>loop</parameter>.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry> a <link linkend="GMainLoop">GMainLoop</link>.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> the <link linkend="GMainContext">GMainContext</link> of <parameter>loop</parameter></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-new">g_main_new()</title><programlisting>#define g_main_new(is_running)</programlisting><warning><para><literal>g_main_new</literal> is deprecated and should not be used in newly-written code.</para></warning><para>Creates a new <link linkend="GMainLoop">GMainLoop</link> for the default main loop. A compatibilitymacro, see <link linkend="g-main-loop-new">g_main_loop_new</link>().</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>is_running</parameter> :</entry><entry>set to <literal>TRUE</literal> to indicate that the loop is running. This is notvery important since calling <link linkend="g-main-run">g_main_run</link>() will set this to <literal>TRUE</literal> anyway.</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>a new <link linkend="GMainLoop">GMainLoop</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-destroy">g_main_destroy()</title><programlisting>#define g_main_destroy(loop)</programlisting><warning><para><literal>g_main_destroy</literal> is deprecated and should not be used in newly-written code.</para></warning><para>Frees the memory allocated for the <link linkend="GMainLoop">GMainLoop</link>. A compatibility macro, see<link linkend="g-main-loop-destroy">g_main_loop_destroy</link>().</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry>a <link linkend="GMainLoop">GMainLoop</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-run">g_main_run()</title><programlisting>#define g_main_run(loop)</programlisting><warning><para><literal>g_main_run</literal> is deprecated and should not be used in newly-written code.</para></warning><para>Runs a main loop until it stops running. A compatibility macro, see <link linkend="g-main-loop-run">g_main_loop_run</link>().</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry>a <link linkend="GMainLoop">GMainLoop</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-quit">g_main_quit()</title><programlisting>#define g_main_quit(loop)</programlisting><warning><para><literal>g_main_quit</literal> is deprecated and should not be used in newly-written code.</para></warning><para>Stops the <link linkend="GMainLoop">GMainLoop</link>. If <link linkend="g-main-run">g_main_run</link>() was called to run the <link linkend="GMainLoop">GMainLoop</link>,it will now return. A compatibility macro, see <link linkend="g-main-loop-quit">g_main_loop_quit</link>().</para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>loop</parameter> :</entry><entry>a <link linkend="GMainLoop">GMainLoop</link>.</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-main-is-running">g_main_is_running()</title><programlisting>#define g_main_is_running(loop)</programlisting><warning><para>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -