Skip to content

Commit

Permalink
Merge pull request #2930 from zjeffer/fix/zjeffer/hyprland-clang-tidy
Browse files Browse the repository at this point in the history
fix clang-tidy errors in hyprland module
  • Loading branch information
Alexays authored Feb 25, 2024
2 parents fb19352 + 42f4386 commit 3a33c0b
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ CheckOptions:
- { key: readability-identifier-naming.FunctionCase, value: camelBack }
- { key: readability-identifier-naming.VariableCase, value: camelBack }
- { key: readability-identifier-naming.PrivateMemberCase, value: camelBack }
- { key: readability-identifier-naming.PrivateMemberPrefix, value: m_ }
- { key: readability-identifier-naming.PrivateMemberSuffix, value: _ }
- { key: readability-identifier-naming.EnumCase, value: CamelCase }
- { key: readability-identifier-naming.EnumConstantCase, value: UPPER_CASE }
- { key: readability-identifier-naming.GlobalConstantCase, value: UPPER_CASE }
Expand Down
10 changes: 5 additions & 5 deletions include/modules/hyprland/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class IPC {
public:
IPC() { startIPC(); }

void registerForIPC(const std::string&, EventHandler*);
void unregisterForIPC(EventHandler*);
void registerForIPC(const std::string& ev, EventHandler* ev_handler);
void unregisterForIPC(EventHandler* handler);

static std::string getSocket1Reply(const std::string& rq);
Json::Value getSocket1JsonReply(const std::string& rq);
Expand All @@ -30,9 +30,9 @@ class IPC {
void startIPC();
void parseIPC(const std::string&);

std::mutex m_callbackMutex;
util::JsonParser m_parser;
std::list<std::pair<std::string, EventHandler*>> m_callbacks;
std::mutex callbackMutex_;
util::JsonParser parser_;
std::list<std::pair<std::string, EventHandler*>> callbacks_;
};

inline std::unique_ptr<IPC> gIPC;
Expand Down
2 changes: 1 addition & 1 deletion include/modules/hyprland/language.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Language : public waybar::ALabel, public EventHandler {
std::string short_description;
};

auto getLayout(const std::string&) -> Layout;
static auto getLayout(const std::string&) -> Layout;

std::mutex mutex_;
const Bar& bar_;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/hyprland/submap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ namespace waybar::modules::hyprland {
class Submap : public waybar::ALabel, public EventHandler {
public:
Submap(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~Submap();
~Submap() override;

auto update() -> void override;

private:
void onEvent(const std::string&) override;
void onEvent(const std::string& ev) override;

std::mutex mutex_;
const Bar& bar_;
Expand Down
18 changes: 9 additions & 9 deletions include/modules/hyprland/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Window : public waybar::AAppIconLabel, public EventHandler {
std::string last_window;
std::string last_window_title;

static auto parse(const Json::Value&) -> Workspace;
static auto parse(const Json::Value& value) -> Workspace;
};

struct WindowData {
Expand All @@ -41,22 +41,22 @@ class Window : public waybar::AAppIconLabel, public EventHandler {
static auto parse(const Json::Value&) -> WindowData;
};

auto getActiveWorkspace(const std::string&) -> Workspace;
auto getActiveWorkspace() -> Workspace;
void onEvent(const std::string&) override;
static auto getActiveWorkspace(const std::string&) -> Workspace;
static auto getActiveWorkspace() -> Workspace;
void onEvent(const std::string& ev) override;
void queryActiveWorkspace();
void setClass(const std::string&, bool enable);

bool separate_outputs;
bool separateOutputs_;
std::mutex mutex_;
const Bar& bar_;
util::JsonParser parser_;
WindowData window_data_;
WindowData windowData_;
Workspace workspace_;
std::string solo_class_;
std::string last_solo_class_;
std::string soloClass_;
std::string lastSoloClass_;
bool solo_;
bool all_floating_;
bool allFloating_;
bool swallowing_;
bool fullscreen_;
};
Expand Down
46 changes: 23 additions & 23 deletions src/modules/hyprland/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ void IPC::startIPC() {
return;
}

auto file = fdopen(socketfd, "r");
auto* file = fdopen(socketfd, "r");

while (true) {
char buffer[1024]; // Hyprland socket2 events are max 1024 bytes
std::array<char, 1024> buffer; // Hyprland socket2 events are max 1024 bytes

auto recievedCharPtr = fgets(buffer, 1024, file);
auto* receivedCharPtr = fgets(buffer.data(), buffer.size(), file);

if (!recievedCharPtr) {
if (receivedCharPtr == nullptr) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
continue;
}

std::string messageRecieved(buffer);
messageRecieved = messageRecieved.substr(0, messageRecieved.find_first_of('\n'));
spdlog::debug("hyprland IPC received {}", messageRecieved);
parseIPC(messageRecieved);
std::string messageReceived(buffer.data());
messageReceived = messageReceived.substr(0, messageReceived.find_first_of('\n'));
spdlog::debug("hyprland IPC received {}", messageReceived);
parseIPC(messageReceived);

std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
Expand All @@ -78,35 +78,35 @@ void IPC::startIPC() {

void IPC::parseIPC(const std::string& ev) {
std::string request = ev.substr(0, ev.find_first_of('>'));
std::unique_lock lock(m_callbackMutex);
std::unique_lock lock(callbackMutex_);

for (auto& [eventname, handler] : m_callbacks) {
for (auto& [eventname, handler] : callbacks_) {
if (eventname == request) {
handler->onEvent(ev);
}
}
}

void IPC::registerForIPC(const std::string& ev, EventHandler* ev_handler) {
if (!ev_handler) {
if (ev_handler == nullptr) {
return;
}

std::unique_lock lock(m_callbackMutex);
m_callbacks.emplace_back(ev, ev_handler);
std::unique_lock lock(callbackMutex_);
callbacks_.emplace_back(ev, ev_handler);
}

void IPC::unregisterForIPC(EventHandler* ev_handler) {
if (!ev_handler) {
if (ev_handler == nullptr) {
return;
}

std::unique_lock lock(m_callbackMutex);
std::unique_lock lock(callbackMutex_);

for (auto it = m_callbacks.begin(); it != m_callbacks.end();) {
for (auto it = callbacks_.begin(); it != callbacks_.end();) {
auto& [eventname, handler] = *it;
if (handler == ev_handler) {
m_callbacks.erase(it++);
callbacks_.erase(it++);
} else {
++it;
}
Expand Down Expand Up @@ -135,9 +135,9 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
}

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

if (!instanceSig) {
if (instanceSig == nullptr) {
spdlog::error("Hyprland IPC: HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)");
return "";
}
Expand Down Expand Up @@ -169,26 +169,26 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
return "";
}

char buffer[8192] = {0};
std::array<char, 8192> buffer = {0};
std::string response;

do {
sizeWritten = read(serverSocket, buffer, 8192);
sizeWritten = read(serverSocket, buffer.data(), 8192);

if (sizeWritten < 0) {
spdlog::error("Hyprland IPC: Couldn't read (5)");
close(serverSocket);
return "";
}
response.append(buffer, sizeWritten);
response.append(buffer.data(), sizeWritten);
} while (sizeWritten > 0);

close(serverSocket);
return response;
}

Json::Value IPC::getSocket1JsonReply(const std::string& rq) {
return m_parser.parse(getSocket1Reply("j/" + rq));
return parser_.parse(getSocket1Reply("j/" + rq));
}

} // namespace waybar::modules::hyprland
25 changes: 12 additions & 13 deletions src/modules/hyprland/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Language::Language(const std::string& id, const Bar& bar, const Json::Value& con
: ALabel(config, "language", id, "{}", 0, true), bar_(bar) {
modulesReady = true;

if (!gIPC.get()) {
if (!gIPC) {
gIPC = std::make_unique<IPC>();
}

Expand Down Expand Up @@ -102,11 +102,11 @@ void Language::initLanguage() {
}

auto Language::getLayout(const std::string& fullName) -> Layout {
const auto CONTEXT = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
rxkb_context_parse_default_ruleset(CONTEXT);
auto* const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES);
rxkb_context_parse_default_ruleset(context);

rxkb_layout* layout = rxkb_layout_first(CONTEXT);
while (layout) {
rxkb_layout* layout = rxkb_layout_first(context);
while (layout != nullptr) {
std::string nameOfLayout = rxkb_layout_get_description(layout);

if (nameOfLayout != fullName) {
Expand All @@ -115,21 +115,20 @@ auto Language::getLayout(const std::string& fullName) -> Layout {
}

auto name = std::string(rxkb_layout_get_name(layout));
auto variant_ = rxkb_layout_get_variant(layout);
std::string variant = variant_ == nullptr ? "" : std::string(variant_);
const auto* variantPtr = rxkb_layout_get_variant(layout);
std::string variant = variantPtr == nullptr ? "" : std::string(variantPtr);

auto short_description_ = rxkb_layout_get_brief(layout);
std::string short_description =
short_description_ == nullptr ? "" : std::string(short_description_);
const auto* descriptionPtr = rxkb_layout_get_brief(layout);
std::string description = descriptionPtr == nullptr ? "" : std::string(descriptionPtr);

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

rxkb_context_unref(CONTEXT);
rxkb_context_unref(context);

return info;
}

rxkb_context_unref(CONTEXT);
rxkb_context_unref(context);

spdlog::debug("hyprland language didn't find matching layout");

Expand Down
2 changes: 1 addition & 1 deletion src/modules/hyprland/submap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config)
: ALabel(config, "submap", id, "{}", 0, true), bar_(bar) {
modulesReady = true;

if (!gIPC.get()) {
if (!gIPC) {
gIPC = std::make_unique<IPC>();
}

Expand Down
Loading

0 comments on commit 3a33c0b

Please sign in to comment.