VirtualBox

Changeset 35749 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 28, 2011 9:17:46 AM (14 years ago)
Author:
vboxsync
Message:

FE/Qt4-OSX: Make the key handling more dynamic.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.cpp

    r35745 r35749  
    5656# include "VBoxUtils.h"
    5757# include <Carbon/Carbon.h>
     58# include <QTimer>
    5859#endif /* Q_WS_MAC */
    5960
     
    303304
    304305#ifdef Q_WS_MAC
    305     m_uDarwinKeyModifiers = GetCurrentEventKeyModifiers();
     306    m_uDarwinKeyModifiers = 0;
    306307    UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHotKeyEditor::darwinEventHandlerProc, this);
    307308    ::DarwinGrabKeyboard(false /* just modifiers */);
     309
     310    m_pRemoveTimer = new QTimer(this);
     311    m_pRemoveTimer->setInterval(200);
     312    connect(m_pRemoveTimer, SIGNAL(timeout()),
     313            this, SLOT(removePendingKeys()));
    308314#endif /* Q_WS_MAC */
    309315}
     
    515521            modifierMask = ::DarwinAdjustModifierMask(modifierMask, pvCocoaEvent);
    516522            UInt32 changed = m_uDarwinKeyModifiers ^ modifierMask;
    517             m_uDarwinKeyModifiers = modifierMask;
    518523
    519524            /* Convert to keycode: */
     
    526531            if (changed)
    527532            {
     533                /* Stop the delete pending keys timer. */
     534                m_pRemoveTimer->stop();
     535                /* If modifierMask is empty, no key is pressed anymore. Stop
     536                 * all key handling and the deletion of keys. This is the
     537                 * status the user want. */
     538                if (!modifierMask)
     539                    m_fStartNewSequence = true;
    528540                /* Key release: */
    529                 if (!(changed & modifierMask))
     541                else if (!(changed & modifierMask))
    530542                {
    531                     /* Remove pressed symbol: */
    532                     m_pressedKeys.remove(iKeyCode);
    533 
    534                     /* If pressed key map is empty => start new sequence: */
    535                     if (m_pressedKeys.isEmpty())
    536                         m_fStartNewSequence = true;
     543                    /* Queue pressed symbol for removing: */
     544                    m_removeKeys.insert(iKeyCode);
     545                    m_pRemoveTimer->start();
    537546                }
    538547                /* Key press: */
     
    542551                    if (m_fStartNewSequence)
    543552                        m_shownKeys.clear();
    544 
     553                    /* Make sure any keys pending for removal are removed. */
     554                    removePendingKeys();
    545555                    /* Check maximum combo size: */
    546556                    if (m_shownKeys.size() < UIHotKeyCombination::m_iMaxComboSize)
     
    555565                }
    556566            }
     567            /* Save the new modifier mask state. */
     568            m_uDarwinKeyModifiers = modifierMask;
    557569
    558570            /* Update text: */
     
    563575    return false;
    564576}
     577
     578void UIHotKeyEditor::removePendingKeys()
     579{
     580    /* Stop the timer, we process all pending keys at once. */
     581    m_pRemoveTimer->stop();
     582    /* Something to do? */
     583    if (!m_removeKeys.isEmpty())
     584    {
     585        /* Remove every key. */
     586        foreach(int v, m_removeKeys)
     587        {
     588            m_pressedKeys.remove(v);
     589            m_shownKeys.remove(v);
     590        }
     591        m_removeKeys.clear();
     592        if (m_pressedKeys.isEmpty())
     593            m_fStartNewSequence = true;
     594    }
     595    /* Make sure the user see what happens. */
     596    updateText();
     597}
     598
    565599#endif /* Q_WS_MAC */
    566600
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h

    r35730 r35749  
    9090    bool m_fStartNewSequence;
    9191
    92 #ifdef Q_WS_MAC
     92#ifdef RT_OS_DARWIN
     93    QSet<int> m_removeKeys;
     94    QTimer* m_pRemoveTimer;
    9395    /* The current modifier key mask. Used to figure out which modifier
    9496     * key was pressed when we get a kEventRawKeyModifiersChanged event. */
    9597    uint32_t m_uDarwinKeyModifiers;
    96 #endif /* Q_WS_MAC */
     98private slots:
     99    void removePendingKeys();
     100#endif /* RT_OS_DARWIN */
    97101};
    98102
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