VirtualBox

Changeset 99442 in vbox


Ignore:
Timestamp:
Apr 18, 2023 12:26:53 PM (20 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10407. Some more fixes for guarding XServer calls.

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

Legend:

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

    r98994 r99442  
    540540# elif defined(VBOX_WS_X11)
    541541
    542     /* Make sure it's generic XCB event: */
    543     if (eventType != "xcb_generic_event_t")
    544         return false;
    545     xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage);
    546 
    547     switch (pEvent->response_type & ~0x80)
    548     {
    549         /* Watch for key-events: */
    550         case XCB_KEY_PRESS:
    551         case XCB_KEY_RELEASE:
     542    if (uiCommon().X11ServerAvailable())
     543    {
     544        /* Make sure it's generic XCB event: */
     545        if (eventType != "xcb_generic_event_t")
     546            return false;
     547        xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage);
     548
     549        switch (pEvent->response_type & ~0x80)
    552550        {
    553             /* Delegate key-event handling to the keyboard-handler: */
    554             return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId());
     551            /* Watch for key-events: */
     552            case XCB_KEY_PRESS:
     553            case XCB_KEY_RELEASE:
     554                {
     555                    /* Delegate key-event handling to the keyboard-handler: */
     556                    return machineLogic()->keyboardHandler()->nativeEventFilter(pMessage, screenId());
     557                }
     558                /* Watch for button-events: */
     559            case XCB_BUTTON_PRESS:
     560            case XCB_BUTTON_RELEASE:
     561                {
     562                    /* Delegate button-event handling to the mouse-handler: */
     563                    return machineLogic()->mouseHandler()->nativeEventFilter(pMessage, screenId());
     564                }
     565            default:
     566                break;
    555567        }
    556         /* Watch for button-events: */
    557         case XCB_BUTTON_PRESS:
    558         case XCB_BUTTON_RELEASE:
    559         {
    560             /* Delegate button-event handling to the mouse-handler: */
    561             return machineLogic()->mouseHandler()->nativeEventFilter(pMessage, screenId());
    562         }
    563         default:
    564             break;
    565568    }
    566569
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMouseHandler.cpp

    r99072 r99442  
    313313# elif defined(VBOX_WS_X11)
    314314
    315     /* Cast to XCB event: */
    316     xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage);
    317 
    318     /* Depending on event type: */
    319     switch (pEvent->response_type & ~0x80)
    320     {
    321         /* Watch for button-events: */
    322         case XCB_BUTTON_PRESS:
    323         {
    324             /* Do nothing if mouse is actively grabbed: */
    325             if (uimachine()->isMouseCaptured())
     315    if (uiCommon().X11ServerAvailable())
     316    {
     317        /* Cast to XCB event: */
     318        xcb_generic_event_t *pEvent = static_cast<xcb_generic_event_t*>(pMessage);
     319
     320        /* Depending on event type: */
     321        switch (pEvent->response_type & ~0x80)
     322        {
     323            /* Watch for button-events: */
     324            case XCB_BUTTON_PRESS:
     325                {
     326                    /* Do nothing if mouse is actively grabbed: */
     327                    if (uimachine()->isMouseCaptured())
     328                        break;
     329
     330                    /* If we see a mouse press from a grab while the mouse is not captured,
     331                     * release the keyboard before letting the event owner see it. This is
     332                     * because some owners cannot deal with failures to grab the keyboard
     333                     * themselves (e.g. window managers dragging windows). */
     334
     335                    /* Cast to XCB button-event: */
     336                    xcb_button_press_event_t *pButtonEvent = static_cast<xcb_button_press_event_t*>(pMessage);
     337
     338                    /* If this event is from our button grab then it will be reported relative to the root
     339                     * window and not to ours. In that case release the keyboard capture, re-capture it
     340                     * delayed, which will fail if we have lost the input focus in the mean-time, replay
     341                     * the button event for normal delivery (possibly straight back to us, but not relative
     342                     * to root this time) and tell Qt not to further process this event: */
     343                    if (pButtonEvent->event == pButtonEvent->root)
     344                    {
     345                        machineLogic()->keyboardHandler()->releaseKeyboard();
     346                        /** @todo It would be nicer to do this in the normal Qt button event
     347                         *       handler to avoid avoidable races if the event was not for us. */
     348                        machineLogic()->keyboardHandler()->captureKeyboard(uScreenId);
     349                        /* Re-send the event so that the window which it was meant for gets it: */
     350                        xcb_allow_events_checked(NativeWindowSubsystem::X11GetConnection(), XCB_ALLOW_REPLAY_POINTER, pButtonEvent->time);
     351                        /* Do not let Qt see the event: */
     352                        return true;
     353                    }
     354                }
     355            default:
    326356                break;
    327 
    328             /* If we see a mouse press from a grab while the mouse is not captured,
    329              * release the keyboard before letting the event owner see it. This is
    330              * because some owners cannot deal with failures to grab the keyboard
    331              * themselves (e.g. window managers dragging windows). */
    332 
    333             /* Cast to XCB button-event: */
    334             xcb_button_press_event_t *pButtonEvent = static_cast<xcb_button_press_event_t*>(pMessage);
    335 
    336             /* If this event is from our button grab then it will be reported relative to the root
    337              * window and not to ours. In that case release the keyboard capture, re-capture it
    338              * delayed, which will fail if we have lost the input focus in the mean-time, replay
    339              * the button event for normal delivery (possibly straight back to us, but not relative
    340              * to root this time) and tell Qt not to further process this event: */
    341             if (pButtonEvent->event == pButtonEvent->root)
    342             {
    343                 machineLogic()->keyboardHandler()->releaseKeyboard();
    344                 /** @todo It would be nicer to do this in the normal Qt button event
    345                   *       handler to avoid avoidable races if the event was not for us. */
    346                 machineLogic()->keyboardHandler()->captureKeyboard(uScreenId);
    347                 /* Re-send the event so that the window which it was meant for gets it: */
    348                 xcb_allow_events_checked(NativeWindowSubsystem::X11GetConnection(), XCB_ALLOW_REPLAY_POINTER, pButtonEvent->time);
    349                 /* Do not let Qt see the event: */
    350                 return true;
    351             }
    352         }
    353         default:
    354             break;
    355     }
    356 
     357        }
     358    }
    357359# else
    358360
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