sway/workspaces: clang-tidy

This commit is contained in:
Austin Horstman 2024-07-16 18:26:28 -05:00
parent 17132b250d
commit 9c40137d05
No known key found for this signature in database
2 changed files with 11 additions and 13 deletions

View File

@ -19,7 +19,7 @@ namespace waybar::modules::sway {
class Workspaces : public AModule, public sigc::trackable { class Workspaces : public AModule, public sigc::trackable {
public: public:
Workspaces(const std::string&, const waybar::Bar&, const Json::Value&); Workspaces(const std::string&, const waybar::Bar&, const Json::Value&);
virtual ~Workspaces() = default; ~Workspaces() override = default;
auto update() -> void override; auto update() -> void override;
private: private:
@ -38,10 +38,10 @@ class Workspaces : public AModule, public sigc::trackable {
Gtk::Button& addButton(const Json::Value&); Gtk::Button& addButton(const Json::Value&);
void onButtonReady(const Json::Value&, Gtk::Button&); void onButtonReady(const Json::Value&, Gtk::Button&);
std::string getIcon(const std::string&, const Json::Value&); std::string getIcon(const std::string&, const Json::Value&);
const std::string getCycleWorkspace(std::vector<Json::Value>::iterator, bool prev) const; std::string getCycleWorkspace(std::vector<Json::Value>::iterator, bool prev) const;
uint16_t getWorkspaceIndex(const std::string& name) const; uint16_t getWorkspaceIndex(const std::string& name) const;
std::string trimWorkspaceName(std::string); static std::string trimWorkspaceName(std::string);
bool handleScroll(GdkEventScroll*) override; bool handleScroll(GdkEventScroll* /*unused*/) override;
const Bar& bar_; const Bar& bar_;
std::vector<Json::Value> workspaces_; std::vector<Json::Value> workspaces_;

View File

@ -11,15 +11,14 @@ namespace waybar::modules::sway {
// Helper function to assign a number to a workspace, just like sway. In fact // Helper function to assign a number to a workspace, just like sway. In fact
// this is taken quite verbatim from `sway/ipc-json.c`. // this is taken quite verbatim from `sway/ipc-json.c`.
int Workspaces::convertWorkspaceNameToNum(std::string name) { int Workspaces::convertWorkspaceNameToNum(std::string name) {
if (isdigit(name[0])) { if (isdigit(name[0]) != 0) {
errno = 0; errno = 0;
char *endptr = NULL; char *endptr = nullptr;
long long parsed_num = strtoll(name.c_str(), &endptr, 10); long long parsed_num = strtoll(name.c_str(), &endptr, 10);
if (errno != 0 || parsed_num > INT32_MAX || parsed_num < 0 || endptr == name.c_str()) { if (errno != 0 || parsed_num > INT32_MAX || parsed_num < 0 || endptr == name.c_str()) {
return -1; return -1;
} else {
return (int)parsed_num;
} }
return (int)parsed_num;
} }
return -1; return -1;
} }
@ -47,7 +46,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
bar_(bar), bar_(bar),
box_(bar.orientation, 0) { box_(bar.orientation, 0) {
if (config["format-icons"]["high-priority-named"].isArray()) { if (config["format-icons"]["high-priority-named"].isArray()) {
for (auto &it : config["format-icons"]["high-priority-named"]) { for (const auto &it : config["format-icons"]["high-priority-named"]) {
high_priority_named_.push_back(it.asString()); high_priority_named_.push_back(it.asString());
} }
} }
@ -70,7 +69,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
m_windowRewriteRules = waybar::util::RegexCollection( m_windowRewriteRules = waybar::util::RegexCollection(
windowRewrite, m_windowRewriteDefault, windowRewrite, m_windowRewriteDefault,
[this](std::string &window_rule) { return windowRewritePriorityFunction(window_rule); }); [](std::string &window_rule) { return windowRewritePriorityFunction(window_rule); });
ipc_.subscribe(R"(["workspace"])"); ipc_.subscribe(R"(["workspace"])");
ipc_.subscribe(R"(["window"])"); ipc_.subscribe(R"(["window"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent)); ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
@ -414,7 +413,7 @@ std::string Workspaces::getIcon(const std::string &name, const Json::Value &node
} }
bool Workspaces::handleScroll(GdkEventScroll *e) { bool Workspaces::handleScroll(GdkEventScroll *e) {
if (gdk_event_get_pointer_emulated((GdkEvent *)e)) { if (gdk_event_get_pointer_emulated((GdkEvent *)e) != 0) {
/** /**
* Ignore emulated scroll events on window * Ignore emulated scroll events on window
*/ */
@ -464,8 +463,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
return true; return true;
} }
const std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterator it, std::string Workspaces::getCycleWorkspace(std::vector<Json::Value>::iterator it, bool prev) const {
bool prev) const {
if (prev && it == workspaces_.begin() && !config_["disable-scroll-wraparound"].asBool()) { if (prev && it == workspaces_.begin() && !config_["disable-scroll-wraparound"].asBool()) {
return (*(--workspaces_.end()))["name"].asString(); return (*(--workspaces_.end()))["name"].asString();
} }