VirtualBox

Changeset 107153 in vbox


Ignore:
Timestamp:
Nov 27, 2024 9:45:17 AM (7 weeks ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10407. Adding a lookup table to convert evdev scan codes to HID usage codes.

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

Legend:

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

    r106611 r107153  
    108108UIKeyboardHandler *UIKeyboardHandler::m_spKeyboardHandler = 0;
    109109#endif /* VBOX_WS_WIN */
     110
     111#define CODE_ARRAY_LENGTH 255
     112
     113LONG evcode_hid[CODE_ARRAY_LENGTH][2] = {
     114    {0x7, 0x0}, //NULL
     115    {0x7, 0x29}, //"Escape"
     116    {0x7, 0x1e}, //"Digit1"
     117    {0x7, 0x1f}, //"Digit2"
     118    {0x7, 0x20}, //"Digit3"
     119    {0x7, 0x21}, //"Digit4"
     120    {0x7, 0x22}, //"Digit5"
     121    {0x7, 0x23}, //"Digit6"
     122    {0x7, 0x24}, //"Digit7"
     123    {0x7, 0x25}, //"Digit8"
     124    {0x7, 0x26}, //"Digit9"
     125    {0x7, 0x27}, //"Digit0"
     126    {0x7, 0x2d}, //"Minus"
     127    {0x7, 0x2e}, //"Equal"
     128    {0x7, 0x2a}, //"Backspace"
     129    {0x7, 0x2b}, //"Tab"
     130    {0x7, 0x14}, //"KeyQ"
     131    {0x7, 0x1a}, //"KeyW"
     132    {0x7, 0x8}, //"KeyE"
     133    {0x7, 0x15}, //"KeyR"
     134    {0x7, 0x17}, //"KeyT"
     135    {0x7, 0x1c}, //"KeyY"
     136    {0x7, 0x18}, //"KeyU"
     137    {0x7, 0xc}, //"KeyI"
     138    {0x7, 0x12}, //"KeyO"
     139    {0x7, 0x13}, //"KeyP"
     140    {0x7, 0x2f}, //"BracketLeft"
     141    {0x7, 0x30}, //"BracketRight"
     142    {0x7, 0x28}, //"Enter"
     143    {0x7, 0xe0}, //"ControlLeft"
     144    {0x7, 0x4}, //"KeyA"
     145    {0x7, 0x16}, //"KeyS"
     146    {0x7, 0x7}, //"KeyD"
     147    {0x7, 0x9}, //"KeyF"
     148    {0x7, 0xa}, //"KeyG"
     149    {0x7, 0xb}, //"KeyH"
     150    {0x7, 0xd}, //"KeyJ"
     151    {0x7, 0xe}, //"KeyK"
     152    {0x7, 0xf}, //"KeyL"
     153    {0x7, 0x33}, //"Semicolon"
     154    {0x7, 0x34}, //"Quote"
     155    {0x7, 0x35}, //"Backquote"
     156    {0x7, 0xe1}, //"ShiftLeft"
     157    {0x7, 0x31}, //"Backslash"
     158    {0x7, 0x1d}, //"KeyZ"
     159    {0x7, 0x1b}, //"KeyX"
     160    {0x7, 0x6}, //"KeyC"
     161    {0x7, 0x19}, //"KeyV"
     162    {0x7, 0x5}, //"KeyB"
     163    {0x7, 0x11}, //"KeyN"
     164    {0x7, 0x10}, //"KeyM"
     165    {0x7, 0x36}, //"Comma"
     166    {0x7, 0x37}, //"Period"
     167    {0x7, 0x38}, //"Slash"
     168    {0x7, 0xe5}, //"ShiftRight"
     169    {0x7, 0x55}, //"NumpadMultiply"
     170    {0x7, 0xe2}, //"AltLeft"
     171    {0x7, 0x2c}, //"Space"
     172    {0x7, 0x39}, //"CapsLock"
     173    {0x7, 0x3a}, //"F1"
     174    {0x7, 0x3b}, //"F2"
     175    {0x7, 0x3c}, //"F3"
     176    {0x7, 0x3d}, //"F4"
     177    {0x7, 0x3e}, //"F5"
     178    {0x7, 0x3f}, //"F6"
     179    {0x7, 0x40}, //"F7"
     180    {0x7, 0x41}, //"F8"
     181    {0x7, 0x42}, //"F9"
     182    {0x7, 0x43}, //"F10"
     183    {0x7, 0x53}, //"NumLock"
     184    {0x7, 0x47}, //"ScrollLock"
     185    {0x7, 0x5f}, //"Numpad7"
     186    {0x7, 0x60}, //"Numpad8"
     187    {0x7, 0x61}, //"Numpad9"
     188    {0x7, 0x56}, //"NumpadSubtract"
     189    {0x7, 0x5c}, //"Numpad4"
     190    {0x7, 0x5d}, //"Numpad5"
     191    {0x7, 0x5e}, //"Numpad6"
     192    {0x7, 0x57}, //"NumpadAdd"
     193    {0x7, 0x59}, //"Numpad1"
     194    {0x7, 0x5a}, //"Numpad2"
     195    {0x7, 0x5b}, //"Numpad3"
     196    {0x7, 0x62}, //"Numpad0"
     197    {0x7, 0x63}, //"NumpadDecimal"
     198    {0x0, 0x0}, //NULL
     199    {0x7, 0x94}, //"Lang5"
     200    {0x7, 0x64}, //"IntlBackslash"
     201    {0x7, 0x44}, //"F11"
     202    {0x7, 0x45}, //"F12"
     203    {0x7, 0x87}, //"IntlRo"
     204    {0x7, 0x92}, //"Lang3"
     205    {0x7, 0x93}, //"Lang4"
     206    {0x7, 0x8a}, //"Convert"
     207    {0x7, 0x88}, //"KanaMode"
     208    {0x7, 0x8b}, //"NonConvert"
     209    {0x0, 0x0}, //NULL
     210    {0x7, 0x58}, //"NumpadEnter"
     211    {0x7, 0xe4}, //"ControlRight"
     212    {0x7, 0x54}, //"NumpadDivide"
     213    {0x7, 0x46}, //"PrintScreen"
     214    {0x7, 0xe6}, //"AltRight"
     215    {0x0, 0x0}, //NULL
     216    {0x7, 0x4a}, //"Home"
     217    {0x7, 0x52}, //"ArrowUp"
     218    {0x7, 0x4b}, //"PageUp"
     219    {0x7, 0x50}, //"ArrowLeft"
     220    {0x7, 0x4f}, //"ArrowRight"
     221    {0x7, 0x4d}, //"End"
     222    {0x7, 0x51}, //"ArrowDown"
     223    {0x7, 0x4e}, //"PageDown"
     224    {0x7, 0x49}, //"Insert"
     225    {0x7, 0x4c}, //"Delete"
     226    {0x0, 0x0}, //NULL
     227    {0x7, 0x7f}, //"AudioVolumeMute"
     228    {0x7, 0x81}, //"AudioVolumeDown"
     229    {0x7, 0x80}, //"AudioVolumeUp"
     230    {0x7, 0x66}, //"Power"
     231    {0x7, 0x67}, //"NumpadEqual"
     232    {0x7, 0xd7}, //NULL
     233    {0x7, 0x48}, //"Pause"
     234    {0xc, 0x29f}, //"ShowAllWindows"
     235    {0x7, 0x85}, //"NumpadComma"
     236    {0x7, 0x90}, //"Lang1"
     237    {0x7, 0x91}, //"Lang2"
     238    {0x7, 0x89}, //"IntlYen"
     239    {0x7, 0xe3}, //"MetaLeft"
     240    {0x7, 0xe7}, //"MetaRight"
     241    {0x7, 0x65}, //"ContextMenu"
     242    {0xc, 0x226}, //"BrowserStop"
     243    {0x7, 0x79}, //"Again"
     244    {0x0, 0x0}, //NULL
     245    {0x7, 0x7a}, //"Undo"
     246    {0x7, 0x77}, //"Select"
     247    {0x7, 0x7c}, //"Copy"
     248    {0x7, 0x74}, //"Open"
     249    {0x7, 0x7d}, //"Paste"
     250    {0x7, 0x7e}, //"Find"
     251    {0x7, 0x7b}, //"Cut"
     252    {0x7, 0x75}, //"Help"
     253    {0x0, 0x0}, //NULL
     254    {0xc, 0x192}, //"LaunchApp2"
     255    {0x0, 0x0}, //NULL
     256    {0x0, 0x0}, //NULL
     257    {0x0, 0x0}, //NULL
     258    {0xc, 0x194}, //"LaunchApp1"
     259    {0x0, 0x0}, //NULL
     260    {0x0, 0x0}, //NULL
     261    {0x0, 0x0}, //NULL
     262    {0x0, 0x0}, //NULL
     263    {0x0, 0x0}, //NULL
     264    {0xc, 0x196}, //NULL
     265    {0x0, 0x0}, //NULL
     266    {0xc, 0x19e}, //NULL
     267    {0x0, 0x0}, //NULL
     268    {0x0, 0x0}, //NULL
     269    {0xc, 0x18a}, //"LaunchMail"
     270    {0xc, 0x22a}, //"BrowserFavorites"
     271    {0x0, 0x0}, //NULL
     272    {0xc, 0x224}, //"BrowserBack"
     273    {0xc, 0x225}, //"BrowserForward"
     274    {0x0, 0x0}, //NULL
     275    {0xc, 0xb8}, //"Eject"
     276    {0x0, 0x0}, //NULL
     277    {0xc, 0xb5}, //"MediaTrackNext"
     278    {0xc, 0xcd}, //"MediaPlayPause"
     279    {0xc, 0xb6}, //"MediaTrackPrevious"
     280    {0xc, 0xb7}, //"MediaStop"
     281    {0xc, 0xb2}, //"MediaRecord"
     282    {0xc, 0xb4}, //"MediaRewind"
     283    {0xc, 0x8c}, //NULL
     284    {0x0, 0x0}, //NULL
     285    {0xc, 0x183}, //"MediaSelect"
     286    {0xc, 0x223}, //"BrowserHome"
     287    {0xc, 0x227}, //"BrowserRefresh"
     288    {0xc, 0x94}, //NULL
     289    {0x0, 0x0}, //NULL
     290    {0x0, 0x0}, //NULL
     291    {0x0, 0x0}, //NULL
     292    {0x0, 0x0}, //NULL
     293    {0x7, 0xb6}, //"NumpadParenLeft"
     294    {0x7, 0xb7}, //"NumpadParenRight"
     295    {0xc, 0x201}, //NULL
     296    {0xc, 0x279}, //NULL
     297    {0x7, 0x68}, //"F13"
     298    {0x7, 0x69}, //"F14"
     299    {0x7, 0x6a}, //"F15"
     300    {0x7, 0x6b}, //"F16"
     301    {0x7, 0x6c}, //"F17"
     302    {0x7, 0x6d}, //"F18"
     303    {0x7, 0x6e}, //"F19"
     304    {0x7, 0x6f}, //"F20"
     305    {0x7, 0x70}, //"F21"
     306    {0x7, 0x71}, //"F22"
     307    {0x7, 0x72}, //"F23"
     308    {0x7, 0x73}, //"F24"
     309    {0x0, 0x0}, //NULL
     310    {0x0, 0x0}, //NULL
     311    {0x0, 0x0}, //NULL
     312    {0x0, 0x0}, //NULL
     313    {0x0, 0x0}, //NULL
     314    {0x0, 0x0}, //NULL
     315    {0xc, 0xb1}, //"MediaPause"
     316    {0x0, 0x0}, //NULL
     317    {0x0, 0x0}, //NULL
     318    {0xc, 0x2a2}, //NULL
     319    {0x0, 0x0}, //NULL
     320    {0xc, 0x203}, //NULL
     321    {0xc, 0xb0}, //"MediaPlay"
     322    {0xc, 0xb3}, //"MediaFastForward"
     323    {0xc, 0xe5}, //NULL
     324    {0xc, 0x208}, //NULL
     325    {0x0, 0x0}, //NULL
     326    {0x0, 0x0}, //NULL
     327    {0x0, 0x0}, //NULL
     328    {0x0, 0x0}, //NULL
     329    {0x0, 0x0}, //NULL
     330    {0x0, 0x0}, //NULL
     331    {0xc, 0x221}, //"BrowserSearch"
     332    {0x0, 0x0}, //NULL
     333    {0x0, 0x0}, //NULL
     334    {0x0, 0x0}, //NULL
     335    {0x0, 0x0}, //NULL
     336    {0x0, 0x0}, //NULL
     337    {0x0, 0x0}, //NULL
     338    {0xc, 0x70}, //"BrightnessDown"
     339    {0xc, 0x6f}, //"BrightnessUp"
     340    {0x0, 0x0}, //NULL
     341    {0x0, 0x0}, //NULL
     342    {0xc, 0x7c}, //NULL
     343    {0xc, 0x7a}, //NULL
     344    {0xc, 0x79}, //NULL
     345    {0xc, 0x28c}, //"MailSend"
     346    {0xc, 0x289}, //"MailReply"
     347    {0xc, 0x28b}, //"MailForward"
     348    {0xc, 0x207}, //NULL
     349    {0xc, 0x1a7}, //NULL
     350    {0x0, 0x0}, //NULL
     351    {0x0, 0x0}, //NULL
     352    {0x0, 0x0}, //NULL
     353    {0x0, 0x0}, //NULL
     354    {0x0, 0x0}, //NULL
     355    {0x0, 0x0}, //NULL
     356    {0x0, 0x0}, //NULL
     357    {0x0, 0x0}, //NULL
     358    {0xc, 0x75}, //NULL
     359    {0x0, 0x0}, //NULL
     360    {0x0, 0x0}, //NULL
     361    {0x0, 0x0}, //NULL
     362    {0x0, 0x0}, //NULL
     363    {0x0, 0x0}, //NULL
     364    {0x0, 0x0}, //NULL
     365    {0x0, 0x0}, //NULL
     366    {0x0, 0x0}, //NULL
     367    {0x0, 0x0}, //NULL
     368    {0x0, 0x0}, //NULL
     369};
    110370
    111371/* Factory function to create keyboard-handler: */
     
    20112271
    20122272#ifdef VBOX_WS_NIX
    2013 void UIKeyboardHandler::handleKeyEvent(quint32 nativeScanCode, bool fRelease)
    2014 {
     2273void UIKeyboardHandler::handleKeyEvent(quint32 uEvDevCode, bool fRelease)
     2274{
     2275
     2276    // printf("UIKeyboardHandler::handleKeyEvent %u %u\n", nativeScanCode, nativeScanCode >> 0xE0);
    20152277    if (NativeWindowSubsystem::displayServerType() == VBGHDISPLAYSERVERTYPE_PURE_WAYLAND)
    20162278    {
    2017         /* On Linux xcb, wayland etc has an offset of 8 in scancodes (they start from 7 instead of 0): */
    2018         if (!fRelease)
    2019             uimachine()->putScancode(nativeScanCode - 8);
    2020         else
    2021             uimachine()->putScancode((nativeScanCode - 8) | 0x80);
     2279        AssertMsgReturnVoid(uEvDevCode < CODE_ARRAY_LENGTH, ("Received evdev code is not in conversation table"));
     2280        uimachine()->putUsageCode(evcode_hid[uEvDevCode][1], evcode_hid[uEvDevCode][0], fRelease);
     2281        //m_pMachine->putUsageCode(sequence[i].first, sequence[i].second, false);
     2282    //     /* On Linux xcb, wayland etc has an offset of 8 in scancodes (they start from 7 instead of 0): */
     2283    //     if (!fRelease)
     2284    //         uimachine()->putScancode(nativeScanCode - 8);
     2285    //     else
     2286    //         uimachine()->putScancode((nativeScanCode - 8) | 0x80);
    20222287    }
    20232288}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h

    r106611 r107153  
    122122
    123123#ifdef VBOX_WS_NIX
    124     void handleKeyEvent(quint32 nativeScanCode, bool fRelease);
     124    void handleKeyEvent(quint32 uEvDevCode, bool fRelease);
    125125#endif
    126126
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r106611 r107153  
    9696#  include <xcb/xcb.h>
    9797#endif
     98
     99#include <xkbcommon/xkbcommon.h>
    98100
    99101#ifdef DEBUG_andy
     
    20212023void UIMachineView::keyPressEvent(QKeyEvent *pEvent)
    20222024{
    2023     machineLogic()->keyboardHandler()->handleKeyEvent(pEvent->nativeScanCode(), false /* is release*/);
     2025    /* It looks like that QKeyEvent::nativeScanCode returns evdev codes with an offset of 8: */
     2026    quint32 uEvDevCode = pEvent->nativeScanCode() - 8;
     2027    machineLogic()->keyboardHandler()->handleKeyEvent(uEvDevCode, false /* is release*/);
    20242028    QAbstractScrollArea::keyPressEvent(pEvent);
    20252029}
     
    20272031void UIMachineView::keyReleaseEvent(QKeyEvent *pEvent)
    20282032{
    2029     machineLogic()->keyboardHandler()->handleKeyEvent(pEvent->nativeScanCode(), true /* is release*/);
     2033    /* It looks like that QKeyEvent::nativeScanCode returns evdev codes with an offset of 8: */
     2034    quint32 uEvDevCode = pEvent->nativeScanCode() - 8;
     2035    machineLogic()->keyboardHandler()->handleKeyEvent(uEvDevCode, true /* is release*/);
    20302036    QAbstractScrollArea::keyReleaseEvent(pEvent);
    20312037}
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