actually fixed config fetching in hyprland lua

This commit is contained in:
2026-05-26 01:12:36 +02:00
parent de11767d3b
commit f00af9d70f
6 changed files with 139 additions and 42 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ Singleton {
PersistentProperties { PersistentProperties {
id: props id: props
property bool enabled: Hypr.options["animations:enabled"] === 0 property bool enabled: Hypr.options.animations.enabled === 0
reloadableId: "gamemode" reloadableId: "gamemode"
} }
-1
View File
@@ -158,6 +158,5 @@ Singleton {
HyprExtras { HyprExtras {
id: extras id: extras
} }
} }
+2 -2
View File
@@ -30,8 +30,8 @@ MouseArea {
property real ey: screen.height property real ey: screen.height
required property LazyLoader loader required property LazyLoader loader
property bool onClient property bool onClient
property real realBorderWidth: onClient ? (Hypr.options["general:border_size"] ?? 1) : 2 property real realBorderWidth: onClient ? (Hypr.options.general.border_size ?? 1) : 2
property real realRounding: onClient ? (Hypr.options["decoration:rounding"] ?? 0) : 0 property real realRounding: onClient ? (Hypr.options.decoration.rounding ?? 0) : 0
property real rsx: Math.min(sx, ex) property real rsx: Math.min(sx, ex)
property real rsy: Math.min(sy, ey) property real rsy: Math.min(sy, ey)
required property ShellScreen screen required property ShellScreen screen
+16 -16
View File
@@ -43,7 +43,7 @@ SettingsPage {
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSpinBox { SettingSpinBox {
@@ -51,34 +51,34 @@ SettingsPage {
name: "Corner radius" name: "Corner radius"
object: Config.screenshot object: Config.screenshot
setting: "corner_radius" setting: "corner_radius"
shouldBeActive: Config.screenshot.mode === "manual"
step: 1 step: 1
visible: Config.screenshot.mode === "manual"
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSwitch { SettingSwitch {
name: "Enable drop shadow" name: "Enable drop shadow"
object: Config.screenshot object: Config.screenshot
setting: "drop_shadow" setting: "drop_shadow"
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSwitch { SettingSwitch {
name: "Enable rounded corners" name: "Enable rounded corners"
object: Config.screenshot object: Config.screenshot
setting: "rounded_corners" setting: "rounded_corners"
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSpinBox { SettingSpinBox {
@@ -86,23 +86,23 @@ SettingsPage {
name: "Shadow blur radius" name: "Shadow blur radius"
object: Config.screenshot object: Config.screenshot
setting: "shadow_blur_radius" setting: "shadow_blur_radius"
shouldBeActive: Config.screenshot.mode === "manual"
step: 1 step: 1
visible: Config.screenshot.mode === "manual"
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSwitch { SettingSwitch {
name: "Shadow color broken atm" name: "Shadow color broken atm"
object: Config.Screenshot object: Config.Screenshot
setting: "shadow_color" setting: "shadow_color"
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSpinBox { SettingSpinBox {
@@ -110,12 +110,12 @@ SettingsPage {
name: "Shadow passes" name: "Shadow passes"
object: Config.screenshot object: Config.screenshot
setting: "shadow_blur_passes" setting: "shadow_blur_passes"
shouldBeActive: Config.screenshot.mode === "manual"
step: 1 step: 1
visible: Config.screenshot.mode === "manual"
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSpinBox { SettingSpinBox {
@@ -123,12 +123,12 @@ SettingsPage {
name: "Shadow offset X" name: "Shadow offset X"
object: Config.screenshot object: Config.screenshot
setting: "shadow_offset_x" setting: "shadow_offset_x"
shouldBeActive: Config.screenshot.mode === "manual"
step: 1 step: 1
visible: Config.screenshot.mode === "manual"
} }
Separator { Separator {
visible: Config.screenshot.mode === "manual" shouldBeActive: Config.screenshot.mode === "manual"
} }
SettingSpinBox { SettingSpinBox {
@@ -136,8 +136,8 @@ SettingsPage {
name: "Shadow offset Y" name: "Shadow offset Y"
object: Config.screenshot object: Config.screenshot
setting: "shadow_offset_y" setting: "shadow_offset_y"
shouldBeActive: Config.screenshot.mode === "manual"
step: 1 step: 1
visible: Config.screenshot.mode === "manual"
} }
} }
} }
+112 -19
View File
@@ -1,8 +1,13 @@
#include "hyprextras.hpp" #include "hyprextras.hpp"
#include "hyprdevices.hpp" #include "hyprdevices.hpp"
#include <functional>
#include <memory>
#include <qdir.h> #include <qdir.h>
#include <qjsonarray.h> #include <qjsonarray.h>
#include <qjsondocument.h>
#include <qjsonobject.h>
#include <qlocalsocket.h> #include <qlocalsocket.h>
#include <qloggingcategory.h> #include <qloggingcategory.h>
#include <qmetatype.h> #include <qmetatype.h>
@@ -163,6 +168,65 @@ static QString buildHlConfigCall(const QString& key, const QVariant& value) {
return out; return out;
} }
static QVariant parseGetOptionValue(const QJsonObject& obj) {
if (obj.contains(QStringLiteral("bool"))) {
return obj.value(QStringLiteral("bool")).toBool();
}
if (obj.contains(QStringLiteral("int"))) {
return obj.value(QStringLiteral("int")).toInt();
}
if (obj.contains(QStringLiteral("float"))) {
return obj.value(QStringLiteral("float")).toDouble();
}
if (obj.contains(QStringLiteral("str"))) {
return obj.value(QStringLiteral("str")).toString();
}
if (obj.contains(QStringLiteral("current"))) {
return obj.value(QStringLiteral("current")).toVariant();
}
if (obj.contains(QStringLiteral("value"))) {
return obj.value(QStringLiteral("value")).toVariant();
}
if (obj.contains(QStringLiteral("data"))) {
const auto data = obj.value(QStringLiteral("data"));
if (data.isObject()) {
const auto d = data.toObject();
if (d.contains(QStringLiteral("current"))) {
return d.value(QStringLiteral("current")).toVariant();
}
if (d.contains(QStringLiteral("value"))) {
return d.value(QStringLiteral("value")).toVariant();
}
} else {
return data.toVariant();
}
}
return {};
}
static void insertNestedValue(QVariantMap& root, const QStringList& path, const QVariant& value) {
if (path.isEmpty()) {
return;
}
if (path.size() == 1) {
root.insert(path.first(), value);
return;
}
const QString head = path.first();
QVariantMap child = root.value(head).toMap();
insertNestedValue(child, path.mid(1), value);
root.insert(head, child);
}
} // namespace } // namespace
HyprExtras::HyprExtras(QObject* parent) HyprExtras::HyprExtras(QObject* parent)
@@ -203,7 +267,7 @@ HyprExtras::HyprExtras(QObject* parent)
m_socket->connectToServer(m_eventSocket, QLocalSocket::ReadOnly); m_socket->connectToServer(m_eventSocket, QLocalSocket::ReadOnly);
} }
QVariantHash HyprExtras::options() const { QVariantMap HyprExtras::options() const {
return m_options; return m_options;
} }
@@ -269,30 +333,59 @@ void HyprExtras::refreshOptions() {
m_optionsRefresh->close(); m_optionsRefresh->close();
} }
m_optionsRefresh = makeRequestJson(QStringLiteral("descriptions"), [this](bool success, const QJsonDocument& response) { ++m_optionsRefreshGeneration;
m_optionsRefresh.reset(); const quint64 generation = m_optionsRefreshGeneration;
if (!success) {
static const QStringList optionKeys = {
QStringLiteral("general:border_size"),
QStringLiteral("decoration:rounding"),
QStringLiteral("animations:enabled"),
};
auto nextOptions = std::make_shared<QVariantMap>();
auto step = std::make_shared<std::function<void(int)> >();
*step = [this, generation, nextOptions, step](int index) {
if (generation != m_optionsRefreshGeneration) {
return; return;
} }
const auto options = response.array(); if (index >= optionKeys.size()) {
bool dirty = false; if (m_options != *nextOptions) {
m_options = *nextOptions;
for (const auto& o : std::as_const(options)) { emit optionsChanged();
const auto obj = o.toObject();
const auto key = obj.value(QStringLiteral("value")).toString();
const auto value = obj.value(QStringLiteral("data")).toObject().value(QStringLiteral("current")).toVariant();
if (m_options.value(key) != value) {
dirty = true;
m_options.insert(key, value);
} }
return;
} }
if (dirty) { const QString key = optionKeys.at(index);
emit optionsChanged();
} m_optionsRefresh = makeRequestJson(
}); QStringLiteral("getoption ") + key,
[this, generation, nextOptions, step, index, key](bool success, const QJsonDocument& response)
{
m_optionsRefresh.reset();
if (generation != m_optionsRefreshGeneration) {
return;
}
if (success && response.isObject()) {
const QVariant value = parseGetOptionValue(response.object());
if (value.isValid()) {
insertNestedValue(*nextOptions, key.split(QLatin1Char(':'), Qt::SkipEmptyParts), value);
} else {
qCWarning(lcHypr) << "refreshOptions: getoption returned no usable value for" << key;
}
} else if (!success) {
qCWarning(lcHypr) << "refreshOptions: getoption request error for" << key;
}
(*step)(index + 1);
});
};
(*step)(0);
} }
void HyprExtras::refreshDevices() { void HyprExtras::refreshDevices() {
+8 -3
View File
@@ -1,9 +1,13 @@
#pragma once #pragma once
#include <functional>
#include <qjsondocument.h>
#include <qlocalsocket.h> #include <qlocalsocket.h>
#include <qobject.h> #include <qobject.h>
#include <qqmlintegration.h> #include <qqmlintegration.h>
#include <qsharedpointer.h> #include <qsharedpointer.h>
#include <qstringlist.h>
#include <qvariant.h> #include <qvariant.h>
namespace ZShell::internal::hypr { namespace ZShell::internal::hypr {
@@ -15,13 +19,13 @@ Q_OBJECT
QML_ELEMENT QML_ELEMENT
Q_MOC_INCLUDE("hyprdevices.hpp") Q_MOC_INCLUDE("hyprdevices.hpp")
Q_PROPERTY(QVariantHash options READ options NOTIFY optionsChanged) Q_PROPERTY(QVariantMap options READ options NOTIFY optionsChanged)
Q_PROPERTY(ZShell::internal::hypr::HyprDevices* devices READ devices CONSTANT) Q_PROPERTY(ZShell::internal::hypr::HyprDevices* devices READ devices CONSTANT)
public: public:
explicit HyprExtras(QObject* parent = nullptr); explicit HyprExtras(QObject* parent = nullptr);
[[nodiscard]] QVariantHash options() const; [[nodiscard]] QVariantMap options() const;
[[nodiscard]] HyprDevices* devices() const; [[nodiscard]] HyprDevices* devices() const;
Q_INVOKABLE void message(const QString& message); Q_INVOKABLE void message(const QString& message);
@@ -42,11 +46,12 @@ QString m_eventSocket;
QLocalSocket* m_socket; QLocalSocket* m_socket;
bool m_socketValid; bool m_socketValid;
QVariantHash m_options; QVariantMap m_options;
HyprDevices* const m_devices; HyprDevices* const m_devices;
SocketPtr m_optionsRefresh; SocketPtr m_optionsRefresh;
SocketPtr m_devicesRefresh; SocketPtr m_devicesRefresh;
quint64 m_optionsRefreshGeneration = 0;
void socketError(QLocalSocket::LocalSocketError error) const; void socketError(QLocalSocket::LocalSocketError error) const;
void socketStateChanged(QLocalSocket::LocalSocketState state); void socketStateChanged(QLocalSocket::LocalSocketState state);