VirtualBox

Changeset 99434 in vbox


Ignore:
Timestamp:
Apr 18, 2023 6:51:53 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156893
Message:

FE/Qt: bugref:10407. More fixes to prevent crashes in pure Wayland case.

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

Legend:

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

    r99381 r99434  
    245245#ifdef VBOX_WS_X11
    246246    /* Detect display server type: */
    247     m_enmDisplayServerType = NativeWindowSubsystem::X11DetectDisplayServerType();
     247    m_enmDisplayServerType = NativeWindowSubsystem::detectDisplayServerType();
    248248#endif
    249249
     
    331331#ifdef VBOX_WS_X11
    332332    /* Check whether we have compositing manager running: */
    333     m_fCompositingManagerRunning = NativeWindowSubsystem::IsCompositingManagerRunning(X11XServerAvailable());
     333    m_fCompositingManagerRunning = NativeWindowSubsystem::isCompositingManagerRunning(X11XServerAvailable());
    334334
    335335    /* Acquire current Window Manager type: */
    336     m_enmWindowManagerType = NativeWindowSubsystem::WindowManagerType(X11XServerAvailable());
     336    m_enmWindowManagerType = NativeWindowSubsystem::windowManagerType(X11XServerAvailable());
    337337#endif /* VBOX_WS_X11 */
    338338
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UICursor.cpp

    r98103 r99434  
    4949        (UICommon::qtRTMajorVersion() == 5 && UICommon::qtRTMinorVersion() < 11))
    5050    {
    51         if (NativeWindowSubsystem::X11CheckExtension("RENDER"))
     51        if (NativeWindowSubsystem::checkExtension(uiCommon().X11XServerAvailable(), "RENDER"))
    5252            pWidget->setCursor(cursor);
    5353    }
     
    7575        (UICommon::qtRTMajorVersion() == 5 && UICommon::qtRTMinorVersion() < 11))
    7676    {
    77         if (NativeWindowSubsystem::X11CheckExtension("RENDER"))
     77        if (NativeWindowSubsystem::checkExtension(uiCommon().X11XServerAvailable(), "RENDER"))
    7878            pWidget->setCursor(cursor);
    7979    }
     
    101101        (UICommon::qtRTMajorVersion() == 5 && UICommon::qtRTMinorVersion() < 11))
    102102    {
    103         if (NativeWindowSubsystem::X11CheckExtension("RENDER"))
     103        if (NativeWindowSubsystem::checkExtension(uiCommon().X11XServerAvailable(), "RENDER"))
    104104            pWidget->unsetCursor();
    105105    }
     
    127127        (UICommon::qtRTMajorVersion() == 5 && UICommon::qtRTMinorVersion() < 11))
    128128    {
    129         if (NativeWindowSubsystem::X11CheckExtension("RENDER"))
     129        if (NativeWindowSubsystem::checkExtension(uiCommon().X11XServerAvailable(), "RENDER"))
    130130            pWidget->unsetCursor();
    131131    }
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.cpp

    r99407 r99434  
    861861
    862862#elif defined(VBOX_WS_X11)
    863     if (uiCommon().X11XServerAvailable())
    864         fResult &= NativeWindowSubsystem::X11ActivateWindow(wId, fSwitchDesktop);
     863
     864    fResult &= NativeWindowSubsystem::activateWindow(uiCommon().X11XServerAvailable(), wId, fSwitchDesktop);
    865865
    866866#else
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r99372 r99434  
    396396        if (!MakeSureMultiThreadingIsSafe())
    397397            break;
    398         DisplayServerType enmDisplayServerType = NativeWindowSubsystem::X11DetectDisplayServerType();
     398        DisplayServerType enmDisplayServerType = NativeWindowSubsystem::detectDisplayServerType();
    399399        if (NativeWindowSubsystem::X11XServerAvailable(enmDisplayServerType))
    400400            /* Force using Qt platform plugin 'xcb', we have X11 specific code: */
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r99390 r99434  
    21462146{
    21472147#ifdef VBOX_WS_X11
    2148     NativeWindowSubsystem::SetWMClass(uiCommon().X11XServerAvailable(), this, "VirtualBox Manager", "VirtualBox Manager");
     2148    NativeWindowSubsystem::setWMClass(uiCommon().X11XServerAvailable(), this, "VirtualBox Manager", "VirtualBox Manager");
    21492149#endif
    21502150
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/x11/VBoxUtils-x11.cpp

    r99381 r99434  
    6060
    6161
    62 bool NativeWindowSubsystem::IsCompositingManagerRunning(bool fIsXServerAvailable)
     62bool NativeWindowSubsystem::isCompositingManagerRunning(bool fIsXServerAvailable)
    6363{
    6464    if (fIsXServerAvailable)
     
    8181}
    8282
    83 X11WMType NativeWindowSubsystem::WindowManagerType(bool fIsXServerAvailable)
     83X11WMType NativeWindowSubsystem::windowManagerType(bool fIsXServerAvailable)
    8484{
    8585    if (fIsXServerAvailable)
     
    9090X11WMType NativeWindowSubsystem::WaylandWindowManagerType()
    9191{
    92     /// @todo implement
     92    /// @wayland implement
    9393    return X11WMType_Unknown;
    9494}
     
    150150}
    151151
     152bool NativeWindowSubsystem::checkExtension(bool fIsXServerAvailable, const char *pExtensionName)
     153{
     154    if (fIsXServerAvailable)
     155        return X11CheckExtension(pExtensionName);
     156    return WaylandCheckExtension(pExtensionName);
     157}
     158
    152159bool NativeWindowSubsystem::X11CheckExtension(const char *pExtensionName)
    153160{
     
    158165    int first_error;
    159166    return XQueryExtension(pDisplay, pExtensionName, &major_opcode, &first_event, &first_error);
     167}
     168
     169bool NativeWindowSubsystem::WaylandCheckExtension(const char *pExtensionName)
     170{
     171    Q_UNUSED(pExtensionName);
     172    /// @todo implement
     173    return false;
    160174}
    161175
     
    385399}
    386400
     401bool NativeWindowSubsystem::activateWindow(bool fIsXServerAvailable, WId wId, bool fSwitchDesktop)
     402{
     403    if (fIsXServerAvailable)
     404        return X11ActivateWindow(wId, fSwitchDesktop);
     405    return WaylandActivateWindow(wId, fSwitchDesktop);
     406}
     407
    387408bool NativeWindowSubsystem::X11ActivateWindow(WId wId, bool fSwitchDesktop)
    388409{
     
    422443    XRaiseWindow(pDisplay, wId);
    423444    return fResult;
     445}
     446
     447bool NativeWindowSubsystem::WaylandActivateWindow(WId wId, bool fSwitchDesktop)
     448{
     449    /// @todo implement
     450    Q_UNUSED(wId);
     451    Q_UNUSED(fSwitchDesktop);
     452    return false;
    424453}
    425454
     
    615644}
    616645
    617 void NativeWindowSubsystem::SetWMClass(bool fIsXServerAvailable, QWidget *pWidget, const QString &strNameString, const QString &strClassString)
     646void NativeWindowSubsystem::setWMClass(bool fIsXServerAvailable, QWidget *pWidget, const QString &strNameString, const QString &strClassString)
    618647{
    619648    if (fIsXServerAvailable)
     
    655684}
    656685
    657 void NativeWindowSubsystem::X11SetXwaylandMayGrabKeyboardFlag(QWidget *pWidget)
    658 {
    659     XXSendClientMessage(NativeWindowSubsystem::X11GetDisplay(), pWidget->window()->winId(),
    660                         "_XWAYLAND_MAY_GRAB_KEYBOARD", 1);
     686void NativeWindowSubsystem::setXwaylandMayGrabKeyboardFlag(bool fIsXServerAvailable, QWidget *pWidget)
     687{
     688    if (fIsXServerAvailable)
     689        XXSendClientMessage(NativeWindowSubsystem::X11GetDisplay(), pWidget->window()->winId(),
     690                            "_XWAYLAND_MAY_GRAB_KEYBOARD", 1);
    661691}
    662692
     
    708738}
    709739
    710 DisplayServerType NativeWindowSubsystem::X11DetectDisplayServerType()
     740DisplayServerType NativeWindowSubsystem::detectDisplayServerType()
    711741{
    712742    const char *pSessionType = RTEnvGet("XDG_SESSION_TYPE");
  • trunk/src/VBox/Frontends/VirtualBox/src/platform/x11/VBoxUtils-x11.h

    r99381 r99434  
    105105{
    106106    /** Wrapper function for X11IsCompositingManagerRunning and WaylandIsCompositingManagerRunning. */
    107     bool IsCompositingManagerRunning(bool fIsXServerAvailable);
     107    bool isCompositingManagerRunning(bool fIsXServerAvailable);
    108108    /** X11: Determines and returns whether the compositing manager is running. */
    109109    bool X11IsCompositingManagerRunning();
     
    112112
    113113    /** Wrapper for window manager type functions. */
    114     X11WMType WindowManagerType(bool fIsXServerAvailable);
     114    X11WMType windowManagerType(bool fIsXServerAvailable);
    115115    /** X11: Determines and returns current Window Manager type. */
    116116    X11WMType X11WindowManagerType();
     
    118118    X11WMType WaylandWindowManagerType();
    119119
     120    /** Wrapper for X11CheckExtension and WaylandCheckExtension functions. */
     121    bool checkExtension(bool fIsXServerAvailable, const char *extensionName);
    120122    /** X11: Returns true if XLib extension with name @p extensionName is avaible, false otherwise. */
    121     bool X11CheckExtension(const char *extensionName);
     123    bool X11CheckExtension(const char *pExtensionName);
     124    bool WaylandCheckExtension(const char *pExtensionName);
     125
    122126
    123127    /** X11: Returns whether there are any DBus services whose name contains the substring 'screensaver'. */
     
    128132    SHARED_LIBRARY_STUFF void X11InhibitUninhibitScrenSaver(bool fInhibit, QVector<X11ScreenSaverInhibitMethod*> &inOutInhibitMethods);
    129133
     134    /** Wrapper function for X11ActivateWindow or WaylandActivateWindow. */
     135    bool activateWindow(bool fIsXServerAvailable, WId wId, bool fSwitchDesktop);
    130136    /** Activates window with certain @a wId, @a fSwitchDesktop if requested. */
    131137    bool X11ActivateWindow(WId wId, bool fSwitchDesktop);
     138    /** Activates window with certain @a wId, @a fSwitchDesktop if requested. */
     139    bool WaylandActivateWindow(WId wId, bool fSwitchDesktop);
    132140
    133141    /** X11: Test whether the current window manager supports full screen mode. */
     
    142150
    143151    /** Wrapper function for WMClass setters. */
    144     SHARED_LIBRARY_STUFF void SetWMClass(bool fIsXServerAvailable, QWidget *pWidget, const QString &strNameString, const QString &strClassString);
     152    SHARED_LIBRARY_STUFF void setWMClass(bool fIsXServerAvailable, QWidget *pWidget, const QString &strNameString, const QString &strClassString);
    145153    /** X11: Assigns WM_CLASS property for passed @a pWidget. */
    146154    SHARED_LIBRARY_STUFF void X11SetWMClass(QWidget *pWidget, const QString &strNameString, const QString &strClassString);
     
    152160      *      so that e.g. alt+tab will get send to the VM instead of moving the
    153161      *      focus away from the VM. */
    154     SHARED_LIBRARY_STUFF void X11SetXwaylandMayGrabKeyboardFlag(QWidget *pWidget);
     162    SHARED_LIBRARY_STUFF void setXwaylandMayGrabKeyboardFlag(bool fIsXServerAvailable, QWidget *pWidget);
    155163
    156164    /** X11: Gets the X11 display pointer. */
     
    161169    SHARED_LIBRARY_STUFF uint32_t X11GetAppRootWindow();
    162170    /** Detects and returns display server type. */
    163     SHARED_LIBRARY_STUFF DisplayServerType X11DetectDisplayServerType();
     171    SHARED_LIBRARY_STUFF DisplayServerType detectDisplayServerType();
    164172    /** Returns true if @a enmDisplayServerType is either xorg or xwayland. */
    165173    SHARED_LIBRARY_STUFF bool X11XServerAvailable(DisplayServerType enmDisplayServerType);
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp

    r99407 r99434  
    266266
    267267#elif defined(VBOX_WS_X11)
    268 
    269         /* On X11, we are using XCB stuff to grab the keyboard.
    270          * This stuff is a part of the active keyboard grabbing functionality.
    271          * Active keyboard grabbing causes a problems on many window managers - a window cannot
    272          * be moved using the mouse. So we additionally grab the mouse buttons as well to detect
    273          * that the user is trying to click outside of the internal window geometry and release
    274          * the keyboard before the target window sees the click. (GNOME Shell's hot corner has
    275          * the same problem. At present we just let that problem be.) */
     268        if (uiCommon().X11XServerAvailable())
     269        {
     270            /* On X11, we are using XCB stuff to grab the keyboard.
     271             * This stuff is a part of the active keyboard grabbing functionality.
     272             * Active keyboard grabbing causes a problems on many window managers - a window cannot
     273             * be moved using the mouse. So we additionally grab the mouse buttons as well to detect
     274             * that the user is trying to click outside of the internal window geometry and release
     275             * the keyboard before the target window sees the click. (GNOME Shell's hot corner has
     276             * the same problem. At present we just let that problem be.) */
    276277
    277278# if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
    278         /* Make sure we really do still have the focus.  Qt as of version 5.13 started
    279          * reporting it with delay, so ask the X server directly.  We could remove the
    280          * version check some time in the future.  If we do, remove the comment above
    281          * about the focus notification dance, as it will no longer be relevant. */
    282         xcb_get_input_focus_cookie_t xcbFocusCookie = xcb_get_input_focus(NativeWindowSubsystem::X11GetConnection());
    283         xcb_get_input_focus_reply_t *pFocusReply = xcb_get_input_focus_reply(NativeWindowSubsystem::X11GetConnection(),
    284                                                                              xcbFocusCookie, 0);
    285         xcb_window_t xcbFocusWindow = pFocusReply->focus;
    286         free(pFocusReply);
    287         if (xcbFocusWindow != m_windows[m_iKeyboardCaptureViewIndex]->winId())
    288             return true;
     279            /* Make sure we really do still have the focus.  Qt as of version 5.13 started
     280             * reporting it with delay, so ask the X server directly.  We could remove the
     281             * version check some time in the future.  If we do, remove the comment above
     282             * about the focus notification dance, as it will no longer be relevant. */
     283            xcb_get_input_focus_cookie_t xcbFocusCookie = xcb_get_input_focus(NativeWindowSubsystem::X11GetConnection());
     284            xcb_get_input_focus_reply_t *pFocusReply = xcb_get_input_focus_reply(NativeWindowSubsystem::X11GetConnection(),
     285                                                                                 xcbFocusCookie, 0);
     286            xcb_window_t xcbFocusWindow = pFocusReply->focus;
     287            free(pFocusReply);
     288            if (xcbFocusWindow != m_windows[m_iKeyboardCaptureViewIndex]->winId())
     289                return true;
    289290# endif
    290291
    291         /* Grab the mouse button.
    292          * We do not check for failure as we do not currently implement a back-up plan. */
    293         /* If any previous grab is still in process, release it. */
    294         if (m_hButtonGrabWindow != 0)
    295             xcb_ungrab_button_checked(NativeWindowSubsystem::X11GetConnection(), XCB_BUTTON_INDEX_ANY,
    296                                       m_hButtonGrabWindow, XCB_MOD_MASK_ANY);
    297         m_hButtonGrabWindow = NativeWindowSubsystem::X11GetAppRootWindow();
    298         xcb_grab_button_checked(NativeWindowSubsystem::X11GetConnection(), 0, m_hButtonGrabWindow,
    299                                 XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
    300                                 XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_ANY, XCB_MOD_MASK_ANY);
    301         /* And grab the keyboard, using XCB directly, as Qt does not report failure. */
    302         xcb_grab_keyboard_cookie_t xcbGrabCookie = xcb_grab_keyboard(NativeWindowSubsystem::X11GetConnection(), false,
    303                                                                      m_views[m_iKeyboardCaptureViewIndex]->winId(),
    304                                                                      XCB_TIME_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
    305         xcb_grab_keyboard_reply_t *pGrabReply = xcb_grab_keyboard_reply(NativeWindowSubsystem::X11GetConnection(),
    306                                                                         xcbGrabCookie, NULL);
    307         if (pGrabReply == NULL || pGrabReply->status != XCB_GRAB_STATUS_SUCCESS)
    308         {
    309             /* Release the mouse button grab.
     292            /* Grab the mouse button.
    310293             * We do not check for failure as we do not currently implement a back-up plan. */
    311             xcb_ungrab_button_checked(NativeWindowSubsystem::X11GetConnection(), XCB_BUTTON_INDEX_ANY,
    312                                       m_hButtonGrabWindow, XCB_MOD_MASK_ANY);
    313             m_hButtonGrabWindow = 0;
    314             /* Try again later: */
     294            /* If any previous grab is still in process, release it. */
     295            if (m_hButtonGrabWindow != 0)
     296                xcb_ungrab_button_checked(NativeWindowSubsystem::X11GetConnection(), XCB_BUTTON_INDEX_ANY,
     297                                          m_hButtonGrabWindow, XCB_MOD_MASK_ANY);
     298            m_hButtonGrabWindow = NativeWindowSubsystem::X11GetAppRootWindow();
     299            xcb_grab_button_checked(NativeWindowSubsystem::X11GetConnection(), 0, m_hButtonGrabWindow,
     300                                    XCB_EVENT_MASK_BUTTON_PRESS, XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC,
     301                                    XCB_NONE, XCB_NONE, XCB_BUTTON_INDEX_ANY, XCB_MOD_MASK_ANY);
     302            /* And grab the keyboard, using XCB directly, as Qt does not report failure. */
     303            xcb_grab_keyboard_cookie_t xcbGrabCookie = xcb_grab_keyboard(NativeWindowSubsystem::X11GetConnection(), false,
     304                                                                         m_views[m_iKeyboardCaptureViewIndex]->winId(),
     305                                                                         XCB_TIME_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
     306            xcb_grab_keyboard_reply_t *pGrabReply = xcb_grab_keyboard_reply(NativeWindowSubsystem::X11GetConnection(),
     307                                                                            xcbGrabCookie, NULL);
     308            if (pGrabReply == NULL || pGrabReply->status != XCB_GRAB_STATUS_SUCCESS)
     309            {
     310                /* Release the mouse button grab.
     311                 * We do not check for failure as we do not currently implement a back-up plan. */
     312                xcb_ungrab_button_checked(NativeWindowSubsystem::X11GetConnection(), XCB_BUTTON_INDEX_ANY,
     313                                          m_hButtonGrabWindow, XCB_MOD_MASK_ANY);
     314                m_hButtonGrabWindow = 0;
     315                /* Try again later: */
     316                free(pGrabReply);
     317                return false;
     318            }
    315319            free(pGrabReply);
    316             return false;
    317         }
    318         free(pGrabReply);
    319 
     320        }
    320321#else
    321322
     
    370371
    371372#elif defined(VBOX_WS_X11)
    372 
    373         /* On X11, we are using XCB stuff to grab the keyboard.
    374          * This stuff is a part of the active keyboard grabbing functionality.
    375          * Active keyboard grabbing causes a problems on many window managers - a window cannot
    376          * be moved using the mouse. So we finally releasing additionally grabbed mouse as well
    377          * to allow further user interactions. */
    378 
    379         /* Ungrab using XCB: */
    380         xcb_ungrab_keyboard(NativeWindowSubsystem::X11GetConnection(), XCB_TIME_CURRENT_TIME);
    381         /* Release the mouse button grab.
    382          * We do not check for failure as we do not currently implement a back-up plan. */
    383         xcb_ungrab_button_checked(NativeWindowSubsystem::X11GetConnection(), XCB_BUTTON_INDEX_ANY,
    384                                   m_hButtonGrabWindow, XCB_MOD_MASK_ANY);
    385         m_hButtonGrabWindow = 0;
    386 
     373        if (uiCommon().X11XServerAvailable())
     374        {
     375            /* On X11, we are using XCB stuff to grab the keyboard.
     376             * This stuff is a part of the active keyboard grabbing functionality.
     377             * Active keyboard grabbing causes a problems on many window managers - a window cannot
     378             * be moved using the mouse. So we finally releasing additionally grabbed mouse as well
     379             * to allow further user interactions. */
     380
     381            /* Ungrab using XCB: */
     382            xcb_ungrab_keyboard(NativeWindowSubsystem::X11GetConnection(), XCB_TIME_CURRENT_TIME);
     383            /* Release the mouse button grab.
     384             * We do not check for failure as we do not currently implement a back-up plan. */
     385            xcb_ungrab_button_checked(NativeWindowSubsystem::X11GetConnection(), XCB_BUTTON_INDEX_ANY,
     386                                      m_hButtonGrabWindow, XCB_MOD_MASK_ANY);
     387            m_hButtonGrabWindow = 0;
     388        }
    387389#else
    388390
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp

    r99407 r99434  
    149149    if (gEDataManager->distinguishMachineWindowGroups(uiCommon().managedVMUuid()))
    150150        strWindowName = QString("VirtualBox Machine UUID: %1").arg(uiCommon().managedVMUuid().toString());
    151     if (uiCommon().X11XServerAvailable())
    152     {
    153         /* Assign WM_CLASS property: */
    154         NativeWindowSubsystem::X11SetWMClass(this, strWindowName, strWindowClass);
    155         /* Tell the WM we are well behaved wrt Xwayland keyboard-grabs: */
    156         NativeWindowSubsystem::X11SetXwaylandMayGrabKeyboardFlag(this);
    157     }
     151    /* Assign WM_CLASS property: */
     152    NativeWindowSubsystem::setWMClass(uiCommon().X11XServerAvailable(), this, strWindowName, strWindowClass);
     153    /* Tell the WM we are well behaved wrt Xwayland keyboard-grabs: */
     154    NativeWindowSubsystem::setXwaylandMayGrabKeyboardFlag(uiCommon().X11XServerAvailable(), this);
    158155#endif
    159156}
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