2

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))

  • Here on Debian Jessie with Gnuplot 4.6.6, libgtkmm-3.0-dev 3.14.0-1, and g++ V 4.9.2 (with flag -std=c++11) it works. – maij Dec 18 '16 at 21:14
  • Thanks, @maij. I'll try it on different platforms and post results here. – Dima Litvinov Dec 19 '16 at 23:36
  • @DimaLitvinov On this site you can answer your own question. If your "UPD" section solves the issue, you should post it as an answer and accept it. –  Dec 23 '17 at 19:56
  • @Ivan Thanks, but - for complete solution there should exist a fix from the socket side (not from the gnuplot side). – Dima Litvinov Dec 24 '17 at 20:48

1 Answers1

1

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!

John Lucas
  • 11
  • 2
  • Don't change the generated file, but use the respective command line parameter `./configure --disable-x11-external` – Christoph Nov 05 '18 at 18:41