VirtualBox

Changeset 59359 in vbox


Ignore:
Timestamp:
Jan 15, 2016 11:39:44 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
105047
Message:

FE/Qt: Qt5 migration (part 56): Reworking keyboard-handler: Some cleanup for Mac OS X.

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

Legend:

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

    r59356 r59359  
    240240#if defined(Q_WS_MAC)
    241241
    242         /* On Mac, we use the Qt methods + disabling global hot keys + watching modifiers (for right/left separation). */
     242        /* On Mac, keyboard grabbing is ineffective,
     243         * a low-level keyboard-hook is used instead.
     244         * It is being installed on focus-in event and uninstalled on focus-out.
     245         * S.a. UIKeyboardHandler::eventFilter for more information. */
     246
     247        /* On Mac, we also
     248         * use the Qt method to grab the keyboard,
     249         * disable global hot keys and
     250         * enable watching modifiers (for right/left separation). */
     251        // TODO: Is that really needed?
    243252        ::DarwinDisableGlobalHotKeys(true);
    244253        m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
     
    246255#elif defined(Q_WS_WIN)
    247256
    248         /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */
     257        /* On Win, keyboard grabbing is ineffective,
     258         * a low-level keyboard-hook is used instead.
     259         * It is being installed on window-activate event and uninstalled on window-deactivate.
     260         * S.a. UIKeyboardHandler::eventFilter for more information. */
    249261
    250262#elif defined(Q_WS_X11)
     
    300312#else
    301313
    302         /* On other platforms we are just praying Qt method will work. */
     314        /* On other platforms we are just praying Qt method to work: */
    303315        m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard();
    304316
     
    324336#if defined(Q_WS_MAC)
    325337
     338        /* On Mac, keyboard grabbing is ineffective,
     339         * a low-level keyboard-hook is used instead.
     340         * It is being installed on focus-in event and uninstalled on focus-out.
     341         * S.a. UIKeyboardHandler::eventFilter for more information. */
     342
     343        /* On Mac, we also
     344         * use the Qt method to release the keyboard,
     345         * enable global hot keys and
     346         * disable watching modifiers (for right/left separation). */
     347        // TODO: Is that really needed?
    326348        ::DarwinDisableGlobalHotKeys(false);
    327349        m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
     
    329351#elif defined(Q_WS_WIN)
    330352
    331         /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */
     353        /* On Win, keyboard grabbing is ineffective,
     354         * a low-level keyboard-hook is used instead.
     355         * It is being installed on window-activate event and uninstalled on window-deactivate.
     356         * S.a. UIKeyboardHandler::eventFilter for more information. */
    332357
    333358#elif defined(Q_WS_X11)
     
    369394#else
    370395
     396        /* On other platforms we are just praying Qt method to work: */
    371397        m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard();
    372398
    373399#endif
    374400
    375         /* Reset keyboard-capture index: */
     401        /* Forget which screen had captured keyboard: */
    376402        m_iKeyboardCaptureViewIndex = -1;
    377403
     
    459485
    460486#ifdef Q_WS_WIN
    461 /** Tell keyboard event handler to skip host keyboard events. Used for HID LEDs sync
    462  * when on Windows host a keyboard event is generated in order to change corresponding LED. */
    463487void UIKeyboardHandler::winSkipKeyboardEvents(bool fSkip)
    464488{
     
    974998#if defined(Q_WS_MAC)
    975999
    976     /* We have to make sure the callback for the keyboard events
    977      * is released when closing this view. */
     1000    /* Cleanup keyboard-hook: */
    9781001    if (m_iKeyboardHookViewIndex != -1)
    979         darwinGrabKeyboardEvents(false);
     1002    {
     1003        /* Ungrab the keyboard and unregister the event callback/hook: */
     1004        ::DarwinReleaseKeyboard();
     1005        UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */,
     1006                                                                  UIKeyboardHandler::macKeyboardProc, this);
     1007        /* Update the id: */
     1008        m_iKeyboardHookViewIndex = -1;
     1009    }
    9801010
    9811011#elif defined(Q_WS_WIN)
     
    9851015    m_pAltGrMonitor = 0;
    9861016
    987     /* Cleaning keyboard-hook: */
     1017    /* Cleanup keyboard-hook: */
    9881018    if (m_keyboardHook)
    9891019    {
    990         UnhookWindowsHookEx(m_keyboardHook);
     1020        /* Uninstall existing keyboard-hook: */
     1021        ::UnhookWindowsHookEx(m_keyboardHook);
    9911022        m_keyboardHook = NULL;
     1023        /* Update the id: */
     1024        m_iKeyboardHookViewIndex = -1;
    9921025    }
    9931026
     
    10881121            {
    10891122#ifdef Q_WS_MAC
    1090                 /* If keyboard-event handler is NOT currently installed;
     1123                /* If keyboard-hook is NOT installed;
    10911124                 * Or installed but NOT for that view: */
    1092                 if (m_iKeyboardHookViewIndex != (int)uScreenId)
     1125                if ((int)uScreenId != m_iKeyboardHookViewIndex)
    10931126                {
    1094                     /* If keyboard-event handler is NOT currently installed: */
     1127                    /* If keyboard-hook is NOT currently installed: */
    10951128                    if (m_iKeyboardHookViewIndex == -1)
    10961129                    {
    1097                         /* Install the keyboard-event handler: */
    1098                         darwinGrabKeyboardEvents(true);
     1130                        /* Disable mouse and keyboard event compression/delaying
     1131                         * to make sure we *really* get all of the events: */
     1132                        ::CGSetLocalEventsSuppressionInterval(0.0);
     1133                        ::darwinSetMouseCoalescingEnabled(false);
     1134
     1135                        /* Bring the caps lock state up to date,
     1136                         * otherwise e.g. a later Shift key press will accidentally inject a CapsLock key press and release,
     1137                         * see UIKeyboardHandler::macKeyboardEvent for the code handling modifier key state changes. */
     1138                        m_uDarwinKeyModifiers ^= (m_uDarwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock;
     1139
     1140                        /* Register the event callback/hook and grab the keyboard: */
     1141                        UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */,
     1142                                                                                UIKeyboardHandler::macKeyboardProc, this);
     1143                        ::DarwinGrabKeyboard(false);
    10991144                    }
    11001145                    /* Update the id: */
     
    11221167            {
    11231168#ifdef Q_WS_MAC
    1124                 /* If keyboard-event handler is installed for that view: */
    1125                 if (m_iKeyboardHookViewIndex == (int)uScreenId)
     1169                /* If keyboard-hook is installed: */
     1170                if ((int)uScreenId == m_iKeyboardHookViewIndex)
    11261171                {
    1127                     /* Remove the keyboard-event handler: */
    1128                     darwinGrabKeyboardEvents(false);
     1172                    /* Ungrab the keyboard and unregister the event callback/hook: */
     1173                    ::DarwinReleaseKeyboard();
     1174                    UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */,
     1175                                                                              UIKeyboardHandler::macKeyboardProc, this);
    11291176                    /* Update the id: */
    11301177                    m_iKeyboardHookViewIndex = -1;
     
    11881235
    11891236#if defined(Q_WS_MAC)
    1190 
    1191 void UIKeyboardHandler::darwinGrabKeyboardEvents(bool fGrab)
    1192 {
    1193     if (fGrab)
    1194     {
    1195         /* Disable mouse and keyboard event compression/delaying to make sure we *really* get all of the events. */
    1196         ::CGSetLocalEventsSuppressionInterval(0.0);
    1197         ::darwinSetMouseCoalescingEnabled(false);
    1198 
    1199         /* Bring the caps lock state up to date, otherwise e.g. a later Shift
    1200          * key press will accidentally inject a CapsLock key press and release,
    1201          * see UIKeyboardHandler::macKeyboardEvent for the code handling
    1202          * modifier key state changes */
    1203         m_uDarwinKeyModifiers ^= (m_uDarwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock;
    1204 
    1205         /* Register the event callback/hook and grab the keyboard. */
    1206         UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */,
    1207                                                                 UIKeyboardHandler::macKeyboardProc, this);
    1208 
    1209         ::DarwinGrabKeyboard (false);
    1210     }
    1211     else
    1212     {
    1213         ::DarwinReleaseKeyboard();
    1214         UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */,
    1215                                                                   UIKeyboardHandler::macKeyboardProc, this);
    1216     }
    1217 }
    12181237
    12191238bool UIKeyboardHandler::macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h

    r59347 r59359  
    150150
    151151#if defined(Q_WS_MAC)
    152     /** Mac: Installs/deinstalls low level keyboard hook. */
    153     void darwinGrabKeyboardEvents(bool fGrab);
    154152    /** Mac: Performs initial pre-processing of all the native keyboard events. */
    155153    static bool macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);
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