From ce076927f3f5d131031cc1d76de9de4958dbafb8 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sat, 2 Sep 2023 15:22:26 -0500 Subject: [PATCH 1/3] chore: cpplint fixes hyprland headers --- include/modules/hyprland/backend.hpp | 2 ++ include/modules/hyprland/language.hpp | 4 ++++ include/modules/hyprland/submap.hpp | 4 ++++ include/modules/hyprland/window.hpp | 4 ++++ include/modules/hyprland/workspaces.hpp | 7 ++++++- 5 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/modules/hyprland/backend.hpp b/include/modules/hyprland/backend.hpp index e23b1582..7d97b553 100644 --- a/include/modules/hyprland/backend.hpp +++ b/include/modules/hyprland/backend.hpp @@ -1,10 +1,12 @@ #pragma once + #include #include #include #include #include #include +#include #include "util/json.hpp" diff --git a/include/modules/hyprland/language.hpp b/include/modules/hyprland/language.hpp index 30789d06..eb220609 100644 --- a/include/modules/hyprland/language.hpp +++ b/include/modules/hyprland/language.hpp @@ -1,5 +1,9 @@ +#pragma once + #include +#include + #include "ALabel.hpp" #include "bar.hpp" #include "modules/hyprland/backend.hpp" diff --git a/include/modules/hyprland/submap.hpp b/include/modules/hyprland/submap.hpp index e2a84981..4ff232ff 100644 --- a/include/modules/hyprland/submap.hpp +++ b/include/modules/hyprland/submap.hpp @@ -1,5 +1,9 @@ +#pragma once + #include +#include + #include "ALabel.hpp" #include "bar.hpp" #include "modules/hyprland/backend.hpp" diff --git a/include/modules/hyprland/window.hpp b/include/modules/hyprland/window.hpp index fd68b049..c9f0be03 100644 --- a/include/modules/hyprland/window.hpp +++ b/include/modules/hyprland/window.hpp @@ -1,5 +1,9 @@ +#pragma once + #include +#include + #include "AAppIconLabel.hpp" #include "bar.hpp" #include "modules/hyprland/backend.hpp" diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 96443629..b994c9e4 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -1,7 +1,12 @@ +#pragma once + #include #include +#include #include +#include +#include #include "AModule.hpp" #include "bar.hpp" @@ -11,7 +16,7 @@ namespace waybar::modules::hyprland { class Workspace { public: - Workspace(const Json::Value& workspace_data); + explicit Workspace(const Json::Value& workspace_data); std::string& select_icon(std::map& icons_map); Gtk::Button& button() { return button_; }; From 8fc41877135b6480785f9a4a3ed9f8ff934902a6 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sat, 2 Sep 2023 23:21:44 -0500 Subject: [PATCH 2/3] refactor: replace strcpy with snprintf --- src/modules/hyprland/backend.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/modules/hyprland/backend.cpp b/src/modules/hyprland/backend.cpp index 6e586966..def38f81 100644 --- a/src/modules/hyprland/backend.cpp +++ b/src/modules/hyprland/backend.cpp @@ -166,9 +166,13 @@ std::string IPC::getSocket1Reply(const std::string& rq) { std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock"; - strcpy(serverAddress.sun_path, socketPath.c_str()); + // Use snprintf to copy the socketPath string into serverAddress.sun_path + if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) < 0) { + spdlog::error("Hyprland IPC: Couldn't copy socket path (6)"); + return ""; + } - if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, SUN_LEN(&serverAddress)) < 0) { + if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, sizeof(serverAddress)) < 0) { spdlog::error("Hyprland IPC: Couldn't connect to " + socketPath + ". (3)"); return ""; } From 4cb8efbecc3596a1d32ae9186a5414903368b34f Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Sat, 2 Sep 2023 23:34:11 -0500 Subject: [PATCH 3/3] chore: cpplint fixes hyprland classes --- src/modules/hyprland/backend.cpp | 6 ++++-- src/modules/hyprland/language.cpp | 4 +--- src/modules/hyprland/submap.cpp | 2 +- src/modules/hyprland/window.cpp | 3 +-- src/modules/hyprland/workspaces.cpp | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/modules/hyprland/backend.cpp b/src/modules/hyprland/backend.cpp index def38f81..5a48d369 100644 --- a/src/modules/hyprland/backend.cpp +++ b/src/modules/hyprland/backend.cpp @@ -167,12 +167,14 @@ std::string IPC::getSocket1Reply(const std::string& rq) { std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock"; // Use snprintf to copy the socketPath string into serverAddress.sun_path - if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) < 0) { + if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) < + 0) { spdlog::error("Hyprland IPC: Couldn't copy socket path (6)"); return ""; } - if (connect(SERVERSOCKET, (sockaddr*)&serverAddress, sizeof(serverAddress)) < 0) { + if (connect(SERVERSOCKET, reinterpret_cast(&serverAddress), sizeof(serverAddress)) < + 0) { spdlog::error("Hyprland IPC: Couldn't connect to " + socketPath + ". (3)"); return ""; } diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 423e2b5c..5339ee9e 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -4,8 +4,7 @@ #include #include -#include - +#include "util/sanitize_str.hpp" #include "util/string.hpp" namespace waybar::modules::hyprland { @@ -97,7 +96,6 @@ void Language::initLanguage() { spdlog::debug("hyprland language initLanguage found {}", layout_.full_name); dp.emit(); - } catch (std::exception& e) { spdlog::error("hyprland language initLanguage failed with {}", e.what()); } diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index 22acbf31..d1d9a116 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -2,7 +2,7 @@ #include -#include +#include "util/sanitize_str.hpp" namespace waybar::modules::hyprland { diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index 60de074c..77723bc0 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -6,12 +6,11 @@ #include #include -#include -#include #include #include "modules/hyprland/backend.hpp" #include "util/rewrite_string.hpp" +#include "util/sanitize_str.hpp" namespace waybar::modules::hyprland { diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 75fb19e3..3f27df8a 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -327,7 +327,7 @@ Workspace::Workspace(const Json::Value &workspace_data) button_.set_relief(Gtk::RELIEF_NONE); content_.set_center_widget(label_); button_.add(content_); -}; +} void add_or_remove_class(const Glib::RefPtr &context, bool condition, const std::string &class_name) {