How to get Gtk::Socket to work properly?

I want to embed a random Xwindow inside my Gtk application, and I knew that Gtk::Socket is what just does that. First of all, I don’t care if it doesn’t work on Wayland because my whole program is tied to X11 anyway. I’ve written a simple example to try that widget, but that didn’t work well at all.
Here’s my code:

#include <gtkmm.h>
#include <gtkmm/socket.h>
#include <gtkmm/plug.h>

int main(int argc , char** argv){
    auto app = Gtk::Application::create();
    Gtk::Window window;
    window.set_size_request(1000 , 1000); 
    Gtk::Socket socket;

    Window xw(0x5e0003e);

    std::cout << socket.get_plug_window().get() << std::endl;

    return app->run(window);
  1. I tried to embed gnome-calculator and another Gtk program both got embedded most of the time, but they didn’t update their displays at all, but I knew that they were receiving input because they close when I click on their close button (I mean the one of the embedded window not the parent window).
  2. I tried to embed Firefox and I could interact with it inside my window very well, but it didn’t receive hover events so it only responded to mouse clicks.
  3. with all the tests the embedded application didn’t resize as the parent window gets resized instead it shrinks to the parent window initial size, and when I try to decrease the parent size, it just eats up the child window and it doesn’t return after increasing the size, and when I try to increase the size of the parent the rest becomes transparent (Not really transparent but it copies whatever is behind it at the moment of resizing).
  4. In rare conditions the window that I want to embed disappears from the screen but does not get embedded in the parent window, I’m assuming that I need to wait for the parent window to get shown before I embed the window, I’m not sure if that’s right.

In summary, what I need to achieve is the following:

  1. Make the embedded window get all types of events.
  2. Make the embedded window aware of size changes, and also make the Gtk::Socket request more size if needed.
  3. Make sure that the child window updates its display when necessary (I believe 2 & 3 are related).
  4. Make sure that I reparent the window at the correct time so it doesn’t just disappear and get actually embedded in the parent window.

Are any of these possible in Gtk? or do I need to use some X11 API directly? The XEmbed protocol mentions that the parent window needs to use some window management API to control the size and other things in its child so does Gtk::Socket take care of that or shall I do some work myself? Either way, point me in the right direction. If it’s possible in Gtk I would like a simple example demonstrating that.

Also, an additional question: Does the embedded window just get moved by the window manager to the coordinates of the parent window or is the child window actually being drawn in the parent?

Thanks in advance for any kind of help.

I have never used GtkSocket, but my suggestion is to look at the related tests:


In addition there’s the GTKMM programming guide: Overview

Hope it helps!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.