VirtualBox

Ticket #15863: setGeometry.patch

File setGeometry.patch, 9.4 KB (added by Michael Thayer, 8 years ago)

Second try at a fix

  • src/VBox/Frontends/VirtualBox/src/extensions/QIMainWindow.cpp

     
    2121
    2222/* GUI includes: */
    2323# include "QIMainWindow.h"
     24# include "VBoxGlobal.h"
    2425
    2526#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2627
     
    3839    resize(m_geometry.size());
    3940#else /* VBOX_WS_MAC */
    4041    /* Use the new approach for Windows/X11: */
    41     setGeometry(m_geometry);
     42    VBoxGlobal::setTopLevelGeometry(this, m_geometry);
    4243#endif /* !VBOX_WS_MAC */
    4344
    4445    /* Maximize (if necessary): */
  • src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

     
    3636# include <QDir>
    3737# include <QLocale>
    3838# include <QSpinBox>
     39# include <QMainWindow>
    3940# ifdef VBOX_WS_WIN
    4041#  include <QEventLoop>
    4142# endif /* VBOX_WS_WIN */
     
    4950# endif /* VBOX_GUI_WITH_PIDFILE */
    5051# if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
    5152#  include <QScreen>
     53#  include <xcb/xcb.h>
     54#  include <xcb/xcb_icccm.h>
    5255# endif /* VBOX_WS_X11 && QT_VERSION >= 0x050000 */
    5356
    5457/* GUI includes: */
     
    37023705    pSpinBox->setMinimumWidth(iTextWidth + iSpinBoxDelta);
    37033706}
    37043707
     3708/* static */
     3709void VBoxGlobal::setTopLevelGeometry(QMainWindow *window, int x, int y, int w, int h)
     3710{
     3711#if defined(VBOX_WS_X11) && QT_VERSION >= 0x050000
     3712# define QWINDOWSIZE_MAX ((1<<24)-1)
     3713    if (window->isVisible())
     3714    {
     3715        /* X11 window managers are not required to accept geometry changes on
     3716         * the top-level window.  Unfortunately, current at Qt 5.6 and 5.7, Qt
     3717         * assumes that the change will succeed, and resizes all sub-windows
     3718         * unconditionally.  By calling ConfigureWindow directly, Qt will see
     3719         * our change request as an externally triggered one on success and not
     3720         * at all if it is rejected. */
     3721        uint16_t fMask =   XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
     3722                         | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
     3723        uint32_t values[] = { (uint32_t)x, (uint32_t)y, (uint32_t)w, (uint32_t)h };
     3724        xcb_configure_window(QX11Info::connection(), (xcb_window_t)window->winId(),
     3725                             fMask, values);
     3726        xcb_size_hints_t hints;
     3727        hints.flags = XCB_ICCCM_SIZE_HINT_US_POSITION | XCB_ICCCM_SIZE_HINT_US_SIZE;
     3728        hints.x          = x;
     3729        hints.y          = y;
     3730        hints.width      = w;
     3731        hints.height     = h;
     3732        hints.min_width  = window->minimumSize().width();
     3733        hints.min_height = window->minimumSize().height();
     3734        hints.max_width  = window->maximumSize().width();
     3735        hints.max_height = window->maximumSize().height();
     3736        if (hints.min_width > 0 && hints.min_height > 0)
     3737            hints.flags |= XCB_ICCCM_SIZE_HINT_P_MIN_SIZE;
     3738        if (hints.max_width < QWINDOWSIZE_MAX && hints.max_height < QWINDOWSIZE_MAX)
     3739            hints.flags |= XCB_ICCCM_SIZE_HINT_P_MAX_SIZE;
     3740        xcb_change_property(QX11Info::connection(), XCB_PROP_MODE_REPLACE,
     3741                            (xcb_window_t)window->winId(), XCB_ATOM_WM_NORMAL_HINTS,
     3742                            XCB_ATOM_WM_SIZE_HINTS, 32, sizeof(hints) >> 2, &hints);
     3743        xcb_flush(QX11Info::connection());
     3744    }
     3745    else
     3746        /* Call the Qt method if the window is not visible as otherwise no
     3747         * Configure event will arrive to tell Qt what geometry we want. */
     3748        window->setGeometry(x, y, w, h);
     3749# else
     3750    window->setGeometry(x, y, w, h);
     3751# endif
     3752}
     3753
     3754/* static */
     3755void VBoxGlobal::setTopLevelGeometry(QMainWindow *window, QRect rect)
     3756{
     3757    VBoxGlobal::setTopLevelGeometry(window, rect.x(), rect.y(), rect.width(), rect.height());
     3758}
     3759
    37053760// Public slots
    37063761////////////////////////////////////////////////////////////////////////////////
    37073762
  • src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

     
    2626#include <QHash>
    2727#include <QFileIconProvider>
    2828#include <QReadWriteLock>
     29# include <QMainWindow>
    2930#ifdef VBOX_WS_MAC
    3031# include <QSet>
    3132#endif /* VBOX_WS_MAC */
     
    442443     * to strict the minimum width to reflect at least [n] symbols. */
    443444    static void setMinimumWidthAccordingSymbolCount(QSpinBox *pSpinBox, int cCount);
    444445
     446    /** Set top-level window geometry, taking into account that this may fail
     447     * on X11. */
     448    static void setTopLevelGeometry(QMainWindow *window, int x, int y, int w, int h);
     449    static void setTopLevelGeometry(QMainWindow *window, QRect rect);
     450
    445451signals:
    446452
    447453    /** Notifies listeners about the VBoxSVC availability change. */
  • src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineWindowFullscreen.cpp

     
    350350            geo = QRect(QPoint(0, 0), QSize(800, 600).boundedTo(workingArea.size()));
    351351        /* Move window to the center of working-area: */
    352352        geo.moveCenter(workingArea.center());
    353         setGeometry(geo);
     353        VBoxGlobal::setTopLevelGeometry(this, geo);
    354354    }
    355355
    356356#elif defined(VBOX_WS_WIN)
  • src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp

     
    371371            {
    372372                /* Restore window geometry: */
    373373                m_normalGeometry = geo;
    374                 setGeometry(m_normalGeometry);
     374                VBoxGlobal::setTopLevelGeometry(this, m_normalGeometry);
    375375            }
    376376            /* If previous machine-state was NOT SAVED: */
    377377            else
     
    378378            {
    379379                /* Restore only window position: */
    380380                m_normalGeometry = QRect(geo.x(), geo.y(), width(), height());
    381                 setGeometry(m_normalGeometry);
     381                VBoxGlobal::setTopLevelGeometry(this, m_normalGeometry);
    382382                /* And normalize to the optimal-size: */
    383383                normalizeGeometry(false /* adjust position */);
    384384            }
     
    400400            /* Move newly created window to the screen-center: */
    401401            m_normalGeometry = geometry();
    402402            m_normalGeometry.moveCenter(availableGeo.center());
    403             setGeometry(m_normalGeometry);
     403            VBoxGlobal::setTopLevelGeometry(this, m_normalGeometry);
    404404        }
    405405
    406406        /* Normalize to the optimal size: */
     
    574574        frGeo = VBoxGlobal::normalizeGeometry(frGeo, gpDesktop->overallAvailableRegion());
    575575
    576576    /* Finally, set the frame geometry: */
    577     setGeometry(frGeo.left() + dl, frGeo.top() + dt,
    578                 frGeo.width() - dl - dr, frGeo.height() - dt - db);
     577    VBoxGlobal::setTopLevelGeometry(this, frGeo.left() + dl, frGeo.top() + dt,
     578                                    frGeo.width() - dl - dr, frGeo.height() - dt - db);
    579579#else /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
    580580    /* Customer request: There should no be
    581581     * machine-window resize/move on machine-view resize: */
  • src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineWindowScale.cpp

     
    101101        {
    102102            /* Restore window geometry: */
    103103            m_normalGeometry = geo;
    104             setGeometry(m_normalGeometry);
     104            VBoxGlobal::setTopLevelGeometry(this, m_normalGeometry);
    105105
    106106            /* Maximize (if necessary): */
    107107            if (gEDataManager->machineWindowShouldBeMaximized(machineLogic()->visualStateType(),
     
    120120            /* Move newly created window to the screen-center: */
    121121            m_normalGeometry = geometry();
    122122            m_normalGeometry.moveCenter(availableGeo.center());
    123             setGeometry(m_normalGeometry);
     123            VBoxGlobal::setTopLevelGeometry(this, m_normalGeometry);
    124124        }
    125125
    126126        /* Normalize to the optimal size: */
     
    201201        frGeo = VBoxGlobal::normalizeGeometry(frGeo, gpDesktop->overallAvailableRegion());
    202202
    203203    /* Finally, set the frame geometry: */
    204     setGeometry(frGeo.left() + dl, frGeo.top() + dt,
    205                 frGeo.width() - dl - dr, frGeo.height() - dt - db);
     204    VBoxGlobal::setTopLevelGeometry(this, frGeo.left() + dl, frGeo.top() + dt,
     205                                    frGeo.width() - dl - dr, frGeo.height() - dt - db);
    206206#else /* VBOX_GUI_WITH_CUSTOMIZATIONS1 */
    207207    /* Customer request: There should no be
    208208     * machine-window resize/move on machine-view resize: */

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette