VirtualBox

Ignore:
Timestamp:
Dec 25, 2007 5:42:01 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
26954
Message:

FE/Qt: Made C-A-D pressed while the VM is in focus and running act as a last resort and ungrab the keyboard and mouse if the user accidentially forgets the host key and can't see it on the statusbar.

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

Legend:

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

    r5999 r6184  
    8181    void setMouseIntegrationEnabled (bool enabled);
    8282
    83     bool isMouseAbsolute() const { return mouse_absolute; }
     83    bool isMouseAbsolute() const { return mMouseAbsolute; }
    8484
    8585    void setAutoresizeGuest (bool on);
     
    146146    {
    147147        emit keyboardStateChanged (
    148             (kbd_captured ? KeyboardCaptured : 0) |
     148            (mKbdCaptured ? KeyboardCaptured : 0) |
    149149            (mIsHostkeyPressed ? HostKeyPressed : 0));
    150150    }
    151151
    152152    void emitMouseStateChanged() {
    153         emit mouseStateChanged ((mouse_captured ? MouseCaptured : 0) |
    154                                 (mouse_absolute ? MouseAbsolute : 0) |
    155                                 (!mouse_integration ? MouseAbsoluteDisabled : 0));
     153        emit mouseStateChanged ((mMouseCaptured ? MouseCaptured : 0) |
     154                                (mMouseAbsolute ? MouseAbsolute : 0) |
     155                                (!mMouseIntegration ? MouseAbsoluteDisabled : 0));
    156156    }
    157157
     
    166166#endif
    167167
    168     void captureKbd (bool capture, bool emit_signal = true);
    169     void captureMouse (bool capture, bool emit_signal = true);
     168    void captureKbd (bool aCapture, bool aEmitSignal = true);
     169    void captureMouse (bool aCapture, bool aEmitSignal = true);
    170170
    171171    bool processHotKey (const QKeySequence &key, QMenuData *data);
     
    179179    void setPointerShape (MousePointerChangeEvent *me);
    180180
    181     bool isPaused() { return last_state == CEnums::Paused; }
    182     bool isRunning() { return last_state == CEnums::Running; }
     181    bool isPaused() { return mLastState == CEnums::Paused; }
     182    bool isRunning() { return mLastState == CEnums::Running; }
    183183
    184184    static void dimImage (QImage &img);
     
    198198    const VBoxGlobalSettings &gs;
    199199
    200     CEnums::MachineState last_state;
    201 
    202     bool attached : 1;
    203     bool kbd_captured : 1;
    204     bool mouse_captured : 1;
    205     bool mouse_absolute : 1;
    206     bool mouse_integration : 1;
    207     QPoint last_pos;
    208     QPoint captured_pos;
     200    CEnums::MachineState mLastState;
     201
     202    bool mAttached : 1;
     203    bool mKbdCaptured : 1;
     204    bool mMouseCaptured : 1;
     205    bool mMouseAbsolute : 1;
     206    bool mMouseIntegration : 1;
     207    QPoint mLastPos;
     208    QPoint mCapturedPos;
    209209
    210210        bool mDisableAutoCapture : 1;
     
    217217    bool mIsHostkeyAlone : 1;
    218218
    219     /** kbd_captured value during the the last host key press or release */
     219    /** mKbdCaptured value during the the last host key press or release */
    220220    bool hostkey_in_capture : 1;
    221221
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp

    r6059 r6184  
    137137    else if (EventClass == kEventClassCommand)
    138138    {
    139         if (view->kbd_captured)
     139        if (view->mKbdCaptured)
    140140            return 0;
    141141    }
     
    599599    , mConsole (console)
    600600    , gs (vboxGlobal().settings())
    601     , attached (false)
    602     , kbd_captured (false)
    603     , mouse_captured (false)
    604     , mouse_absolute (false)
    605     , mouse_integration (true)
     601    , mAttached (false)
     602    , mKbdCaptured (false)
     603    , mMouseCaptured (false)
     604    , mMouseAbsolute (false)
     605    , mMouseIntegration (true)
    606606    , mDisableAutoCapture (false)
    607607    , mIsHostkeyPressed (false)
     
    814814void VBoxConsoleView::attach()
    815815{
    816     if (!attached)
    817     {
    818         attached = true;
     816    if (!mAttached)
     817    {
     818        mAttached = true;
    819819    }
    820820}
     
    833833void VBoxConsoleView::detach()
    834834{
    835     if (attached)
     835    if (mAttached)
    836836    {
    837837        /* reuse the focus event handler to uncapture everything */
    838838        focusEvent (false);
    839         attached = false;
     839        mAttached = false;
    840840    }
    841841}
     
    922922void VBoxConsoleView::setMouseIntegrationEnabled (bool enabled)
    923923{
    924     if (mouse_integration == enabled)
     924    if (mMouseIntegration == enabled)
    925925        return;
    926926
    927     if (mouse_absolute)
     927    if (mMouseAbsolute)
    928928        captureMouse (!enabled, false);
    929929
     
    945945        viewport()->setCursor (QCursor (BlankCursor));
    946946
    947     mouse_integration = enabled;
     947    mMouseIntegration = enabled;
    948948
    949949    emitMouseStateChanged();
     
    991991bool VBoxConsoleView::event (QEvent *e)
    992992{
    993     if (attached)
     993    if (mAttached)
    994994    {
    995995        switch (e->type())
     
    10371037                 * So it is necessary to perform updateMouseClipping() for
    10381038                 * the guest resize event if the mouse cursor was captured. */
    1039                 if (mouse_captured)
     1039                if (mMouseCaptured)
    10401040                    updateMouseClipping();
    10411041
     
    11011101                 * supported (change mouse shape type event may arrive after
    11021102                 * mouse capability change that disables integration */
    1103                 if (mouse_absolute)
     1103                if (mMouseAbsolute)
    11041104                    setPointerShape (me);
    11051105                return true;
     
    11081108            {
    11091109                MouseCapabilityEvent *me = (MouseCapabilityEvent *) e;
    1110                 if (mouse_absolute != me->supportsAbsolute())
     1110                if (mMouseAbsolute != me->supportsAbsolute())
    11111111                {
    1112                     mouse_absolute = me->supportsAbsolute();
     1112                    mMouseAbsolute = me->supportsAbsolute();
    11131113                    /* correct the mouse capture state and reset the cursor
    11141114                     * to the default shape if necessary */
    1115                     if (mouse_absolute)
     1115                    if (mMouseAbsolute)
    11161116                    {
    11171117                        CMouse mouse = mConsole.GetMouse();
     
    11221122                        viewport()->unsetCursor();
    11231123                    emitMouseStateChanged();
    1124                     vboxProblem().remindAboutMouseIntegration (mouse_absolute);
     1124                    vboxProblem().remindAboutMouseIntegration (mMouseAbsolute);
    11251125                }
    11261126                if (me->needsHostCursor())
     
    12811281                        /* activate the main menu */
    12821282                        if (mMainWnd->isTrueSeamless() || mMainWnd->isTrueFullscreen())
    1283                             mMainWnd->popupMainMenu (mouse_captured);
     1283                            mMainWnd->popupMainMenu (mMouseCaptured);
    12841284                        else
    12851285                            mMainWnd->menuBar()->setFocus();
     
    13361336bool VBoxConsoleView::eventFilter (QObject *watched, QEvent *e)
    13371337{
    1338     if (attached && watched == viewport())
     1338    if (mAttached && watched == viewport())
    13391339    {
    13401340        switch (e->type())
     
    13631363            case QEvent::Resize:
    13641364            {
    1365                 if (mouse_captured)
     1365                if (mMouseCaptured)
    13661366                    updateMouseClipping();
    13671367            }
     
    14751475{
    14761476#if 0
    1477     LogFlow (("### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X (kbd_captured=%d)\n",
    1478               event.vkCode, event.scanCode, event.flags, event.dwExtraInfo, kbd_captured));
     1477    LogFlow (("### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X (mKbdCaptured=%d)\n",
     1478              event.vkCode, event.scanCode, event.flags, event.dwExtraInfo, mKbdCaptured));
    14791479    char buf [256];
    14801480    sprintf (buf, "### vkCode=%08X, scanCode=%08X, flags=%08X, dwExtraInfo=%08X",
     
    14911491        return true;
    14921492
    1493     if (!kbd_captured)
     1493    if (!mKbdCaptured)
    14941494        return false;
    14951495
     
    15311531bool VBoxConsoleView::winEvent (MSG *msg)
    15321532{
    1533     if (!attached || ! (
     1533    if (!mAttached || ! (
    15341534        msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
    15351535        msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP
     
    16111611
    16121612    bool result = keyEvent (vkey, scan, flags);
    1613     if (!result && kbd_captured)
     1613    if (!result && mKbdCaptured)
    16141614    {
    16151615        /* keyEvent() returned that it didn't process the message, but since the
     
    16401640bool VBoxConsoleView::pmEvent (QMSG *aMsg)
    16411641{
    1642     if (!attached || aMsg->msg != WM_CHAR)
     1642    if (!mAttached || aMsg->msg != WM_CHAR)
    16431643        return false;
    16441644
     
    17141714
    17151715    bool result = keyEvent (vkey, scan, flags);
    1716     if (!result && kbd_captured)
     1716    if (!result && mKbdCaptured)
    17171717    {
    17181718        /* keyEvent() returned that it didn't process the message, but since the
     
    17451745        case XKeyPress:
    17461746        case XKeyRelease:
    1747             if (attached)
     1747            if (mAttached)
    17481748                break;
    17491749            /*  else fall through */
     
    19821982//      released after we got focus, and grab the mouse only after then.
    19831983//      btw, the similar would be good the for keyboard auto-capture, too.
    1984 //            if (!(mouse_absolute && mouse_integration))
     1984//            if (!(mMouseAbsolute && mMouseIntegration))
    19851985//                captureMouse (true);
    19861986        }
     
    21022102 *  Called on every key press and release (while in focus).
    21032103 *
    2104  *  @key        virtual scan code (virtual key on Win32 and KeySym on X11)
    2105  *  @scan       hardware scan code
    2106  *  @flags      flags, a combination of Key* constants
    2107  *  @aUniKey    Unicode translation of the key. Optional.
     2104 *  @param aKey        virtual scan code (virtual key on Win32 and KeySym on X11)
     2105 *  @param aScan       hardware scan code
     2106 *  @param aFlags      flags, a combination of Key* constants
     2107 *  @param aUniKey     Unicode translation of the key. Optional.
    21082108 *
    21092109 *  @return     true to consume the event and false to pass it to Qt
     
    21672167                 * to synchronize the state. */
    21682168                fixModifierState (codes, &count);
     2169            }
     2170
     2171            /* Check if it's C-A-D */
     2172            if (aScan == 0x53 /* Del */ &&
     2173                ((mPressedKeys [0x38] & IsKeyPressed) /* Alt */ ||
     2174                 (mPressedKeys [0x38] & IsExtKeyPressed)) &&
     2175                ((mPressedKeys [0x1d] & IsKeyPressed) /* Ctrl */ ||
     2176                 (mPressedKeys [0x1d] & IsExtKeyPressed)))
     2177            {
     2178                /* Use the C-A-D combination as a last resort to get the
     2179                 * keyboard and mouse back to the host when the user forgets
     2180                 * the Host Key. Note that it's always possible to send C-A-D
     2181                 * to the guest using the Host+Del combination. BTW, it would
     2182                 * be preferrable to completely ignore C-A-D in guests, but
     2183                 * that's not possible because we cannot predict what other
     2184                 * keys will be pressed next when one of C, A, D is held. */
     2185
     2186                if (isRunning() && mKbdCaptured)
     2187                {
     2188                    captureKbd (false);
     2189                    if (!(mMouseAbsolute && mMouseIntegration))
     2190                        captureMouse (false);
     2191                }
     2192
     2193                return true;
    21692194            }
    21702195
     
    21932218            }
    21942219
    2195             if (kbd_captured)
     2220            if (mKbdCaptured)
    21962221                mPressedKeys [aScan] |= IsKbdCaptured;
    21972222            else
     
    22022227    {
    22032228        /* currently this is used in winLowKeyboardEvent() only */
    2204         hostkey_in_capture = kbd_captured;
     2229        hostkey_in_capture = mKbdCaptured;
    22052230    }
    22062231
     
    22502275                    if (isRunning())
    22512276                    {
    2252                         bool captured = kbd_captured;
     2277                        bool captured = mKbdCaptured;
    22532278                        bool ok = true;
    22542279                        if (!captured)
     
    22722297                        {
    22732298                            captureKbd (!captured, false);
    2274                             if (!(mouse_absolute && mouse_integration))
    2275                                 captureMouse (kbd_captured);
     2299                            if (!(mMouseAbsolute && mMouseIntegration))
     2300                                captureMouse (mKbdCaptured);
    22762301                        }
    22772302                    }
     
    24282453    }
    24292454
    2430     if (mouse_captured)
     2455    if (mMouseCaptured)
    24312456    {
    24322457#ifdef Q_WS_WIN32
     
    24362461
    24372462        CMouse mouse = mConsole.GetMouse();
    2438         mouse.PutMouseEvent (aGlobalPos.x() - last_pos.x(),
    2439                              aGlobalPos.y() - last_pos.y(),
     2463        mouse.PutMouseEvent (aGlobalPos.x() - mLastPos.x(),
     2464                             aGlobalPos.y() - mLastPos.y(),
    24402465                             wheel, state);
    24412466
     
    24692494
    24702495        if (rect.contains (aGlobalPos, true))
    2471             last_pos = aGlobalPos;
     2496            mLastPos = aGlobalPos;
    24722497        else
    24732498        {
    2474             last_pos = rect.center();
    2475             QCursor::setPos (last_pos);
     2499            mLastPos = rect.center();
     2500            QCursor::setPos (mLastPos);
    24762501        }
    24772502
     
    24962521        if (p != aPos)
    24972522        {
    2498             last_pos = viewport()->mapToGlobal (p);
    2499             QCursor::setPos (last_pos);
     2523            mLastPos = viewport()->mapToGlobal (p);
     2524            QCursor::setPos (mLastPos);
    25002525        }
    25012526        else
    25022527        {
    2503             last_pos = aGlobalPos;
     2528            mLastPos = aGlobalPos;
    25042529        }
    25052530#else
     
    25182543        if (p != aGlobalPos)
    25192544        {
    2520             last_pos =  p;
    2521             QCursor::setPos (last_pos);
     2545            mLastPos =  p;
     2546            QCursor::setPos (mLastPos);
    25222547        }
    25232548        else
    25242549        {
    2525             last_pos = aGlobalPos;
     2550            mLastPos = aGlobalPos;
    25262551        }
    25272552#endif
     
    25292554        return true; /* stop further event handling */
    25302555    }
    2531     else /* !mouse_captured */
     2556    else /* !mMouseCaptured */
    25322557    {
    25332558#ifdef Q_WS_MAC
     
    25602585        }
    25612586
    2562         if (mouse_absolute && mouse_integration)
     2587        if (mMouseAbsolute && mMouseIntegration)
    25632588        {
    25642589            int cw = contentsWidth(), ch = contentsHeight();
     
    26682693        case CEnums::Running:
    26692694        {
    2670             if (last_state == CEnums::Paused)
     2695            if (mLastState == CEnums::Paused)
    26712696            {
    26722697                if (mode != VBoxDefs::TimerMode && mFrameBuf)
     
    26912716    }
    26922717
    2693     last_state = state;
     2718    mLastState = state;
    26942719}
    26952720
     
    27792804 *  system (including most system combinations like Alt-Tab).
    27802805 *
    2781  *  @capture        true to capture, false to uncapture
    2782  *  @emit_signal    whether to emit keyboardStateChanged() or not
     2806 *  @param aCapture     true to capture, false to uncapture.
     2807 *  @param aEmitSignal  Whether to emit keyboardStateChanged() or not.
    27832808 */
    2784 void VBoxConsoleView::captureKbd (bool capture, bool emit_signal)
    2785 {
    2786     AssertMsg (attached, ("Console must be attached"));
    2787 
    2788     if (kbd_captured == capture)
     2809void VBoxConsoleView::captureKbd (bool aCapture, bool aEmitSignal /* = true */)
     2810{
     2811    AssertMsg (mAttached, ("Console must be attached"));
     2812
     2813    if (mKbdCaptured == aCapture)
    27892814        return;
    27902815
     
    27992824    /**/
    28002825#elif defined (Q_WS_X11)
    2801         if (capture)
     2826        if (aCapture)
    28022827                XGrabKey (x11Display(), AnyKey, AnyModifier,
    28032828                  topLevelWidget()->winId(), False,
     
    28072832                    topLevelWidget()->winId());
    28082833#elif defined (Q_WS_MAC)
    2809     if (capture)
     2834    if (aCapture)
    28102835    {
    28112836        ::DarwinDisableGlobalHotKeys (true);
     
    28182843    }
    28192844#else
    2820     if (capture)
     2845    if (aCapture)
    28212846        grabKeyboard();
    28222847    else
     
    28242849#endif
    28252850
    2826     kbd_captured = capture;
    2827 
    2828     if (emit_signal)
     2851    mKbdCaptured = aCapture;
     2852
     2853    if (aEmitSignal)
    28292854        emitKeyboardStateChanged ();
    28302855}
     
    28342859 *  unavailable to the host applications.
    28352860 *
    2836  *  @capture    true to capture, false to uncapture
     2861 *  @param aCapture     true to capture, false to uncapture.
     2862 *  @param aEmitSignal  Whether to emit mouseStateChanged() or not.
    28372863 */
    2838 void VBoxConsoleView::captureMouse (bool capture, bool emit_signal)
    2839 {
    2840     AssertMsg (attached, ("Console must be attached"));
    2841 
    2842     if (mouse_captured == capture)
     2864void VBoxConsoleView::captureMouse (bool aCapture, bool aEmitSignal /* = true */)
     2865{
     2866    AssertMsg (mAttached, ("Console must be attached"));
     2867
     2868    if (mMouseCaptured == aCapture)
    28432869        return;
    28442870
    2845     if (capture)
     2871    if (aCapture)
    28462872    {
    28472873        /* memorize the host position where the cursor was captured */
    2848         captured_pos = QCursor::pos();
     2874        mCapturedPos = QCursor::pos();
    28492875#ifdef Q_WS_WIN32
    28502876        viewport()->setCursor (QCursor (BlankCursor));
    28512877        /* move the mouse to the center of the visible area */
    28522878        QCursor::setPos (mapToGlobal (visibleRect().center()));
    2853         last_pos = QCursor::pos();
     2879        mLastPos = QCursor::pos();
    28542880#elif defined (Q_WS_MAC)
    28552881        /* move the mouse to the center of the visible area */
    2856         last_pos = mapToGlobal (visibleRect().center());
    2857         QCursor::setPos (last_pos);
     2882        mLastPos = mapToGlobal (visibleRect().center());
     2883        QCursor::setPos (mLastPos);
    28582884        /* grab all mouse events. */
    28592885        viewport()->grabMouse();
    28602886#else
    28612887        viewport()->grabMouse();
    2862         last_pos = QCursor::pos();
     2888        mLastPos = QCursor::pos();
    28632889#endif
    28642890    }
     
    28732899    }
    28742900
    2875     mouse_captured = capture;
     2901    mMouseCaptured = aCapture;
    28762902
    28772903    updateMouseClipping();
    28782904
    2879     if (emit_signal)
     2905    if (aEmitSignal)
    28802906        emitMouseStateChanged ();
    28812907}
     
    29412967void VBoxConsoleView::releaseAllPressedKeys (bool aReleaseHostKey)
    29422968{
    2943     AssertMsg (attached, ("Console must be attached"));
     2969    AssertMsg (mAttached, ("Console must be attached"));
    29442970
    29452971    CKeyboard keyboard = mConsole.GetKeyboard();
     
    30083034void VBoxConsoleView::sendChangedKeyStates()
    30093035{
    3010     AssertMsg (attached, ("Console must be attached"));
     3036    AssertMsg (mAttached, ("Console must be attached"));
    30113037
    30123038    LONG codes [2];
     
    30363062void VBoxConsoleView::updateMouseClipping()
    30373063{
    3038     AssertMsg (attached, ("Console must be attached"));
    3039 
    3040     if ( mouse_captured ) {
    3041         viewport()->setCursor( QCursor( BlankCursor ) );
     3064    AssertMsg (mAttached, ("Console must be attached"));
     3065
     3066    if (mMouseCaptured)
     3067    {
     3068        viewport()->setCursor (QCursor (BlankCursor));
    30423069#ifdef Q_WS_WIN32
    30433070        QRect r = viewport()->rect();
    3044         r.moveTopLeft( viewport()->mapToGlobal( QPoint( 0, 0 ) ) );
     3071        r.moveTopLeft (viewport()->mapToGlobal (QPoint (0, 0)));
    30453072        RECT rect = { r.left(), r.top(), r.right() + 1, r.bottom() + 1 };
    3046         ::ClipCursor( &rect );
    3047 #endif
    3048     } else {
     3073        ::ClipCursor (&rect);
     3074#endif
     3075    }
     3076    else
     3077    {
    30493078#ifdef Q_WS_WIN32
    3050         ::ClipCursor( NULL );
     3079        ::ClipCursor (NULL);
    30513080#endif
    30523081        /* return the cursor to where it was when we captured it and show it */
    3053         QCursor::setPos( captured_pos );
     3082        QCursor::setPos (mCapturedPos);
    30543083        viewport()->unsetCursor();
    30553084    }
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