VirtualBox

Changeset 6674 in vbox


Ignore:
Timestamp:
Jan 31, 2008 7:23:08 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27747
Message:

FE/Qt: OS/2: Let key events reach Qt when the keyboard is not captured (e.g. a Close dialog is shown); provide special hot keys (Host+`, Host+1, Host+2) for system combinations (Ctrl+Esc, Alt+Tab, Alt+Shift+Tab).

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

Legend:

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

    r6467 r6674  
    3434#if defined (Q_WS_PM)
    3535#include "src/os2/VBoxHlp.h"
     36#define UM_PREACCEL_CHAR WM_USER
    3637#endif
    3738
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r6649 r6674  
    9696#if defined (Q_WS_WIN32)
    9797
    98 static HHOOK g_kbdhook = NULL;
    99 static VBoxConsoleView *g_view = 0;
     98static HHOOK gKbdHook = NULL;
     99static VBoxConsoleView *gView = 0;
    100100
    101101LRESULT CALLBACK VBoxConsoleView::lowLevelKeyboardProc (int nCode,
    102102                                                        WPARAM wParam, LPARAM lParam)
    103103{
    104     Assert (g_view);
    105     if (g_view && nCode == HC_ACTION &&
    106             g_view->winLowKeyboardEvent (wParam, *(KBDLLHOOKSTRUCT *) lParam))
     104    Assert (gView);
     105    if (gView && nCode == HC_ACTION &&
     106            gView->winLowKeyboardEvent (wParam, *(KBDLLHOOKSTRUCT *) lParam))
    107107        return 1;
    108108
     
    753753
    754754#if defined (Q_WS_WIN)
    755     g_view = this;
     755    gView = this;
    756756#endif
    757757
    758758#if defined (Q_WS_PM)
    759     bool ok = VBoxHlpInstallKbdHook (0, winId(), WM_CHAR);
     759    bool ok = VBoxHlpInstallKbdHook (0, winId(), UM_PREACCEL_CHAR);
    760760    Assert (ok);
    761761    NOREF (ok);
     
    770770{
    771771#if defined (Q_WS_PM)
    772     bool ok = VBoxHlpUninstallKbdHook (0, winId(), WM_CHAR);
     772    bool ok = VBoxHlpUninstallKbdHook (0, winId(), UM_PREACCEL_CHAR);
    773773    Assert (ok);
    774774    NOREF (ok);
     
    776776
    777777#if defined (Q_WS_WIN)
    778     if (g_kbdhook)
    779         UnhookWindowsHookEx (g_kbdhook);
    780     g_view = 0;
     778    if (gKbdHook)
     779        UnhookWindowsHookEx (gKbdHook);
     780    gView = 0;
    781781    if (mAlphaCursor)
    782782        DestroyIcon (mAlphaCursor);
     
    12691269
    12701270            case QEvent::KeyPress:
    1271             {
     1271#ifdef Q_WS_PM
     1272            case QEvent::KeyRelease:
     1273            {
     1274                /// @todo temporary solution to send Alt+Tab and friends to
     1275                //  the guest. The proper solution is to write a keyboard
     1276                //  driver that will steal these combos from the host (it's
     1277                //  impossible to do so using hooks on OS/2).
     1278
    12721279                QKeyEvent *ke = (QKeyEvent *) e;
     1280                if (mIsHostkeyPressed)
     1281                {
     1282                    bool pressed = e->type() == QEvent::KeyPress;
     1283                    CKeyboard keyboard = mConsole.GetKeyboard();
     1284
     1285                    /* whether the host key is Shift so that it will modify
     1286                     * the hot key values? Note that we don't distinguish
     1287                     * between left and right shift here (too much hassle) */
     1288                    const bool kShift = (gs.hostKey() == VK_SHIFT ||
     1289                                        gs.hostKey() == VK_LSHIFT) &&
     1290                                        (ke->state() & ShiftButton);
     1291                    /* define hot keys according to the Shift state */
     1292                    const int kAltTab      = kShift ? Key_Exclam     : Key_1;
     1293                    const int kAltShiftTab = kShift ? Key_At         : Key_2;
     1294                    const int kCtrlEsc     = kShift ? Key_AsciiTilde : Key_QuoteLeft;
     1295
     1296                    /* Simulate Alt+Tab on Host+1 and Alt+Shift+Tab on Host+2 */
     1297                    if (ke->key() == kAltTab || ke->key() == kAltShiftTab)
     1298                    {
     1299                        if (pressed)
     1300                        {
     1301                            /* Send the Alt press to the guest */
     1302                            if (!(mPressedKeysCopy [0x38] & IsKeyPressed))
     1303                            {
     1304                                /* store the press in *Copy to have it automatically
     1305                                 * released when the Host key is released */
     1306                                mPressedKeysCopy [0x38] |= IsKeyPressed;
     1307                                keyboard.PutScancode (0x38);
     1308                            }
     1309
     1310                            /* Make sure Shift is pressed if it's Key_2 and released
     1311                             * if it's Key_1 */
     1312                            if (ke->key() == kAltTab &&
     1313                                (mPressedKeysCopy [0x2A] & IsKeyPressed))
     1314                            {
     1315                                mPressedKeysCopy [0x2A] &= ~IsKeyPressed;
     1316                                keyboard.PutScancode (0xAA);
     1317                            }
     1318                            else
     1319                            if (ke->key() == kAltShiftTab &&
     1320                                !(mPressedKeysCopy [0x2A] & IsKeyPressed))
     1321                            {
     1322                                mPressedKeysCopy [0x2A] |= IsKeyPressed;
     1323                                keyboard.PutScancode (0x2A);
     1324                            }
     1325                        }
     1326
     1327                        keyboard.PutScancode (pressed ? 0x0F : 0x8F);
     1328
     1329                        ke->accept();
     1330                        return true;
     1331                    }
     1332
     1333                    /* Simulate Ctrl+Esc on Host+Tilde */
     1334                    if (ke->key() == kCtrlEsc)
     1335                    {
     1336                        /* Send the Ctrl press to the guest */
     1337                        if (pressed && !(mPressedKeysCopy [0x1d] & IsKeyPressed))
     1338                        {
     1339                            /* store the press in *Copy to have it automatically
     1340                             * released when the Host key is released */
     1341                            mPressedKeysCopy [0x1d] |= IsKeyPressed;
     1342                            keyboard.PutScancode (0x1d);
     1343                        }
     1344
     1345                        keyboard.PutScancode (pressed ? 0x01 : 0x81);
     1346
     1347                        ke->accept();
     1348                        return true;
     1349                    }
     1350                }
     1351                if (e->type() == QEvent::KeyRelease)
     1352                    break;
     1353
     1354                /* fall through for normal processing of KeyPress */
     1355#else
     1356            {
     1357                QKeyEvent *ke = (QKeyEvent *) e;
     1358#endif
    12731359                if (mIsHostkeyPressed)
    12741360                {
     
    12951381
    12961382                        CKeyboard keyboard = mConsole.GetKeyboard();
    1297                         Assert (!keyboard.isNull());
    12981383                        keyboard.PutScancodes (combo, 6);
    12991384                    }
     
    14161501            case QEvent::WindowActivate:
    14171502            {
    1418                 g_kbdhook = SetWindowsHookEx (WH_KEYBOARD_LL, lowLevelKeyboardProc,
     1503                gKbdHook = SetWindowsHookEx (WH_KEYBOARD_LL, lowLevelKeyboardProc,
    14191504                                              GetModuleHandle (NULL), 0);
    1420                 AssertMsg (g_kbdhook, ("SetWindowsHookEx(): err=%d", GetLastError()));
     1505                AssertMsg (gKbdHook, ("SetWindowsHookEx(): err=%d", GetLastError()));
    14211506                break;
    14221507            }
    14231508            case QEvent::WindowDeactivate:
    14241509            {
    1425                 if (g_kbdhook)
     1510                if (gKbdHook)
    14261511                {
    1427                     UnhookWindowsHookEx (g_kbdhook);
    1428                     g_kbdhook = NULL;
     1512                    UnhookWindowsHookEx (gKbdHook);
     1513                    gKbdHook = NULL;
    14291514                }
    14301515                break;
     
    15591644
    15601645    /* check for the special flag possibly set at the end of this function */
    1561     if ((msg->lParam >> 25) & 0x1)
     1646    if (msg->lParam & (0x1 << 25))
     1647    {
     1648        msg->lParam &= ~(0x1 << 25);
    15621649        return false;
     1650    }
    15631651
    15641652#if 0
     
    16611749bool VBoxConsoleView::pmEvent (QMSG *aMsg)
    16621750{
    1663     if (!mAttached || aMsg->msg != WM_CHAR)
     1751    if (!mAttached)
     1752        return false;
     1753
     1754    if (aMsg->msg == UM_PREACCEL_CHAR)
     1755    {
     1756        /* we are inside the input hook */
     1757
     1758        /* let the message go through the normal system pipeline */
     1759        if (!mKbdCaptured)
     1760            return false;
     1761    }
     1762
     1763    if (aMsg->msg != WM_CHAR &&
     1764        aMsg->msg != UM_PREACCEL_CHAR)
    16641765        return false;
    16651766
    16661767    /* check for the special flag possibly set at the end of this function */
    16671768    if (SHORT2FROMMP (aMsg->mp2) & 0x8000)
     1769    {
     1770        aMsg->mp2 = MPFROM2SHORT (SHORT1FROMMP (aMsg->mp2),
     1771                                  SHORT2FROMMP (aMsg->mp2) & ~0x8000);
    16681772        return false;
     1773    }
    16691774
    16701775#if 0
    16711776    {
    16721777        char buf [256];
    1673         sprintf (buf, "*** WM_CHAR: f=%04X rep=%03d scan=%02X ch=%04X vk=%04X",
     1778        sprintf (buf, "*** %s: f=%04X rep=%03d scan=%02X ch=%04X vk=%04X",
     1779                 (aMsg->msg == WM_CHAR ? "WM_CHAR" : "UM_PREACCEL_CHAR"),
    16741780                 SHORT1FROMMP (aMsg->mp1), CHAR3FROMMP (aMsg->mp1),
    16751781                 CHAR4FROMMP (aMsg->mp1), SHORT1FROMMP (aMsg->mp2),
     
    17421848         * shortcuts for example). So send it direcltly to the window with the
    17431849         * special flag in the reserved area of lParam (to avoid recursion). */
    1744         ::WinSendMsg (aMsg->hwnd, aMsg->msg,
     1850        ::WinSendMsg (aMsg->hwnd, WM_CHAR,
    17451851                      aMsg->mp1,
    17461852                      MPFROM2SHORT (SHORT1FROMMP (aMsg->mp2),
     
    23492455        emitKeyboardStateChanged();
    23502456
    2351     /* process HOST+<key> shortcuts. currently, <key> is limited to
    2352      * alphanumeric chars. */
     2457    /* Process Host+<key> shortcuts. currently, <key> is limited to
     2458     * alphanumeric chars. Other Host+<key> combinations are handled in
     2459     * event(). */
    23532460    if (hotkey)
    23542461    {
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