/*************************************************************************** embed.cpp - description ------------------- Simple test case to embed the first X 11 Window found with a title starting with the given string using QXEmbed under KDE. Compilation: Here these lines will compile the test case: # moc embed.cpp > embed.moc # gcc -I /usr/include/qt3/ -I /usr/include/kde/ -lqt-mt -lkdeui embed.cpp -o embed Obviously, you may have to adjust the paths Usage: 1) In an R console, create an X11 device 2) Run this program, click "Capture" ***************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include // function below is a slightly adapted copy from http://lists.trolltech.com/qt-interest/1999-10/msg00224.html // this could be tweaked a little more, since for instance we know we're only looking for toplevel windows Window Window_With_Name (Display *dp, Window top, const QString &name) { Window *children, dummy; unsigned int nchildren; int i; Window w=0; char *window_name; if (XFetchName (dp, top, &window_name)) { if (QString (window_name).startsWith (name)) return (top); } if (!XQueryTree (dp, top, &dummy, &dummy, &children, &nchildren)) return (0); for (i=0; iaddWidget (label); caption_edit = new QLineEdit (this); caption_edit->setText ("R Graphics"); layout->addWidget (caption_edit); QPushButton *button = new QPushButton ("Capture", this); connect (button, SIGNAL (clicked ()), this, SLOT (embedRGraphics ())); layout->addWidget (button); show (); }; public slots: void embedRGraphics () { Window w = Window_With_Name (qt_xdisplay (), qApp->desktop ()->winId (), caption_edit->text ()); if (!w) { qDebug ("No such window found"); return; } else { qDebug ("embedding window id %p", w); } // capture QXEmbed *capture = new QXEmbed (0, 0, Qt::WDestructiveClose); capture->setProtocol (QXEmbed::XPLAIN); capture->embed (w); capture->show (); qDebug ("done embedding", w); }; private: QLineEdit *caption_edit; }; static KCmdLineOptions options[] = { { 0, 0, 0 } }; int main (int argc, char *argv[]) { KAboutData aboutdata ("embedtest", "embedtest", "0.1", "a test case", KAboutData::License_GPL, "(c) 2006", 0); KCmdLineArgs::init (argc, argv, &aboutdata); KApplication app; new EmbedDialog (); return app.exec (); } #include "embed.moc"