VirtualBox

Changeset 59372 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jan 18, 2016 9:24:42 AM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Qt5 migration (part 59): Reworking keyboard-handler: Cleanup for Windows.

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

Legend:

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

    r59361 r59372  
    639639bool UIKeyboardHandler::winEventFilter(MSG *pMsg, ulong uScreenId)
    640640{
    641     /* Check if some system event should be filtered-out.
    642      * Returning 'true' means filtering-out,
    643      * Returning 'false' means passing event to Qt. */
    644     bool fResult = false; /* Pass to Qt by default: */
    645 
    646     /* Skip this event if m_fSkipKeyboardEvents is set by winSkipKeyboardEvents(). */
     641    /* Ignore this event if m_fSkipKeyboardEvents is set by winSkipKeyboardEvents(). */
    647642    if (m_fSkipKeyboardEvents)
    648643        return false;
    649644
     645    /* Check if some system event should be filtered out.
     646     * Returning @c true means filtering-out,
     647     * Returning @c false means passing event to Qt. */
     648    bool fResult = false; /* Pass to Qt by default. */
     649
     650    /* Depending on message type: */
    650651    switch (pMsg->message)
    651652    {
     653        /* Watch for key-events: */
    652654        case WM_KEYDOWN:
    653655        case WM_KEYUP:
     
    655657        case WM_SYSKEYUP:
    656658        {
    657             /* Check for the special flag possibly set at the end of this function: */
     659            /* Check for our own special flag to ignore this event.
     660             * That flag could only be set later in this function
     661             * so having it here means this event came here
     662             * for the second time already. */
    658663            if (pMsg->lParam & (0x1 << 25))
    659664            {
     665                /* Remove that flag as well: */
    660666                pMsg->lParam &= ~(0x1 << 25);
    661667                fResult = false;
     
    663669            }
    664670
    665             /* Scancodes 0x80 and 0x00 are ignored: */
    666             unsigned scan = (pMsg->lParam >> 16) & 0x7F;
    667             if (!scan)
     671            /* Scan codes 0x80 and 0x00 should be filtered out: */
     672            unsigned uScan = (pMsg->lParam >> 16) & 0x7F;
     673            if (!uScan)
    668674            {
    669675                fResult = true;
     
    671677            }
    672678
    673             int vkey = pMsg->wParam;
    674 
    675             int flags = 0;
     679            /* Get the virtual key: */
     680            int iVKey = pMsg->wParam;
     681
     682            /* Calculate flags: */
     683            int iFlags = 0;
    676684            if (pMsg->lParam & 0x1000000)
    677                 flags |= KeyExtended;
     685                iFlags |= KeyExtended;
    678686            if (!(pMsg->lParam & 0x80000000))
    679                 flags |= KeyPressed;
    680 
    681             /* If present - why not just assert this? */
    682             if (m_pAltGrMonitor)
    683             {
    684                 /* Bail out if we are sure that this is a fake left control. */
    685                 if (m_pAltGrMonitor->isCurrentEventDefinitelyFake(scan, flags & KeyPressed, flags & KeyExtended))
     687                iFlags |= KeyPressed;
     688
     689            /* Make sure AltGr monitor exists: */
     690            AssertPtrReturn(m_pAltGrMonitor, false);
     691            {
     692                /* Filter event out if we are sure that this is a fake left control event: */
     693                if (m_pAltGrMonitor->isCurrentEventDefinitelyFake(uScan, iFlags & KeyPressed, iFlags & KeyExtended))
    686694                {
    687695                    fResult = true;
     
    689697                }
    690698                /* Update AltGR monitor state from key-event: */
    691                 m_pAltGrMonitor->updateStateFromKeyEvent(scan, flags & KeyPressed, flags & KeyExtended);
     699                m_pAltGrMonitor->updateStateFromKeyEvent(uScan, iFlags & KeyPressed, iFlags & KeyExtended);
    692700                /* And release left Ctrl key early (if required): */
    693701                if (m_pAltGrMonitor->isLeftControlReleaseNeeded())
     
    696704
    697705            /* Check for special Korean keys. Based on the keyboard layout selected
    698              * on the host, the scancode in lParam might be 0x71/0x72 or 0xF1/0xF2.
    699              * In either case, we must deliver 0xF1/0xF2 scancode to the guest when
     706             * on the host, the scan code in lParam might be 0x71/0x72 or 0xF1/0xF2.
     707             * In either case, we must deliver 0xF1/0xF2 scan code to the guest when
    700708             * the key is pressed and nothing when it's released. */
    701             if (scan == 0x71 || scan == 0x72)
    702             {
    703                 scan |= 0x80;
    704                 flags = KeyPressed;     /* Because a release would be ignored. */
    705                 vkey  = VK_PROCESSKEY;  /* In case it was 0xFF */
     709            if (uScan == 0x71 || uScan == 0x72)
     710            {
     711                uScan |= 0x80;
     712                iFlags = KeyPressed;   /* Because a release would be ignored. */
     713                iVKey = VK_PROCESSKEY; /* In case it was 0xFF. */
    706714            }
    707715
    708716            /* When one of the SHIFT keys is held and one of the cursor movement
    709717             * keys is pressed, Windows duplicates SHIFT press/release messages,
    710              * but with the virtual key code set to 0xFF. These virtual keys are also
    711              * sent in some other situations (Pause, PrtScn, etc.). Ignore suc messages. */
    712             if (vkey == 0xFF)
     718             * but with the virtual keycode set to 0xFF. These virtual keys are also
     719             * sent in some other situations (Pause, PrtScn, etc.). Filter out such messages. */
     720            if (iVKey == 0xFF)
    713721            {
    714722                fResult = true;
     
    716724            }
    717725
    718             switch (vkey)
     726            /* Handle special virtual keys: */
     727            switch (iVKey)
    719728            {
    720729                case VK_SHIFT:
     
    723732                {
    724733                    /* Overcome Win32 modifier key generalization: */
    725                     int keyscan = scan;
    726                     if (flags & KeyExtended)
    727                         keyscan |= 0xE000;
    728                     switch (keyscan)
     734                    int iKeyscan = uScan;
     735                    if (iFlags & KeyExtended)
     736                        iKeyscan |= 0xE000;
     737                    switch (iKeyscan)
    729738                    {
    730                         case 0x002A: vkey = VK_LSHIFT; break;
    731                         case 0x0036: vkey = VK_RSHIFT; break;
    732                         case 0x001D: vkey = VK_LCONTROL; break;
    733                         case 0xE01D: vkey = VK_RCONTROL; break;
    734                         case 0x0038: vkey = VK_LMENU; break;
    735                         case 0xE038: vkey = VK_RMENU; break;
     739                        case 0x002A: iVKey = VK_LSHIFT;  break;
     740                        case 0x0036: iVKey = VK_RSHIFT;  break;
     741                        case 0x001D: iVKey = VK_LCONTROL; break;
     742                        case 0xE01D: iVKey = VK_RCONTROL; break;
     743                        case 0x0038: iVKey = VK_LMENU;    break;
     744                        case 0xE038: iVKey = VK_RMENU;    break;
    736745                    }
    737746                    break;
     
    739748                case VK_NUMLOCK:
    740749                    /* Win32 sets the extended bit for the NumLock key. Reset it: */
    741                     flags &= ~KeyExtended;
     750                    iFlags &= ~KeyExtended;
    742751                    break;
    743752                case VK_SNAPSHOT:
    744                     flags |= KeyPrint;
     753                    iFlags |= KeyPrint;
    745754                    break;
    746755                case VK_PAUSE:
    747                     flags |= KeyPause;
     756                    iFlags |= KeyPause;
    748757                    break;
    749758            }
    750759
    751             bool result = keyEvent(vkey, scan, flags, uScreenId);
     760            /* Finally, handle parsed key-event: */
     761            fResult = keyEvent(iVKey, uScan, iFlags, uScreenId);
     762
    752763            /* Always let Windows see key releases to prevent stuck keys.
    753764             * Hopefully this won't cause any other issues. */
     
    757768                break;
    758769            }
    759             if (!result && m_fIsKeyboardCaptured)
    760             {
    761                 /* keyEvent() returned that it didn't process the message, but since the
    762                  * keyboard is captured, we don't want to pass it to Windows. We just want
    763                  * to let Qt process the message (to handle non-alphanumeric <HOST>+key
    764                  * shortcuts for example). So send it directly to the window with the
    765                  * special flag in the reserved area of lParam (to avoid recursion). */
     770
     771            /* Above keyEvent() returned that it didn't processed the event, but since the
     772             * keyboard is captured, we don't want to pass it to Windows. We just want
     773             * to let Qt process the message (to handle non-alphanumeric <HOST>+key
     774             * shortcuts for example). So send it directly to the window with the
     775             * special flag in the reserved area of lParam (to avoid recursion). */
     776            if (!fResult && m_fIsKeyboardCaptured)
     777            {
    766778                ::SendMessage(pMsg->hwnd, pMsg->message,
    767779                              pMsg->wParam, pMsg->lParam | (0x1 << 25));
     
    771783
    772784            /* These special keys have to be handled by Windows as well to update the
    773              * internal modifier state and to enable/disable the keyboard LED */
    774             if (vkey == VK_NUMLOCK || vkey == VK_CAPITAL || vkey == VK_LSHIFT || vkey == VK_RSHIFT)
     785             * internal modifier state and to enable/disable the keyboard LED: */
     786            if (iVKey == VK_NUMLOCK || iVKey == VK_CAPITAL || iVKey == VK_LSHIFT || iVKey == VK_RSHIFT)
    775787            {
    776788                fResult = false;
     
    778790            }
    779791
    780             fResult = result;
    781792            break;
    782793        }
     
    784795            break;
    785796    }
     797
    786798    /* Return result: */
    787799    return fResult;
     
    14161428#elif defined(Q_WS_WIN)
    14171429
     1430/* static */
    14181431LRESULT CALLBACK UIKeyboardHandler::winKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
    14191432{
     1433    /* All keyboard class events needs to be handled: */
    14201434    if (nCode == HC_ACTION && m_spKeyboardHandler && m_spKeyboardHandler->winKeyboardEvent(wParam, *(KBDLLHOOKSTRUCT*)lParam))
    14211435        return 1;
    14221436
     1437    /* Pass the event along: */
    14231438    return CallNextHookEx(NULL, nCode, wParam, lParam);
    14241439}
     
    14551470        return true;
    14561471
     1472    /* Compose the MSG: */
    14571473    MSG message;
    14581474    message.hwnd = (HWND)m_views[m_iKeyboardHookViewIndex]->winId();
     
    14661482        message.lParam &= ~0x1000000;
    14671483
    1468     /* We suppose here that this hook is always called on the main GUI thread */
     1484    /* Pass event to view's event handler: */
     1485#if QT_VERSION < 0x050000
    14691486    long dummyResult;
    14701487    return m_views[m_iKeyboardHookViewIndex]->winEvent(&message, &dummyResult);
     1488#endif /* QT_VERSION < 0x050000 */
    14711489}
    14721490
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r59361 r59372  
    17371737bool UIMachineView::winEvent(MSG *pMsg, long* /* piResult */)
    17381738{
     1739    /* Make sure arguments valid: */
    17391740    AssertPtrReturn(pMsg, false);
    17401741
     
    17451746    switch (pMsg->message)
    17461747    {
     1748        /* Watch for key-events: */
    17471749        case WM_KEYDOWN:
    17481750        case WM_KEYUP:
     
    17511753        {
    17521754            /* Can't do COM inter-process calls from a SendMessage handler,
    1753              * see http://support.microsoft.com/kb/131056 */
     1755             * see http://support.microsoft.com/kb/131056. */
    17541756            if (vboxGlobal().isSeparateProcess() && InSendMessage())
    17551757            {
     
    17691771    }
    17701772
     1773    /* Return result: */
    17711774    return fResult;
    17721775}
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