Cannot embed gnuplot x11 window into Gtk3 socket

1.1k views Asked by At

I'm creating Gtk::Socket in my Gtk3 (actually, gtkmm) application and trying to embed gnuplot's window into it. But it does not work: the socket remains to stay as a black rectangle, while gnuplot window appears standalone elsewhere.

Meanwhile, Gtk::Plug plugs into this socket perfectly. In Gtk2 this trick with gnuplot works well too.

Here is socket.cpp

#include <iostream>
#include <fstream>
#include <gtkmm.h>
#include <gtkmm/socket.h>

using namespace std;

void plug_added(){
  cout << "A plug was added" << endl;
}

bool plug_removed(){
  cout << "A Plug was removed" << endl;
  return true;
}

class MySocketWindow : public Gtk::Window
{
  public:
    MySocketWindow()
    {
        auto socket = Gtk::manage(new Gtk::Socket());
        add(*socket);
        socket->signal_plug_added().connect(sigc::ptr_fun(plug_added));
        socket->signal_plug_removed().connect(sigc::ptr_fun(plug_removed));
        cout << "Socket id is: " << hex << socket->get_id() << endl;
        show_all();
    }
};

int main(int argc, char** argv)
{
  auto app =
    Gtk::Application::create(argc, argv, "org.gtkmm.example.socket");
  MySocketWindow win;
  app->run(win);
  return 0;
}

Compile and run:

$ g++ --std=c++0x socket.cpp -o socket `pkg-config gtkmm-3.0 --cflags --libs`
$ ./socket &
[1] 22832
$ Socket id is: 2c00007

Start gnuplot:

gnuplot> set term x11 window "2c00007"
Terminal type set to 'x11'
Options are 'XID 0x2C00007 nopersist enhanced'
gnuplot> plot sin(x)

So, are there any differences in Gtk3 sockets over Gtk2 which prevent gnuplot from connecting?

Ubuntu Xenial 16.04.1 x64, gnuplot-4.6.6, libgtkmm-3.0-dev 3.18.0, g++ 5.4.0 doesn't work

Ubuntu Trusty 14.04.4 x86, gnuplot-4.6.4, libgtkmm-3.0-dev 3.10.1, g++ 4.8.4 works

UPD:

Digging deeper into gnuplot sources reveal that Gnuplot creates "X11 Visual" structure for its window that is different to socket's one. To fix this, change the line:

    plot->window = XCreateWindow(dpy, plot->external_container, plot->x, plot->y, plot->width,
                 plot->height, 0, dep, InputOutput, vis, 0, NULL);

to

    plot->window = XCreateWindow(dpy, plot->external_container, plot->x, plot->y, plot->width,
                 plot->height, 0, dep, InputOutput, gattr.visual, 0, NULL);

(line 6339 of gplt_x11.c (at version 5.5.2))

1

There are 1 answers

1
John Lucas On

It seems that recent updates allow this to be fixed via a #define. Pull gnuplot (5.2.5 is what I have) and build locally with the following changed in the config.hin file before you build:

#undef EXTERNAL_X11_WINDOW to #define EXTERNAL_X11_WINDOW

Then follow the provided instructions to install and you should be set!