## gstxoverlay gstxoverlay — Interface for setting/getting a Window on elements supporting it |

## Synopsis

    #include <gst/interfaces/xoverlay.h>

                        GstXOverlay;
                        GstXOverlayClass;
    void                gst_x_overlay_set_xwindow_id        (GstXOverlay *overlay,
                                                             gulong xwindow_id);
    void                gst_x_overlay_got_xwindow_id        (GstXOverlay *overlay,
                                                             gulong xwindow_id);
    void                gst_x_overlay_prepare_xwindow_id    (GstXOverlay *overlay);
    void                gst_x_overlay_expose                (GstXOverlay *overlay);
    void                gst_x_overlay_handle_events         (GstXOverlay *overlay,
                                                             gboolean handle_events);

## Object Hierarchy

      GInterface
       +----GstXOverlay

## Prerequisites

GstXOverlay requires GstObject, GstImplementsInterface and GstElement.

## Description

The XOverlay interface is used for 2 main purposes :

- To get a grab on the Window where the video sink element is going to render. This is achieved by either being informed about the Window identifier that the video sink element generated, or by forcing the video sink element to use a specific Window identifier for rendering.

- To force a redrawing of the latest video frame the video sink element displayed on the Window. Indeed if the GstPipeline is in GST_STATE_PAUSED state, moving the Window around will damage its content. Application developers will want to handle the Expose events themselves and force the video sink element to refresh the Window's content.

Using the Window created by the video sink is probably the simplest scenario, in some cases, though, it might not be flexible enough for application developers if they need to catch events such as mouse moves and button clicks.

Setting a specific Window identifier on the video sink element is the most flexible solution but it has some issues. Indeed the application needs to set its Window identifier at the right time to avoid internal Window creation from the video sink element. To solve this issue a GstMessage is posted on the bus to inform the application that it should set the Window identifier immediately. Here is an example on how to do that correctly:

    static GstBusSyncReply
    create_window (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
    {
     // ignore anything but 'prepare-xwindow-id' element messages
     if (GST_MESSAGE_TYPE (message) != GST_MESSAGE_ELEMENT)
       return GST_BUS_PASS;

     if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
       return GST_BUS_PASS;

     win = XCreateSimpleWindow (disp, root, 0, 0, 320, 240, 0, 0, 0);

     XSetWindowBackgroundPixmap (disp, win, None);

     XMapRaised (disp, win);

     XSync (disp, FALSE);

     gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (GST_MESSAGE_SRC (message)),
         win);

     gst_message_unref (message);

     return GST_BUS_DROP;
    }
    ...
    int
    main (int argc, char **argv)
    {
    ...
     bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
     gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, pipeline);
    ...
    }

## Details

### GstXOverlay

    typedef struct _GstXOverlay GstXOverlay;

Opaque GstXOverlay data structure.

### GstXOverlayClass

    typedef struct {
      GTypeInterface klass;

      /* virtual functions */
      void (* set_xwindow_id) (GstXOverlay *overlay,
                               gulong       xwindow_id);

      void (* expose)         (GstXOverlay *overlay);

      void (* handle_events)  (GstXOverlay *overlay,
                               gboolean     handle_events);
    } GstXOverlayClass;

GstXOverlay interface

GTypeInterface `klass`; | parent interface type.
`set_xwindow_id` () | virtual method to configure the XWindow id
`expose` () | virtual method to handle expose events
`handle_events` () | virtual method to handle events

### gst_x_overlay_set_xwindow_id ()

    void                gst_x_overlay_set_xwindow_id        (GstXOverlay *overlay,
                                                             gulong xwindow_id);

This will call the video overlay's set_xwindow_id method. You should use this method to tell to a XOverlay to display video output to a specific XWindow. Passing 0 as the xwindow_id will tell the overlay to stop using that window and create an internal one.

`overlay` : | a GstXOverlay to set the XWindow on.
`xwindow_id` : | a XID referencing the XWindow.

### gst_x_overlay_got_xwindow_id ()

    void                gst_x_overlay_got_xwindow_id        (GstXOverlay *overlay,
                                                             gulong xwindow_id);

This will post a "have-xwindow-id" element message on the bus.

This function should only be used by video overlay plugin developers.

`overlay` : | a GstXOverlay which got a XWindow.
`xwindow_id` : | a XID referencing the XWindow.

### gst_x_overlay_prepare_xwindow_id ()

    void                gst_x_overlay_prepare_xwindow_id    (GstXOverlay *overlay);

This will post a "prepare-xwindow-id" element message on the bus to give applications an opportunity to call `gst_x_overlay_set_xwindow_id()` before a plugin creates its own window.

This function should only be used by video overlay plugin developers.

`overlay` : | a GstXOverlay which does not yet have an XWindow.

### gst_x_overlay_expose ()

    void                gst_x_overlay_expose                (GstXOverlay *overlay);

Tell an overlay that it has been exposed. This will redraw the current frame in the drawable even if the pipeline is PAUSED.

`overlay` : | a GstXOverlay to expose.

### gst_x_overlay_handle_events ()

    void                gst_x_overlay_handle_events         (GstXOverlay *overlay,
                                                             gboolean handle_events);

Tell an overlay that it should handle events from the window system. These events are forwared upstream as navigation events. In some window system, events are not propagated in the window hierarchy if a client is listening for them. This method allows you to disable events handling completely from the XOverlay.

`overlay` : | a GstXOverlay to expose.
`handle_events` : | a gboolean indicating if events should be handled or not.