plugin/hypr: add more helpers

Also refresh options on dynamic option application
This commit is contained in:
2 * r + 2 * t 2025-09-25 00:40:55 +10:00
parent 57e3989185
commit f0ca30692d
5 changed files with 45 additions and 8 deletions

View file

@ -23,6 +23,6 @@ ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
text: qsTr("Switch layout") text: qsTr("Switch layout")
onClicked: Hypr.message("switchxkblayout all next") onClicked: Hypr.extras.message("switchxkblayout all next")
} }
} }

View file

@ -51,10 +51,40 @@ HyprDevices* HyprExtras::devices() const {
} }
void HyprExtras::message(const QString& message) { void HyprExtras::message(const QString& message) {
if (message.isEmpty()) {
return;
}
makeRequest(message, [](bool, const QByteArray&) { makeRequest(message, [](bool, const QByteArray&) {
}); });
} }
void HyprExtras::batchMessage(const QStringList& messages) {
if (messages.isEmpty()) {
return;
}
makeRequest("[[BATCH]]" + messages.join(";"), [](bool, const QByteArray&) {
});
}
void HyprExtras::applyOptions(const QVariantHash& options) {
if (options.isEmpty()) {
return;
}
QString request = "[[BATCH]]";
for (auto it = options.constBegin(); it != options.constEnd(); ++it) {
request += QString("keyword %1 %2;").arg(it.key(), it.value().toString());
}
makeRequest(request, [this](bool success, const QByteArray&) {
if (success) {
refreshOptions();
}
});
}
void HyprExtras::refreshOptions() { void HyprExtras::refreshOptions() {
if (!m_optionsRefresh.isNull()) { if (!m_optionsRefresh.isNull()) {
m_optionsRefresh->close(); m_optionsRefresh->close();

View file

@ -21,6 +21,8 @@ public:
[[nodiscard]] HyprDevices* devices() const; [[nodiscard]] HyprDevices* devices() const;
Q_INVOKABLE void message(const QString& message); 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 refreshOptions();
Q_INVOKABLE void refreshDevices(); Q_INVOKABLE void refreshDevices();

View file

@ -13,7 +13,16 @@ Singleton {
property alias enabled: props.enabled property alias enabled: props.enabled
function setDynamicConfs(): void { function setDynamicConfs(): void {
Hypr.message("[[BATCH]]keyword animations:enabled 0;keyword decoration:shadow:enabled 0;keyword decoration:blur:enabled 0;keyword general:gaps_in 0;keyword general:gaps_out 0;keyword general:border_size 1;keyword decoration:rounding 0;keyword general:allow_tearing 1"); Hypr.extras.applyOptions({
"animations:enabled": 0,
"decoration:shadow:enabled": 0,
"decoration:blur:enabled": 0,
"general:gaps_in": 0,
"general:gaps_out": 0,
"general:border_size": 1,
"decoration:rounding": 0,
"general:allow_tearing": 1
});
} }
onEnabledChanged: { onEnabledChanged: {
@ -22,7 +31,7 @@ Singleton {
if (Config.utilities.toasts.gameModeChanged) if (Config.utilities.toasts.gameModeChanged)
Toaster.toast(qsTr("Game mode enabled"), qsTr("Disabled Hyprland animations, blur, gaps and shadows"), "gamepad"); Toaster.toast(qsTr("Game mode enabled"), qsTr("Disabled Hyprland animations, blur, gaps and shadows"), "gamepad");
} else { } else {
Hypr.message("reload"); Hypr.extras.message("reload");
if (Config.utilities.toasts.gameModeChanged) if (Config.utilities.toasts.gameModeChanged)
Toaster.toast(qsTr("Game mode disabled"), qsTr("Hyprland settings restored"), "gamepad"); Toaster.toast(qsTr("Game mode disabled"), qsTr("Hyprland settings restored"), "gamepad");
} }

View file

@ -35,10 +35,6 @@ Singleton {
signal configReloaded signal configReloaded
function message(message: string): void {
extras.message(message);
}
function dispatch(request: string): void { function dispatch(request: string): void {
Hyprland.dispatch(request); Hyprland.dispatch(request);
} }
@ -77,7 +73,7 @@ Singleton {
if (n === "configreloaded") { if (n === "configreloaded") {
root.configReloaded(); root.configReloaded();
extras.message("[[BATCH]]keyword bindln ,Caps_Lock,global,caelestia:refreshDevices;keyword bindln ,Num_Lock,global,caelestia:refreshDevices"); extras.batchMessage(["keyword bindln ,Caps_Lock,global,caelestia:refreshDevices", "keyword bindln ,Num_Lock,global,caelestia:refreshDevices"]);
} else if (["workspace", "moveworkspace", "activespecial", "focusedmon"].includes(n)) { } else if (["workspace", "moveworkspace", "activespecial", "focusedmon"].includes(n)) {
Hyprland.refreshWorkspaces(); Hyprland.refreshWorkspaces();
Hyprland.refreshMonitors(); Hyprland.refreshMonitors();