VirtualBox

Changeset 245 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jan 23, 2007 4:51:51 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
17775
Message:

FE/Qt: synchronize the num lock state between host and guest

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h

    r1 r245  
    8484    void onFullscreenChange (bool on);
    8585   
     86    void FixModifierState (LONG *codes, uint *count);
     87
    8688signals:
    8789
     
    100102    bool winEvent (MSG *msg);
    101103#elif defined(Q_WS_X11)
    102     bool x11Event( XEvent *event );
     104    bool x11Event (XEvent *event );
    103105#endif
    104106
     
    145147
    146148    bool processHotKey (const QKeySequence &key, QMenuData *data);
     149    void updateModifiers (bool fNumLock, bool fCapsLock, bool fScrollLock);
    147150
    148151    void releaseAllKeysPressed (bool release_hostkey = true);
     
    193196    bool autoresize_guest : 1;
    194197
     198    bool mfNumLock;
     199    bool mfScrollLock;
     200    bool mfCapsLock;
     201    long muNumLockAdaptionCnt;
     202
    195203    QTimer *resize_hint_timer;
    196204
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxDefs.h

    r237 r245  
    148148        SessionStateChangeEventType = QEvent::User + 7,
    149149        SnapshotEventType = QEvent::User + 8,
     150        ModifierKeyChangeEventType = QEvent::User + 9,
    150151        EnumerateMediaEventType = QEvent::User + 100,
    151152        ActivateMenuEventType = QEvent::User + 101,
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r242 r245  
    194194};
    195195
     196/** Modifier key change event */
     197class ModifierKeyChangeEvent : public QEvent
     198{
     199public:
     200    ModifierKeyChangeEvent(bool fNumLock, bool fScrollLock, bool fCapsLock) :
     201        QEvent ((QEvent::Type) VBoxDefs::ModifierKeyChangeEventType),
     202        mfNumLock(fNumLock), mfScrollLock(fScrollLock), mfCapsLock(fCapsLock) {}
     203    bool NumLock()    const { return mfNumLock; }
     204    bool ScrollLock() const { return mfScrollLock; }
     205    bool CapsLock()   const { return mfCapsLock; }
     206private:
     207    bool mfNumLock, mfScrollLock, mfCapsLock;
     208};
     209
    196210//
    197211// VBoxConsoleCallback class
     
    280294    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fScrollLock, BOOL fCapsLock)
    281295    {
    282         /** @todo */
    283         Q_UNUSED (fNumLock);
    284         Q_UNUSED (fScrollLock);
    285         Q_UNUSED (fCapsLock);
     296        QApplication::postEvent (
     297            view, new ModifierKeyChangeEvent (fNumLock, fScrollLock, fCapsLock));
    286298        return S_OK;
    287299    }
     
    337349    , ignore_mainwnd_resize (false)
    338350    , autoresize_guest (false)
     351    , muNumLockAdaptionCnt (2)
    339352    , mode (rm)
    340353{
     
    763776                    vboxProblem().remindAboutMouseIntegration (mouse_absolute);
    764777                }
     778                return true;
     779            }
     780
     781            case VBoxDefs::ModifierKeyChangeEventType:
     782            {
     783                ModifierKeyChangeEvent *me = (ModifierKeyChangeEvent* )e;
     784                if (me->NumLock() != mfNumLock)
     785                    muNumLockAdaptionCnt = 2;
     786                mfNumLock    = me->NumLock();
     787                mfScrollLock = me->ScrollLock();
     788                mfCapsLock   = me->CapsLock();
    765789                return true;
    766790            }
     
    12571281
    12581282/**
     1283 *  Synchronize the views of the host and the guest to the modifier keys.
     1284 *  This function will add up to 6 additional keycodes to codes.
     1285 *
     1286 *  @param  codes  pointer to keycodes which are sent to the keyboard
     1287 *  @param  count  pointer to the keycodes counter
     1288 */
     1289void VBoxConsoleView::FixModifierState(LONG *codes, uint *count)
     1290{
     1291    unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0, uKeyMaskScroll = 0;
     1292
     1293#if defined(Q_WS_X11)
     1294
     1295    Window   wDummy1, wDummy2;
     1296    int      iDummy3, iDummy4, iDummy5, iDummy6;
     1297    unsigned uMask;
     1298
     1299    uKeyMaskCaps          = LockMask;
     1300    XModifierKeymap* map  = XGetModifierMapping(qt_xdisplay());
     1301    KeyCode keyCodeNum    = XKeysymToKeycode(qt_xdisplay(), XK_Num_Lock);
     1302    KeyCode keyCodeScroll = XKeysymToKeycode(qt_xdisplay(), XK_Scroll_Lock);
     1303
     1304    for (int i = 0; i < 8; i++)
     1305    {
     1306        if (   keyCodeNum != NoSymbol
     1307            && map->modifiermap[map->max_keypermod * i] == keyCodeNum)
     1308            uKeyMaskNum    = 1 << i;
     1309        else if (   keyCodeScroll != NoSymbol
     1310                 && map->modifiermap[map->max_keypermod * i] == keyCodeScroll)
     1311            uKeyMaskScroll = 1 << i;
     1312    }
     1313    XQueryPointer(qt_xdisplay(), DefaultRootWindow(qt_xdisplay()), &wDummy1, &wDummy2,
     1314                  &iDummy3, &iDummy4, &iDummy5, &iDummy6, &uMask);
     1315    XFreeModifiermap(map);
     1316
     1317    if (muNumLockAdaptionCnt && (mfNumLock ^ !!(uMask & uKeyMaskNum)))
     1318    {
     1319        muNumLockAdaptionCnt--;
     1320        codes[(*count)++] = 0x45;
     1321        codes[(*count)++] = 0x45 | 0x80;
     1322    }
     1323
     1324#elif defined(Q_WS_WIN32)
     1325
     1326    if (muNumLockAdaptionCnt && (mfNumLock ^ !!(GetKeyState(VK_NUMLOCK))))
     1327    {
     1328        muNumLockAdaptionCnt--;
     1329        codes[(*count)++] = 0x45;
     1330        codes[(*count)++] = 0x45 | 0x80;
     1331    }
     1332
     1333#else
     1334
     1335#warning Adapt VBoxConsoleView::FixModifierState
     1336
     1337#endif
     1338
     1339
     1340}
     1341
     1342/**
    12591343 *  Called on every key press and release (while in focus).
    12601344 *
     
    12751359    const bool is_hostkey = key == gs.hostKey();
    12761360
    1277     LONG buf [2];
     1361    LONG buf [16];
    12781362    LONG *codes = buf;
    12791363    uint count = 0;
     
    13311415            else
    13321416                keys_pressed [scan] &= ~IsKbdCaptured;
     1417
     1418            // Check if the guest has the same view on the modifier keys (NumLock,
     1419            // CapsLock, ScrollLock) as the X server. If not, send KeyPress events
     1420            // to synchronize the state.
     1421            FixModifierState (codes, &count);
     1422           
    13331423        }
    13341424    }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette