Compare commits

..

2 Commits

Author SHA1 Message Date
9fe00051e0 debug++ 2024-04-08 11:49:36 +01:00
c51ab381da deferred apply
When we get a configure event defer applying it until all pending
callbacks are processsed. This ensures we only only process configure
events that match the last thing we requested.
2024-04-08 11:42:08 +01:00
8 changed files with 86 additions and 56 deletions

View File

@ -7,6 +7,3 @@ Dependencies:
'frameworks/extra-cmake-modules': '@latest-kf6'
'third-party/wayland': '@latest'
'third-party/wayland-protocols': '@latest'
Options:
require-passing-tests-on: ['Linux', 'FreeBSD', 'Windows']

View File

@ -4,13 +4,13 @@
cmake_minimum_required(VERSION 3.16)
project(layershellqt)
set(PROJECT_VERSION "6.1.5")
set(PROJECT_VERSION "6.0.80")
set(PROJECT_VERSION_MAJOR 6)
set(CMAKE_C_STANDARD 99)
set(QT_MIN_VERSION "6.6.0")
set(KF6_MIN_VERSION "6.2.0")
set(KF6_MIN_VERSION "6.0.0")
set(KDE_COMPILERSETTINGS_LEVEL "5.82")
set(CMAKE_CXX_STANDARD 20)
@ -31,7 +31,7 @@ include(GenerateExportHeader)
include(KDEClangFormat)
include(ECMQtDeclareLoggingCategory)
include(ECMQmlModule)
include(KDEGitCommitHooks)
find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient Qml)
find_package(WaylandScanner REQUIRED)
@ -53,8 +53,6 @@ ecm_setup_version(${PROJECT_VERSION} VARIABLE_PREFIX LAYERSHELLQT
file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h)
kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES})
kde_configure_git_pre_commit_hook(CHECKS CLANG_FORMAT)
ecm_set_disabled_deprecation_versions(QT 6.5
KF 5.240
)

View File

@ -4,47 +4,20 @@
* SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "../interfaces/window.h"
#include <QQmlExtensionPlugin>
#include "../interfaces/window.h"
#include <qqml.h>
QML_DECLARE_TYPEINFO(LayerShellQt::Window, QML_HAS_ATTACHED_PROPERTIES)
class ExtQMargins
{
QMargins m_margins;
Q_GADGET
Q_PROPERTY(int left READ left WRITE setLeft FINAL)
Q_PROPERTY(int right READ right WRITE setRight FINAL)
Q_PROPERTY(int top READ top WRITE setTop FINAL)
Q_PROPERTY(int bottom READ bottom WRITE setBottom FINAL)
QML_FOREIGN(QMargins)
QML_EXTENDED(ExtQMargins)
public:
ExtQMargins(const QMargins &margins);
int left() const { return m_margins.left(); }
void setLeft(int left) { m_margins.setLeft(left); }
int right() const { return m_margins.right(); }
void setRight(int right) { m_margins.setRight(right); }
int top() const { return m_margins.top(); }
void setTop(int top) { m_margins.setTop(top); }
int bottom() const { return m_margins.bottom(); }
void setBottom(int bottom) { m_margins.setBottom(bottom); }
};
class Plugin : public QQmlExtensionPlugin
{
Q_PLUGIN_METADATA(IID "org.kde.layershellqt")
Q_OBJECT
public:
void registerTypes(const char *uri) override
{
void registerTypes(const char *uri) override {
Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.layershell"));
qmlRegisterType<LayerShellQt::Window>(uri, 1, 0, "Window");
qmlRegisterExtendedUncreatableType<QMargins, ExtQMargins>(uri, 1, 0, "ExtQMargins", QStringLiteral("Only created from C++"));
}
};

View File

@ -32,4 +32,5 @@ QtWaylandClient::QWaylandShellSurface *QWaylandLayerShellIntegration::createShel
return new QWaylandLayerSurface(this, window);
}
}

View File

@ -18,19 +18,14 @@ class QWaylandXdgActivationV1;
namespace LayerShellQt
{
class LAYERSHELLQT_EXPORT QWaylandLayerShellIntegration : public QtWaylandClient::QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>,
public QtWayland::zwlr_layer_shell_v1
class LAYERSHELLQT_EXPORT QWaylandLayerShellIntegration : public QtWaylandClient::QWaylandShellIntegrationTemplate<QWaylandLayerShellIntegration>, public QtWayland::zwlr_layer_shell_v1
{
public:
QWaylandLayerShellIntegration();
~QWaylandLayerShellIntegration() override;
QWaylandXdgActivationV1 *activation() const
{
return m_xdgActivation.data();
}
QWaylandXdgActivationV1 *activation() const { return m_xdgActivation.data(); }
QtWaylandClient::QWaylandShellSurface *createShellSurface(QtWaylandClient::QWaylandWindow *window) override;
private:
QScopedPointer<QWaylandXdgActivationV1> m_xdgActivation;
};

View File

@ -67,10 +67,15 @@ QWaylandLayerSurface::QWaylandLayerSurface(QWaylandLayerShellIntegration *shell,
});
setDesiredSize(window->windowContentGeometry().size());
requestWaylandSync();
}
QWaylandLayerSurface::~QWaylandLayerSurface()
{
for (auto syncCallback: m_waitForSyncCallbacks) {
wl_callback_destroy(syncCallback);
}
m_waitForSyncCallbacks.clear();
destroy();
}
@ -83,9 +88,17 @@ void QWaylandLayerSurface::zwlr_layer_surface_v1_closed()
void QWaylandLayerSurface::zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height)
{
qDebug() << "got configure";
ack_configure(serial);
m_pendingSize = QSize(width, height);
// because configure lacks a way to match it up with our resize requests
// we apply it only when our callback sync is complete
if (!m_waitForSyncCallbacks.isEmpty()) {
m_hasPendingConfigureToApply = true;
return;
}
if (!m_configured) {
m_configured = true;
applyConfigure();
@ -95,6 +108,8 @@ void QWaylandLayerSurface::zwlr_layer_surface_v1_configure(uint32_t serial, uint
// are not painting to the window.
window()->applyConfigureWhenPossible();
}
qDebug() << "end got confiure";
}
void QWaylandLayerSurface::attachPopup(QtWaylandClient::QWaylandShellSurface *popup)
@ -111,6 +126,7 @@ void QWaylandLayerSurface::attachPopup(QtWaylandClient::QWaylandShellSurface *po
void QWaylandLayerSurface::applyConfigure()
{
m_configuring = true;
qDebug() << "resizing panel to " << m_pendingSize;
window()->resizeFromApplyConfigure(m_pendingSize);
m_configuring = false;
}
@ -127,6 +143,7 @@ void QWaylandLayerSurface::setDesiredSize(const QSize &size)
if (verticallyConstrained) {
effectiveSize.setHeight(0);
}
qDebug() << "requesting size " << effectiveSize;
set_size(effectiveSize.width(), effectiveSize.height());
}
@ -170,6 +187,7 @@ void QWaylandLayerSurface::setWindowGeometry(const QRect &geometry)
}
setDesiredSize(geometry.size());
requestWaylandSync();
}
bool QWaylandLayerSurface::requestActivate()
@ -184,12 +202,14 @@ bool QWaylandLayerSurface::requestActivate()
return true;
} else {
const auto focusWindow = QGuiApplication::focusWindow();
const auto wlWindow = focusWindow ? static_cast<QtWaylandClient::QWaylandWindow *>(focusWindow->handle()) : window();
const auto wlWindow = focusWindow ? static_cast<QtWaylandClient::QWaylandWindow*>(focusWindow->handle()) : window();
if (const auto seat = wlWindow->display()->lastInputDevice()) {
const auto tokenProvider = activation->requestXdgActivationToken(wlWindow->display(), wlWindow->wlSurface(), 0, QString());
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this, [this](const QString &token) {
m_shell->activation()->activate(token, window()->wlSurface());
});
const auto tokenProvider = activation->requestXdgActivationToken(
wlWindow->display(), wlWindow->wlSurface(), 0, QString());
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this,
[this](const QString &token) {
m_shell->activation()->activate(token, window()->wlSurface());
});
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, tokenProvider, &QObject::deleteLater);
return true;
}
@ -208,14 +228,55 @@ void QWaylandLayerSurface::requestXdgActivationToken(quint32 serial)
if (!activation->isActive()) {
return;
}
auto tokenProvider = activation->requestXdgActivationToken(window()->display(), window()->wlSurface(), serial, QString());
auto tokenProvider = activation->requestXdgActivationToken(
window()->display(), window()->wlSurface(), serial, QString());
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this, [this](const QString &token) {
Q_EMIT window()->xdgActivationTokenCreated(token);
});
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, this,
[this](const QString &token) {
Q_EMIT window()->xdgActivationTokenCreated(token);
});
connect(tokenProvider, &QWaylandXdgActivationTokenV1::done, tokenProvider, &QObject::deleteLater);
}
const wl_callback_listener QWaylandLayerSurface::syncCallbackListener = {
.done = [](void *data, struct wl_callback *callback, uint32_t time){
Q_UNUSED(time);
wl_callback_destroy(callback);
QWaylandLayerSurface *layerSurface = static_cast<QWaylandLayerSurface *>(data);
layerSurface->m_waitForSyncCallbacks.removeOne(callback);
layerSurface->handleWaylandSyncDone();
}
};
void QWaylandLayerSurface::requestWaylandSync()
{
auto syncCallback = wl_display_sync(m_window->display()->wl_display());
m_waitForSyncCallbacks.append(syncCallback);
wl_callback_add_listener(syncCallback, &syncCallbackListener, this);
}
void QWaylandLayerSurface::handleWaylandSyncDone()
{
qDebug() << "handle sync done";
if (!window()->window()->isVisible() || !m_waitForSyncCallbacks.isEmpty()) {
return;
}
if (m_hasPendingConfigureToApply) {
m_hasPendingConfigureToApply = false;
if (!m_configured) {
m_configured = true;
applyConfigure();
sendExpose();
} else {
// Later configures are resizes, so we have to queue them up for a time when we
// are not painting to the window.
window()->applyConfigureWhenPossible();
}
}
qDebug() << "end handle sync done";
}
void QWaylandLayerSurface::sendExpose()
{
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
@ -226,3 +287,4 @@ void QWaylandLayerSurface::sendExpose()
}
}

View File

@ -30,7 +30,7 @@ public:
bool isExposed() const override
{
return m_configured;
return m_configured && m_waitForSyncCallbacks.isEmpty();
}
void attachPopup(QtWaylandClient::QWaylandShellSurface *popup) override;
@ -50,6 +50,8 @@ public:
void requestXdgActivationToken(quint32 serial) override;
private:
void requestWaylandSync();
void handleWaylandSyncDone();
void sendExpose();
void zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height) override;
void zwlr_layer_surface_v1_closed() override;
@ -62,8 +64,11 @@ private:
bool m_configured = false;
bool m_configuring = false;
};
bool m_hasPendingConfigureToApply = false;
static const wl_callback_listener syncCallbackListener;
QList<struct wl_callback*> m_waitForSyncCallbacks;
};
}
#endif

View File

@ -39,7 +39,6 @@ Item
LayerShell.Window.anchors: LayerShell.Window.AnchorLeft
LayerShell.Window.layer: LayerShell.Window.LayerTop
LayerShell.Window.exclusionZone: width
LayerShell.Window.margins.left: 100
width: 100
height: 100