2024-02-04 12:58:58 +00:00
|
|
|
#include "qmlglobal.hpp"
|
|
|
|
|
|
|
|
#include <qcontainerfwd.h>
|
|
|
|
#include <qcoreapplication.h>
|
|
|
|
#include <qguiapplication.h>
|
2024-02-04 13:17:18 +00:00
|
|
|
#include <qlogging.h>
|
2024-02-04 12:58:58 +00:00
|
|
|
#include <qobject.h>
|
2024-02-04 13:17:18 +00:00
|
|
|
#include <qqmlcontext.h>
|
|
|
|
#include <qqmlengine.h>
|
2024-02-04 12:58:58 +00:00
|
|
|
#include <qqmllist.h>
|
|
|
|
#include <qtmetamacros.h>
|
|
|
|
#include <qtypes.h>
|
|
|
|
|
|
|
|
#include "qmlscreen.hpp"
|
2024-02-04 13:17:18 +00:00
|
|
|
#include "rootwrapper.hpp"
|
2024-02-04 12:58:58 +00:00
|
|
|
|
2024-02-26 08:57:47 +00:00
|
|
|
QuickshellGlobal::QuickshellGlobal(QObject* parent): QObject(parent) {
|
2024-02-04 12:58:58 +00:00
|
|
|
auto* app = QCoreApplication::instance();
|
|
|
|
auto* guiApp = qobject_cast<QGuiApplication*>(app);
|
|
|
|
|
|
|
|
if (guiApp != nullptr) {
|
|
|
|
// clang-format off
|
2024-02-26 08:57:47 +00:00
|
|
|
QObject::connect(guiApp, &QGuiApplication::primaryScreenChanged, this, &QuickshellGlobal::updateScreens);
|
|
|
|
QObject::connect(guiApp, &QGuiApplication::screenAdded, this, &QuickshellGlobal::updateScreens);
|
|
|
|
QObject::connect(guiApp, &QGuiApplication::screenRemoved, this, &QuickshellGlobal::updateScreens);
|
2024-02-04 12:58:58 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
this->updateScreens();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-26 08:57:47 +00:00
|
|
|
qsizetype QuickshellGlobal::screensCount(QQmlListProperty<QuickshellScreenInfo>* prop) {
|
|
|
|
return static_cast<QuickshellGlobal*>(prop->object)->mScreens.size(); // NOLINT
|
2024-02-04 12:58:58 +00:00
|
|
|
}
|
|
|
|
|
2024-02-26 08:57:47 +00:00
|
|
|
QuickshellScreenInfo*
|
|
|
|
QuickshellGlobal::screenAt(QQmlListProperty<QuickshellScreenInfo>* prop, qsizetype i) {
|
|
|
|
return static_cast<QuickshellGlobal*>(prop->object)->mScreens.at(i); // NOLINT
|
2024-02-04 12:58:58 +00:00
|
|
|
}
|
|
|
|
|
2024-02-26 08:57:47 +00:00
|
|
|
QQmlListProperty<QuickshellScreenInfo> QuickshellGlobal::screens() {
|
|
|
|
return QQmlListProperty<QuickshellScreenInfo>(
|
2024-02-04 12:58:58 +00:00
|
|
|
this,
|
|
|
|
nullptr,
|
2024-02-26 08:57:47 +00:00
|
|
|
&QuickshellGlobal::screensCount,
|
|
|
|
&QuickshellGlobal::screenAt
|
2024-02-04 12:58:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-02-26 08:57:47 +00:00
|
|
|
void QuickshellGlobal::reload(bool hard) {
|
2024-02-04 13:17:18 +00:00
|
|
|
auto* rootobj = QQmlEngine::contextForObject(this)->engine()->parent();
|
|
|
|
auto* root = qobject_cast<RootWrapper*>(rootobj);
|
|
|
|
|
|
|
|
if (root == nullptr) {
|
|
|
|
qWarning() << "cannot find RootWrapper for reload, ignoring request";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
root->reloadGraph(hard);
|
|
|
|
}
|
|
|
|
|
2024-02-26 08:57:47 +00:00
|
|
|
void QuickshellGlobal::updateScreens() {
|
2024-02-04 12:58:58 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-02-26 08:57:47 +00:00
|
|
|
this->mScreens[i] = new QuickshellScreenInfo(this, screens[i]);
|
2024-02-04 12:58:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
emit this->screensChanged();
|
|
|
|
}
|