Properly reset keyboard focus in qwindow-compositor when hiding
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Mon, 11 Jun 2012 13:46:03 +0000 (16:46 +0300)
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 19 Jun 2012 06:46:44 +0000 (08:46 +0200)
Surfaces with null buffer attached should be handled similarly to
destroyed surfaces. qtwayland makes sure the focus surface is reset,
if needed, but it's up to qwindow-compositor to pick a new one.

Change-Id: I68ec7fe3fe3e2795ae52ef60d9343cb527205c68
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
examples/qwindow-compositor/qwindowcompositor.cpp
examples/qwindow-compositor/qwindowcompositor.h

index 65aafb0..c30aba3 100644 (file)
@@ -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);
index c411332..2efc095 100644 (file)
@@ -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();