feat(application): add WindowHints.resizeAroundCenter

pull/18/head
reionwong 4 weeks ago
parent af93f6280f
commit 2f3d718714

@ -29,11 +29,17 @@ private slots:
hints->setAlwaysOnTop(true);
hints->setAlwaysOnTop(true);
QCOMPARE(onTopChanged.count(), 1);
QVERIFY(!hints->resizeAroundCenter());
QSignalSpy anchorChanged(hints, &Cutefish::WindowHints::resizeAroundCenterChanged);
hints->setResizeAroundCenter(true);
hints->setResizeAroundCenter(true);
QCOMPARE(anchorChanged.count(), 1);
window.create();
window.destroy();
window.create();
QVERIFY(hints->skipTaskbar());
QVERIFY(hints->alwaysOnTop());
QVERIFY(hints->resizeAroundCenter());
}
void qmlAndCppShareHintsAcrossSurfaceRecreation()
@ -49,6 +55,7 @@ private slots:
height: 80
WindowHints.skipTaskbar: true
WindowHints.alwaysOnTop: true
WindowHints.resizeAroundCenter: true
property bool skipped: WindowHints.skipTaskbar
property bool onTop: WindowHints.alwaysOnTop
}
@ -67,6 +74,7 @@ private slots:
QVERIFY(QTest::qWaitForWindowExposed(window));
QVERIFY(hints->skipTaskbar());
QVERIFY(hints->alwaysOnTop());
QVERIFY(hints->resizeAroundCenter());
hints->setSkipTaskbar(false);
QCOMPARE(object->property("skipped").toBool(), false);
hints->setAlwaysOnTop(false);

@ -77,4 +77,15 @@ void WaylandWindowHints::setAlwaysOnTop(wl_surface *surface, bool alwaysOnTop)
wl_display_flush(native->display());
}
void WaylandWindowHints::setResizeAroundCenter(wl_surface *surface, bool center)
{
if (!m_manager || !surface)
return;
cutefish_window_hints_v1_set_resize_anchor(m_manager, surface,
center ? CUTEFISH_WINDOW_HINTS_V1_RESIZE_ANCHOR_CENTER
: CUTEFISH_WINDOW_HINTS_V1_RESIZE_ANCHOR_TOP_LEFT);
auto *native = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
wl_display_flush(native->display());
}
} // namespace Cutefish

@ -20,6 +20,7 @@ public:
bool available() const { return m_manager != nullptr; }
void setSkipTaskbar(wl_surface *surface, bool skip);
void setAlwaysOnTop(wl_surface *surface, bool alwaysOnTop);
void setResizeAroundCenter(wl_surface *surface, bool center);
Q_SIGNALS:
void availableChanged();

@ -53,6 +53,15 @@ void WindowHints::setAlwaysOnTop(bool alwaysOnTop)
Q_EMIT alwaysOnTopChanged();
}
void WindowHints::setResizeAroundCenter(bool center)
{
if (m_resizeAroundCenter == center)
return;
m_resizeAroundCenter = center;
apply();
Q_EMIT resizeAroundCenterChanged();
}
bool WindowHints::available() const
{
return m_window && WaylandWindowHints::instance()->available();
@ -102,6 +111,7 @@ void WindowHints::apply()
native->nativeResourceForWindow(QByteArrayLiteral("surface"), m_window));
WaylandWindowHints::instance()->setSkipTaskbar(surface, m_skipTaskbar);
WaylandWindowHints::instance()->setAlwaysOnTop(surface, m_alwaysOnTop);
WaylandWindowHints::instance()->setResizeAroundCenter(surface, m_resizeAroundCenter);
}
} // namespace Cutefish

@ -13,6 +13,9 @@ class WindowHints : public QObject
Q_OBJECT
Q_PROPERTY(bool skipTaskbar READ skipTaskbar WRITE setSkipTaskbar NOTIFY skipTaskbarChanged)
Q_PROPERTY(bool alwaysOnTop READ alwaysOnTop WRITE setAlwaysOnTop NOTIFY alwaysOnTopChanged)
// When the window resizes itself, keep its centre rather than its top-left corner.
Q_PROPERTY(bool resizeAroundCenter READ resizeAroundCenter WRITE setResizeAroundCenter
NOTIFY resizeAroundCenterChanged)
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
public:
@ -24,11 +27,14 @@ public:
void setSkipTaskbar(bool skip);
bool alwaysOnTop() const { return m_alwaysOnTop; }
void setAlwaysOnTop(bool alwaysOnTop);
bool resizeAroundCenter() const { return m_resizeAroundCenter; }
void setResizeAroundCenter(bool center);
bool available() const;
Q_SIGNALS:
void skipTaskbarChanged();
void alwaysOnTopChanged();
void resizeAroundCenterChanged();
void availableChanged();
protected:
@ -43,6 +49,7 @@ private:
QMetaObject::Connection m_destroyedConnection;
bool m_skipTaskbar = false;
bool m_alwaysOnTop = false;
bool m_resizeAroundCenter = false;
bool m_surfaceDying = false;
};

@ -9,7 +9,11 @@
These hints grant no focus or privileged shell role.
</description>
<enum name="error">
<entry name="invalid_value" value="0" summary="expected a boolean"/>
<entry name="invalid_value" value="0" summary="a value is out of range"/>
</enum>
<enum name="resize_anchor">
<entry name="top_left" value="0" summary="the top-left corner stays put"/>
<entry name="center" value="1" summary="the centre stays put"/>
</enum>
<request name="destroy" type="destructor"/>
<request name="set_skip_taskbar">
@ -32,5 +36,17 @@
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="on_top" type="uint"/>
</request>
<request name="set_resize_anchor">
<description summary="choose the point a client resize keeps in place">
When the client changes the size of a normal window on its own, with a
new buffer or window geometry rather than in answer to a configure, the
compositor keeps this point of the window where it was and then keeps
the window inside the work area. Resizes the compositor initiates,
interactive resizes and maximized, fullscreen or tiled windows are
unaffected. top_left is the default.
</description>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="anchor" type="uint" enum="resize_anchor"/>
</request>
</interface>
</protocol>

Loading…
Cancel
Save