cleanup for hyprland lua configs
This commit is contained in:
@@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Hyprland
|
||||
import QtQuick
|
||||
import ZShell
|
||||
import qs.Helpers
|
||||
@@ -79,8 +80,8 @@ Singleton {
|
||||
}
|
||||
|
||||
function reloadHyprRules(): void {
|
||||
const barStr = "keyword layerrule %1 %2, match:namespace ZShell-Bar";
|
||||
const authStr = "keyword layerrule %1 %2, match:namespace ZShell-Auth";
|
||||
const barStr = Hyprland.usingLua ? `eval 'hl.layer_rule({ match = { namespace = "ZShell-Bar" }, %1 = true, %2 = true })'` : "keyword layerrule %1 %2, match:namespace ZShell-Bar";
|
||||
const authStr = Hyprland.usingLua ? `eval 'hl.layer_rule({ match = { namespace = "ZShell-Auth" }, %1 = true, %2 = true })'` : "keyword layerrule %1 %2, match:namespace ZShell-Auth";
|
||||
Hypr.extras.batchMessage([barStr.arg("blur").arg(transparency.enabled ? 1 : 0), barStr.arg("ignore_alpha").arg(transparency.base - 0.03)]);
|
||||
Hypr.extras.batchMessage([authStr.arg("blur").arg(transparency.enabled ? 1 : 0), authStr.arg("ignore_alpha").arg(transparency.base - 0.03)]);
|
||||
}
|
||||
@@ -93,6 +94,14 @@ Singleton {
|
||||
|
||||
Component.onCompleted: debounceTimer.triggered()
|
||||
|
||||
Connections {
|
||||
function onUsingLuaChanged(): void {
|
||||
root.reloadHyprRules();
|
||||
}
|
||||
|
||||
target: Hyprland
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onConfigReloaded(): void {
|
||||
root.reloadHyprRules();
|
||||
|
||||
+1
-1
@@ -279,7 +279,7 @@ Variants {
|
||||
deformAmount: 0.08
|
||||
implicitHeight: panels.settings.height * (1 + extraHeight)
|
||||
implicitWidth: panels.settings.width
|
||||
panel: panels.settings
|
||||
panel: panels.settingsWrapper
|
||||
radius: Appearance.rounding.large
|
||||
topLeftRadius: Appearance.rounding.large + Appearance.padding.smaller
|
||||
topRightRadius: Appearance.rounding.large + Appearance.padding.smaller
|
||||
|
||||
@@ -79,7 +79,8 @@ Item {
|
||||
}
|
||||
|
||||
onPressed: {
|
||||
Hyprland.dispatch(`workspace ${button.modelData.name}`);
|
||||
const ws = button.modelData.name;
|
||||
Hyprland.dispatch(Hyprland.usingLua ? `hl.dsp.focus({ workspace= "${ws}"})` : `workspace ${ws}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
#include "hyprextras.hpp"
|
||||
#include "hyprdevices.hpp"
|
||||
|
||||
#include <qdir.h>
|
||||
#include <qjsonarray.h>
|
||||
#include <qlocalsocket.h>
|
||||
#include <qloggingcategory.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
Q_LOGGING_CATEGORY(lcHypr, "ZShell.internal.hypr", QtInfoMsg)
|
||||
|
||||
namespace ZShell::internal::hypr {
|
||||
|
||||
HyprExtras::HyprExtras(QObject* parent)
|
||||
@@ -16,8 +20,7 @@ HyprExtras::HyprExtras(QObject* parent)
|
||||
, m_devices(new HyprDevices(this)) {
|
||||
const auto his = qEnvironmentVariable("HYPRLAND_INSTANCE_SIGNATURE");
|
||||
if (his.isEmpty()) {
|
||||
qWarning()
|
||||
<< "HyprExtras::HyprExtras: $HYPRLAND_INSTANCE_SIGNATURE is unset. Unable to connect to Hyprland socket.";
|
||||
qCWarning(lcHypr) << "$HYPRLAND_INSTANCE_SIGNATURE is unset. Unable to connect to Hyprland socket.";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,8 +29,7 @@ HyprExtras::HyprExtras(QObject* parent)
|
||||
hyprDir = "/tmp/hypr/" + his;
|
||||
|
||||
if (!QDir(hyprDir).exists()) {
|
||||
qWarning() << "HyprExtras::HyprExtras: Hyprland socket directory does not exist. Unable to connect to "
|
||||
"Hyprland socket.";
|
||||
qCWarning(lcHypr) << "Hyprland socket directory does not exist. Unable to connect to Hyprland socket.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +64,7 @@ void HyprExtras::message(const QString& message) {
|
||||
|
||||
makeRequest(message, [](bool success, const QByteArray& res) {
|
||||
if (!success) {
|
||||
qWarning() << "HyprExtras::message: request error:" << QString::fromUtf8(res);
|
||||
qCWarning(lcHypr) << "message: request error:" << QString::fromUtf8(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -74,7 +76,7 @@ void HyprExtras::batchMessage(const QStringList& messages) {
|
||||
|
||||
makeRequest("[[BATCH]]" + messages.join(";"), [](bool success, const QByteArray& res) {
|
||||
if (!success) {
|
||||
qWarning() << "HyprExtras::batchMessage: request error:" << QString::fromUtf8(res);
|
||||
qCWarning(lcHypr) << "batchMessage: request error:" << QString::fromUtf8(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -84,16 +86,18 @@ void HyprExtras::applyOptions(const QVariantHash& options) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString request = "[[BATCH]]";
|
||||
QString request;
|
||||
request.reserve(12 + options.size() * 40);
|
||||
request += QLatin1String("[[BATCH]]");
|
||||
for (auto it = options.constBegin(); it != options.constEnd(); ++it) {
|
||||
request += QString("keyword %1 %2;").arg(it.key(), it.value().toString());
|
||||
request += QLatin1String("keyword ") + it.key() + QLatin1Char(' ') + it.value().toString() + QLatin1Char(';');
|
||||
}
|
||||
|
||||
makeRequest(request, [this](bool success, const QByteArray& res) {
|
||||
if (success) {
|
||||
refreshOptions();
|
||||
} else {
|
||||
qWarning() << "HyprExtras::applyOptions: request error" << QString::fromUtf8(res);
|
||||
qCWarning(lcHypr) << "applyOptions: request error" << QString::fromUtf8(res);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -143,15 +147,15 @@ void HyprExtras::refreshDevices() {
|
||||
|
||||
void HyprExtras::socketError(QLocalSocket::LocalSocketError error) const {
|
||||
if (!m_socketValid) {
|
||||
qWarning() << "HyprExtras::socketError: unable to connect to Hyprland event socket:" << error;
|
||||
qCWarning(lcHypr) << "socketError: unable to connect to Hyprland event socket:" << error;
|
||||
} else {
|
||||
qWarning() << "HyprExtras::socketError: Hyprland event socket error:" << error;
|
||||
qCWarning(lcHypr) << "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.";
|
||||
qCWarning(lcHypr) << "socketStateChanged: Hyprland event socket disconnected.";
|
||||
}
|
||||
|
||||
m_socketValid = state == QLocalSocket::ConnectedState;
|
||||
@@ -204,7 +208,7 @@ HyprExtras::SocketPtr HyprExtras::makeRequest(
|
||||
});
|
||||
|
||||
QObject::connect(socket.data(), &QLocalSocket::errorOccurred, this, [=](QLocalSocket::LocalSocketError err) {
|
||||
qWarning() << "HyprExtras::makeRequest: error making request:" << err << "| request:" << request;
|
||||
qCWarning(lcHypr) << "makeRequest: error making request:" << err << "| request:" << request;
|
||||
callback(false, {});
|
||||
socket->close();
|
||||
});
|
||||
|
||||
@@ -1,56 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include "hyprdevices.hpp"
|
||||
#include <qlocalsocket.h>
|
||||
#include <qobject.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qsharedpointer.h>
|
||||
#include <qvariant.h>
|
||||
|
||||
namespace ZShell::internal::hypr {
|
||||
|
||||
class HyprExtras : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
class HyprDevices;
|
||||
|
||||
Q_PROPERTY(QVariantHash options READ options NOTIFY optionsChanged)
|
||||
Q_PROPERTY(ZShell::internal::hypr::HyprDevices* devices READ devices CONSTANT)
|
||||
class HyprExtras : public QObject {
|
||||
Q_OBJECT
|
||||
QML_ELEMENT
|
||||
Q_MOC_INCLUDE("hyprdevices.hpp")
|
||||
|
||||
Q_PROPERTY(QVariantHash options READ options NOTIFY optionsChanged)
|
||||
Q_PROPERTY(ZShell::internal::hypr::HyprDevices* devices READ devices CONSTANT)
|
||||
|
||||
public:
|
||||
explicit HyprExtras(QObject* parent = nullptr);
|
||||
explicit HyprExtras(QObject* parent = nullptr);
|
||||
|
||||
[[nodiscard]] QVariantHash options() const;
|
||||
[[nodiscard]] HyprDevices* devices() const;
|
||||
[[nodiscard]] QVariantHash options() const;
|
||||
[[nodiscard]] HyprDevices* devices() const;
|
||||
|
||||
Q_INVOKABLE void message(const QString& message);
|
||||
Q_INVOKABLE void batchMessage(const QStringList& messages);
|
||||
Q_INVOKABLE void applyOptions(const QVariantHash& options);
|
||||
Q_INVOKABLE void message(const QString& message);
|
||||
Q_INVOKABLE void batchMessage(const QStringList& messages);
|
||||
Q_INVOKABLE void applyOptions(const QVariantHash& options);
|
||||
|
||||
Q_INVOKABLE void refreshOptions();
|
||||
Q_INVOKABLE void refreshDevices();
|
||||
Q_INVOKABLE void refreshOptions();
|
||||
Q_INVOKABLE void refreshDevices();
|
||||
|
||||
signals:
|
||||
void optionsChanged();
|
||||
void optionsChanged();
|
||||
|
||||
private:
|
||||
using SocketPtr = QSharedPointer<QLocalSocket>;
|
||||
using SocketPtr = QSharedPointer<QLocalSocket>;
|
||||
|
||||
QString m_requestSocket;
|
||||
QString m_eventSocket;
|
||||
QLocalSocket* m_socket;
|
||||
bool m_socketValid;
|
||||
QString m_requestSocket;
|
||||
QString m_eventSocket;
|
||||
QLocalSocket* m_socket;
|
||||
bool m_socketValid;
|
||||
|
||||
QVariantHash m_options;
|
||||
HyprDevices* const m_devices;
|
||||
QVariantHash m_options;
|
||||
HyprDevices* const m_devices;
|
||||
|
||||
SocketPtr m_optionsRefresh;
|
||||
SocketPtr m_devicesRefresh;
|
||||
SocketPtr m_optionsRefresh;
|
||||
SocketPtr m_devicesRefresh;
|
||||
|
||||
void socketError(QLocalSocket::LocalSocketError error) const;
|
||||
void socketStateChanged(QLocalSocket::LocalSocketState state);
|
||||
void readEvent();
|
||||
void handleEvent(const QString& event);
|
||||
void socketError(QLocalSocket::LocalSocketError error) const;
|
||||
void socketStateChanged(QLocalSocket::LocalSocketState state);
|
||||
void readEvent();
|
||||
void handleEvent(const QString& event);
|
||||
|
||||
SocketPtr makeRequestJson(const QString& request, const std::function<void(bool, QJsonDocument)>& callback);
|
||||
SocketPtr makeRequest(const QString& request, const std::function<void(bool, QByteArray)>& callback);
|
||||
SocketPtr makeRequestJson(const QString& request, const std::function<void(bool, QJsonDocument)>& callback);
|
||||
SocketPtr makeRequest(const QString& request, const std::function<void(bool, QByteArray)>& callback);
|
||||
};
|
||||
|
||||
} // namespace ZShell::internal::hypr
|
||||
|
||||
Reference in New Issue
Block a user