VirtualBox

Changeset 649 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Feb 5, 2007 7:23:22 PM (18 years ago)
Author:
vboxsync
Message:

FE/Qt: Attempted to workaround the metacity 2.16 bug by using XGrabKey on Linux instead of XGrabKeyboard (used by QWidget::grabKeyboard()).

File:
1 edited

Legend:

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

    r648 r649  
    10261026bool VBoxConsoleView::winLowKeyboardEvent (UINT msg, const KBDLLHOOKSTRUCT &event)
    10271027{
    1028 //    Log (("### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X (kbd_captured=%d)\n",
    1029 //              event.vkCode, event.scanCode, event.flags, event.dwExtraInfo, kbd_captured));
    1030 //    char buf[256];
    1031 //    sprintf (buf,
    1032 //               "### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X",
    1033 //             event.vkCode, event.scanCode, event.flags, event.dwExtraInfo);
    1034 //    ((QMainWindow*)mainwnd)->statusBar()->message (buf);
    1035 
    1036     // Sometimes it happens that Win inserts additional events on some key
    1037     // press/release. For example, it prepends ALT_GR in German layout with
    1038     // the VK_LCONTROL vkey with curious 0x21D scan code (seems to be necessary
    1039     // to specially treat ALT_GR to enter additional chars to regular apps).
    1040     // These events are definitely unwanted in VM, so filter them out.
     1028#if 0
     1029    LogFlow (("### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X (kbd_captured=%d)\n",
     1030              event.vkCode, event.scanCode, event.flags, event.dwExtraInfo, kbd_captured));
     1031    char buf [256];
     1032    sprintf (buf, "### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X",
     1033             event.vkCode, event.scanCode, event.flags, event.dwExtraInfo);
     1034    mainwnd->statusBar()->message (buf);
     1035#endif
     1036
     1037    /* Sometimes it happens that Win inserts additional events on some key
     1038     * press/release. For example, it prepends ALT_GR in German layout with
     1039     * the VK_LCONTROL vkey with curious 0x21D scan code (seems to be necessary
     1040     * to specially treat ALT_GR to enter additional chars to regular apps).
     1041     * These events are definitely unwanted in VM, so filter them out. */
    10411042    if (hasFocus() && (event.scanCode & ~0xFF))
    10421043        return true;
     
    10451046        return false;
    10461047
    1047     // it's possible that a key has been pressed while the keyboard was not
    1048     // captured, but is being released under the capture. Detect this situation
    1049     // and return false to let Windows process the message normally and update
    1050     // its key state table (to avoid the stuck key effect).
     1048    /* it's possible that a key has been pressed while the keyboard was not
     1049     * captured, but is being released under the capture. Detect this situation
     1050     * and return false to let Windows process the message normally and update
     1051     * its key state table (to avoid the stuck key effect). */
    10511052    uint8_t what_pressed = (event.flags & 0x01) && (event.vkCode != VK_RSHIFT)
    10521053                           ? IsExtKeyPressed
     
    10661067        (event.flags & 0xFF) << 24;
    10671068
    1068     // Windows sets here the extended bit when the Right Shift key is pressed,
    1069     // which is totally wrong. Undo it.
     1069    /* Windows sets here the extended bit when the Right Shift key is pressed,
     1070     * which is totally wrong. Undo it. */
    10701071    if (event.vkCode == VK_RSHIFT)
    10711072        message.lParam &= ~0x1000000;
    10721073
    1073     // we suppose here that this hook is always called on the main GUI thread
     1074    /* we suppose here that this hook is always called on the main GUI thread */
    10741075    return winEvent (&message);
    10751076}
     
    10881089        return false;
    10891090
    1090     // check for the special flag possibly set at the end of this function
     1091    /* check for the special flag possibly set at the end of this function */
    10911092    if ((msg->lParam >> 25) & 0x1)
    10921093        return false;
    10931094
    1094 //    V_DEBUG((
    1095 //        "*** WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
    1096 //        msg->message, msg->wParam,
    1097 //        (msg->lParam & 0xFFFF),
    1098 //        ((msg->lParam >> 16) & 0xFF),
    1099 //        ((msg->lParam >> 24) & 0x1),
    1100 //        ((msg->lParam >> 25) & 0xF),
    1101 //        ((msg->lParam >> 29) & 0x1),
    1102 //        ((msg->lParam >> 30) & 0x1),
    1103 //        ((msg->lParam >> 31) & 0x1)
    1104 //    ));
    1105 //    char buf[256];
    1106 //    sprintf (buf,
    1107 //             "WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
    1108 //             msg->message, msg->wParam,
    1109 //             (msg->lParam & 0xFFFF),
    1110 //             ((msg->lParam >> 16) & 0xFF),
    1111 //             ((msg->lParam >> 24) & 0x1),
    1112 //             ((msg->lParam >> 25) & 0xF),
    1113 //             ((msg->lParam >> 29) & 0x1),
    1114 //             ((msg->lParam >> 30) & 0x1),
    1115 //             ((msg->lParam >> 31) & 0x1));
    1116 //    ((QMainWindow*)mainwnd)->statusBar()->message (buf);
     1095#if 0
     1096    LogFlow (("*** WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
     1097              msg->message, msg->wParam,
     1098              (msg->lParam & 0xFFFF),
     1099              ((msg->lParam >> 16) & 0xFF),
     1100              ((msg->lParam >> 24) & 0x1),
     1101              ((msg->lParam >> 25) & 0xF),
     1102              ((msg->lParam >> 29) & 0x1),
     1103              ((msg->lParam >> 30) & 0x1),
     1104              ((msg->lParam >> 31) & 0x1)));
     1105    char buf [256];
     1106    sprintf (buf, "WM_%04X: vk=%04X rep=%05d scan=%02X ext=%01d rzv=%01X ctx=%01d prev=%01d tran=%01d",
     1107             msg->message, msg->wParam,
     1108             (msg->lParam & 0xFFFF),
     1109             ((msg->lParam >> 16) & 0xFF),
     1110             ((msg->lParam >> 24) & 0x1),
     1111             ((msg->lParam >> 25) & 0xF),
     1112             ((msg->lParam >> 29) & 0x1),
     1113             ((msg->lParam >> 30) & 0x1),
     1114             ((msg->lParam >> 31) & 0x1));
     1115    mainwnd->statusBar()->message (buf);
     1116#endif
    11171117
    11181118    int scan = (msg->lParam >> 16) & 0x7F;
    1119     // scancodes 0x80 and 0x00 are ignored
     1119    /* scancodes 0x80 and 0x00 are ignored */
    11201120    if (!scan)
    11211121        return true;
     
    11231123    int vkey = msg->wParam;
    11241124
    1125     // When one of the SHIFT keys is held and one of the cursor movement
    1126     // keys is pressed, Windows duplicates SHIFT press/release messages,
    1127     // but with the virtual key code set to 0xFF. These virtual keys are also
    1128     // sent in some other situations (Pause, PrtScn, etc.). Ignore such messages.
     1125    /* When one of the SHIFT keys is held and one of the cursor movement
     1126     * keys is pressed, Windows duplicates SHIFT press/release messages,
     1127     * but with the virtual key code set to 0xFF. These virtual keys are also
     1128     * sent in some other situations (Pause, PrtScn, etc.). Ignore such
     1129     * messages. */
    11291130    if (vkey == 0xFF)
    11301131        return true;
     
    11421143        case VK_MENU:
    11431144        {
    1144             // overcome stupid Win32 modifier key generalization
     1145            /* overcome stupid Win32 modifier key generalization */
    11451146            int keyscan = scan;
    11461147            if (flags & KeyExtended)
     
    11581159        }
    11591160        case VK_NUMLOCK:
    1160             // Win32 sets the extended bit for the NumLock key. Reset it.
     1161            /* Win32 sets the extended bit for the NumLock key. Reset it. */
    11611162            flags &= ~KeyExtended;
    11621163            break;
     
    11721173    if (!result && kbd_captured)
    11731174    {
    1174         // keyEvent() returned that it didn't process the message, but since the
    1175         // keyboard is captured, we don't want to pass it to Windows. We just want
    1176         // to let Qt process the message (to handle non-alphanumeric <HOST>+key
    1177         // shortcuts for example). So send it direcltly to the window with the
    1178         // special flag in the reserved area of lParam (to avoid recursion).
     1175        /* keyEvent() returned that it didn't process the message, but since the
     1176         * keyboard is captured, we don't want to pass it to Windows. We just want
     1177         * to let Qt process the message (to handle non-alphanumeric <HOST>+key
     1178         * shortcuts for example). So send it direcltly to the window with the
     1179         * special flag in the reserved area of lParam (to avoid recursion). */
    11791180        ::SendMessage (msg->hwnd, msg->message,
    11801181                       msg->wParam, msg->lParam | (0x1 << 25));
     
    11871188
    11881189/**
    1189  * This routine gets X11 events before they are processed by Qt. This is
    1190  * used for our platform specific keyboard implementation. A return value
    1191  * of TRUE indicates that the event has been processed by us.
     1190 *  This routine gets X11 events before they are processed by Qt. This is
     1191 *  used for our platform specific keyboard implementation. A return value
     1192 *  of TRUE indicates that the event has been processed by us.
    11921193 */
    1193 bool VBoxConsoleView::x11Event(XEvent *event)
     1194bool VBoxConsoleView::x11Event (XEvent *event)
    11941195{
    11951196    static WINEKEYBOARDINFO wineKeyboardInfo;
     
    12011202            if (attached)
    12021203                break;
    1203             // else fall through
     1204            /*  else fall through */
    12041205        /// @todo (AH) later, we might want to handle these as well
    12051206        case KeymapNotify:
    12061207        case MappingNotify:
    12071208        default:
    1208             return false;  // pass the event to Qt
    1209     }
    1210 
    1211     // perform the mega-complex translation using the wine algorithms
     1209            return false; /* pass the event to Qt */
     1210    }
     1211
     1212    /* perform the mega-complex translation using the wine algorithms */
    12121213    handleXKeyEvent (this->x11Display(), event, &wineKeyboardInfo);
    12131214
    1214 //    char buf[256];
    1215 //    sprintf (buf,
    1216 //             "pressed=%d keycode=%08X state=%08X flags=%08X scan=%04X",
    1217 //             event->type == XKeyPress ? 1 : 0, event->xkey.keycode,
    1218 //             event->xkey.state, wineKeyboardInfo.dwFlags, wineKeyboardInfo.wScan);
    1219 //    ((QMainWindow*)mainwnd)->statusBar()->message (buf);
     1215#if 0
     1216    char buf [256];
     1217    sprintf (buf, "pr=%d kc=%08X st=%08X fl=%08lX scan=%04X",
     1218             event->type == XKeyPress ? 1 : 0, event->xkey.keycode,
     1219             event->xkey.state, wineKeyboardInfo.dwFlags, wineKeyboardInfo.wScan);
     1220    mainwnd->statusBar()->message (buf);
     1221    LogFlow (("### %s\n", buf));
     1222#endif
    12201223
    12211224    int scan = wineKeyboardInfo.wScan & 0x7F;
     
    19221925        return;
    19231926
    1924     // on Win32, keyboard grabbing is ineffective,
    1925     // low-level keyboard hook is used instead
    1926 #ifndef Q_WS_WIN32
     1927    /* On Win32, keyboard grabbing is ineffective, a low-level keyboard hook is
     1928     * used instead. On X11, we use XGrabKey instead of XGrabKeyboard (called
     1929     * by QWidget::grabKeyboard()) because the latter causes problems under
     1930     * metacity 2.16 (in particular, due to a bug, a window cannot be moved
     1931     * using the mouse if it is currently grabing the keyboard). */
     1932#if defined (Q_WS_WIN32)
     1933    /**/
     1934#elif defined (Q_WS_X11)
     1935        if (capture)
     1936                XGrabKey (x11Display(), AnyKey, AnyModifier,
     1937                  topLevelWidget()->winId(), False,
     1938                  GrabModeAsync, GrabModeAsync);
     1939        else
     1940                XUngrabKey (x11Display(),  AnyKey, AnyModifier,
     1941                    topLevelWidget()->winId());
     1942#else
    19271943    if (capture)
    19281944        grabKeyboard();
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