VirtualBox

Changeset 59373 in vbox


Ignore:
Timestamp:
Jan 18, 2016 9:38:33 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105062
Message:

FE/Qt: Qt5 migration (part 60): Reworking keyboard-handler: Policy change for Windows: Use focus related events for keyboard-hook management instead of window-activation related events, similar to Mac OS X.

File:
1 edited

Legend:

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

    r59372 r59373  
    251251        /* On Win, keyboard grabbing is ineffective,
    252252         * a low-level keyboard-hook is used instead.
    253          * It is being installed on window-activate event and uninstalled on window-deactivate.
     253         * It is being installed on focus-in event and uninstalled on focus-out.
    254254         * S.a. UIKeyboardHandler::eventFilter for more information. */
    255255
     
    350350        /* On Win, keyboard grabbing is ineffective,
    351351         * a low-level keyboard-hook is used instead.
    352          * It is being installed on window-activate event and uninstalled on window-deactivate.
     352         * It is being installed on focus-in event and uninstalled on focus-out.
    353353         * S.a. UIKeyboardHandler::eventFilter for more information. */
    354354
     
    12091209bool UIKeyboardHandler::eventFilter(QObject *pWatchedObject, QEvent *pEvent)
    12101210{
    1211     /* Check if pWatchedObject object is window: */
    1212     if (UIMachineWindow *pWatchedWindow = isItListenedWindow(pWatchedObject))
    1213     {
    1214         /* Get corresponding screen index: */
    1215         ulong uScreenId = m_windows.key(pWatchedWindow);
    1216         NOREF(uScreenId);
    1217         /* Handle window events: */
    1218         switch (pEvent->type())
    1219         {
    1220 #ifdef Q_WS_WIN
    1221             /* Install/uninstall low-level keyboard-hook on every activation/deactivation to:
    1222              * a) avoid excess hook calls when we're not active and;
    1223              * b) be always in front of any other possible hooks. */
    1224             case QEvent::WindowActivate:
    1225             {
    1226                 /* If keyboard hook is NOT currently created;
    1227                  * Or created but NOT for that window: */
    1228                 if (!m_keyboardHook || m_iKeyboardHookViewIndex != uScreenId)
    1229                 {
    1230                     /* If keyboard-hook present: */
    1231                     if (m_keyboardHook)
    1232                     {
    1233                         /* We should remove existing keyboard-hook first: */
    1234                         UnhookWindowsHookEx(m_keyboardHook);
    1235                         m_keyboardHook = NULL;
    1236                     }
    1237                     /* Register new keyboard-hook: */
    1238                     m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, UIKeyboardHandler::winKeyboardProc, GetModuleHandle(NULL), 0);
    1239                     AssertMsg(m_keyboardHook, ("SetWindowsHookEx(): err=%d", GetLastError()));
    1240                     /* Remember which view had captured keyboard: */
    1241                     m_iKeyboardHookViewIndex = uScreenId;
    1242                 }
    1243                 break;
    1244             }
    1245             case QEvent::WindowDeactivate:
    1246             {
    1247                 /* If keyboard is currently captured: */
    1248                 if (m_keyboardHook && m_iKeyboardHookViewIndex == uScreenId)
    1249                 {
    1250                     /* We should remove existing keyboard-hook: */
    1251                     UnhookWindowsHookEx(m_keyboardHook);
    1252                     m_keyboardHook = NULL;
    1253                     /* Remember what there is no window captured keyboard: */
    1254                     m_iKeyboardHookViewIndex = -1;
    1255                 }
    1256                 break;
    1257             }
    1258 #endif /* Q_WS_WIN */
    1259             default:
    1260                 break;
    1261         }
    1262     }
    1263 
    1264     else
    1265 
    12661211    /* Check if pWatchedObject object is view: */
    12671212    if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject))
     
    12751220            case QEvent::FocusIn:
    12761221            {
    1277 #ifdef Q_WS_MAC
     1222#if defined(Q_WS_MAC)
     1223
    12781224                /* If keyboard-hook is NOT installed;
    12791225                 * Or installed but NOT for that view: */
    12801226                if ((int)uScreenId != m_iKeyboardHookViewIndex)
    12811227                {
    1282                     /* If keyboard-hook is NOT currently installed: */
     1228                    /* If keyboard-hook is NOT installed: */
    12831229                    if (m_iKeyboardHookViewIndex == -1)
    12841230                    {
     
    13011247                    m_iKeyboardHookViewIndex = uScreenId;
    13021248                }
    1303 #endif /* Q_WS_MAC */
     1249
     1250#elif defined(Q_WS_WIN)
     1251
     1252                /* If keyboard-hook is NOT installed;
     1253                 * Or installed but NOT for that view: */
     1254                if (!m_keyboardHook || (int)uScreenId != m_iKeyboardHookViewIndex)
     1255                {
     1256                    /* If keyboard-hook is installed: */
     1257                    if (m_keyboardHook)
     1258                    {
     1259                        /* Uninstall existing keyboard-hook: */
     1260                        UnhookWindowsHookEx(m_keyboardHook);
     1261                        m_keyboardHook = 0;
     1262                    }
     1263                    /* Install new keyboard-hook: */
     1264                    m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, UIKeyboardHandler::winKeyboardProc, GetModuleHandle(NULL), 0);
     1265                    AssertMsg(m_keyboardHook, ("SetWindowsHookEx(): err=%d", GetLastError()));
     1266                    /* Update the id: */
     1267                    m_iKeyboardHookViewIndex = uScreenId;
     1268                }
     1269
     1270#endif /* Q_WS_WIN */
    13041271
    13051272                if (isSessionRunning())
     
    13211288            case QEvent::FocusOut:
    13221289            {
    1323 #ifdef Q_WS_MAC
     1290#if defined(Q_WS_MAC)
     1291
    13241292                /* If keyboard-hook is installed: */
    13251293                if ((int)uScreenId == m_iKeyboardHookViewIndex)
     
    13321300                    m_iKeyboardHookViewIndex = -1;
    13331301                }
    1334 #endif /* Q_WS_MAC */
     1302
     1303#elif defined(Q_WS_WIN)
     1304
     1305                /* If keyboard-hook is installed: */
     1306                if (m_keyboardHook)
     1307                {
     1308                    /* Uninstall existing keyboard-hook: */
     1309                    UnhookWindowsHookEx(m_keyboardHook);
     1310                    m_keyboardHook = 0;
     1311                    /* Update the id: */
     1312                    m_iKeyboardHookViewIndex = -1;
     1313                }
     1314
     1315#endif /* Q_WS_WIN */
    13351316
    13361317                /* Release keyboard: */
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