feat: add layershell support

This commit is contained in:
outfoxxed 2024-02-04 04:58:58 -08:00
parent 56502b79f6
commit d76100781f
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
12 changed files with 677 additions and 11 deletions

59
src/cpp/qmlglobal.cpp Normal file
View file

@ -0,0 +1,59 @@
#include "qmlglobal.hpp"
#include <qcontainerfwd.h>
#include <qcoreapplication.h>
#include <qguiapplication.h>
#include <qobject.h>
#include <qqmllist.h>
#include <qtmetamacros.h>
#include <qtypes.h>
#include "qmlscreen.hpp"
QtShellGlobal::QtShellGlobal(QObject* parent): QObject(parent) {
auto* app = QCoreApplication::instance();
auto* guiApp = qobject_cast<QGuiApplication*>(app);
if (guiApp != nullptr) {
// clang-format off
QObject::connect(guiApp, &QGuiApplication::primaryScreenChanged, this, &QtShellGlobal::updateScreens);
QObject::connect(guiApp, &QGuiApplication::screenAdded, this, &QtShellGlobal::updateScreens);
QObject::connect(guiApp, &QGuiApplication::screenRemoved, this, &QtShellGlobal::updateScreens);
// clang-format on
this->updateScreens();
}
}
qsizetype QtShellGlobal::screensCount(QQmlListProperty<QtShellScreenInfo>* prop) {
return static_cast<QtShellGlobal*>(prop->object)->mScreens.size(); // NOLINT
}
QtShellScreenInfo* QtShellGlobal::screenAt(QQmlListProperty<QtShellScreenInfo>* prop, qsizetype i) {
return static_cast<QtShellGlobal*>(prop->object)->mScreens.at(i); // NOLINT
}
QQmlListProperty<QtShellScreenInfo> QtShellGlobal::screens() {
return QQmlListProperty<QtShellScreenInfo>(
this,
nullptr,
&QtShellGlobal::screensCount,
&QtShellGlobal::screenAt
);
}
void QtShellGlobal::updateScreens() {
auto screens = QGuiApplication::screens();
this->mScreens.resize(screens.size());
for (auto i = 0; i < screens.size(); i++) {
if (this->mScreens[i] != nullptr) {
this->mScreens[i]->screen = nullptr;
this->mScreens[i]->setParent(nullptr); // delete if not owned by the js engine
}
this->mScreens[i] = new QtShellScreenInfo(this, screens[i]);
}
emit this->screensChanged();
}