Copyright | Will Thompson Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | None |
Language | Haskell2010 |
Together with Plug
, Socket
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 Socket
widget
and passes that widget’s window ID to the other process, which then
creates a Plug
with that window ID. Any widgets contained in the
Plug
then will appear inside the first application’s window.
The socket’s window ID is obtained by using socketGetId
.
Before using this function, the socket must have been realized,
and for hence, have been added to its parent.
Obtaining the window ID of a socket.
C code
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 %#x\n", gtk_socket_get_id (socket));
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 using socketGetPlugWindow
.
If it returns a non-Nothing
value, then the plug has been
successfully created inside of the socket.
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. To prevent this from happening, you can connect to the plugRemoved signal.
The communication between a Socket
and a Plug
follows the
XEmbed Protocol.
This protocol has also been implemented in other toolkits, e.g. Qt,
allowing the same level of integration when embedding a Qt widget
in GTK or vice versa.
The Plug
and Socket
widgets are only available when GTK+
is compiled for the X11 platform and GDK_WINDOWING_X11
is defined.
They can only be used on a GdkX11Display
. To use Plug
and
Socket
, you need to include the gtk/gtkx.h
header.
Synopsis
- newtype Socket = Socket (ManagedPtr Socket)
- class (GObject o, IsDescendantOf Socket o) => IsSocket o
- toSocket :: (MonadIO m, IsSocket o) => o -> m Socket
- noSocket :: Maybe Socket
- socketAddId :: (HasCallStack, MonadIO m, IsSocket a) => a -> CULong -> m ()
- socketGetId :: (HasCallStack, MonadIO m, IsSocket a) => a -> m CULong
- socketGetPlugWindow :: (HasCallStack, MonadIO m, IsSocket a) => a -> m (Maybe Window)
- socketNew :: (HasCallStack, MonadIO m) => m Socket
- type C_SocketPlugAddedCallback = Ptr () -> Ptr () -> IO ()
- type SocketPlugAddedCallback = IO ()
- afterSocketPlugAdded :: (IsSocket a, MonadIO m) => a -> SocketPlugAddedCallback -> m SignalHandlerId
- genClosure_SocketPlugAdded :: MonadIO m => SocketPlugAddedCallback -> m (GClosure C_SocketPlugAddedCallback)
- mk_SocketPlugAddedCallback :: C_SocketPlugAddedCallback -> IO (FunPtr C_SocketPlugAddedCallback)
- noSocketPlugAddedCallback :: Maybe SocketPlugAddedCallback
- onSocketPlugAdded :: (IsSocket a, MonadIO m) => a -> SocketPlugAddedCallback -> m SignalHandlerId
- wrap_SocketPlugAddedCallback :: SocketPlugAddedCallback -> C_SocketPlugAddedCallback
- type C_SocketPlugRemovedCallback = Ptr () -> Ptr () -> IO CInt
- type SocketPlugRemovedCallback = IO Bool
- afterSocketPlugRemoved :: (IsSocket a, MonadIO m) => a -> SocketPlugRemovedCallback -> m SignalHandlerId
- genClosure_SocketPlugRemoved :: MonadIO m => SocketPlugRemovedCallback -> m (GClosure C_SocketPlugRemovedCallback)
- mk_SocketPlugRemovedCallback :: C_SocketPlugRemovedCallback -> IO (FunPtr C_SocketPlugRemovedCallback)
- noSocketPlugRemovedCallback :: Maybe SocketPlugRemovedCallback
- onSocketPlugRemoved :: (IsSocket a, MonadIO m) => a -> SocketPlugRemovedCallback -> m SignalHandlerId
- wrap_SocketPlugRemovedCallback :: SocketPlugRemovedCallback -> C_SocketPlugRemovedCallback
Exported types
Memory-managed wrapper type.
Instances
Eq Socket Source # | |
IsGValue Socket Source # | Convert |
GObject Socket Source # | |
Defined in GI.Gtk.Objects.Socket gobjectType :: IO GType # | |
HasParentTypes Socket Source # | |
Defined in GI.Gtk.Objects.Socket | |
type ParentTypes Socket Source # | |
Defined in GI.Gtk.Objects.Socket |
class (GObject o, IsDescendantOf Socket o) => IsSocket o Source #
Instances
(GObject o, IsDescendantOf Socket o) => IsSocket o Source # | |
Defined in GI.Gtk.Objects.Socket |
Methods
Overloaded methods
addId
:: (HasCallStack, MonadIO m, IsSocket a) | |
=> a |
|
-> CULong |
|
-> m () |
Adds an XEMBED client, such as a Plug
, to the Socket
. The
client may be in the same process or in a different process.
To embed a Plug
in a Socket
, you can either create the
Plug
with gtk_plug_new (0)
, call
plugGetId
to get the window ID of the plug, and then pass that to the
socketAddId
, or you can call socketGetId
to get the
window ID for the socket, and call plugNew
passing in that
ID.
The Socket
must have already be added into a toplevel window
before you can make this call.
getId
:: (HasCallStack, MonadIO m, IsSocket a) | |
=> a |
|
-> m CULong | Returns: the window ID for the socket |
getPlugWindow
:: (HasCallStack, MonadIO m, IsSocket a) | |
=> a |
|
-> m (Maybe Window) | Returns: the window of the plug if
available, or |
Retrieves the window of the plug. Use this to check if the plug has been created inside of the socket.
Since: 2.14
new
:: (HasCallStack, MonadIO m) | |
=> m Socket | Returns: the new |
Create a new empty Socket
.
Signals
plugAdded
type C_SocketPlugAddedCallback = Ptr () -> Ptr () -> IO () Source #
Type for the callback on the (unwrapped) C side.
type SocketPlugAddedCallback = IO () Source #
This signal is emitted when a client is successfully added to the socket.
afterSocketPlugAdded :: (IsSocket a, MonadIO m) => a -> SocketPlugAddedCallback -> m SignalHandlerId Source #
Connect a signal handler for the plugAdded signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
socket #plugAdded callback
genClosure_SocketPlugAdded :: MonadIO m => SocketPlugAddedCallback -> m (GClosure C_SocketPlugAddedCallback) Source #
Wrap the callback into a GClosure
.
mk_SocketPlugAddedCallback :: C_SocketPlugAddedCallback -> IO (FunPtr C_SocketPlugAddedCallback) Source #
Generate a function pointer callable from C code, from a C_SocketPlugAddedCallback
.
noSocketPlugAddedCallback :: Maybe SocketPlugAddedCallback Source #
A convenience synonym for
.Nothing
:: Maybe
SocketPlugAddedCallback
onSocketPlugAdded :: (IsSocket a, MonadIO m) => a -> SocketPlugAddedCallback -> m SignalHandlerId Source #
Connect a signal handler for the plugAdded signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
socket #plugAdded callback
wrap_SocketPlugAddedCallback :: SocketPlugAddedCallback -> C_SocketPlugAddedCallback Source #
Wrap a SocketPlugAddedCallback
into a C_SocketPlugAddedCallback
.
plugRemoved
type C_SocketPlugRemovedCallback = Ptr () -> Ptr () -> IO CInt Source #
Type for the callback on the (unwrapped) C side.
afterSocketPlugRemoved :: (IsSocket a, MonadIO m) => a -> SocketPlugRemovedCallback -> m SignalHandlerId Source #
Connect a signal handler for the plugRemoved signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
socket #plugRemoved callback
genClosure_SocketPlugRemoved :: MonadIO m => SocketPlugRemovedCallback -> m (GClosure C_SocketPlugRemovedCallback) Source #
Wrap the callback into a GClosure
.
mk_SocketPlugRemovedCallback :: C_SocketPlugRemovedCallback -> IO (FunPtr C_SocketPlugRemovedCallback) Source #
Generate a function pointer callable from C code, from a C_SocketPlugRemovedCallback
.
noSocketPlugRemovedCallback :: Maybe SocketPlugRemovedCallback Source #
A convenience synonym for
.Nothing
:: Maybe
SocketPlugRemovedCallback
onSocketPlugRemoved :: (IsSocket a, MonadIO m) => a -> SocketPlugRemovedCallback -> m SignalHandlerId Source #
Connect a signal handler for the plugRemoved signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
socket #plugRemoved callback