Skip to content

Commit 1142979

Browse files
committed
chore: lint
1 parent 8a89706 commit 1142979

File tree

6 files changed

+98
-137
lines changed

6 files changed

+98
-137
lines changed

include/modules/niri/backend.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class IPC {
2626

2727
// The data members are only safe to access while dataMutex_ is locked.
2828
std::lock_guard<std::mutex> lockData() { return std::lock_guard(dataMutex_); }
29-
const std::vector<Json::Value> &workspaces() const { return workspaces_; }
30-
const std::vector<Json::Value> &windows() const { return windows_; }
31-
const std::vector<std::string> &keyboardLayoutNames() const { return keyboardLayoutNames_; }
29+
const std::vector<Json::Value>& workspaces() const { return workspaces_; }
30+
const std::vector<Json::Value>& windows() const { return windows_; }
31+
const std::vector<std::string>& keyboardLayoutNames() const { return keyboardLayoutNames_; }
3232
unsigned keyboardLayoutCurrent() const { return keyboardLayoutCurrent_; }
3333

3434
private:

include/modules/niri/language.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace waybar::modules::niri {
1010

1111
class Language : public ALabel, public EventHandler {
1212
public:
13-
Language(const std::string&, const Bar&, const Json::Value&);
13+
Language(const std::string &, const Bar &, const Json::Value &);
1414
~Language() override;
1515
void update() override;
1616

src/modules/niri/backend.cpp

Lines changed: 53 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,47 @@
88
#include <sys/types.h>
99
#include <sys/un.h>
1010
#include <unistd.h>
11-
#include "giomm/datainputstream.h"
12-
#include "giomm/dataoutputstream.h"
13-
#include "giomm/unixinputstream.h"
14-
#include "giomm/unixoutputstream.h"
1511

1612
#include <iostream>
1713
#include <string>
1814
#include <thread>
1915

16+
#include "giomm/datainputstream.h"
17+
#include "giomm/dataoutputstream.h"
18+
#include "giomm/unixinputstream.h"
19+
#include "giomm/unixoutputstream.h"
20+
2021
namespace waybar::modules::niri {
2122

2223
int IPC::connectToSocket() {
23-
const char* socket_path = getenv("NIRI_SOCKET");
24+
const char *socket_path = getenv("NIRI_SOCKET");
2425

25-
if (socket_path == nullptr) {
26-
spdlog::warn("Niri is not running, niri IPC will not be available.");
27-
return -1;
28-
}
26+
if (socket_path == nullptr) {
27+
spdlog::warn("Niri is not running, niri IPC will not be available.");
28+
return -1;
29+
}
2930

30-
struct sockaddr_un addr;
31-
int socketfd = socket(AF_UNIX, SOCK_STREAM, 0);
31+
struct sockaddr_un addr;
32+
int socketfd = socket(AF_UNIX, SOCK_STREAM, 0);
3233

33-
if (socketfd == -1) {
34-
throw std::runtime_error("socketfd failed");
35-
}
34+
if (socketfd == -1) {
35+
throw std::runtime_error("socketfd failed");
36+
}
3637

37-
addr.sun_family = AF_UNIX;
38+
addr.sun_family = AF_UNIX;
3839

39-
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
40+
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
4041

41-
addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
42+
addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
4243

43-
int l = sizeof(struct sockaddr_un);
44+
int l = sizeof(struct sockaddr_un);
4445

45-
if (connect(socketfd, (struct sockaddr*)&addr, l) == -1) {
46-
close(socketfd);
47-
throw std::runtime_error("unable to connect");
48-
}
46+
if (connect(socketfd, (struct sockaddr *)&addr, l) == -1) {
47+
close(socketfd);
48+
throw std::runtime_error("unable to connect");
49+
}
4950

50-
return socketfd;
51+
return socketfd;
5152
}
5253

5354
void IPC::startIPC() {
@@ -61,8 +62,7 @@ void IPC::startIPC() {
6162
spdlog::error("Niri IPC: failed to start, reason: {}", e.what());
6263
return;
6364
}
64-
if (socketfd == -1)
65-
return;
65+
if (socketfd == -1) return;
6666

6767
spdlog::info("Niri IPC starting");
6868

@@ -87,7 +87,7 @@ void IPC::startIPC() {
8787

8888
try {
8989
parseIPC(line);
90-
} catch (std::exception& e) {
90+
} catch (std::exception &e) {
9191
spdlog::warn("Failed to parse IPC message: {}, reason: {}", line, e.what());
9292
} catch (...) {
9393
throw;
@@ -98,11 +98,10 @@ void IPC::startIPC() {
9898
}).detach();
9999
}
100100

101-
void IPC::parseIPC(const std::string& line) {
101+
void IPC::parseIPC(const std::string &line) {
102102
const auto ev = parser_.parse(line);
103103
const auto members = ev.getMemberNames();
104-
if (members.size() != 1)
105-
throw std::runtime_error("Event must have a single member");
104+
if (members.size() != 1) throw std::runtime_error("Event must have a single member");
106105

107106
{
108107
auto lock = lockData();
@@ -112,17 +111,15 @@ void IPC::parseIPC(const std::string& line) {
112111
const auto &values = payload["workspaces"];
113112
std::copy(values.begin(), values.end(), std::back_inserter(workspaces_));
114113

115-
std::sort(workspaces_.begin(), workspaces_.end(),
116-
[](const auto &a, const auto &b) {
117-
const auto &aOutput = a["output"].asString();
118-
const auto &bOutput = b["output"].asString();
119-
const auto aIdx = a["idx"].asUInt();
120-
const auto bIdx = b["idx"].asUInt();
121-
if (aOutput == bOutput)
122-
return aIdx < bIdx;
123-
return aOutput < bOutput;
124-
});
125-
} else if (const auto& payload = ev["WorkspaceActivated"]) {
114+
std::sort(workspaces_.begin(), workspaces_.end(), [](const auto &a, const auto &b) {
115+
const auto &aOutput = a["output"].asString();
116+
const auto &bOutput = b["output"].asString();
117+
const auto aIdx = a["idx"].asUInt();
118+
const auto bIdx = b["idx"].asUInt();
119+
if (aOutput == bOutput) return aIdx < bIdx;
120+
return aOutput < bOutput;
121+
});
122+
} else if (const auto &payload = ev["WorkspaceActivated"]) {
126123
const auto id = payload["id"].asUInt64();
127124
const auto focused = payload["focused"].asBool();
128125
auto it = std::find_if(workspaces_.begin(), workspaces_.end(),
@@ -132,19 +129,18 @@ void IPC::parseIPC(const std::string& line) {
132129
const auto &output = ws["output"].asString();
133130
for (auto &ws : workspaces_) {
134131
const auto got_activated = (ws["id"].asUInt64() == id);
135-
if (ws["output"] == output)
136-
ws["is_active"] = got_activated;
132+
if (ws["output"] == output) ws["is_active"] = got_activated;
137133

138-
if (focused)
139-
ws["is_focused"] = got_activated;
134+
if (focused) ws["is_focused"] = got_activated;
140135
}
141136
} else {
142137
spdlog::error("Activated unknown workspace");
143138
}
144-
} else if (const auto& payload = ev["WorkspaceActiveWindowChanged"]) {
139+
} else if (const auto &payload = ev["WorkspaceActiveWindowChanged"]) {
145140
const auto workspaceId = payload["workspace_id"].asUInt64();
146-
auto it = std::find_if(workspaces_.begin(), workspaces_.end(),
147-
[workspaceId](const auto &ws) { return ws["id"].asUInt64() == workspaceId; });
141+
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [workspaceId](const auto &ws) {
142+
return ws["id"].asUInt64() == workspaceId;
143+
});
148144
if (it != workspaces_.end()) {
149145
auto &ws = *it;
150146
ws["active_window_id"] = payload["active_window_id"];
@@ -157,9 +153,8 @@ void IPC::parseIPC(const std::string& line) {
157153
keyboardLayoutCurrent_ = layouts["current_idx"].asUInt();
158154

159155
keyboardLayoutNames_.clear();
160-
for (const auto &fullName : names)
161-
keyboardLayoutNames_.push_back(fullName.asString());
162-
} else if (const auto& payload = ev["KeyboardLayoutSwitched"]) {
156+
for (const auto &fullName : names) keyboardLayoutNames_.push_back(fullName.asString());
157+
} else if (const auto &payload = ev["KeyboardLayoutSwitched"]) {
163158
keyboardLayoutCurrent_ = payload["idx"].asUInt();
164159
} else if (const auto &payload = ev["WindowsChanged"]) {
165160
windows_.clear();
@@ -201,14 +196,14 @@ void IPC::parseIPC(const std::string& line) {
201196

202197
std::unique_lock lock(callbackMutex_);
203198

204-
for (auto& [eventname, handler] : callbacks_) {
199+
for (auto &[eventname, handler] : callbacks_) {
205200
if (eventname == members[0]) {
206201
handler->onEvent(ev);
207202
}
208203
}
209204
}
210205

211-
void IPC::registerForIPC(const std::string& ev, EventHandler* ev_handler) {
206+
void IPC::registerForIPC(const std::string &ev, EventHandler *ev_handler) {
212207
if (ev_handler == nullptr) {
213208
return;
214209
}
@@ -217,15 +212,15 @@ void IPC::registerForIPC(const std::string& ev, EventHandler* ev_handler) {
217212
callbacks_.emplace_back(ev, ev_handler);
218213
}
219214

220-
void IPC::unregisterForIPC(EventHandler* ev_handler) {
215+
void IPC::unregisterForIPC(EventHandler *ev_handler) {
221216
if (ev_handler == nullptr) {
222217
return;
223218
}
224219

225220
std::unique_lock lock(callbackMutex_);
226221

227222
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
228-
auto& [eventname, handler] = *it;
223+
auto &[eventname, handler] = *it;
229224
if (handler == ev_handler) {
230225
it = callbacks_.erase(it);
231226
} else {
@@ -234,10 +229,9 @@ void IPC::unregisterForIPC(EventHandler* ev_handler) {
234229
}
235230
}
236231

237-
Json::Value IPC::send(const Json::Value& request) {
232+
Json::Value IPC::send(const Json::Value &request) {
238233
int socketfd = connectToSocket();
239-
if (socketfd == -1)
240-
throw std::runtime_error("Niri is not running");
234+
if (socketfd == -1) throw std::runtime_error("Niri is not running");
241235

242236
auto unix_istream = Gio::UnixInputStream::create(socketfd, true);
243237
auto unix_ostream = Gio::UnixOutputStream::create(socketfd, false);
@@ -256,13 +250,12 @@ Json::Value IPC::send(const Json::Value& request) {
256250
throw std::runtime_error("error writing to niri socket");
257251

258252
std::string line;
259-
if (!istream->read_line(line))
260-
throw std::runtime_error("error reading from niri socket");
253+
if (!istream->read_line(line)) throw std::runtime_error("error reading from niri socket");
261254

262255
std::istringstream iss(std::move(line));
263256
Json::Value response;
264257
iss >> response;
265258
return response;
266259
}
267260

268-
} // namespace waybar::modules::hyprland
261+
} // namespace waybar::modules::niri

src/modules/niri/language.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ Language::Language(const std::string &id, const Bar &bar, const Json::Value &con
1212
: ALabel(config, "language", id, "{}", 0, true), bar_(bar) {
1313
label_.hide();
1414

15-
if (!gIPC)
16-
gIPC = std::make_unique<IPC>();
15+
if (!gIPC) gIPC = std::make_unique<IPC>();
1716

1817
gIPC->registerForIPC("KeyboardLayoutsChanged", this);
1918
gIPC->registerForIPC("KeyboardLayoutSwitched", this);
@@ -33,8 +32,7 @@ void Language::updateFromIPC() {
3332
auto ipcLock = gIPC->lockData();
3433

3534
layouts_.clear();
36-
for (const auto &fullName : gIPC->keyboardLayoutNames())
37-
layouts_.push_back(getLayout(fullName));
35+
for (const auto &fullName : gIPC->keyboardLayoutNames()) layouts_.push_back(getLayout(fullName));
3836

3937
current_idx_ = gIPC->keyboardLayoutCurrent();
4038
}
@@ -89,7 +87,7 @@ void Language::update() {
8987
ALabel::update();
9088
}
9189

92-
void Language::onEvent(const Json::Value& ev) {
90+
void Language::onEvent(const Json::Value &ev) {
9391
if (ev["KeyboardLayoutsChanged"]) {
9492
updateFromIPC();
9593
} else if (ev["KeyboardLayoutSwitched"]) {
@@ -102,10 +100,10 @@ void Language::onEvent(const Json::Value& ev) {
102100
}
103101

104102
Language::Layout Language::getLayout(const std::string &fullName) {
105-
auto* const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
103+
auto *const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
106104
rxkb_context_parse_default_ruleset(context);
107105

108-
rxkb_layout* layout = rxkb_layout_first(context);
106+
rxkb_layout *layout = rxkb_layout_first(context);
109107
while (layout != nullptr) {
110108
std::string nameOfLayout = rxkb_layout_get_description(layout);
111109

@@ -115,10 +113,10 @@ Language::Layout Language::getLayout(const std::string &fullName) {
115113
}
116114

117115
auto name = std::string(rxkb_layout_get_name(layout));
118-
const auto* variantPtr = rxkb_layout_get_variant(layout);
116+
const auto *variantPtr = rxkb_layout_get_variant(layout);
119117
std::string variant = variantPtr == nullptr ? "" : std::string(variantPtr);
120118

121-
const auto* descriptionPtr = rxkb_layout_get_brief(layout);
119+
const auto *descriptionPtr = rxkb_layout_get_brief(layout);
122120
std::string description = descriptionPtr == nullptr ? "" : std::string(descriptionPtr);
123121

124122
Layout info = Layout{nameOfLayout, name, variant, description};

0 commit comments

Comments
 (0)