gi-gtk-3.0.32: Gtk bindings
CopyrightWill Thompson Iñaki García Etxebarria and Jonas Platte
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellNone
LanguageHaskell2010

GI.Gtk.Objects.Socket

Description

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

Exported types

newtype Socket Source #

Memory-managed wrapper type.

Constructors

Socket (ManagedPtr Socket) 

Instances

Instances details
Eq Socket Source # 
Instance details

Defined in GI.Gtk.Objects.Socket

Methods

(==) :: Socket -> Socket -> Bool #

(/=) :: Socket -> Socket -> Bool #

IsGValue Socket Source #

Convert Socket to and from GValue with toGValue and fromGValue.

Instance details

Defined in GI.Gtk.Objects.Socket

GObject Socket Source # 
Instance details

Defined in GI.Gtk.Objects.Socket

Methods

gobjectType :: IO GType #

HasParentTypes Socket Source # 
Instance details

Defined in GI.Gtk.Objects.Socket

type ParentTypes Socket Source # 
Instance details

Defined in GI.Gtk.Objects.Socket

class (GObject o, IsDescendantOf Socket o) => IsSocket o Source #

Type class for types which can be safely cast to Socket, for instance with toSocket.

Instances

Instances details
(GObject o, IsDescendantOf Socket o) => IsSocket o Source # 
Instance details

Defined in GI.Gtk.Objects.Socket

toSocket :: (MonadIO m, IsSocket o) => o -> m Socket Source #

Cast to Socket, for types for which this is known to be safe. For general casts, use castTo.

noSocket :: Maybe Socket Source #

A convenience alias for Nothing :: Maybe Socket.

Methods

Overloaded methods

addId

socketAddId Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

socket_: a Socket

-> CULong

window: the Window of a client participating in the XEMBED protocol.

-> 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

socketGetId Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

socket_: a Socket.

-> m CULong

Returns: the window ID for the socket

Gets the window ID of a Socket widget, which can then be used to create a client embedded inside the socket, for instance with plugNew.

The Socket must have already be added into a toplevel window before you can make this call.

getPlugWindow

socketGetPlugWindow Source #

Arguments

:: (HasCallStack, MonadIO m, IsSocket a) 
=> a

socket_: a Socket.

-> m (Maybe Window)

Returns: the window of the plug if available, or Nothing

Retrieves the window of the plug. Use this to check if the plug has been created inside of the socket.

Since: 2.14

new

socketNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m Socket

Returns: the new Socket.

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

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

plugRemoved

type C_SocketPlugRemovedCallback = Ptr () -> Ptr () -> IO CInt Source #

Type for the callback on the (unwrapped) C side.

type SocketPlugRemovedCallback Source #

Arguments

 = IO Bool

Returns: True to stop other handlers from being invoked.

This signal is emitted when a client is removed from the socket. The default action is to destroy the Socket widget, so if you want to reuse it you must add a signal handler that returns True.

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

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