VirtualBox

Ignore:
Timestamp:
Aug 22, 2016 2:29:26 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8151: Runtime UI: Move the X11 Qt4 keyboard capture code into appropriate place.

File:
1 edited

Legend:

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

    r63609 r63610  
    294294# if QT_VERSION < 0x050000
    295295
    296         /* On X11, we are using passive XGrabKey for normal (windowed) mode
    297          * instead of XGrabKeyboard (called by QWidget::grabKeyboard())
    298          * because XGrabKeyboard causes a problem under metacity - a window cannot be moved
    299          * using the mouse if it is currently actively grabbing the keyboard;
    300          * For static modes we are using usual (active) keyboard grabbing. */
    301         switch (machineLogic()->visualStateType())
    302         {
    303             /* If window is moveable we are making passive keyboard grab: */
    304             case UIVisualStateType_Normal:
    305             case UIVisualStateType_Scale:
    306             {
    307                 XGrabKey(QX11Info::display(), AnyKey, AnyModifier, m_windows[uScreenId]->winId(), False, GrabModeAsync, GrabModeAsync);
    308                 break;
    309             }
    310             /* If window is NOT moveable we are making active keyboard grab: */
    311             case UIVisualStateType_Fullscreen:
    312             case UIVisualStateType_Seamless:
    313             {
    314                 /* Keyboard grabbing can fail because of some keyboard shortcut is still grabbed by window manager.
    315                  * We can't be sure this shortcut will be released at all, so we will retry to grab keyboard for 50 times,
    316                  * and after we will just ignore that issue: */
    317                 int cTriesLeft = 50;
    318                 Window hWindow;
    319 
    320                 /* Only do our keyboard grab if there are no other focus events
    321                  * for this window on the queue.  This can prevent problems
    322                  * including two windows fighting to grab the keyboard. */
    323                 hWindow = m_windows[uScreenId]->winId();
    324                 if (!checkForX11FocusEvents(hWindow))
    325                     while (cTriesLeft && XGrabKeyboard(QX11Info::display(),
    326                            hWindow, False, GrabModeAsync, GrabModeAsync,
    327                            CurrentTime))
    328                         --cTriesLeft;
    329                 break;
    330             }
    331             /* Should we try to grab keyboard in default case? I think - NO. */
    332             default:
    333                 break;
    334         }
     296        /* Nothing for now. */
    335297
    336298# else /* QT_VERSION >= 0x050000 */
     
    352314#else
    353315
    354         /* On other platforms we are just praying Qt method to work: */
    355         m_views[uScreenId]->grabKeyboard();
     316        /* Nothing for now. */
    356317
    357318#endif
     
    390351        m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
    391352
    392 #elif defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
     353#elif defined(VBOX_WS_WIN)
     354
     355        /* Nothing for now. */
     356
     357#elif defined(VBOX_WS_X11)
     358# if QT_VERSION < 0x050000
     359
     360        /* On X11, we are using passive XGrabKey for normal (windowed) mode
     361         * instead of XGrabKeyboard (called by QWidget::grabKeyboard()) because
     362         * XGrabKeyboard causes a problem under metacity - a window cannot be
     363         * moved using the mouse if it is currently actively grabbing the keyboard;
     364         * For static modes we are using usual (active) keyboard grabbing. */
     365
     366        switch (machineLogic()->visualStateType())
     367        {
     368            /* If window is moveable we are making passive keyboard grab: */
     369            case UIVisualStateType_Normal:
     370            case UIVisualStateType_Scale:
     371            {
     372                XGrabKey(QX11Info::display(), AnyKey, AnyModifier, m_windows[m_iKeyboardCaptureViewIndex]->winId(), False, GrabModeAsync, GrabModeAsync);
     373                break;
     374            }
     375            /* If window is NOT moveable we are making active keyboard grab: */
     376            case UIVisualStateType_Fullscreen:
     377            case UIVisualStateType_Seamless:
     378            {
     379                /* Keyboard grabbing can fail because of some keyboard shortcut is still grabbed by window manager.
     380                 * We can't be sure this shortcut will be released at all, so we will retry to grab keyboard for 50 times,
     381                 * and after we will just ignore that issue: */
     382                int cTriesLeft = 50;
     383                Window hWindow;
     384
     385                /* Only do our keyboard grab if there are no other focus events
     386                 * for this window on the queue.  This can prevent problems
     387                 * including two windows fighting to grab the keyboard. */
     388                hWindow = m_windows[m_iKeyboardCaptureViewIndex]->winId();
     389                if (!checkForX11FocusEvents(hWindow))
     390                    while (cTriesLeft && XGrabKeyboard(QX11Info::display(),
     391                           hWindow, False, GrabModeAsync, GrabModeAsync,
     392                           CurrentTime))
     393                        --cTriesLeft;
     394                break;
     395            }
     396            /* Should we try to grab keyboard in default case? I think - NO. */
     397            default:
     398                break;
     399        }
     400
     401# else /* QT_VERSION >= 0x050000 */
    393402
    394403        /* On X11, we are using XCB stuff to grab the keyboard.
     
    414423        free(pGrabReply);
    415424
    416 #endif /* VBOX_WS_X11 && QT_VERSION >= 0x050000 */
     425# endif /* QT_VERSION >= 0x050000 */
     426#else
     427
     428        /* On other platforms we are just praying Qt method to work: */
     429        m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
     430
     431#endif
    417432
    418433        /* Store new keyboard-captured state value: */
Note: See TracChangeset for help on using the changeset viewer.

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