Reset the keyboard and pointer focus when attaching a null buffer
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 22 May 2012 17:15:02 +0000 (20:15 +0300)
committerLaszlo Agocs <laszlo.p.agocs@nokia.com>
Wed, 23 May 2012 07:35:08 +0000 (09:35 +0200)
Improve QMenu/QMenuBar usability with keyboard: We really do not want
the keyboard focus to remain on hidden windows. For example when
opening a menu and pressing escape the focus must not be left on the
(existing, but hidden) menu widget's window.

This isn't perfect (ideally the compositor implementations should be
able to control this somehow by deciding to which window return the
focus to when the focused window goes away) but is better than nothing
and is identical to what Weston does.

Change-Id: Iad963182b74903cc3843460641611467db3c02ef
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/compositor/wayland_wrapper/wlsurface.cpp

index f0dca77..579c27b 100644 (file)
@@ -405,6 +405,14 @@ void Surface::attach(struct wl_buffer *buffer)
     }
 
     m_bufferQueue <<  createSurfaceBuffer(buffer);
+
+    if (!buffer) {
+        InputDevice *inputDevice = m_compositor->defaultInputDevice();
+        if (inputDevice->keyboardFocus() == this)
+            inputDevice->setKeyboardFocus(0);
+        if (inputDevice->mouseFocus() == this)
+            inputDevice->setMouseFocus(0, QPointF(), QPointF());
+    }
 }
 
 void Surface::damage(const QRect &rect)