feat(application): add the restore size window hint

pull/18/head
reionwong 3 weeks ago
parent 5d6cb96456
commit 7b4f78546a

@ -44,6 +44,11 @@ private slots:
hints->setRestoreId(QStringLiteral("preview"));
hints->setRestoreId(QStringLiteral("preview"));
QCOMPARE(restoreIdChanged.count(), 1);
QVERIFY(hints->restoreSize().isEmpty());
QSignalSpy restoreSizeChanged(hints, &Cutefish::WindowHints::restoreSizeChanged);
hints->setRestoreSize(QSize(300, 200));
hints->setRestoreSize(QSize(300, 200));
QCOMPARE(restoreSizeChanged.count(), 1);
QVERIFY(!hints->interactiveResize());
window.create();
window.destroy();
@ -53,6 +58,7 @@ private slots:
QVERIFY(hints->resizeAroundCenter());
QVERIFY(hints->serverResize());
QCOMPARE(hints->restoreId(), QStringLiteral("preview"));
QCOMPARE(hints->restoreSize(), QSize(300, 200));
}
void qmlAndCppShareHintsAcrossSurfaceRecreation()

@ -3,6 +3,7 @@
#include <QGuiApplication>
#include <QtGui/qguiapplication_platform.h>
#include <wayland-client.h>
#include <algorithm>
#include <cstring>
#include "cutefish-window-hints-v1-client-protocol.h"
@ -115,4 +116,13 @@ void WaylandWindowHints::setRestoreId(wl_surface *surface, const QString &id)
flushDisplay();
}
void WaylandWindowHints::setRestoreSize(wl_surface *surface, const QSize &size)
{
if (!m_manager || !surface)
return;
cutefish_window_hints_v1_set_restore_size(m_manager, surface, std::max(size.width(), 0),
std::max(size.height(), 0));
flushDisplay();
}
} // namespace Cutefish

@ -2,6 +2,7 @@
#define CUTEFISH_WAYLANDWINDOWHINTS_P_H
#include <QObject>
#include <QSize>
#include <cstdint>
struct wl_registry;
@ -25,6 +26,7 @@ public:
void setResizeAroundCenter(wl_surface *surface, bool center);
void setServerResize(wl_surface *surface, bool enabled);
void setRestoreId(wl_surface *surface, const QString &id);
void setRestoreSize(wl_surface *surface, const QSize &size);
Q_SIGNALS:
void availableChanged();

@ -85,6 +85,15 @@ void WindowHints::setRestoreId(const QString &id)
Q_EMIT restoreIdChanged();
}
void WindowHints::setRestoreSize(const QSize &size)
{
if (m_restoreSize == size)
return;
m_restoreSize = size;
apply();
Q_EMIT restoreSizeChanged();
}
void WindowHints::setInteractiveResize(bool active)
{
if (m_interactiveResize == active)
@ -158,6 +167,7 @@ void WindowHints::apply()
WaylandWindowHints::instance()->setResizeAroundCenter(surface, m_resizeAroundCenter);
WaylandWindowHints::instance()->setServerResize(surface, m_serverResize);
WaylandWindowHints::instance()->setRestoreId(surface, m_restoreId);
WaylandWindowHints::instance()->setRestoreSize(surface, m_restoreSize);
}
} // namespace Cutefish

@ -23,6 +23,9 @@ class WindowHints : public QObject
// Non-empty: the window reopens where the last one with this id was left,
// for the rest of the session. Set it before the window is first shown.
Q_PROPERTY(QString restoreId READ restoreId WRITE setRestoreId NOTIFY restoreIdChanged)
// The size a window first shown maximized or full screen returns to.
// Set it before the window is first shown.
Q_PROPERTY(QSize restoreSize READ restoreSize WRITE setRestoreSize NOTIFY restoreSizeChanged)
// True while the user resizes the window by an edge or corner.
Q_PROPERTY(bool interactiveResize READ interactiveResize NOTIFY interactiveResizeChanged)
Q_PROPERTY(bool available READ available NOTIFY availableChanged)
@ -42,6 +45,8 @@ public:
void setServerResize(bool enabled);
QString restoreId() const { return m_restoreId; }
void setRestoreId(const QString &id);
QSize restoreSize() const { return m_restoreSize; }
void setRestoreSize(const QSize &size);
bool interactiveResize() const { return m_interactiveResize; }
bool available() const;
@ -51,6 +56,7 @@ Q_SIGNALS:
void resizeAroundCenterChanged();
void serverResizeChanged();
void restoreIdChanged();
void restoreSizeChanged();
void interactiveResizeChanged();
void availableChanged();
@ -71,6 +77,7 @@ private:
bool m_resizeAroundCenter = false;
bool m_serverResize = false;
QString m_restoreId;
QSize m_restoreSize;
bool m_interactiveResize = false;
bool m_surfaceDying = false;
};

@ -73,6 +73,20 @@
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="id" type="string"/>
</request>
<request name="set_restore_size">
<description summary="the size a window first shown maximized returns to">
When a window maps maximized or fullscreen, the compositor has no
normal size of its own to return it to. A non-empty size, in surface
coordinates, makes such a window return to a window geometry of this
size when it leaves that state, placed as a normal window of that size
mapping at the same time would have been. Set it before the first
commit. 0x0 is the default and leaves the choice to the compositor; a
negative width or height is an invalid_value error.
</description>
<arg name="surface" type="object" interface="wl_surface"/>
<arg name="width" type="int"/>
<arg name="height" type="int"/>
</request>
<event name="interactive_resize">
<description summary="an interactive resize started or ended">
Sent with active 1 when the user starts resizing one of the client's

Loading…
Cancel
Save