Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8149443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:51:12+00:00 2026-06-06T14:51:12+00:00

I have a need to write a GTK application in C that does some

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:51:13+00:00Added an answer on June 6, 2026 at 2:51 pm

    Take a look to the GtkSocket and GtkPlug classes.

    The main program will create a GtkSocket and the XID you can pass to the other program will be returned by the function gtk_socket_get_id(). Then the other program will use it as argument to the gtk_plug_new() function. All the render will be done in children of this new GtkPlug object.

    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:

    #include <gtk/gtk.h>
    
    int main(int argc, char **argv)
    {
        gtk_init(&argc, &argv);
    
        GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        GtkWidget *sck = gtk_socket_new();
        gtk_container_add(GTK_CONTAINER(wnd), sck);
        gtk_window_set_default_size(GTK_WINDOW(wnd), 400, 300);
        gtk_widget_show_all(wnd);
    
        GdkNativeWindow nwnd = gtk_socket_get_id(GTK_SOCKET(sck));
        g_print("%lu\n", nwnd);
    
        gtk_main();
        return 0;
    }
    

    client.c:

    #include <stdlib.h>
    #include <gtk/gtk.h>
    #include <cairo/cairo.h>
    #include <math.h>
    
    gboolean OnDraw(GtkWidget *w, GdkEvent *ev, gpointer data)
    {
        GtkAllocation size;
        gtk_widget_get_allocation(w, &size);
    
        cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(w));
        cairo_set_source_rgb(cr, 1, 0, 0);
        cairo_arc(cr, size.width/2, size.height/2, size.height/2, 0, 2*M_PI);
        cairo_fill(cr);
        cairo_destroy(cr);
        return TRUE;
    }
    
    int main(int argc, char **argv)
    {
        gtk_init(&argc, &argv);
    
        GdkNativeWindow nwnd = strtoul(argv[1], NULL, 10);
    
        GtkWidget *plug = gtk_plug_new(nwnd);
        GtkWidget *canvas = gtk_drawing_area_new();
        gtk_container_add(GTK_CONTAINER(plug), canvas);
        g_signal_connect(canvas, "expose-event", (GCallback)OnDraw, NULL);
        gtk_widget_show_all(plug);
    
        gtk_main();
        return 0;
    }
    

    The XID to be used is printed by the server and has to be copied/pasted as argument to the client:

    $ ./server
    60817441
    ^Z
    [1]+  Stopped                 ./server
    $ bg
    $ ./client 60817441
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a standalone Java application which will have a embedded HTTP
I need to write a little ruby function that does word wrapping. I have
I have several projects that need to write structured Textfiles, some with fixed size
I'm into a problem with a GTK+ C application. I have a container that,
I have a need to write code that will prorate a value across a
I need to write a regex which will match URLs that do not have
I have some code I need to write a test for that connects to
I suspect that I will shortly have a need to write an integration library
I need to write simple application that can send and receive some UDP package
I need to write data into drive. I have two options: write raw sectors.(_write(handle,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.