Skip to content

Commit 3ff8fc8

Browse files
authored
Merge pull request #3447 from khaneliman/hyprland-disable
hyprland: disable modules instead of rendering empty
2 parents d061d22 + 4295faa commit 3ff8fc8

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

src/modules/hyprland/backend.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,23 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
153153
const auto serverSocket = socket(AF_UNIX, SOCK_STREAM, 0);
154154

155155
if (serverSocket < 0) {
156-
spdlog::error("Hyprland IPC: Couldn't open a socket (1)");
157-
return "";
156+
throw std::runtime_error("Hyprland IPC: Couldn't open a socket (1)");
158157
}
159158

160159
memset(&aiHints, 0, sizeof(struct addrinfo));
161160
aiHints.ai_family = AF_UNSPEC;
162161
aiHints.ai_socktype = SOCK_STREAM;
163162

164163
if (getaddrinfo("localhost", nullptr, &aiHints, &aiRes) != 0) {
165-
spdlog::error("Hyprland IPC: Couldn't get host (2)");
166-
return "";
164+
throw std::runtime_error("Hyprland IPC: Couldn't get host (2)");
167165
}
168166

169167
// get the instance signature
170168
auto* instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");
171169

172170
if (instanceSig == nullptr) {
173-
spdlog::error("Hyprland IPC: HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)");
174-
return "";
171+
throw std::runtime_error(
172+
"Hyprland IPC: HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)");
175173
}
176174

177175
sockaddr_un serverAddress = {0};
@@ -182,14 +180,12 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
182180
// Use snprintf to copy the socketPath string into serverAddress.sun_path
183181
if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) <
184182
0) {
185-
spdlog::error("Hyprland IPC: Couldn't copy socket path (6)");
186-
return "";
183+
throw std::runtime_error("Hyprland IPC: Couldn't copy socket path (6)");
187184
}
188185

189186
if (connect(serverSocket, reinterpret_cast<sockaddr*>(&serverAddress), sizeof(serverAddress)) <
190187
0) {
191-
spdlog::error("Hyprland IPC: Couldn't connect to " + socketPath + ". (3)");
192-
return "";
188+
throw std::runtime_error("Hyprland IPC: Couldn't connect to " + socketPath + ". (3)");
193189
}
194190

195191
auto sizeWritten = write(serverSocket, rq.c_str(), rq.length());

test/hyprland/backend.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ TEST_CASE_METHOD(IPCTestFixture, "XDGRuntimeDirExistsNoHyprDir", "[getSocketFold
5252
REQUIRE(actualPath == expectedPath);
5353
}
5454

55-
TEST_CASE_METHOD(IPCMock, "getSocket1JsonReply handles empty response", "[getSocket1JsonReply]") {
55+
TEST_CASE_METHOD(IPCTestFixture, "getSocket1Reply throws on no socket", "[getSocket1Reply]") {
5656
std::string request = "test_request";
5757

58-
Json::Value jsonResponse = getSocket1JsonReply(request);
59-
60-
REQUIRE(jsonResponse.isNull());
58+
CHECK_THROWS(getSocket1Reply(request));
6159
}

test/hyprland/fixtures/IPCTestFixture.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ class IPCMock : public IPCTestFixture {
1919
public:
2020
// Mock getSocket1Reply to return an empty string
2121
static std::string getSocket1Reply(const std::string& rq) { return ""; }
22+
23+
protected:
24+
const char* instanceSig = "instance_sig";
2225
};

0 commit comments

Comments
 (0)