summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorAlberto Mardegan <alberto.mardegan@canonical.com>2012-12-12 17:18:28 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-06 18:59:07 +0100
commitb5bdd31de41cb5e6d6abedce79864fc01d8d4984 (patch)
tree030b374282b12a2857d80295a993fc550cb722f7 /src/gui
parentf0533ba8c22d6366f9d4fb8e8ce18554cd0d01e9 (diff)
Implement XEmbed protocol
Add a static QWindow::fromWinId(WId id) constructor which can be used to create a QWindow object representing windows created by other processes. Then, QWindow::setParent() can be used to embed a window into a foreign window socket and QWindow::setTransientParent() to stick the current window on top of a foreign window. The changes in the QtWidgets module ensure that the focus chain (TAB navigation) correctly works when a QtWidgets-based window is embedded into another application. As far as the platform implementation is concerned, this commit only implements the embedding functionality in the XCB plugin. So, this is roughly equivalent to the Qt4 QX11EmbedWidget functionality. Change-Id: Iff8f7b9ee974d33fb30f36056f7838b433a413c7 Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qguiapplication.cpp2
-rw-r--r--src/gui/kernel/qplatformintegration.cpp4
-rw-r--r--src/gui/kernel/qplatformintegration.h3
-rw-r--r--src/gui/kernel/qwindow.cpp37
-rw-r--r--src/gui/kernel/qwindow.h2
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp5
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h3
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h5
8 files changed, 53 insertions, 8 deletions
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 7bfc9ccbec..32c52d2fe2 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1605,7 +1605,7 @@ void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate
}
if (QGuiApplicationPrivate::focus_window) {
- QFocusEvent focusIn(QEvent::FocusIn);
+ QFocusEvent focusIn(QEvent::FocusIn, e->reason);
QCoreApplication::sendSpontaneousEvent(QGuiApplicationPrivate::focus_window, &focusIn);
QObject::connect(QGuiApplicationPrivate::focus_window, SIGNAL(focusObjectChanged(QObject*)),
qApp, SLOT(_q_updateFocusObject(QObject*)));
diff --git a/src/gui/kernel/qplatformintegration.cpp b/src/gui/kernel/qplatformintegration.cpp
index fbc7eeb76f..70de75072c 100644
--- a/src/gui/kernel/qplatformintegration.cpp
+++ b/src/gui/kernel/qplatformintegration.cpp
@@ -206,6 +206,10 @@ QPlatformServices *QPlatformIntegration::services() const
state explicitly by using QWindowSystemInterface::handleApplicationStateChanged().
If not set, application state will follow window activation, which is the normal
behavior for desktop platforms.
+
+ \value ForeignWindows The platform allows creating QWindows which represent
+ native windows created by other processes or anyway created by using native
+ libraries.
*/
diff --git a/src/gui/kernel/qplatformintegration.h b/src/gui/kernel/qplatformintegration.h
index 55517cf600..ddee6f05c8 100644
--- a/src/gui/kernel/qplatformintegration.h
+++ b/src/gui/kernel/qplatformintegration.h
@@ -89,7 +89,8 @@ public:
BufferQueueingOpenGL,
WindowMasks,
MultipleWindows,
- ApplicationState
+ ApplicationState,
+ ForeignWindows
};
virtual ~QPlatformIntegration() { }
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 99a54dc847..3d4383301e 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -474,6 +474,10 @@ void QWindow::create()
WId QWindow::winId() const
{
Q_D(const QWindow);
+
+ if (type() == Qt::ForeignWindow)
+ return WId(property("_q_foreignWinId").value<WId>());
+
if(!d->platformWindow)
const_cast<QWindow *>(this)->create();
@@ -499,8 +503,11 @@ QWindow *QWindow::parent() const
the clip of the window, so it will be clipped to the \a parent window.
Setting \a parent to be 0 will make the window become a top level window.
-*/
+ If \a parent is a window created by fromWinId(), then the current window
+ will be embedded inside \a parent, if the platform supports it. Window
+ embedding is currently supported only by the X11 platform plugin.
+*/
void QWindow::setParent(QWindow *parent)
{
Q_D(QWindow);
@@ -2104,6 +2111,34 @@ void QWindowPrivate::maybeQuitOnLastWindowClosed()
}
+/*!
+ Creates a local representation of a window created by another process or by
+ using native libraries below Qt.
+
+ Given the handle \a id to a native window, this method creates a QWindow
+ object which can be used to represent the window when invoking methods like
+ setParent() and setTransientParent().
+ This can be used, on platforms which support it, to embed a window inside a
+ container or to make a window stick on top of a window created by another
+ process.
+
+ \sa setParent()
+ \sa setTransientParent()
+*/
+QWindow *QWindow::fromWinId(WId id)
+{
+ if (!QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ForeignWindows)) {
+ qWarning() << "QWindow::fromWinId(): platform plugin does not support foreign windows.";
+ return 0;
+ }
+
+ QWindow *window = new QWindow;
+ window->setFlags(Qt::ForeignWindow);
+ window->setProperty("_q_foreignWinId", QVariant::fromValue(id));
+ window->create();
+ return window;
+}
+
#ifndef QT_NO_CURSOR
/*!
\brief set the cursor shape for this window
diff --git a/src/gui/kernel/qwindow.h b/src/gui/kernel/qwindow.h
index 0842e9ceb6..ca3ffb0709 100644
--- a/src/gui/kernel/qwindow.h
+++ b/src/gui/kernel/qwindow.h
@@ -257,6 +257,8 @@ public:
void unsetCursor();
#endif
+ static QWindow *fromWinId(WId id);
+
public Q_SLOTS:
void setVisible(bool visible);
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 3609d5dce6..d2add91d66 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -112,9 +112,10 @@ void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leav
}
}
-void QWindowSystemInterface::handleWindowActivated(QWindow *tlw)
+void QWindowSystemInterface::handleWindowActivated(QWindow *tlw, Qt::FocusReason r)
{
- QWindowSystemInterfacePrivate::ActivatedWindowEvent *e = new QWindowSystemInterfacePrivate::ActivatedWindowEvent(tlw);
+ QWindowSystemInterfacePrivate::ActivatedWindowEvent *e =
+ new QWindowSystemInterfacePrivate::ActivatedWindowEvent(tlw, r);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index 22e5983a07..212259c113 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -135,7 +135,8 @@ public:
static void handleEnterEvent(QWindow *w, const QPointF &local = QPointF(), const QPointF& global = QPointF());
static void handleLeaveEvent(QWindow *w);
static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());
- static void handleWindowActivated(QWindow *w);
+ static void handleWindowActivated(QWindow *w, Qt::FocusReason r = Qt::OtherFocusReason);
+
static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState);
static void handleApplicationStateChanged(Qt::ApplicationState newState);
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index eca559abfa..f1bc4667f7 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -139,10 +139,11 @@ public:
class ActivatedWindowEvent : public WindowSystemEvent {
public:
- explicit ActivatedWindowEvent(QWindow *activatedWindow)
- : WindowSystemEvent(ActivatedWindow), activated(activatedWindow)
+ explicit ActivatedWindowEvent(QWindow *activatedWindow, Qt::FocusReason r)
+ : WindowSystemEvent(ActivatedWindow), activated(activatedWindow), reason(r)
{ }
QPointer<QWindow> activated;
+ Qt::FocusReason reason;
};
class WindowStateChangedEvent : public WindowSystemEvent {