diff options
Diffstat (limited to 'plugin/src/Caelestia')
| -rw-r--r-- | plugin/src/Caelestia/Internal/hyprdevices.cpp | 4 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Internal/hyprdevices.hpp | 4 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Internal/hyprextras.cpp | 35 | ||||
| -rw-r--r-- | plugin/src/Caelestia/Internal/hyprextras.hpp | 3 |
4 files changed, 39 insertions, 7 deletions
diff --git a/plugin/src/Caelestia/Internal/hyprdevices.cpp b/plugin/src/Caelestia/Internal/hyprdevices.cpp index 8f63d67..2c94d90 100644 --- a/plugin/src/Caelestia/Internal/hyprdevices.cpp +++ b/plugin/src/Caelestia/Internal/hyprdevices.cpp @@ -40,7 +40,7 @@ bool HyprKeyboard::main() const { return m_lastIpcObject.value("main").toBool(); } -bool HyprKeyboard::updateLastIpcObject(const QJsonObject& object) { +bool HyprKeyboard::updateLastIpcObject(QJsonObject object) { if (m_lastIpcObject == object) { return false; } @@ -89,7 +89,7 @@ QList<HyprKeyboard*> HyprDevices::keyboards() const { return m_keyboards; } -bool HyprDevices::updateLastIpcObject(const QJsonObject& object) { +bool HyprDevices::updateLastIpcObject(QJsonObject object) { const auto val = object.value("keyboards").toArray(); bool dirty = false; diff --git a/plugin/src/Caelestia/Internal/hyprdevices.hpp b/plugin/src/Caelestia/Internal/hyprdevices.hpp index ad762b9..e10df46 100644 --- a/plugin/src/Caelestia/Internal/hyprdevices.hpp +++ b/plugin/src/Caelestia/Internal/hyprdevices.hpp @@ -32,7 +32,7 @@ public: [[nodiscard]] bool numLock() const; [[nodiscard]] bool main() const; - bool updateLastIpcObject(const QJsonObject& object); + bool updateLastIpcObject(QJsonObject object); signals: void lastIpcObjectChanged(); @@ -60,7 +60,7 @@ public: [[nodiscard]] QList<HyprKeyboard*> keyboards() const; - bool updateLastIpcObject(const QJsonObject& object); + bool updateLastIpcObject(QJsonObject object); signals: void keyboardsChanged(); diff --git a/plugin/src/Caelestia/Internal/hyprextras.cpp b/plugin/src/Caelestia/Internal/hyprextras.cpp index 5925918..5308524 100644 --- a/plugin/src/Caelestia/Internal/hyprextras.cpp +++ b/plugin/src/Caelestia/Internal/hyprextras.cpp @@ -12,6 +12,7 @@ HyprExtras::HyprExtras(QObject* parent) , m_requestSocket("") , m_eventSocket("") , m_socket(nullptr) + , m_socketValid(false) , m_devices(new HyprDevices(this)) { const auto his = qEnvironmentVariable("HYPRLAND_INSTANCE_SIGNATURE"); if (his.isEmpty()) { @@ -38,7 +39,11 @@ HyprExtras::HyprExtras(QObject* parent) refreshDevices(); m_socket = new QLocalSocket(this); + + QObject::connect(m_socket, &QLocalSocket::errorOccurred, this, &HyprExtras::socketError); + QObject::connect(m_socket, &QLocalSocket::stateChanged, this, &HyprExtras::socketStateChanged); QObject::connect(m_socket, &QLocalSocket::readyRead, this, &HyprExtras::readEvent); + m_socket->connectToServer(m_eventSocket, QLocalSocket::ReadOnly); } @@ -55,7 +60,10 @@ void HyprExtras::message(const QString& message) { return; } - makeRequest(message, [](bool, const QByteArray&) { + makeRequest(message, [](bool success, const QByteArray& res) { + if (!success) { + qWarning() << "HyprExtras::message: request error:" << QString::fromUtf8(res); + } }); } @@ -64,7 +72,10 @@ void HyprExtras::batchMessage(const QStringList& messages) { return; } - makeRequest("[[BATCH]]" + messages.join(";"), [](bool, const QByteArray&) { + makeRequest("[[BATCH]]" + messages.join(";"), [](bool success, const QByteArray& res) { + if (!success) { + qWarning() << "HyprExtras::batchMessage: request error:" << QString::fromUtf8(res); + } }); } @@ -78,9 +89,11 @@ void HyprExtras::applyOptions(const QVariantHash& options) { request += QString("keyword %1 %2;").arg(it.key(), it.value().toString()); } - makeRequest(request, [this](bool success, const QByteArray&) { + makeRequest(request, [this](bool success, const QByteArray& res) { if (success) { refreshOptions(); + } else { + qWarning() << "HyprExtras::applyOptions: request error" << QString::fromUtf8(res); } }); } @@ -128,6 +141,22 @@ void HyprExtras::refreshDevices() { }); } +void HyprExtras::socketError(QLocalSocket::LocalSocketError error) const { + if (!m_socketValid) { + qWarning() << "HyprExtras::socketError: unable to connect to Hyprland event socket:" << error; + } else { + qWarning() << "HyprExtras::socketError: Hyprland event socket error:" << error; + } +} + +void HyprExtras::socketStateChanged(QLocalSocket::LocalSocketState state) { + if (state == QLocalSocket::UnconnectedState && m_socketValid) { + qWarning() << "HyprExtras::socketStateChanged: Hyprland event socket disconnected."; + } + + m_socketValid = state == QLocalSocket::ConnectedState; +} + void HyprExtras::readEvent() { while (true) { auto rawEvent = m_socket->readLine(); diff --git a/plugin/src/Caelestia/Internal/hyprextras.hpp b/plugin/src/Caelestia/Internal/hyprextras.hpp index f1863ed..9f9e1ad 100644 --- a/plugin/src/Caelestia/Internal/hyprextras.hpp +++ b/plugin/src/Caelestia/Internal/hyprextras.hpp @@ -36,6 +36,7 @@ private: QString m_requestSocket; QString m_eventSocket; QLocalSocket* m_socket; + bool m_socketValid; QVariantHash m_options; HyprDevices* const m_devices; @@ -43,6 +44,8 @@ private: SocketPtr m_optionsRefresh; SocketPtr m_devicesRefresh; + void socketError(QLocalSocket::LocalSocketError error) const; + void socketStateChanged(QLocalSocket::LocalSocketState state); void readEvent(); void handleEvent(const QString& event); |