utils: Provide size hints in native pixels

This is mainly to make the Xcb utils api consistent.
This commit is contained in:
Vlad Zahorodnii 2024-07-10 15:33:21 +03:00
parent 95f56399b8
commit ddfb26fc8e
3 changed files with 24 additions and 27 deletions

View file

@ -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;

View file

@ -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
{

View file

@ -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());
}
/**