VirtualBox

Ignore:
Timestamp:
Sep 29, 2014 4:52:38 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: X11: Runtime UI: Mini-toolbar: Rework it to be window again, fixing conflicts with Unity panels for full-screen and seamless modes.

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

Legend:

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

    r52794 r52891  
    33543354                               1 /* Source indication (1 = normal application) */);
    33553355}
     3356
     3357/* static */
     3358void VBoxGlobal::setTransientFor(QWidget *pWidget, QWidget *pPropWidget)
     3359{
     3360    XSetTransientForHint(pWidget->x11Info().display(),
     3361                         pWidget->window()->winId(),
     3362                         pPropWidget->window()->winId());
     3363}
    33563364#endif /* Q_WS_X11 */
    33573365
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r52794 r52891  
    323323    /** X11: Performs mapping of the passed @a pWidget to host-screen with passed @a uScreenId. */
    324324    static bool setFullScreenMonitorX11(QWidget *pWidget, ulong uScreenId);
     325    /** X11: Ensures @a pPropWidget become transient for the @a pWidget. */
     326    static void setTransientFor(QWidget *pWidget, QWidget *pPropWidget);
    325327#endif /* Q_WS_X11 */
    326328
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp

    r52873 r52891  
    188188    /* Revoke stolen focus: */
    189189    m_pMachineView->setFocus();
    190 #elif defined(Q_WS_MAC)
     190#elif defined(Q_WS_MAC) || defined(Q_WS_X11)
    191191    /* Revoke stolen activation: */
    192192    activateWindow();
    193 #endif /* Q_WS_MAC */
     193#endif /* Q_WS_MAC || Q_WS_X11 */
    194194}
    195195
     
    364364        !pFullscreenLogic->hasHostScreenForGuestScreen(m_uScreenId))
    365365    {
    366         /* Hide mini-toolbar: */
    367         if (   m_pMiniToolBar
    368 #ifdef Q_WS_MAC
    369             && !fSupportsNativeFullScreen
    370 #endif /* Q_WS_MAC */
    371             )
     366        /* If there is mini-toolbar: */
     367        if (m_pMiniToolBar)
     368        {
     369#if   defined(Q_WS_WIN) || defined(Q_WS_X11)
     370            /* Just hide mini-toolbar: */
    372371            m_pMiniToolBar->hide();
     372#elif defined(Q_WS_MAC)
     373            /* If no native full-screen used: */
     374            if (!fSupportsNativeFullScreen)
     375            {
     376                /* Just hide mini-toolbar: */
     377                m_pMiniToolBar->hide();
     378            }
     379#endif /* Q_WS_MAC */
     380        }
    373381        /* Hide window: */
    374382        hide();
     
    425433    adjustMachineViewSize();
    426434
    427     /* Show mini-toolbar: */
    428     if (   m_pMiniToolBar
    429 #ifdef Q_WS_MAC
    430         && !fSupportsNativeFullScreen
    431 #endif /* Q_WS_MAC */
    432         )
     435    /* If there is mini-toolbar: */
     436    if (m_pMiniToolBar)
     437    {
     438#if   defined(Q_WS_WIN)
     439        /* Just show mini-toolbar: */
    433440        m_pMiniToolBar->show();
     441#elif defined(Q_WS_MAC)
     442        /* If no native full-screen used: */
     443        if (!fSupportsNativeFullScreen)
     444        {
     445            /* Just show mini-toolbar: */
     446            m_pMiniToolBar->show();
     447        }
     448#elif defined(Q_WS_X11)
     449        /* Allow mini-toolbar to be located on full-screen area: */
     450        m_pMiniToolBar->showFullScreen();
     451        /* On modern window managers: */
     452        if (fSupportsNativeFullScreen)
     453        {
     454            /* We also can map mini-toolbar directly on corresponding machine-window: */
     455            VBoxGlobal::setFullScreenMonitorX11(m_pMiniToolBar, pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId));
     456        }
     457        /* Make sure mini-toolbar is always on top of machine-window: */
     458        VBoxGlobal::setTransientFor(m_pMiniToolBar, this);
     459#endif /* Q_WS_X11 */
     460    }
    434461
    435462    /* Make sure machine-view have focus: */
     
    452479        const int iHostScreen = pFullscreenLogic->hostScreenForGuestScreen(m_uScreenId);
    453480
     481#ifndef Q_WS_X11
    454482        /* Move mini-toolbar into appropriate place: */
    455483        m_pMiniToolBar->adjustGeometry(iHostScreen);
     484#else /* Q_WS_X11 */
     485        /* On modern WMs we are mapping mini-toolbar to corresponding host-screen directly. */
     486        const bool fSupportsNativeFullScreen = VBoxGlobal::supportsFullScreenMonitorsProtocolX11() &&
     487                                               !gEDataManager->legacyFullscreenModeRequested();
     488        /* Adjust mini-toolbar and move into appropriate place if necessary: */
     489        m_pMiniToolBar->adjustGeometry(fSupportsNativeFullScreen ? -1 : iHostScreen);
     490#endif /* Q_WS_X11 */
    456491    }
    457492}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineWindowSeamless.cpp

    r52873 r52891  
    7474    /* Revoke stolen focus: */
    7575    m_pMachineView->setFocus();
    76 #elif defined(Q_WS_MAC)
     76#elif defined(Q_WS_MAC) || defined(Q_WS_X11)
    7777    /* Revoke stolen activation: */
    7878    activateWindow();
    79 #endif /* Q_WS_MAC */
    80 }
    81 
    82 #ifdef VBOX_WITH_MASKED_SEAMLESS
    83 # ifdef Q_WS_X11
    84 void UIMachineWindowSeamless::sltUpdateMiniToolbarMask(const QRect &geo)
    85 {
    86     /* Make sure mini-toolbar exists: */
    87     AssertPtrReturnVoid(m_pMiniToolBar);
    88 
    89     /* Remember mini-toolbar mask: */
    90     m_maskMiniToolbar = geo;
    91 
    92     /* Re-assign guest mask. */
    93     setMask(m_maskGuest);
    94 }
    95 # endif /* Q_WS_X11 */
    96 #endif /* VBOX_WITH_MASKED_SEAMLESS */
     79#endif /* Q_WS_MAC || Q_WS_X11 */
     80}
    9781
    9882void UIMachineWindowSeamless::prepareVisualState()
     
    153137            actionPool()->action(UIActionIndexRT_M_Machine_S_Close), SLOT(trigger()));
    154138    connect(m_pMiniToolBar, SIGNAL(sigNotifyAboutFocusStolen()), this, SLOT(sltRevokeFocus()));
    155 #ifdef VBOX_WITH_MASKED_SEAMLESS
    156 # ifdef Q_WS_X11
    157     connect(m_pMiniToolBar, SIGNAL(sigNotifyAboutGeometryChange(const QRect&)),
    158             this, SLOT(sltUpdateMiniToolbarMask(const QRect&)));
    159 # endif /* Q_WS_X11 */
    160 #endif /* VBOX_WITH_MASKED_SEAMLESS */
    161139}
    162140#endif /* !Q_WS_MAC */
     
    213191    {
    214192#ifndef Q_WS_MAC
    215         /* Hide mini-toolbar: */
     193        /* If there is mini-toolbar: */
    216194        if (m_pMiniToolBar)
     195        {
     196            /* Just hide mini-toolbar: */
    217197            m_pMiniToolBar->hide();
     198        }
    218199#endif /* !Q_WS_MAC */
    219200        /* Hide window: */
     
    236217
    237218#ifndef Q_WS_MAC
    238     /* Show mini-toolbar: */
     219    /* If there is mini-toolbar: */
    239220    if (m_pMiniToolBar)
     221    {
     222# if   defined(Q_WS_WIN)
     223        /* Just show mini-toolbar: */
    240224        m_pMiniToolBar->show();
     225# elif defined(Q_WS_X11)
     226        /* Allow mini-toolbar to be located on full-screen area: */
     227        m_pMiniToolBar->showMaximized();
     228        /* Make sure mini-toolbar is always on top of machine-window: */
     229        VBoxGlobal::setTransientFor(m_pMiniToolBar, this);
     230# endif /* Q_WS_X11 */
     231    }
    241232#endif /* !Q_WS_MAC */
    242233
     
    319310        maskFull.translate(m_pLeftSpacer->geometry().width(), m_pTopSpacer->geometry().height());
    320311
    321 # ifdef Q_WS_X11
    322     /* Take into account mini-toolbar mask if necessary: */
    323     if (m_pMiniToolBar)
    324         maskFull += m_maskMiniToolbar;
    325 # endif /* Q_WS_X11 */
    326 
    327312    /* Seamless-window for empty full mask should be empty too,
    328313     * but the QWidget::setMask() wrapper doesn't allow this.
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineWindowSeamless.h

    r52870 r52891  
    4343    /** Revokes keyboard-focus. */
    4444    void sltRevokeFocus();
    45 
    46 #ifdef VBOX_WITH_MASKED_SEAMLESS
    47 # ifdef Q_WS_X11
    48     /** Assigns mini-toolbar seamless mask. */
    49     void sltUpdateMiniToolbarMask(const QRect &geo);
    50 # endif /* Q_WS_X11 */
    51 #endif /* VBOX_WITH_MASKED_SEAMLESS */
    5245
    5346private:
     
    9790    /** Holds the guest seamless mask. */
    9891    QRegion m_maskGuest;
    99 # ifdef Q_WS_X11
    100     /** Holds the mini-toolbar seamless mask. */
    101     QRect m_maskMiniToolbar;
    102 # endif /* Q_WS_X11 */
    10392#endif /* VBOX_WITH_MASKED_SEAMLESS */
    10493
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMiniToolBar.cpp

    r52874 r52891  
    5252                                           bool fAutoHide /* = true */)
    5353    : QWidget(pParent,
    54 #if   defined (Q_WS_WIN)
     54#if   defined(Q_WS_WIN)
    5555              Qt::Tool | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint
    56 #elif defined (Q_WS_MAC)
     56#elif defined(Q_WS_MAC) || defined(Q_WS_X11)
    5757              Qt::Window | Qt::FramelessWindowHint
    58 #elif defined (Q_WS_X11)
    59               Qt::Widget
    60 #endif /* RT_OS_DARWIN */
     58#endif /* Q_WS_MAC || Q_WS_X11 */
    6159              )
    6260    /* Variables: General stuff: */
     
    143141void UIRuntimeMiniToolBar::adjustGeometry(int iHostScreen /* = -1 */)
    144142{
     143#ifndef Q_WS_X11
    145144    /* This method could be called before parent-widget
    146145     * become visible, we should skip everything in that case: */
     
    166165        default: break;
    167166    }
    168 #ifdef Q_WS_X11
    169     /* Disregard origin under X11,
    170      * because this is widget, not window: */
    171     screenRect.moveTopLeft(QPoint(0, 0));
    172 #endif /* Q_WS_X11 */
    173167    iX = screenRect.x() + screenRect.width() / 2 - width() / 2;
    174168    switch (m_alignment)
     
    202196    /* Simulate toolbar auto-hiding: */
    203197    simulateToolbarAutoHiding();
     198
     199#else /* Q_WS_X11 */
     200
     201    /* This method could be called before parent-widget
     202     * become visible, we should skip everything in that case: */
     203    if (QApplication::desktop()->screenNumber(parentWidget()) == -1)
     204        return;
     205
     206    /* Determine host-screen number if necessary: */
     207    bool fMoveToHostScreen = true;
     208    if (iHostScreen == -1)
     209    {
     210        fMoveToHostScreen = false;
     211        iHostScreen = QApplication::desktop()->screenNumber(this);
     212    }
     213
     214    /* Choose window geometry: */
     215    QRect screenRect;
     216    switch (m_geometryType)
     217    {
     218        case GeometryType_Available: screenRect = QApplication::desktop()->availableGeometry(iHostScreen); break;
     219        case GeometryType_Full:      screenRect = QApplication::desktop()->screenGeometry(iHostScreen); break;
     220        default: break;
     221    }
     222
     223    /* Move to corresponding host-screen: */
     224    if (fMoveToHostScreen)
     225        move(screenRect.topLeft());
     226
     227    /* Resize embedded-toolbar to minimum size: */
     228    m_pEmbeddedToolbar->resize(m_pEmbeddedToolbar->sizeHint());
     229
     230    /* Calculate embedded-toolbar position: */
     231    int iX = 0, iY = 0;
     232    iX = screenRect.width() / 2 - m_pEmbeddedToolbar->width() / 2;
     233    switch (m_alignment)
     234    {
     235        case Qt::AlignTop:    iY = 0; break;
     236        case Qt::AlignBottom: iY = screenRect.height() - m_pEmbeddedToolbar->height(); break;
     237        default: break;
     238    }
     239
     240    /* Update auto-hide animation: */
     241    m_shownToolbarPosition = QPoint(iX, iY);
     242    switch (m_alignment)
     243    {
     244        case Qt::AlignTop:    m_hiddenToolbarPosition = m_shownToolbarPosition - QPoint(0, m_pEmbeddedToolbar->height() - 3); break;
     245        case Qt::AlignBottom: m_hiddenToolbarPosition = m_shownToolbarPosition + QPoint(0, m_pEmbeddedToolbar->height() - 3); break;
     246    }
     247    m_pAnimation->update();
     248
     249    /* Update embedded-toolbar geometry if known: */
     250    const QString strAnimationState = property("AnimationState").toString();
     251    if (strAnimationState == "Start")
     252        m_pEmbeddedToolbar->move(m_hiddenToolbarPosition);
     253    else if (strAnimationState == "Final")
     254        m_pEmbeddedToolbar->move(m_shownToolbarPosition);
     255
     256    /* Adjust window mask: */
     257    setMask(m_pEmbeddedToolbar->geometry());
     258
     259    /* Simulate toolbar auto-hiding: */
     260    simulateToolbarAutoHiding();
     261#endif /* Q_WS_X11 */
    204262}
    205263
     
    238296void UIRuntimeMiniToolBar::prepare()
    239297{
    240 #ifdef Q_WS_MAC
     298#if defined(Q_WS_MAC) || defined (Q_WS_X11)
    241299    /* Install own event filter: */
    242300    installEventFilter(this);
    243 #endif /* Q_WS_MAC */
     301#endif /* Q_WS_MAC || Q_WS_X11 */
    244302
    245303#if defined(Q_WS_MAC) || defined(Q_WS_WIN)
     
    259317    setAttribute(Qt::WA_TranslucentBackground);
    260318# endif /* Q_WS_WIN */
    261 #endif /* Q_WS_MAC || Q_WS_WIN */
     319#elif defined(Q_WS_X11)
     320    /* Use Qt API to enable translucency if allowed: */
     321    if (QX11Info::isCompositingManagerRunning())
     322        setAttribute(Qt::WA_TranslucentBackground);
     323#endif /* Q_WS_X11 */
    262324
    263325    /* Make sure we have no focus: */
     
    378440}
    379441
     442#ifdef Q_WS_X11
     443void UIRuntimeMiniToolBar::resizeEvent(QResizeEvent*)
     444{
     445    /* Adjust mini-toolbar on resize: */
     446    adjustGeometry();
     447}
     448#endif /* Q_WS_X11 */
     449
    380450bool UIRuntimeMiniToolBar::eventFilter(QObject *pWatched, QEvent *pEvent)
    381451{
     
    388458        pEvent->type() == QEvent::FocusIn)
    389459        emit sigNotifyAboutFocusStolen();
    390 #elif defined(Q_WS_MAC)
    391     /* Due to Qt bug on Mac OS X window will be activated
    392      * even if has Qt::WA_ShowWithoutActivating attribute. */
     460#elif defined(Q_WS_MAC) || defined(Q_WS_X11)
     461    /* Detect if we have window activation stolen. */
    393462    if (pWatched == this &&
    394463        pEvent->type() == QEvent::WindowActivate)
    395464        emit sigNotifyAboutFocusStolen();
    396 #endif /* Q_WS_MAC */
     465#endif /* Q_WS_MAC || Q_WS_X11 */
    397466
    398467    /* Call to base-class: */
     
    423492    /* Update window mask: */
    424493    setMask(m_pEmbeddedToolbar->geometry());
    425 
    426 # ifdef VBOX_WITH_MASKED_SEAMLESS
    427     /* Notify listeners as well: */
    428     const QRect windowGeo = geometry();
    429     emit sigNotifyAboutGeometryChange(windowGeo.intersected(m_pEmbeddedToolbar->geometry().translated(windowGeo.topLeft())));
    430 # endif /* VBOX_WITH_MASKED_SEAMLESS */
    431494#endif /* Q_WS_X11 */
    432495}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIMiniToolBar.h

    r52872 r52891  
    6464    void sigNotifyAboutFocusStolen();
    6565
    66 #ifdef VBOX_WITH_MASKED_SEAMLESS
    67 # ifdef Q_WS_X11
    68     /** Notifies about geometry change. */
    69     void sigNotifyAboutGeometryChange(const QRect &geo);
    70 # endif /* Q_WS_X11 */
    71 #endif /* VBOX_WITH_MASKED_SEAMLESS */
    72 
    7366public:
    7467
     
    118111    void enterEvent(QEvent *pEvent);
    119112    void leaveEvent(QEvent *pEvent);
     113
     114#ifdef Q_WS_X11
     115    /** X11: Resize event handler. */
     116    void resizeEvent(QResizeEvent *pEvent);
     117#endif /* Q_WS_X11 */
    120118
    121119    /** Filters @a pEvent if <i>this</i> object has been
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