diff options
-rw-r--r-- | examples/qwindow-compositor/qwindowcompositor.cpp | 20 | ||||
-rw-r--r-- | examples/qwindow-compositor/qwindowcompositor.h | 3 |
2 files changed, 21 insertions, 2 deletions
diff --git a/examples/qwindow-compositor/qwindowcompositor.cpp b/examples/qwindow-compositor/qwindowcompositor.cpp index 65aafb036..c30aba36c 100644 --- a/examples/qwindow-compositor/qwindowcompositor.cpp +++ b/examples/qwindow-compositor/qwindowcompositor.cpp @@ -87,12 +87,18 @@ QWindowCompositor::~QWindowCompositor() delete m_textureCache; } +void QWindowCompositor::ensureKeyboardFocusSurface(WaylandSurface *oldSurface) +{ + WaylandSurface *kbdFocus = defaultInputDevice()->keyboardFocus(); + if (kbdFocus == oldSurface || !kbdFocus) + defaultInputDevice()->setKeyboardFocus(m_surfaces.isEmpty() ? 0 : m_surfaces.last()); +} + void QWindowCompositor::surfaceDestroyed(QObject *object) { WaylandSurface *surface = static_cast<WaylandSurface *>(object); m_surfaces.removeOne(surface); - if (defaultInputDevice()->keyboardFocus() == surface || !defaultInputDevice()->keyboardFocus()) // typically reset to 0 already in Compositor::surfaceDestroyed() - defaultInputDevice()->setKeyboardFocus(m_surfaces.isEmpty() ? 0 : m_surfaces.last()); + ensureKeyboardFocusSurface(surface); m_renderScheduler.start(0); } @@ -117,6 +123,15 @@ void QWindowCompositor::surfaceMapped() m_renderScheduler.start(0); } +void QWindowCompositor::surfaceUnmapped() +{ + WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender()); + if (m_surfaces.removeOne(surface)) + m_surfaces.insert(0, surface); + + ensureKeyboardFocusSurface(surface); +} + void QWindowCompositor::surfaceDamaged(const QRect &rect) { WaylandSurface *surface = qobject_cast<WaylandSurface *>(sender()); @@ -134,6 +149,7 @@ void QWindowCompositor::surfaceCreated(WaylandSurface *surface) { connect(surface, SIGNAL(destroyed(QObject *)), this, SLOT(surfaceDestroyed(QObject *))); connect(surface, SIGNAL(mapped()), this, SLOT(surfaceMapped())); + connect(surface, SIGNAL(unmapped()), this, SLOT(surfaceUnmapped())); connect(surface, SIGNAL(damaged(const QRect &)), this, SLOT(surfaceDamaged(const QRect &))); connect(surface, SIGNAL(extendedSurfaceReady()), this, SLOT(sendExpose())); m_renderScheduler.start(0); diff --git a/examples/qwindow-compositor/qwindowcompositor.h b/examples/qwindow-compositor/qwindowcompositor.h index c41133241..2efc09593 100644 --- a/examples/qwindow-compositor/qwindowcompositor.h +++ b/examples/qwindow-compositor/qwindowcompositor.h @@ -60,6 +60,7 @@ public: private slots: void surfaceDestroyed(QObject *object); void surfaceMapped(); + void surfaceUnmapped(); void surfaceDamaged(const QRect &rect); void render(); @@ -78,6 +79,8 @@ protected: void changeCursor(const QImage &image, int hotspotX, int hotspotY); + void ensureKeyboardFocusSurface(WaylandSurface *oldSurface); + private slots: void sendExpose(); |