wayland/toplevel: refactor toplevel output tracking to its own file

This commit is contained in:
outfoxxed 2025-06-24 18:52:19 -07:00
parent 20c3da01f1
commit 27f97c3283
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
6 changed files with 119 additions and 82 deletions

View file

@ -23,7 +23,6 @@ namespace qs::wayland::toplevel_management::impl {
QString ToplevelHandle::appId() const { return this->mAppId; }
QString ToplevelHandle::title() const { return this->mTitle; }
QVector<QScreen*> ToplevelHandle::visibleScreens() const { return this->mVisibleScreens; }
ToplevelHandle* ToplevelHandle::parent() const { return this->mParent; }
bool ToplevelHandle::activated() const { return this->mActivated; }
bool ToplevelHandle::maximized() const { return this->mMaximized; }
@ -181,59 +180,13 @@ void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_state(wl_array* stateArray)
}
void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_output_enter(wl_output* output) {
auto* display = QtWaylandClient::QWaylandIntegration::instance()->display();
auto* platformScreen = display->screenForOutput(output);
if (!platformScreen) {
qCDebug(logToplevelManagement) << this << "got pending output enter" << output;
if (this->mPendingVisibleScreens.isEmpty()) {
QObject::connect(
static_cast<QGuiApplication*>(QGuiApplication::instance()), // NOLINT
&QGuiApplication::screenAdded,
this,
&ToplevelHandle::onScreenAdded
);
}
this->mPendingVisibleScreens.append(output);
return;
}
auto* screen = platformScreen->screen();
qCDebug(logToplevelManagement) << this << "got output enter" << screen;
this->mVisibleScreens.append(screen);
emit this->visibleScreenAdded(screen);
qCDebug(logToplevelManagement) << this << "got output enter" << output;
this->visibleScreens.addOutput(output);
}
void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_output_leave(wl_output* output) {
auto* display = QtWaylandClient::QWaylandIntegration::instance()->display();
auto* platformScreen = display->screenForOutput(output);
if (!this->mPendingVisibleScreens.isEmpty()) {
this->mPendingVisibleScreens.removeOne(output);
if (this->mPendingVisibleScreens.isEmpty()) {
qCDebug(logToplevelManagement) << this << "got pending output leave" << output;
QObject::disconnect(
static_cast<QGuiApplication*>(QGuiApplication::instance()), // NOLINT
nullptr,
this,
nullptr
);
}
}
if (!platformScreen) return;
auto* screen = platformScreen->screen();
qCDebug(logToplevelManagement) << this << "got output leave" << screen;
this->mVisibleScreens.removeOne(screen);
emit this->visibleScreenRemoved(screen);
qCDebug(logToplevelManagement) << this << "got output leave" << output;
this->visibleScreens.removeOutput(output);
}
void ToplevelHandle::zwlr_foreign_toplevel_handle_v1_parent(
@ -262,26 +215,4 @@ void ToplevelHandle::onParentClosed() {
emit this->parentChanged();
}
void ToplevelHandle::onScreenAdded(QScreen* screen) {
auto* waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen*>(screen->handle());
if (!waylandScreen) return;
auto* output = waylandScreen->output();
if (this->mPendingVisibleScreens.removeOne(output)) {
qCDebug(logToplevelManagement) << this << "got pending entered output init" << screen;
this->mVisibleScreens.append(screen);
emit this->visibleScreenAdded(screen);
}
if (this->mPendingVisibleScreens.isEmpty()) {
QObject::disconnect(
static_cast<QGuiApplication*>(QGuiApplication::instance()), // NOLINT
nullptr,
this,
nullptr
);
}
}
} // namespace qs::wayland::toplevel_management::impl

View file

@ -6,6 +6,7 @@
#include <qwayland-wlr-foreign-toplevel-management-unstable-v1.h>
#include <qwindow.h>
#include "../output_tracking.hpp"
#include "wayland-wlr-foreign-toplevel-management-unstable-v1-client-protocol.h"
namespace qs::wayland::toplevel_management::impl {
@ -18,7 +19,6 @@ class ToplevelHandle
public:
[[nodiscard]] QString appId() const;
[[nodiscard]] QString title() const;
[[nodiscard]] QVector<QScreen*> visibleScreens() const;
[[nodiscard]] ToplevelHandle* parent() const;
[[nodiscard]] bool activated() const;
[[nodiscard]] bool maximized() const;
@ -32,6 +32,8 @@ public:
void fullscreenOn(QScreen* screen);
void setRectangle(QWindow* window, QRect rect);
WlOutputTracker visibleScreens;
signals:
// sent after the first done event.
void ready();
@ -40,8 +42,6 @@ signals:
void appIdChanged();
void titleChanged();
void visibleScreenAdded(QScreen* screen);
void visibleScreenRemoved(QScreen* screen);
void parentChanged();
void activatedChanged();
void maximizedChanged();
@ -51,7 +51,6 @@ signals:
private slots:
void onParentClosed();
void onRectWindowDestroyed();
void onScreenAdded(QScreen* screen);
private:
void zwlr_foreign_toplevel_handle_v1_done() override;
@ -66,8 +65,6 @@ private:
bool isReady = false;
QString mAppId;
QString mTitle;
QVector<QScreen*> mVisibleScreens;
QVector<wl_output*> mPendingVisibleScreens;
ToplevelHandle* mParent = nullptr;
bool mActivated = false;
bool mMaximized = false;

View file

@ -10,6 +10,7 @@
#include "../../core/util.hpp"
#include "../../window/proxywindow.hpp"
#include "../../window/windowinterface.hpp"
#include "../output_tracking.hpp"
#include "handle.hpp"
#include "manager.hpp"
@ -22,8 +23,8 @@ Toplevel::Toplevel(impl::ToplevelHandle* handle, QObject* parent): QObject(paren
QObject::connect(handle, &impl::ToplevelHandle::titleChanged, this, &Toplevel::titleChanged);
QObject::connect(handle, &impl::ToplevelHandle::parentChanged, this, &Toplevel::parentChanged);
QObject::connect(handle, &impl::ToplevelHandle::activatedChanged, this, &Toplevel::activatedChanged);
QObject::connect(handle, &impl::ToplevelHandle::visibleScreenAdded, this, &Toplevel::screensChanged);
QObject::connect(handle, &impl::ToplevelHandle::visibleScreenRemoved, this, &Toplevel::screensChanged);
QObject::connect(&handle->visibleScreens, &WlOutputTracker::screenAdded, this, &Toplevel::screensChanged);
QObject::connect(&handle->visibleScreens, &WlOutputTracker::screenRemoved, this, &Toplevel::screensChanged);
QObject::connect(handle, &impl::ToplevelHandle::maximizedChanged, this, &Toplevel::maximizedChanged);
QObject::connect(handle, &impl::ToplevelHandle::minimizedChanged, this, &Toplevel::minimizedChanged);
QObject::connect(handle, &impl::ToplevelHandle::fullscreenChanged, this, &Toplevel::fullscreenChanged);
@ -50,7 +51,7 @@ bool Toplevel::activated() const { return this->handle->activated(); }
QList<QuickshellScreenInfo*> Toplevel::screens() const {
QList<QuickshellScreenInfo*> screens;
for (auto* screen: this->handle->visibleScreens()) {
for (auto* screen: this->handle->visibleScreens.screens()) {
screens.push_back(QuickshellTracked::instance()->screenInfo(screen));
}