<refentry id="GtkSocket">
<refmeta>
<refentrytitle>GtkSocket</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GTK Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>GtkSocket</refname><refpurpose>Container for widgets from other processes.</refpurpose>
</refnamediv>

<refsynopsisdiv><title>Synopsis</title>
<synopsis>

#include &lt;gtk/gtk.h&gt;


struct      <link linkend="GtkSocket-struct">GtkSocket</link>;
<link linkend="GtkWidget">GtkWidget</link>*  <link linkend="gtk-socket-new">gtk_socket_new</link>                  (void);
void        <link linkend="gtk-socket-steal">gtk_socket_steal</link>                (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                             <link linkend="GdkNativeWindow">GdkNativeWindow</link> wid);
void        <link linkend="gtk-socket-add-id">gtk_socket_add_id</link>               (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                             <link linkend="GdkNativeWindow">GdkNativeWindow</link> window_id);
<link linkend="GdkNativeWindow">GdkNativeWindow</link> <link linkend="gtk-socket-get-id">gtk_socket_get_id</link>           (<link linkend="GtkSocket">GtkSocket</link> *socket);


</synopsis>
</refsynopsisdiv>

<refsect1>
<title>Object Hierarchy</title>
<synopsis>

  <link linkend="GObject">GObject</link>
   +----<link linkend="GtkObject">GtkObject</link>
         +----<link linkend="GtkWidget">GtkWidget</link>
               +----<link linkend="GtkContainer">GtkContainer</link>
                     +----GtkSocket
</synopsis>

</refsect1>


<refsect1>
<title>Signal Prototypes</title>
<synopsis>

&quot;<link linkend="GtkSocket-plug-added">plug-added</link>&quot;
            void        user_function      (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                            <link linkend="gpointer">gpointer</link> user_data);
&quot;<link linkend="GtkSocket-plug-removed">plug-removed</link>&quot;
            <link linkend="gboolean">gboolean</link>    user_function      (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                            <link linkend="gpointer">gpointer</link> user_data);
</synopsis>
</refsect1>


<refsect1>
<title>Description</title>
<para>
Together with <link linkend="GtkPlug">GtkPlug</link>, <link linkend="GtkSocket">GtkSocket</link> provides the ability
to embed widgets from one process into another process
in a fashion that is transparent to the user. One
process creates a <link linkend="GtkSocket">GtkSocket</link> widget and, passes the
that widget's window ID to the other process, 
which then creates a <link linkend="GtkPlug">GtkPlug</link> with that window ID.
Any widgets contained in the <link linkend="GtkPlug">GtkPlug</link> then will appear
inside the first applications window.
</para>

<para>
The socket's window ID is obtained by using
<link linkend="gtk-socket-get-id">gtk_socket_get_id</link>(). Before using this function,
the socket must have been realized, and for hence,
have been added to its parent.

<example>
<title>Obtaining the window ID of a socket.</title>
<programlisting>
GtkWidget *socket = gtk_socket_new (<!-- -->);
gtk_widget_show (socket);
gtk_container_add (GTK_CONTAINER (parent), socket);

/* The following call is only necessary if one of
 * the ancestors of the socket is not yet visible.
 */
gtk_widget_realize (socket);
g_print ("The ID of the sockets window is %<link linkend="x">x</link>\n",
         gtk_socket_get_id (socket));
</programlisting>
</example>
</para>

<para>
Note that if you pass the window ID of the socket to another
process that will create a plug in the socket, you 
must make sure that the socket widget is not destroyed
until that plug is created. Violating this rule will
cause unpredictable consequences, the most likely
consequence being that the plug will appear as a 
separate toplevel window. You can check if the plug
has been created by examining the
<StructField>plug_window</StructField> field of the
<link linkend="GtkSocket">GtkSocket</link> structure. If this field is non-<literal>NULL</literal>, 
then the plug has been successfully created inside
of the socket.
</para>

<para>
When GTK+ is notified that the embedded window has been
destroyed, then it will destroy the socket as well. You
should always, therefore, be prepared for your sockets
to be destroyed at any time when the main event loop
is running.
</para>

<para>
The communication between a <link linkend="GtkSocket">GtkSocket</link> and a <link linkend="GtkPlug">GtkPlug</link> follows the 
<ulink url="http://www.freedesktop.org/standards/xembed.html">XEmbed</ulink>
protocol. This protocol has also been implemented in other toolkits, e.g.  
<application>Qt</application>, allowing the same level of integration
when embedding a <application>Qt</application> widget in GTK or vice versa.</para>

<para>
A socket can also be used to swallow arbitrary 
pre-existing top-level windows using <link linkend="gtk-socket-steal">gtk_socket_steal</link>(),
though the integration when this is done will not be as close
as between a <link linkend="GtkPlug">GtkPlug</link> and a <link linkend="GtkSocket">GtkSocket</link>.</para>
</refsect1>

<refsect1>
<title>Details</title>
<refsect2>
<title><anchor id="GtkSocket-struct">struct GtkSocket</title>
<programlisting>struct GtkSocket;</programlisting>
<para>
The <link linkend="GtkSocket">GtkSocket</link> structure contains the <structfield>plug_window</structfield>
field.  (This field should be considered read-only. It should
never be set by an application.)
</para></refsect2>
<refsect2>
<title><anchor id="gtk-socket-new">gtk_socket_new ()</title>
<programlisting><link linkend="GtkWidget">GtkWidget</link>*  gtk_socket_new                  (void);</programlisting>
<para>
Create a new empty <link linkend="GtkSocket">GtkSocket</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"><emphasis>Returns</emphasis> :</entry><entry>  the new <link linkend="GtkSocket">GtkSocket</link>.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-socket-steal">gtk_socket_steal ()</title>
<programlisting>void        gtk_socket_steal                (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                             <link linkend="GdkNativeWindow">GdkNativeWindow</link> wid);</programlisting>
<warning>
<para>
<literal>gtk_socket_steal</literal> is deprecated and should not be used in newly-written code.
</para>
</warning>
<para>
Reparents a pre-existing toplevel window into a <link linkend="GtkSocket">GtkSocket</link>. This is
meant to embed clients that do not know about embedding into a
<link linkend="GtkSocket">GtkSocket</link>, however doing so is inherently unreliable, and using
this function is not recommended.
</para>
<para>
The <link linkend="GtkSocket">GtkSocket</link> must have already be added into a toplevel window
 before you can make this call.</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>socket</parameter>&nbsp;:</entry>
<entry> a <link linkend="GtkSocket">GtkSocket</link>
</entry></row>
<row><entry align="right"><parameter>wid</parameter>&nbsp;:</entry>
<entry> the window ID of an existing toplevel window.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-socket-add-id">gtk_socket_add_id ()</title>
<programlisting>void        gtk_socket_add_id               (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                             <link linkend="GdkNativeWindow">GdkNativeWindow</link> window_id);</programlisting>
<para>
Adds an XEMBED client, such as a <link linkend="GtkPlug">GtkPlug</link>, to the <link linkend="GtkSocket">GtkSocket</link>.  The
client may be in the same process or in a different process. 
</para>
<para>
To embed a <link linkend="GtkPlug">GtkPlug</link> in a <link linkend="GtkSocket">GtkSocket</link>, you can either create the
<link linkend="GtkPlug">GtkPlug</link> with <literal>gtk_plug_new (0)</literal>, call 
<link linkend="gtk-plug-get-id">gtk_plug_get_id</link>() to get the window ID of the plug, and then pass that to the
<link linkend="gtk-socket-add-id">gtk_socket_add_id</link>(), or you can call <link linkend="gtk-socket-get-id">gtk_socket_get_id</link>() to get the
window ID for the socket, and call <link linkend="gtk-plug-new">gtk_plug_new</link>() passing in that
ID.
</para>
<para>
The <link linkend="GtkSocket">GtkSocket</link> must have already be added into a toplevel window
 before you can make this call.</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>socket</parameter>&nbsp;:</entry>
<entry> a <link linkend="GtkSocket">GtkSocket</link>
</entry></row>
<row><entry align="right"><parameter>window_id</parameter>&nbsp;:</entry>
<entry> the window ID of a client participating in the XEMBED protocol.
</entry></row>
</tbody></tgroup></informaltable></refsect2>
<refsect2>
<title><anchor id="gtk-socket-get-id">gtk_socket_get_id ()</title>
<programlisting><link linkend="GdkNativeWindow">GdkNativeWindow</link> gtk_socket_get_id           (<link linkend="GtkSocket">GtkSocket</link> *socket);</programlisting>
<para>
Gets the window ID of a <link linkend="GtkSocket">GtkSocket</link> widget, which can then
be used to create a client embedded inside the socket, for
instance with <link linkend="gtk-plug-new">gtk_plug_new</link>(). 
</para>
<para>
The <link linkend="GtkSocket">GtkSocket</link> must have already be added into a toplevel window 
before you can make this call.</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>socket</parameter>&nbsp;:</entry>
<entry> a <link linkend="GtkSocket">GtkSocket</link>.
</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> the window ID for the socket
</entry></row>
</tbody></tgroup></informaltable></refsect2>

</refsect1>

<refsect1>
<title>Signals</title>
<refsect2><title><anchor id="GtkSocket-plug-added">The &quot;plug-added&quot; signal</title>
<programlisting>void        user_function                  (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                            <link linkend="gpointer">gpointer</link> user_data);</programlisting>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>socket</parameter>&nbsp;:</entry>
<entry>the object which received the signal.

</entry></row>
<row><entry align="right"><parameter>user_data</parameter>&nbsp;:</entry>
<entry>user data set when the signal handler was connected.</entry></row>
</tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="GtkSocket-plug-removed">The &quot;plug-removed&quot; signal</title>
<programlisting><link linkend="gboolean">gboolean</link>    user_function                  (<link linkend="GtkSocket">GtkSocket</link> *socket,
                                            <link linkend="gpointer">gpointer</link> user_data);</programlisting>
<para>

</para><informaltable pgwide="1" frame="none" role="params">
<tgroup cols="2">
<colspec colwidth="2*">
<colspec colwidth="8*">
<tbody>
<row><entry align="right"><parameter>socket</parameter>&nbsp;:</entry>
<entry>the object which received the signal.
</entry></row>
<row><entry align="right"><parameter>user_data</parameter>&nbsp;:</entry>
<entry>user data set when the signal handler was connected.</entry></row>
<row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry>

</entry></row>
</tbody></tgroup></informaltable></refsect2>
</refsect1>


<refsect1>
<title>See Also</title>
<para>
<variablelist>

<varlistentry>
<term><link linkend="GtkPlug">GtkPlug</link></term>
<listitem><para>the widget that plugs into a <link linkend="GtkSocket">GtkSocket</link>.</para></listitem>
</varlistentry>

<varlistentry>
<term><ulink url="http://www.freedesktop.org/standards/xembed.html">XEmbed</ulink></term>
<listitem><para>the XEmbed Protocol Specification.</para></listitem>
</varlistentry>

</variablelist>
</para>
</refsect1>

</refentry>
