Skip to content

Commit 14ccbb7

Browse files
committed
refactor(internal): pass usingLua from QML instead of detecting in C++
1 parent c9bee9d commit 14ccbb7

8 files changed

Lines changed: 14 additions & 38 deletions

File tree

modules/bar/Bar.qml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import "components/workspaces"
66
import QtQuick
77
import QtQuick.Layouts
88
import Quickshell
9-
import Quickshell.Hyprland
109
import Caelestia.Config
1110
import qs.components
1211
import qs.services
@@ -84,9 +83,9 @@ ColumnLayout {
8483
const mon = (GlobalConfig.bar.workspaces.perMonitorWorkspaces ? Hypr.monitorFor(screen) : Hypr.focusedMonitor);
8584
const specialWs = mon?.lastIpcObject.specialWorkspace.name;
8685
if (specialWs?.length > 0)
87-
Hypr.dispatch(Hyprland.usingLua ? `hl.dsp.workspace.toggle_special( "${specialWs.slice(8)}" )` : `togglespecialworkspace ${specialWs.slice(8)}`);
86+
Hypr.dispatch(Hypr.usingLua ? `hl.dsp.workspace.toggle_special( "${specialWs.slice(8)}" )` : `togglespecialworkspace ${specialWs.slice(8)}`);
8887
else if (angleDelta.y < 0 || (GlobalConfig.bar.workspaces.perMonitorWorkspaces ? mon.activeWorkspace?.id : Hypr.activeWsId) > 1)
89-
Hypr.dispatch(Hyprland.usingLua ? `hl.dsp.focus({ workspace = "r${angleDelta.y > 0 ? "-" : "+"}1"})` : `workspace r${angleDelta.y > 0 ? "-" : "+"}1`);
88+
Hypr.dispatch(Hypr.usingLua ? `hl.dsp.focus({ workspace = "r${angleDelta.y > 0 ? "-" : "+"}1"})` : `workspace r${angleDelta.y > 0 ? "-" : "+"}1`);
9089
} else if (y < screen.height / 2 && Config.bar.scrollActions.volume) {
9190
// Volume scroll on top half
9291
if (angleDelta.y > 0)

modules/bar/components/workspaces/SpecialWorkspaces.qml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ Item {
227227

228228
const ws = view.itemAt(event.x, event.y) as SpecialWsDelegate;
229229
if (ws?.modelData)
230-
Hypr.dispatch(Hyprland.usingLua ? `hl.dsp.workspace.toggle_special( "${ws.modelData.name.slice(8)}" )` : `togglespecialworkspace ${ws.modelData.name.slice(8)}`);
230+
Hypr.dispatch(Hypr.usingLua ? `hl.dsp.workspace.toggle_special( "${ws.modelData.name.slice(8)}" )` : `togglespecialworkspace ${ws.modelData.name.slice(8)}`);
231231
else
232-
Hypr.dispatch(Hyprland.usingLua ? `hl.dsp.workspace.toggle_special( "special" )` : `togglespecialworkspace special`);
232+
Hypr.dispatch(Hypr.usingLua ? `hl.dsp.workspace.toggle_special( "special" )` : `togglespecialworkspace special`);
233233
}
234234
}
235235

modules/bar/components/workspaces/Workspaces.qml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import QtQuick
44
import QtQuick.Effects
55
import QtQuick.Layouts
66
import Quickshell
7-
import Quickshell.Hyprland
87
import Caelestia.Config
98
import qs.components
109
import qs.services
@@ -98,9 +97,9 @@ StyledClippingRect {
9897
onClicked: event => {
9998
const ws = (layout.childAt(event.x, event.y) as Workspace)?.ws;
10099
if (Hypr.activeWsId !== ws)
101-
Hyprland.dispatch(Hyprland.usingLua ? `hl.dsp.focus({ workspace= "${ws}"})` : `workspace ${ws}`);
100+
Hypr.dispatch(Hypr.usingLua ? `hl.dsp.focus({ workspace= "${ws}"})` : `workspace ${ws}`);
102101
else
103-
Hyprland.dispatch(Hyprland.usingLua ? `hl.dsp.workspace.toggle_special({ "special" })` : `togglespecialworkspace special`);
102+
Hypr.dispatch(Hypr.usingLua ? `hl.dsp.workspace.toggle_special({ "special" })` : `togglespecialworkspace special`);
104103
}
105104
}
106105

modules/windowinfo/Buttons.qml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ pragma ComponentBehavior: Bound
22

33
import QtQuick
44
import QtQuick.Layouts
5-
import Quickshell.Hyprland
65
import Caelestia.Config
76
import qs.components
87
import qs.services
@@ -96,7 +95,7 @@ ColumnLayout {
9695
readonly property bool isCurrent: root.client?.workspace.id === wsId
9796

9897
onClicked: {
99-
Hypr.dispatch(`movetoworkspace ${wsId},address:0x${root.client?.address}`);
98+
Hypr.dispatch(Hypr.usingLua ? `hl.dsp.window.move({ workspace = "${wsId}", follow = true })` : `movetoworkspace ${wsId},address:0x${root.client?.address}`);
10099
}
101100
102101
color: isCurrent ? Colours.tPalette.m3surfaceContainerHighest : Colours.palette.m3tertiaryContainer
@@ -119,7 +118,7 @@ ColumnLayout {
119118
color: Colours.palette.m3secondaryContainer
120119
onColor: Colours.palette.m3onSecondaryContainer
121120
text: root.client?.lastIpcObject.floating ? qsTr("Tile") : qsTr("Float")
122-
onClicked: Hypr.dispatch(Hyprland.usingLua ? `hl.dsp.window.float({ window = "address:0x${root.client?.address}" })` : `togglefloating address:0x${root.client?.address}`)
121+
onClicked: Hypr.dispatch(Hypr.usingLua ? `hl.dsp.window.float({ window = "address:0x${root.client?.address}" })` : `togglefloating address:0x${root.client?.address}`);
123122
}
124123
125124
Loader {
@@ -133,15 +132,15 @@ ColumnLayout {
133132
color: Colours.palette.m3secondaryContainer
134133
onColor: Colours.palette.m3onSecondaryContainer
135134
text: root.client?.lastIpcObject.pinned ? qsTr("Unpin") : qsTr("Pin")
136-
onClicked: Hypr.dispatch(Hyprland.usingLua ? `hl.dsp.window.pin({ window = "address:0x${root.client?.address}" })` : `pin address:0x${root.client?.address}`)
135+
onClicked: Hypr.dispatch(Hypr.usingLua ? `hl.dsp.window.pin({ window = "address:0x${root.client?.address}" })` : `pin address:0x${root.client?.address}`);
137136
}
138137
}
139138
140139
Button {
141140
color: Colours.palette.m3errorContainer
142141
onColor: Colours.palette.m3onErrorContainer
143142
text: qsTr("Kill")
144-
onClicked: Hypr.dispatch(Hyprland.usingLua ? `hl.dsp.window.kill({ window = "address:0x${root.client?.address}" })` : `killwindow address:0x${root.client?.address}`)
143+
onClicked: Hypr.dispatch(Hypr.usingLua ? `hl.dsp.window.kill({ window = "address:0x${root.client?.address}" })` : `killwindow address:0x${root.client?.address}`);
145144
}
146145
}
147146

plugin/src/Caelestia/Internal/hyprextras.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ HyprExtras::HyprExtras(QObject* parent)
3939

4040
refreshOptions();
4141
refreshDevices();
42-
detectConfigProvider();
4342

4443
m_socket = new QLocalSocket(this);
4544

@@ -70,24 +69,6 @@ void HyprExtras::message(const QString& message) {
7069
});
7170
}
7271

73-
bool HyprExtras::usingLua() const {
74-
return m_usingLua;
75-
}
76-
77-
void HyprExtras::detectConfigProvider() {
78-
makeRequest("systeminfo", [this](bool success, const QByteArray& res) {
79-
if (!success) {
80-
return;
81-
}
82-
83-
const bool lua = QString::fromUtf8(res).contains("configProvider: lua");
84-
if (m_usingLua != lua) {
85-
m_usingLua = lua;
86-
emit usingLuaChanged();
87-
}
88-
});
89-
}
90-
9172
void HyprExtras::batchMessage(const QStringList& messages) {
9273
if (messages.isEmpty()) {
9374
return;
@@ -195,7 +176,6 @@ void HyprExtras::readEvent() {
195176
void HyprExtras::handleEvent(const QString& event) {
196177
if (event == "configreloaded") {
197178
refreshOptions();
198-
detectConfigProvider();
199179
} else if (event == "activelayout") {
200180
refreshDevices();
201181
}

plugin/src/Caelestia/Internal/hyprextras.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ class HyprExtras : public QObject {
1717

1818
Q_PROPERTY(QVariantHash options READ options NOTIFY optionsChanged)
1919
Q_PROPERTY(caelestia::internal::hypr::HyprDevices* devices READ devices CONSTANT)
20-
Q_PROPERTY(bool usingLua READ usingLua NOTIFY usingLuaChanged)
20+
Q_PROPERTY(bool usingLua MEMBER m_usingLua NOTIFY usingLuaChanged)
2121

2222
public:
2323
explicit HyprExtras(QObject* parent = nullptr);
2424

2525
[[nodiscard]] QVariantHash options() const;
2626
[[nodiscard]] HyprDevices* devices() const;
27-
[[nodiscard]] bool usingLua() const;
2827

2928
Q_INVOKABLE void message(const QString& message);
3029
Q_INVOKABLE void batchMessage(const QStringList& messages);
@@ -56,7 +55,6 @@ class HyprExtras : public QObject {
5655
void socketStateChanged(QLocalSocket::LocalSocketState state);
5756
void readEvent();
5857
void handleEvent(const QString& event);
59-
void detectConfigProvider();
6058

6159
SocketPtr makeRequestJson(const QString& request, const std::function<void(bool, QJsonDocument)>& callback);
6260
SocketPtr makeRequest(const QString& request, const std::function<void(bool, QByteArray)>& callback);

services/Colours.qml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ pragma ComponentBehavior: Bound
33

44
import QtQuick
55
import Quickshell
6-
import Quickshell.Hyprland
76
import Quickshell.Io
87
import Caelestia
98
import Caelestia.Config
@@ -84,7 +83,7 @@ Singleton {
8483
}
8584

8685
function reloadHyprRules(): void {
87-
const str = Hyprland.usingLua ? `eval 'hl.layer_rule({ match = { namespace = "caelestia-drawers" }, %1 = true, %2 = true })'` : "keyword layerrule %1 %2, match:namespace caelestia-drawers";
86+
const str = Hypr.usingLua ? `eval 'hl.layer_rule({ match = { namespace = "caelestia-drawers" }, %1 = true, %2 = true })'` : "keyword layerrule %1 %2, match:namespace caelestia-drawers";
8887
Hypr.extras.batchMessage([str.arg("blur").arg(transparency.enabled ? 1 : 0), str.arg("ignore_alpha").arg(transparency.base - 0.03)]);
8988
}
9089

services/Hypr.qml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Singleton {
1515
readonly property var toplevels: Hyprland.toplevels
1616
readonly property var workspaces: Hyprland.workspaces
1717
readonly property var monitors: Hyprland.monitors
18+
readonly property bool usingLua: Hyprland.usingLua
1819

1920
readonly property HyprlandToplevel activeToplevel: {
2021
const t = Hyprland.activeToplevel;
@@ -222,5 +223,6 @@ Singleton {
222223

223224
HyprExtras {
224225
id: extras
226+
usingLua: Hyprland.usingLua
225227
}
226228
}

0 commit comments

Comments
 (0)