VirtualBox

Changeset 63599 in vbox


Ignore:
Timestamp:
Aug 19, 2016 1:19:42 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
110298
Message:

FE/Qt: bugref:8151: X11: Runtime UI: Improve user experience with the delayed capturing mechanism by involving 300ms timer instead of trigger which was not quite obvious.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp

    r63587 r63599  
    3939# ifdef VBOX_WS_X11
    4040#  include <QX11Info>
    41 # endif /* VBOX_WS_X11 */
     41#  if QT_VERSION >= 0x050000
     42#   include <QTimer>
     43#  endif
     44# endif
    4245
    4346/* GUI includes: */
     
    255258    }
    256259
    257     /* If such view exists: */
     260    /* If the view exists: */
    258261    if (m_views.contains(uScreenId))
    259262    {
     
    326329
    327330        /* On X11, we do not grab the keyboard as soon as it is captured, but delay it
    328          * until the first keypress after the capture. We do this for several reasons:
     331         * for 300 milliseconds after the formal capture. We do this for several reasons:
    329332         * - First, when several windows are created they all try to capture the keyboard when
    330333         *   they get the focus. Due to the asynchronous nature of X11 the first window may only
     
    335338         *   by refusing to e.g. drag a window using its title bar. */
    336339
     340        /* Delay finalising capture for 300 milliseconds: */
     341        QTimer::singleShot(300, this, SLOT(sltFinaliseCaptureKeyboard()));
     342
    337343# endif /* QT_VERSION >= 0x050000 */
    338344#else
     
    343349#endif
    344350
    345         /* Remember which screen wish to capture the keyboard: */
     351        /* Remember which screen wishes to capture the keyboard: */
    346352        m_iKeyboardCaptureViewIndex = uScreenId;
    347353
    348354#if !defined(VBOX_WS_X11) || QT_VERSION < 0x050000
    349         /* Finalising keyboard capture: */
     355        /* Finalise keyboard capture: */
    350356        finaliseCaptureKeyboard();
    351357#endif
     
    353359}
    354360
    355 void UIKeyboardHandler::finaliseCaptureKeyboard()
     361bool UIKeyboardHandler::finaliseCaptureKeyboard()
    356362{
    357363    /* Do NOT capture the keyboard if it is already captured: */
    358364    if (m_fIsKeyboardCaptured)
    359         return;
     365        return true;
    360366
    361367    /* Make sure capture was really requested: */
    362368    if (m_iKeyboardCaptureViewIndex == -1)
    363         return;
    364 
    365     /* If such view exists: */
     369        return true;
     370
     371    /* If the view exists: */
    366372    if (m_views.contains(m_iKeyboardCaptureViewIndex))
    367373    {
     
    386392            /* Try again later: */
    387393            free(pGrabReply);
    388             return;
     394            return false;
    389395        }
    390396        free(pGrabReply);
     
    397403        /* Notify all the listeners: */
    398404        emit sigStateChange(state());
    399     }
     405
     406        return true;
     407    }
     408
     409    return false;
    400410}
    401411
     
    410420    }
    411421
    412     /* If such view exists: */
     422    /* If the view exists: */
    413423    if (m_views.contains(m_iKeyboardCaptureViewIndex))
    414424    {
     
    13561366        case XCB_KEY_RELEASE:
    13571367        {
    1358             /* If we were asked to grab the keyboard previously but had to delay it
    1359              * then try again on every key press and release event until we manage: */
    1360             finaliseCaptureKeyboard();
    1361 
    13621368            /* Cast to XCB key-event: */
    13631369            xcb_key_press_event_t *pKeyEvent = static_cast<xcb_key_press_event_t*>(pMessage);
     
    15391545        popupCenter().forgetAboutPausedVMInput(machineLogic()->activeMachineWindow());
    15401546}
     1547
     1548#if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
     1549void UIKeyboardHandler::sltFinaliseCaptureKeyboard()
     1550{
     1551    /* Try to finalise keyboard capture: */
     1552    if (!finaliseCaptureKeyboard())
     1553    {
     1554        /* Try again in another 300 milliseconds in case of failure: */
     1555        QTimer::singleShot(300, this, SLOT(sltFinaliseCaptureKeyboard()));
     1556    }
     1557}
     1558#endif
    15411559
    15421560/* Keyboard-handler constructor: */
     
    21022120                    {
    21032121                        captureKeyboard(uScreenId);
    2104                         finaliseCaptureKeyboard();
    21052122#ifdef VBOX_WS_X11
    21062123                        /* Make sure that pending FocusOut events from the
     
    21102127                        qApp->processEvents();
    21112128#endif /* VBOX_WS_X11 */
     2129                        finaliseCaptureKeyboard();
    21122130                        if (fCaptureMouse)
    21132131                        {
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h

    r63587 r63599  
    8383    /** Captures the keyboard for @a uScreenId. */
    8484    void captureKeyboard(ulong uScreenId);
    85     /** Finalises keyboard capturing. */
    86     void finaliseCaptureKeyboard();
     85    /** Finalises keyboard capture. */
     86    bool finaliseCaptureKeyboard();
    8787    /** Releases the keyboard. */
    8888    void releaseKeyboard();
     
    133133    virtual void sltMachineStateChanged();
    134134
     135#if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
     136    /** Finalises keyboard capture. */
     137    void sltFinaliseCaptureKeyboard();
     138#endif
     139
    135140protected:
    136141
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette