[vbox-dev] Regression with Qt 5.13 - guest steals focus

Michael Thayer michael.thayer at oracle.com
Fri Jul 5 15:13:13 GMT 2019

Hello Larry,

Just a semi-shot-in-the-dark, but are you in contact with Fabian, and if
so, I wonder whether this patch would change anything.  It is against
the development code, but should apply easily to 6.0.8.  The idea is
that if Qt now gives us delayed information that we have lost the focus,
ask the X server directly.

Kind regards

Index: src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
--- src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
(revision 131843)
+++ src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
(working copy)
@@ -269,6 +269,14 @@
          * the keyboard before the target window sees the click. (GNOME
Shell's hot corner has
          * the same problem. At present we just let that problem be.) */

+        /* Make sure we really do still have the focus: */
+        xcb_get_input_focus_cookie_t xcbFocusCookie =
+        xcb_get_input_focus_reply_t *pFocusReply =
xcb_get_input_focus_reply(QX11Info::connection(), xcbFocusCookie, 0);
+        xcb_window_t xcbFocusWindow = pFocusReply->focus;
+        free(pFocusReply);
+        if (xcbFocusWindow !=
+            return true;
         /* Grab the mouse button.
          * We do not check for failure as we do not currently implement
a back-up plan. */
         /* If any previous grab is still in process, release it. */

04.07.19 19:16, Larry Finger wrote:
> When a Linux host runs Qt 5.13, any VB guest will constantly steal the
> focus making it nearly impossible to do anything with the host. The
> problem was reported by an openSUSE user at
> https://bugzilla.suse.com/show_bug.cgi?id=1140084.
> The bug is discussed at https://bugreports.qt.io/browse/QTBUG-76742. A
> fix that reduces a focusinTimer timeout from 400 to 200 msec fixes the
> problem. A comment in VB's captureKeyboard() helps explain why that works:
> /* On X11, we do not grab the keyboard as soon as it is captured, but
> delay it
>  * for 300 milliseconds after the formal capture. We do this for several
> reasons:
>  * - First, when several windows are created they all try to capture the
> keyboard when
>  *   they get the focus. Due to the asynchronous nature of X11 the first
> window may only
>  *   gets notified after the last is created, and there is a dance if
> they respond to
>  *   the notifications by grabbing the keyboard and trigger new focus
> changes in the process.
>  * - Second, grabbing the keyboard immediately on focus change upsets
> some window managers,
>  *   they give us the focus then try to grab the keyboard themselves,
> and sulk if they fail
>  *   by refusing to e.g. drag a window using its title bar.
>  *
>  * IMPORTANT! We do the same under all other hosts as well mainly to
> have the
>  *            common behavior everywhere while X11 is forced to behave
> that way. */
> The final statement shows why this 300 msec should not be changed in VB,
> thus the problem needs to fixed in Qt 5.13.
> While the Qt developers are deciding what the "correct" fix should be,
> openSUSE has changed the Qt package in Tumbleweed to reduce the
> focusinTimer timeout from 400 to 200 msec. Thus far, no adverse effects
> have been noted.
> To reiterate, no changes are needed for VirtualBox. I have posted this
> so that other distro maintainers will be aware of the problem in case
> their distro switches to Qt 5.13.
> Thanks to SUSE's Fabian Vogt for his help in solving this problem.
> Larry
> _______________________________________________
> vbox-dev mailing list
> vbox-dev at virtualbox.org
> https://www.virtualbox.org/mailman/listinfo/vbox-dev

Michael Thayer | VirtualBox engineer
ORACLE Deutschland B.V. & Co. KG | Werkstr. 24 | D-71384 Weinstadt

ORACLE Deutschland B.V. & Co. KG
Hauptverwaltung: Riesstraße 25, D-80992 München
Registergericht: Amtsgericht München, HRA 95603

Komplementärin: ORACLE Deutschland Verwaltung B.V.
Hertogswetering 163/167, 3543 AS Utrecht, Niederlande
Handelsregister der Handelskammer Midden-Nederland, Nr. 30143697
Geschäftsführer: Alexander van der Ven, Jan Schultheiss, Val Maher
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pEpkey.asc
Type: application/pgp-keys
Size: 3106 bytes
Desc: not available
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20190705/aa332966/attachment.bin>

More information about the vbox-dev mailing list