#include <QApplication>
#include <QDebug>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QObject>
#include <QTimer>
#include <QX11EmbedContainer>
#include <QX11Info>
#include <X11/cursorfont.h>
#include <X11/Xlib.h>
class Container : public QX11EmbedContainer
{
Q_OBJECT
public:
Container(QMdiArea *_area, Window _client)
:QX11EmbedContainer(),
area(_area)
{
QObject::connect
(this, SIGNAL(clientClosed()),
SLOT(slot_client_closed()));
QObject::connect
(this, SIGNAL(clientIsEmbedded()),
SLOT(slot_client_is_embedded()));
QObject::connect
(this, SIGNAL(error(QX11EmbedContainer::Error)),
SLOT(slot_client_error(QX11EmbedContainer::Error)));
frame = new QMdiSubWindow();
frame->setWidget(this);
embedClient(_client);
}
private:
QMdiArea *area;
QMdiSubWindow *frame;
void exit(void) {QTimer::singleShot(250, qApp, SLOT(quit()));}
public slots:
void slot_client_closed(void) {exit();}
void slot_client_is_embedded(void)
{
area->addSubWindow(frame);
frame->show();
}
void slot_client_error(QX11EmbedContainer::Error error)
{
qDebug() << "error #" << error;
exit();
}
};
class X11EventFilter
{
public:
static bool x11_event_filter(void *msg, long *res)
{
XEvent *ev = reinterpret_cast<XEvent*>(msg);
if (ev->xany.type != EnterNotify) return NULL;
if (X11EventFilter::client == ev->xcrossing.subwindow) {
XDefineCursor
(QX11Info::display(), X11EventFilter::client,
XCreateFontCursor
(QX11Info::display(), XC_left_ptr));
}
return false;
}
static Window client;
};
Window X11EventFilter::client = 0;
/* ugly hack to prevent: undefined reference to `vtable... */
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication *app = new QApplication(argc, argv);
if (app->arguments().count() != 2) {
qFatal("Error - expected window id as argument");
return 1;
}
app->setEventFilter(X11EventFilter::x11_event_filter);
QMdiArea *area = new QMdiArea();
area->show();
X11EventFilter::client = app->arguments()[1].toInt(0, 16);
new Container(area, X11EventFilter::client);
return app->exec();
}
#include <QApplication>
#include <QDebug>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QObject>
#include <QTimer>
#include <QX11EmbedContainer>
#include <QX11Info>
#include <X11/cursorfont.h>
#include <X11/Xlib.h>
class Container : public QX11EmbedContainer
{
Q_OBJECT
public:
Container(QMdiArea *_area, Window _client)
:QX11EmbedContainer(),
area(_area)
{
QObject::connect
(this, SIGNAL(clientClosed()),
SLOT(slot_client_closed()));
QObject::connect
(this, SIGNAL(clientIsEmbedded()),
SLOT(slot_client_is_embedded()));
QObject::connect
(this, SIGNAL(error(QX11EmbedContainer::Error)),
SLOT(slot_client_error(QX11EmbedContainer::Error)));
frame = new QMdiSubWindow();
frame->setWidget(this);
embedClient(_client);
}
private:
QMdiArea *area;
QMdiSubWindow *frame;
void exit(void) {QTimer::singleShot(250, qApp, SLOT(quit()));}
public slots:
void slot_client_closed(void) {exit();}
void slot_client_is_embedded(void)
{
area->addSubWindow(frame);
frame->show();
}
void slot_client_error(QX11EmbedContainer::Error error)
{
qDebug() << "error #" << error;
exit();
}
};
class X11EventFilter
{
public:
static bool x11_event_filter(void *msg, long *res)
{
XEvent *ev = reinterpret_cast<XEvent*>(msg);
if (ev->xany.type != EnterNotify) return NULL;
if (X11EventFilter::client == ev->xcrossing.subwindow) {
XDefineCursor
(QX11Info::display(), X11EventFilter::client,
XCreateFontCursor
(QX11Info::display(), XC_left_ptr));
}
return false;
}
static Window client;
};
Window X11EventFilter::client = 0;
/* ugly hack to prevent: undefined reference to `vtable... */
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication *app = new QApplication(argc, argv);
if (app->arguments().count() != 2) {
qFatal("Error - expected window id as argument");
return 1;
}
app->setEventFilter(X11EventFilter::x11_event_filter);
QMdiArea *area = new QMdiArea();
area->show();
X11EventFilter::client = app->arguments()[1].toInt(0, 16);
new Container(area, X11EventFilter::client);
return app->exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks