From ddfb26fc8e5ac0386c8bed506be32146253167a3 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 10 Jul 2024 15:33:21 +0300 Subject: [PATCH] utils: Provide size hints in native pixels This is mainly to make the Xcb utils api consistent. --- autotests/test_xcb_size_hints.cpp | 8 ++++---- src/utils/xcbutils.h | 21 +++++++++------------ src/x11window.cpp | 22 +++++++++++----------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/autotests/test_xcb_size_hints.cpp b/autotests/test_xcb_size_hints.cpp index be84516eb3..f26540ab48 100644 --- a/autotests/test_xcb_size_hints.cpp +++ b/autotests/test_xcb_size_hints.cpp @@ -187,12 +187,12 @@ void TestXcbSizeHints::testSizeHints() QCOMPARE(geoHints.hasResizeIncrements(), resizeInc.isValid()); QCOMPARE(geoHints.hasSize(), userSize.isValid()); QCOMPARE(geoHints.hasWindowGravity(), gravity != 0); - QTEST(geoHints.baseSize().toSize(), "expectedBaseSize"); + QTEST(geoHints.baseSize(), "expectedBaseSize"); QTEST(geoHints.maxAspect(), "expectedMaxAspect"); - QTEST(geoHints.maxSize().toSize(), "expectedMaxSize"); + QTEST(geoHints.maxSize(), "expectedMaxSize"); QTEST(geoHints.minAspect(), "expectedMinAspect"); - QTEST(geoHints.minSize().toSize(), "expectedMinSize"); - QTEST(geoHints.resizeIncrements().toSize(), "expectedResizeIncrements"); + QTEST(geoHints.minSize(), "expectedMinSize"); + QTEST(geoHints.resizeIncrements(), "expectedResizeIncrements"); QTEST(qint32(geoHints.windowGravity()), "expectedGravity"); auto sizeHints = geoHints.m_sizeHints; diff --git a/src/utils/xcbutils.h b/src/utils/xcbutils.h index b5981d5b96..3b06390518 100644 --- a/src/utils/xcbutils.h +++ b/src/utils/xcbutils.h @@ -1012,38 +1012,35 @@ public: { return testFlag(NormalHints::SizeHints::WindowGravity); } - QSizeF maxSize() const + QSize maxSize() const { if (!hasMaxSize()) { return QSize(INT_MAX, INT_MAX); } - const QSize size(std::max(m_sizeHints->maxWidth, 1), std::max(m_sizeHints->maxHeight, 1)); - return fromXNative(size); + return QSize(std::max(m_sizeHints->maxWidth, 1), std::max(m_sizeHints->maxHeight, 1)); } - QSizeF minSize() const + QSize minSize() const { if (!hasMinSize()) { // according to ICCCM 4.1.23 base size should be used as a fallback return baseSize(); } - const QSize size(m_sizeHints->minWidth, m_sizeHints->minHeight); - return fromXNative(size); + return QSize(m_sizeHints->minWidth, m_sizeHints->minHeight); } - QSizeF baseSize() const + QSize baseSize() const { // Note: not using minSize as fallback if (!hasBaseSize()) { return QSize(0, 0); } - const QSize size(m_sizeHints->baseWidth, m_sizeHints->baseHeight); - return fromXNative(size); + return QSize(m_sizeHints->baseWidth, m_sizeHints->baseHeight); } - QSizeF resizeIncrements() const + QSize resizeIncrements() const { if (!hasResizeIncrements()) { - return fromXNative(QSize(1, 1)); + return QSize(1, 1); } - return Xcb::fromXNative(QSize(std::max(m_sizeHints->widthInc, 1), std::max(m_sizeHints->heightInc, 1))); + return QSize(std::max(m_sizeHints->widthInc, 1), std::max(m_sizeHints->heightInc, 1)); } xcb_gravity_t windowGravity() const { diff --git a/src/x11window.cpp b/src/x11window.cpp index b82dfbc4f2..feee869c20 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -3003,7 +3003,7 @@ bool X11Window::belongsToSameApplication(const Window *other, SameApplicationChe QSizeF X11Window::resizeIncrements() const { - return m_geometryHints.resizeIncrements(); + return Xcb::fromXNative(m_geometryHints.resizeIncrements()); } Xcb::StringProperty X11Window::fetchApplicationMenuServiceName() const @@ -3711,13 +3711,13 @@ QSizeF X11Window::constrainClientSize(const QSizeF &size, SizeMode mode) const return QSizeF(w, h); } - qreal width_inc = m_geometryHints.resizeIncrements().width(); - qreal height_inc = m_geometryHints.resizeIncrements().height(); - qreal basew_inc = m_geometryHints.baseSize().width(); - qreal baseh_inc = m_geometryHints.baseSize().height(); + qreal width_inc = Xcb::fromXNative(m_geometryHints.resizeIncrements()).width(); + qreal height_inc = Xcb::fromXNative(m_geometryHints.resizeIncrements()).height(); + qreal basew_inc = Xcb::fromXNative(m_geometryHints.baseSize()).width(); + qreal baseh_inc = Xcb::fromXNative(m_geometryHints.baseSize()).height(); if (!m_geometryHints.hasBaseSize()) { - basew_inc = m_geometryHints.minSize().width(); - baseh_inc = m_geometryHints.minSize().height(); + basew_inc = Xcb::fromXNative(m_geometryHints.minSize()).width(); + baseh_inc = Xcb::fromXNative(m_geometryHints.minSize()).height(); } w = std::floor((w - basew_inc) / width_inc) * width_inc + basew_inc; @@ -3746,7 +3746,7 @@ QSizeF X11Window::constrainClientSize(const QSizeF &size, SizeMode mode) const // According to ICCCM 4.1.2.3 PMinSize should be a fallback for PBaseSize for size increments, // but not for aspect ratio. Since this code comes from FVWM, handles both at the same time, // and I have no idea how it works, let's hope nobody relies on that. - const QSizeF baseSize = m_geometryHints.baseSize(); + const QSizeF baseSize = Xcb::fromXNative(m_geometryHints.baseSize()); w -= baseSize.width(); h -= baseSize.height(); qreal max_width = max_size.width() - baseSize.width(); @@ -3881,12 +3881,12 @@ void X11Window::getWmNormalHints() QSizeF X11Window::minSize() const { - return rules()->checkMinSize(m_geometryHints.minSize()); + return rules()->checkMinSize(Xcb::fromXNative(m_geometryHints.minSize())); } QSizeF X11Window::maxSize() const { - return rules()->checkMaxSize(m_geometryHints.maxSize()); + return rules()->checkMaxSize(Xcb::fromXNative(m_geometryHints.maxSize())); } QSizeF X11Window::basicUnit() const @@ -3895,7 +3895,7 @@ QSizeF X11Window::basicUnit() const if (!isX11Mode) { return QSize(1, 1); } - return m_geometryHints.resizeIncrements(); + return Xcb::fromXNative(m_geometryHints.resizeIncrements()); } /**