|
|
@ -465,10 +465,12 @@ HyprlandMonitor* HyprlandIpc::focusedMonitor() const { return this->mFocusedMoni
|
|
|
|
|
|
|
|
|
|
|
|
HyprlandMonitor* HyprlandIpc::monitorFor(QuickshellScreenInfo* screen) {
|
|
|
|
HyprlandMonitor* HyprlandIpc::monitorFor(QuickshellScreenInfo* screen) {
|
|
|
|
// Wayland monitors appear after hyprland ones are created and disappear after destruction
|
|
|
|
// Wayland monitors appear after hyprland ones are created and disappear after destruction
|
|
|
|
// so simply not doing any preemptive creation is enough.
|
|
|
|
// so simply not doing any preemptive creation is enough, however if this call creates
|
|
|
|
|
|
|
|
// the HyprlandIpc singleton then monitors won't be initialized, in which case we
|
|
|
|
|
|
|
|
// preemptively create one.
|
|
|
|
|
|
|
|
|
|
|
|
if (screen == nullptr) return nullptr;
|
|
|
|
if (screen == nullptr) return nullptr;
|
|
|
|
return this->findMonitorByName(screen->name(), false);
|
|
|
|
return this->findMonitorByName(screen->name(), !this->monitorsRequested);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HyprlandIpc::setFocusedMonitor(HyprlandMonitor* monitor) {
|
|
|
|
void HyprlandIpc::setFocusedMonitor(HyprlandMonitor* monitor) {
|
|
|
@ -505,19 +507,21 @@ void HyprlandIpc::refreshMonitors(bool canCreate, bool tryAgain) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this->monitorsRequested = true;
|
|
|
|
|
|
|
|
|
|
|
|
qCDebug(logHyprlandIpc) << "parsing monitors response";
|
|
|
|
qCDebug(logHyprlandIpc) << "parsing monitors response";
|
|
|
|
auto json = QJsonDocument::fromJson(resp).array();
|
|
|
|
auto json = QJsonDocument::fromJson(resp).array();
|
|
|
|
|
|
|
|
|
|
|
|
const auto& mList = this->mMonitors.valueList();
|
|
|
|
const auto& mList = this->mMonitors.valueList();
|
|
|
|
auto ids = QVector<qint32>();
|
|
|
|
auto names = QVector<QString>();
|
|
|
|
|
|
|
|
|
|
|
|
for (auto entry: json) {
|
|
|
|
for (auto entry: json) {
|
|
|
|
auto object = entry.toObject().toVariantMap();
|
|
|
|
auto object = entry.toObject().toVariantMap();
|
|
|
|
auto id = object.value("id").toInt();
|
|
|
|
auto name = object.value("name").toString();
|
|
|
|
|
|
|
|
|
|
|
|
auto monitorIter =
|
|
|
|
auto monitorIter =
|
|
|
|
std::find_if(mList.begin(), mList.end(), [id](const HyprlandMonitor* m) {
|
|
|
|
std::find_if(mList.begin(), mList.end(), [name](const HyprlandMonitor* m) {
|
|
|
|
return m->id() == id;
|
|
|
|
return m->name() == name;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
auto* monitor = monitorIter == mList.end() ? nullptr : *monitorIter;
|
|
|
|
auto* monitor = monitorIter == mList.end() ? nullptr : *monitorIter;
|
|
|
@ -534,13 +538,13 @@ void HyprlandIpc::refreshMonitors(bool canCreate, bool tryAgain) {
|
|
|
|
this->mMonitors.insertObject(monitor);
|
|
|
|
this->mMonitors.insertObject(monitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ids.push_back(id);
|
|
|
|
names.push_back(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
auto removedMonitors = QVector<HyprlandMonitor*>();
|
|
|
|
auto removedMonitors = QVector<HyprlandMonitor*>();
|
|
|
|
|
|
|
|
|
|
|
|
for (auto* monitor: mList) {
|
|
|
|
for (auto* monitor: mList) {
|
|
|
|
if (!ids.contains(monitor->id())) {
|
|
|
|
if (!names.contains(monitor->name())) {
|
|
|
|
removedMonitors.push_back(monitor);
|
|
|
|
removedMonitors.push_back(monitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|