Reset keyboard focus when a surface is destroyed
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Mon, 11 Jun 2012 08:36:43 +0000 (11:36 +0300)
committerJørgen Lind <jorgen.lind@nokia.com>
Mon, 11 Jun 2012 10:35:14 +0000 (12:35 +0200)
Only pointer focus was reset, resulting in undefined behavior when
acessing keyboardFocus() after all surfaces had gone away.

Change-Id: I8c9f71e2eadbf69de1dc7856f4a05dd309ab95eb
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
src/compositor/wayland_wrapper/wlcompositor.cpp

index 61ec91e..a67ad58 100644 (file)
@@ -271,18 +271,22 @@ void Compositor::processWaylandEvents()
 
 void Compositor::surfaceDestroyed(Surface *surface)
 {
-    if (defaultInputDevice()->mouseFocus() == surface) {
-        InputDevice *dev = defaultInputDevice();
+    InputDevice *dev = defaultInputDevice();
+    if (dev->mouseFocus() == surface) {
         dev->setMouseFocus(0, QPointF(), QPointF());
         // Make sure the surface is reset regardless of what the grabber
         // interface's focus() does. (e.g. the default implementation does
         // nothing when a button is down which would be disastrous here)
         wl_pointer_set_focus(dev->pointerDevice(), 0, 0, 0);
     }
+    if (dev->keyboardFocus() == surface)
+        dev->setKeyboardFocus(0);
+
     m_surfaces.removeOne(surface);
     m_dirty_surfaces.remove(surface);
     if (m_directRenderSurface == surface)
         setDirectRenderSurface(0, 0);
+
     waylandCompositor()->surfaceAboutToBeDestroyed(surface->waylandSurface());
 }