VirtualBox

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


Ignore:
Timestamp:
Feb 11, 2009 8:26:17 PM (16 years ago)
Author:
vboxsync
Message:

qt/darwin: Don't use HID for right hand modifier keys when Qt is Cocoa based. The HID stuff is *very* slow.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r16691 r16693  
    556556tstDarwinKeyboard4_SOURCES = \
    557557        src/darwin/tstDarwinKeyboard.cpp \
    558         src/darwin/DarwinKeyboard.cpp
    559 tstDarwinKeyboard4_LDFLAGS = -framework IOKit -framework Carbon
     558        src/darwin/DarwinKeyboard.cpp \
     559        src/darwin/VBoxCocoaApplication.m
     560tstDarwinKeyboard4_LDFLAGS = -framework IOKit -framework Carbon -framework AppKit
    560561tstDarwinKeyboard4_LIBS = \
    561562        $(LIB_RUNTIME)
  • trunk/src/VBox/Frontends/VirtualBox/include/DarwinKeyboard.h

    r16469 r16693  
    4343
    4444unsigned DarwinKeycodeToSet1Scancode(unsigned uKeyCode);
    45 UInt32   DarwinAdjustModifierMask(UInt32 fModifiers);
     45UInt32   DarwinAdjustModifierMask(UInt32 fModifiers, const void *pvCocoaEvent);
    4646unsigned DarwinModifierMaskToSet1Scancode(UInt32 fModifiers);
    4747unsigned DarwinModifierMaskToDarwinKeycode(UInt32 fModifiers);
  • trunk/src/VBox/Frontends/VirtualBox/include/QIHotKeyEdit.h

    r16610 r16693  
    8888    static pascal OSStatus darwinEventHandlerProc (EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData);
    8989# endif
    90     bool darwinKeyboardEvent (EventRef inEvent);
     90    bool darwinKeyboardEvent (const void *pvCocoaEvent, EventRef inEvent);
    9191#endif
    9292
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h

    r16691 r16693  
    164164    bool x11Event (XEvent *event);
    165165#elif defined(Q_WS_MAC)
    166     bool darwinKeyboardEvent (EventRef inEvent);
     166    bool darwinKeyboardEvent (const void *pvCocoaEvent, EventRef inEvent);
    167167    void darwinGrabKeyboardEvents (bool fGrab);
    168168#endif
  • trunk/src/VBox/Frontends/VirtualBox/src/QIHotKeyEdit.cpp

    r16691 r16693  
    677677    UInt32 EventClass = ::GetEventClass (inEvent);
    678678    if (EventClass == kEventClassKeyboard)
    679         return edit->darwinKeyboardEvent (inEvent);
     679        return edit->darwinKeyboardEvent (pvCocoaEvent, inEvent);
    680680    return false;
    681681}
     
    690690    if (EventClass == kEventClassKeyboard)
    691691    {
    692         if (edit->darwinKeyboardEvent (inEvent))
     692        if (edit->darwinKeyboardEvent (NULL, inEvent))
    693693            return 0;
    694694    }
     
    697697# endif /* !QT_MAC_USE_COCOA */
    698698
    699 bool QIHotKeyEdit::darwinKeyboardEvent (EventRef inEvent)
     699bool QIHotKeyEdit::darwinKeyboardEvent (const void *pvCocoaEvent, EventRef inEvent)
    700700{
    701701#if 0 /* for debugging */
     
    719719                                 sizeof (modifierMask), NULL, &modifierMask);
    720720
    721             modifierMask = ::DarwinAdjustModifierMask (modifierMask);
     721            modifierMask = ::DarwinAdjustModifierMask (modifierMask, pvCocoaEvent);
    722722            UInt32 changed = mDarwinKeyModifiers ^ modifierMask;
    723723            mDarwinKeyModifiers = modifierMask;
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r16691 r16693  
    151151    if (eventClass == kEventClassKeyboard)
    152152    {
    153         if (view->darwinKeyboardEvent (inEvent))
     153        if (view->darwinKeyboardEvent (pvCocoaEvent, inEvent))
    154154            return true;
    155155    }
     
    196196    if (eventClass == kEventClassKeyboard)
    197197    {
    198         if (view->darwinKeyboardEvent (inEvent))
     198        if (view->darwinKeyboardEvent (NULL, inEvent))
    199199            return 0;
    200200    }
     
    239239    if (eventClass == kEventClassKeyboard)
    240240    {
    241         if (view->darwinKeyboardEvent (inEvent))
     241        if (view->darwinKeyboardEvent (NULL, inEvent))
    242242            return true;
    243243    }
     
    21932193 *  it receives a raw keyboard event.
    21942194 *
     2195 *  @param pvCocoaEvent The Cocoa keyboard event. Can be NULL in some configs.
    21952196 *  @param inEvent      The keyboard event.
    21962197 *
    21972198 *  @return true if the key was processed, false if it wasn't processed and should be passed on.
    21982199 */
    2199 bool VBoxConsoleView::darwinKeyboardEvent (EventRef inEvent)
     2200bool VBoxConsoleView::darwinKeyboardEvent (const void *pvCocoaEvent, EventRef inEvent)
    22002201{
    22012202    bool ret = false;
     
    22372238        ::GetEventParameter (inEvent, kEventParamKeyModifiers, typeUInt32, NULL,
    22382239                             sizeof (newMask), NULL, &newMask);
    2239         newMask = ::DarwinAdjustModifierMask (newMask);
     2240        newMask = ::DarwinAdjustModifierMask (newMask, pvCocoaEvent);
    22402241        UInt32 changed = newMask ^ mDarwinKeyModifiers;
    22412242        if (changed)
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/DarwinKeyboard.cpp

    r16469 r16693  
    2020 * additional information or have any questions.
    2121 */
    22 
    23 
    24 
    25 #define USE_HID_FOR_MODIFIERS
    26 
    2722
    2823/*******************************************************************************
     
    3934#endif
    4035
    41 #ifdef USE_HID_FOR_MODIFIERS
     36#ifdef RT_ARCH_X86
     37# define USE_HID_FOR_MODIFIERS
    4238# include <mach/mach.h>
    4339# include <mach/mach_error.h>
     
    5147#include <ApplicationServices/ApplicationServices.h>
    5248#include <Carbon/Carbon.h>
     49
     50#ifndef USE_HID_FOR_MODIFIERS
     51# include "VBoxCocoaApplication.h"
     52#endif
     53
    5354
    5455__BEGIN_DECLS
     
    972973 * @returns left/right adjusted fModifiers.
    973974 * @param   fModifiers      The mask to adjust.
    974  */
    975 UInt32 DarwinAdjustModifierMask(UInt32 fModifiers)
    976 {
    977 #ifdef USE_HID_FOR_MODIFIERS
    978     /*
    979      * Update the keyboard cache.
    980      */
    981     darwinHIDKeyboardCacheUpdate();
    982 
     975 * @param   pvCocoaEvent    The associated Cocoa keyboard event. This is NULL
     976 *                          when using HID for modifier corrections.
     977 *
     978 */
     979UInt32 DarwinAdjustModifierMask(UInt32 fModifiers, const void *pvCocoaEvent)
     980{
    983981    /*
    984982     * Check if there is anything to adjust and perform the adjustment.
     
    986984    if (fModifiers & (shiftKey | rightShiftKey | controlKey | rightControlKey | optionKey | rightOptionKey | cmdKey | kEventKeyModifierRightCmdKeyMask))
    987985    {
    988         const UInt32 fHIDModifiers = g_fHIDModifierMask;
     986#ifndef USE_HID_FOR_MODIFIERS
     987        /*
     988         * Convert the Cocoa modifiers to Carbon ones.
     989         */
     990        AssertPtr(pvCocoaEvent);
     991        VBoxCocoaApplication_printEvent("dbg-adjMods: ", pvCocoaEvent);
     992        uint32_t fAltModifiers = VBoxCocoaApplication_getEventModifierFlagsXlated(pvCocoaEvent);
     993
     994#else  /* USE_HID_FOR_MODIFIERS */
     995        /*
     996         * Update the keyboard cache.
     997         */
     998        darwinHIDKeyboardCacheUpdate();
     999        const UInt32 fAltModifiers = g_fHIDModifierMask;
     1000
     1001#endif /* USE_HID_FOR_MODIFIERS */
    9891002#ifdef DEBUG_PRINTF
    990         RTPrintf("dbg-fHIDModifier=%#x fModifiers=%#x", fHIDModifiers, fModifiers);
     1003        RTPrintf("dbg-fAltModifiers=%#x fModifiers=%#x", fAltModifiers, fModifiers);
    9911004#endif
    9921005        if (   (fModifiers    & (rightShiftKey | shiftKey))
    993             && (fHIDModifiers & (rightShiftKey | shiftKey)))
     1006            && (fAltModifiers & (rightShiftKey | shiftKey)))
    9941007        {
    9951008            fModifiers &= ~(rightShiftKey | shiftKey);
    996             fModifiers |= fHIDModifiers & (rightShiftKey | shiftKey);
     1009            fModifiers |= fAltModifiers & (rightShiftKey | shiftKey);
    9971010        }
    9981011
    9991012        if (   (fModifiers    & (rightControlKey | controlKey))
    1000             && (fHIDModifiers & (rightControlKey | controlKey)))
     1013            && (fAltModifiers & (rightControlKey | controlKey)))
    10011014        {
    10021015            fModifiers &= ~(rightControlKey | controlKey);
    1003             fModifiers |= fHIDModifiers & (rightControlKey | controlKey);
     1016            fModifiers |= fAltModifiers & (rightControlKey | controlKey);
    10041017        }
    10051018
    10061019        if (   (fModifiers    & (optionKey | rightOptionKey))
    1007             && (fHIDModifiers & (optionKey | rightOptionKey)))
     1020            && (fAltModifiers & (optionKey | rightOptionKey)))
    10081021        {
    10091022            fModifiers &= ~(optionKey | rightOptionKey);
    1010             fModifiers |= fHIDModifiers & (optionKey | rightOptionKey);
     1023            fModifiers |= fAltModifiers & (optionKey | rightOptionKey);
    10111024        }
    10121025
    10131026        if (   (fModifiers    & (cmdKey | kEventKeyModifierRightCmdKeyMask))
    1014             && (fHIDModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask)))
     1027            && (fAltModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask)))
    10151028        {
    10161029            fModifiers &= ~(cmdKey | kEventKeyModifierRightCmdKeyMask);
    1017             fModifiers |= fHIDModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask);
     1030            fModifiers |= fAltModifiers & (cmdKey | kEventKeyModifierRightCmdKeyMask);
    10181031        }
    10191032#ifdef DEBUG_PRINTF
    1020         RTPrintf(" -> %#x", fModifiers);
     1033        RTPrintf(" -> %#x\n", fModifiers);
    10211034#endif
    10221035    }
    1023 #endif /* USE_HID_FOR_MODIFIERS */
    1024 
    10251036    return fModifiers;
    10261037}
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaApplication.h

    r16691 r16693  
    8585void VBoxCocoaApplication_setCallback(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser);
    8686void VBoxCocoaApplication_unsetCallback(uint32_t fMask, PFNVBOXCACALLBACK pfnCallback, void *pvUser);
     87unsigned long VBoxCocoaApplication_getEventModifierFlags(const void *pvEvent);
     88uint32_t VBoxCocoaApplication_getEventModifierFlagsXlated(const void *pvEvent);
    8789const char *VBoxCocoaApplication_eventTypeName(unsigned long eEvtType);
    8890void VBoxCocoaApplication_printEvent(const char *pszPrefix, const void *pvEvent);
     91
    8992
    9093/** @} */
  • trunk/src/VBox/Frontends/VirtualBox/src/darwin/VBoxCocoaApplication.m

    r16691 r16693  
    2525*******************************************************************************/
    2626#include "VBoxCocoaApplication.h"
     27#include "DarwinKeyboard.h"
    2728#include <iprt/assert.h>
    2829#import <AppKit/NSEvent.h>
     
    193194{
    194195    [g_pVBoxCocoaApp unsetCallback:fMask :pfnCallback :pvUser];
     196}
     197
     198
     199/**
     200 * Calls the -(NSUInteger)modifierFlags method on a NSEvent object.
     201 *
     202 * @return  The Cocoa event modifier mask.
     203 * @param   pvEvent     The NSEvent object.
     204 */
     205unsigned long VBoxCocoaApplication_getEventModifierFlags(const void *pvEvent)
     206{
     207    NSEvent *pEvent = (NSEvent *)pvEvent;
     208    return [pEvent modifierFlags];
     209}
     210
     211
     212/**
     213 * Calls the -(NSUInteger)modifierFlags method on a NSEvent object and
     214 * converts the flags to carbon style.
     215 *
     216 * @return  The Carbon modifier mask.
     217 * @param   pvEvent     The NSEvent object.
     218 */
     219uint32_t VBoxCocoaApplication_getEventModifierFlagsXlated(const void *pvEvent)
     220{
     221    NSEvent    *pEvent  = (NSEvent *)pvEvent;
     222    NSUInteger  fCocoa  = [pEvent modifierFlags];
     223    uint32_t    fCarbon = 0;
     224    if (fCocoa)
     225    {
     226        if (fCocoa & NSAlphaShiftKeyMask)
     227            fCarbon |= alphaLock;
     228        if (fCocoa & (NSShiftKeyMask | NX_DEVICELSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK))
     229        {
     230            if (fCocoa & (NX_DEVICERSHIFTKEYMASK | NX_DEVICERSHIFTKEYMASK))
     231            {
     232                if (fCocoa & NX_DEVICERSHIFTKEYMASK)
     233                    fCarbon |= rightShiftKey;
     234                if (fCocoa & NX_DEVICELSHIFTKEYMASK)
     235                    fCarbon |= shiftKey;
     236            }
     237            else
     238                fCarbon |= shiftKey;
     239        }
     240
     241        if (fCocoa & (NSControlKeyMask | NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK))
     242        {
     243            if (fCocoa & (NX_DEVICELCTLKEYMASK | NX_DEVICERCTLKEYMASK))
     244            {
     245                if (fCocoa & NX_DEVICERCTLKEYMASK)
     246                    fCarbon |= rightControlKey;
     247                if (fCocoa & NX_DEVICELCTLKEYMASK)
     248                    fCarbon |= controlKey;
     249            }
     250            else
     251                fCarbon |= controlKey;
     252        }
     253
     254        if (fCocoa & (NSAlternateKeyMask | NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK))
     255        {
     256            if (fCocoa & (NX_DEVICELALTKEYMASK | NX_DEVICERALTKEYMASK))
     257            {
     258                if (fCocoa & NX_DEVICERALTKEYMASK)
     259                    fCarbon |= rightOptionKey;
     260                if (fCocoa & NX_DEVICELALTKEYMASK)
     261                    fCarbon |= optionKey;
     262            }
     263            else
     264                fCarbon |= optionKey;
     265        }
     266
     267        if (fCocoa & (NSCommandKeyMask | NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK))
     268        {
     269            if (fCocoa & (NX_DEVICELCMDKEYMASK | NX_DEVICERCMDKEYMASK))
     270            {
     271                if (fCocoa & NX_DEVICERCMDKEYMASK)
     272                    fCarbon |= kEventKeyModifierRightCmdKeyMask;
     273                if (fCocoa & NX_DEVICELCMDKEYMASK)
     274                    fCarbon |= cmdKey;
     275            }
     276            else
     277                fCarbon |= cmdKey;
     278        }
     279
     280        //if (fCocoa & NSNumericPadKeyMask)
     281        //    fCarbon |= ???;
     282
     283        //if (fCocoa & NSHelpKeyMask)
     284        //    fCarbon |= ???;
     285
     286        //if (fCocoa & NSFunctionKeyMask)
     287        //    fCarbon |= ???;
     288    }
     289
     290    return fCarbon;
    195291}
    196292
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