Mouse click stops working on host/guest due to window focusOutEvent problem in Qt GUI

Discussions related to using VirtualBox on Linux hosts.
Post Reply
Cryptkeeper
Posts: 1
Joined: 7. May 2021, 17:31

Mouse click stops working on host/guest due to window focusOutEvent problem in Qt GUI

Post by Cryptkeeper »

Hi,

for more than two years now (so probably since VB version 6.0 or so) from time to time I am affected by a very anoying bug. Then mouse clicks stops working on the host and the guest as well. I can still move the mouse pointer but clicks are not recognized anymore. The only solution then is to shut down *all* running guest instances. Then the mouse clicks starts working again.

I am sure it is not a drag and drop problem like in https://www.virtualbox.org/ticket/14743

There will be no entry in the logs, when the bug occurs. It happend very randomly to me but after a while with a screen record I figured out the following steps to reliable reproduce the bug:

1) Click on the taskbar to restore VM window from minimized state
2) Press down the mouse button on the taskbar and keep it pressed
3) Release the mouse button and immediatly press it again
4) Now no further clicks are registered until VM is shut down

(I agree that this looks like a very special and rare circumstance - however I think that this bug is a race condition and as I often switch between different windows with the taskbar I'm hit by it very often.)

Here is a screencast of the bug as GIF: https://s3.gifyu.com/images/vbox-bug.gif

When the bug occurs *xprop* on the hosts exits with the error "xprop: error: Can't grab the mouse" - on the guest it just hangs as no click is registered. Also the bug only occurs with the Qt front end of VirtualBox - with the SDL front end I couldn't reproduce the error.

From the steps I assume that the bug is kind of a race condition on the minimize respectively focus out / focus in event of the window. So I tried to build VirtualBox from source and try to trace the bug. And indeed I figured out, that the bug does not occure if I comment out the following 3 lines in the file src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp.

Code: Select all

void UIMachineView::focusOutEvent(QFocusEvent *pEvent)
{
    /* If native event filter exists: */
    if (m_pNativeEventFilter)
    {
        /* Uninstall/destroy existing native event filter: */
            
        //qApp->removeNativeEventFilter(m_pNativeEventFilter);
        //delete m_pNativeEventFilter;
        //m_pNativeEventFilter = 0;
    }

    /* Call to base-class: */
    QAbstractScrollArea::focusOutEvent(pEvent);
}
I tried to dig deeper but I'm kind of stuck. Because I don't know what this native event filter is used for and why it is destroyed on focus out event.

Can anyone help me to debug this further?

Thanks a lot!
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Mouse click stops working on host/guest due to window focusOutEvent problem in Qt GUI

Post by scottgus1 »

Good detective work! This would be a good thing to post on the Bugtracker, for the devs to see. Most of us, especially me, haven't gone that deep into the code to know how to fix this.
Seann
Posts: 5
Joined: 28. Jan 2015, 19:41

Re: Mouse click stops working on host/guest due to window focusOutEvent problem in Qt GUI

Post by Seann »

I have been having the same problem as well for years. My temporary workaround was not to go into full screen mode. I recently upgraded to Fedora 33 and VirtualBox 6.1.22 and problem seemed to be fixed (or so I thought) because it usually happened right away. After running in full screen for three days my mouse pointer was hung. I tried xwininfo and xprop to determine which process had control of my mouse. With either command I received 'Can't grab the mouse'. When searching for the solution I was able to find this forum post.

I guess this is a long way of saying, "me too!"
CyanideJunkie
Posts: 1
Joined: 5. Apr 2022, 18:45

Re: Mouse click stops working on host/guest due to window focusOutEvent problem in Qt GUI

Post by CyanideJunkie »

One of the reasons I switched to virt-manager(QEMU/KVM) on Linux (Arch) host is due to this same problem, been happening a few years now.

So today after about a year of no VirtualBox on my machine I decided to try it out again... with Windows 10 Enterprise as the guest.
After about 30minutes my system AGAIN stopped registering mouse clicks in BOTH guest and host.

I was frustrated and walked away from the PC for about 30minutes or so... when I came back I saw Linux killed this virtualbox guest instance in my absence and the mouse was working again.. and no OOM is not the issue.. I have 64GiB RAM and only used at that time about 24GiB in total.

So.. no, not to happy with VBox as this has been an issue for waaaay to long now.
Post Reply