I have a need to write a GTK application in C that does some animation using Cairo that will render into a GTK widget that exists in another running application. The idea is to do the very same thing you can do with VLC and Mplayer. For example Mplayer has the -wid option:
-wid (also see -guiwid) (X11, OpenGL and DirectX only)
This tells MPlayer to attach to an existing window. Useful to embed MPlayer in a browser (e.g. the plugger extension). This option
fills the given window completely, thus aspect scaling, panscan, etc
are no longer handled by MPlayer but must be managed by the
application that created the window.
With this Mplayer option you can create a GTK application with a GTKImage widget, get it’s Xid and then play a movie in the GTK application using Mplayer with the Xid specified.
I’m trying to do the same thing except render/draw into the external window using Cairo. Anybody have suggestions or better yet a small code sample?
Take a look to the
GtkSocketandGtkPlugclasses.The main program will create a
GtkSocketand theXIDyou can pass to the other program will be returned by the functiongtk_socket_get_id(). Then the other program will use it as argument to thegtk_plug_new()function. All the render will be done in children of this newGtkPlugobject.UPDATE: Well, if you want… here it is a minimal example of
GtkSocket/GtkPlug. You don’t say if you are using GTK+2 or GTK+3, so I’m assuming version 2.server.c:
client.c:
The XID to be used is printed by the
serverand has to be copied/pasted as argument to theclient: