From cbc074b51a48b4ddb77810634e5378a84626c884 Mon Sep 17 00:00:00 2001 From: Toni500git Date: Sat, 31 Aug 2024 17:16:46 +0200 Subject: [PATCH] misc: format some code in src/ and include/ --- .clang-format | 3 +- include/query.hpp | 14 ++-- src/display.cpp | 6 +- src/gui.cpp | 9 ++- src/query/unix/utils/dewm.cpp | 120 +++++++++++++++--------------- src/query/unix/utils/packages.cpp | 2 +- src/util.cpp | 18 +++-- 7 files changed, 88 insertions(+), 84 deletions(-) diff --git a/.clang-format b/.clang-format index 25fb476..bbcb366 100644 --- a/.clang-format +++ b/.clang-format @@ -48,6 +48,8 @@ SpaceInEmptyParentheses: false SpacesInSquareBrackets: false IndentAccessModifiers: false AccessModifierOffset: -4 +IndentCaseBlocks: false +IndentCaseLabels: true # Control formatting of C++11 features Cpp11BracedListStyle: false @@ -62,7 +64,6 @@ ReflowComments: true AllowShortIfStatementsOnASingleLine: false AllowShortLoopsOnASingleLine: false AllowShortFunctionsOnASingleLine: All -IndentCaseLabels: true AlignConsecutiveShortCaseStatements: Enabled: true diff --git a/include/query.hpp b/include/query.hpp index 03530da..cb03360 100644 --- a/include/query.hpp +++ b/include/query.hpp @@ -11,8 +11,7 @@ #include "config.hpp" #include "util.hpp" -extern "C" -{ +extern "C" { #include #include #include @@ -22,7 +21,8 @@ extern "C" #include } -using systemInfo_t = std::unordered_map>>; +using systemInfo_t = + std::unordered_map>>; using variant = std::variant; namespace Query @@ -163,10 +163,10 @@ class CPU std::string& name(); std::string& nproc(); - float& freq_max(); - float& freq_min(); - float& freq_cur(); - float& freq_bios_limit(); + float& freq_max(); + float& freq_min(); + float& freq_cur(); + float& freq_bios_limit(); private: static bool m_bInit; diff --git a/src/display.cpp b/src/display.cpp index 70b8450..203e302 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -148,8 +148,8 @@ std::vector Display::render(const Config& config, const colors_t& c // erase each element for each instance of MAGIC_LINE layout.erase(std::remove_if(layout.begin(), layout.end(), - [](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }), - layout.end()); + [](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }), + layout.end()); size_t i; for (i = 0; i < layout.size(); i++) @@ -167,7 +167,7 @@ std::vector Display::render(const Config& config, const colors_t& c } const size_t& spaces = (maxLineLength + (config.m_disable_source ? 1 : config.offset)) - - (i < asciiArt.size() ? pureAsciiArtLens.at(i) : 0); + (i < asciiArt.size() ? pureAsciiArtLens.at(i) : 0); debug("spaces: {}", spaces); diff --git a/src/gui.cpp b/src/gui.cpp index 658a02c..ec195d9 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1,16 +1,17 @@ #ifdef GUI_MODE #define STB_IMAGE_IMPLEMENTATION +#include "gui.hpp" + +#include #include #include -#include #include "config.hpp" #include "display.hpp" #include "fmt/ranges.h" #include "gdkmm/pixbufanimation.h" #include "gtkmm/enums.h" -#include "gui.hpp" #include "pangomm/fontdescription.h" #include "parse.hpp" #include "query.hpp" @@ -52,8 +53,8 @@ static std::vector render_with_image(const Config& config, const co // erase each element for each instance of MAGIC_LINE layout.erase(std::remove_if(layout.begin(), layout.end(), - [](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }), - layout.end()); + [](const std::string_view str) { return str.find(MAGIC_LINE) != std::string::npos; }), + layout.end()); for (size_t i = 0; i < layout.size(); i++) { diff --git a/src/query/unix/utils/dewm.cpp b/src/query/unix/utils/dewm.cpp index fdbc1fe..f1d526a 100644 --- a/src/query/unix/utils/dewm.cpp +++ b/src/query/unix/utils/dewm.cpp @@ -66,68 +66,68 @@ std::string prettify_wm_name(const std::string_view name) noexcept // ngl this looks beatiful thanks to clang-format :D switch (fnv1a16::hash(str_tolower(name.data()))) { - case "2bwm"_fnv1a16: return "2bwm"; - case "9wm"_fnv1a16: return "9wm"; - case "awesome"_fnv1a16: return "awesome"; - case "beryl"_fnv1a16: return "beryl"; - case "blackbox"_fnv1a16: return "blackbox"; - case "bspwm"_fnv1a16: return "bspwm"; - case "budgie-wm"_fnv1a16: return "budgie-wm"; - case "chromeos-wm"_fnv1a16: return "chromeos-wm"; - case "cinnamon"_fnv1a16: return "Muffin"; - case "compiz"_fnv1a16: return "compiz"; - case "deepin-wm"_fnv1a16: return "deepin-wm"; - case "dminiwm"_fnv1a16: return "dminiwm"; - case "dtwm"_fnv1a16: return "dtwm"; - case "dwm"_fnv1a16: return "dwm"; - case "e16"_fnv1a16: return "e16"; - case "echinus"_fnv1a16: return "echinus"; - case "emerald"_fnv1a16: return "emerald"; - case "enlightenment"_fnv1a16: return "enlightenment"; - case "finder"_fnv1a16: return "finder"; - case "fluxbox"_fnv1a16: return "fluxbox"; - case "flwm"_fnv1a16: return "flwm"; - case "flwm_topside"_fnv1a16: return "flwm_topside"; - case "fvwm"_fnv1a16: return "fvwm"; - + case "2bwm"_fnv1a16: return "2bwm"; + case "9wm"_fnv1a16: return "9wm"; + case "awesome"_fnv1a16: return "awesome"; + case "beryl"_fnv1a16: return "beryl"; + case "blackbox"_fnv1a16: return "blackbox"; + case "bspwm"_fnv1a16: return "bspwm"; + case "budgie-wm"_fnv1a16: return "budgie-wm"; + case "chromeos-wm"_fnv1a16: return "chromeos-wm"; + case "cinnamon"_fnv1a16: return "Muffin"; + case "compiz"_fnv1a16: return "compiz"; + case "deepin-wm"_fnv1a16: return "deepin-wm"; + case "dminiwm"_fnv1a16: return "dminiwm"; + case "dtwm"_fnv1a16: return "dtwm"; + case "dwm"_fnv1a16: return "dwm"; + case "e16"_fnv1a16: return "e16"; + case "echinus"_fnv1a16: return "echinus"; + case "emerald"_fnv1a16: return "emerald"; + case "enlightenment"_fnv1a16: return "enlightenment"; + case "finder"_fnv1a16: return "finder"; + case "fluxbox"_fnv1a16: return "fluxbox"; + case "flwm"_fnv1a16: return "flwm"; + case "flwm_topside"_fnv1a16: return "flwm_topside"; + case "fvwm"_fnv1a16: return "fvwm"; + case "gnome-shell"_fnv1a16: case "gnome-session-binary"_fnv1a16: - case "mutter"_fnv1a16: return "Mutter"; - - case "herbstluftwm"_fnv1a16: return "herbstluftwm"; - case "howm"_fnv1a16: return "howm"; - case "hyprland"_fnv1a16: return "Hyprland"; - case "i3"_fnv1a16: return "i3"; - case "i3wm"_fnv1a16: return "i3wm"; - case "icewm"_fnv1a16: return "icewm"; - case "kwin"_fnv1a16: return "Kwin"; - case "marco"_fnv1a16: return "Marco"; - case "metacity"_fnv1a16: return "Metacity"; - case "monsterwm"_fnv1a16: return "monsterwm"; - case "muffin"_fnv1a16: return "Muffin"; - case "musca"_fnv1a16: return "musca"; - case "mwm"_fnv1a16: return "mwm"; - case "notion"_fnv1a16: return "notion"; - case "openbox"_fnv1a16: return "Openbox"; - case "pekwm"_fnv1a16: return "pekwm"; - case "qtile"_fnv1a16: return "Qtile"; - case "ratpoison"_fnv1a16: return "ratpoison"; - case "sawfish"_fnv1a16: return "sawfish"; - case "scrotwm"_fnv1a16: return "scrotwm"; - case "spectrwm"_fnv1a16: return "spectrwm"; - case "stumpwm"_fnv1a16: return "stumpwm"; - case "subtle"_fnv1a16: return "subtle"; - case "sway"_fnv1a16: return "sway"; - case "swm"_fnv1a16: return "swm"; - case "tinywm"_fnv1a16: return "tinywm"; - case "twin"_fnv1a16: return "twin"; - case "wayfire"_fnv1a16: return "wayfire"; - case "weston"_fnv1a16: return "weston"; - case "wmaker"_fnv1a16: return "wmaker"; - case "wmfs"_fnv1a16: return "wmfs"; - case "wmii"_fnv1a16: return "wmii"; - case "xfwm4"_fnv1a16: return "Xfwm4"; - case "xmonad"_fnv1a16: return "XMonad"; + case "mutter"_fnv1a16: return "Mutter"; + + case "herbstluftwm"_fnv1a16: return "herbstluftwm"; + case "howm"_fnv1a16: return "howm"; + case "hyprland"_fnv1a16: return "Hyprland"; + case "i3"_fnv1a16: return "i3"; + case "i3wm"_fnv1a16: return "i3wm"; + case "icewm"_fnv1a16: return "icewm"; + case "kwin"_fnv1a16: return "Kwin"; + case "marco"_fnv1a16: return "Marco"; + case "metacity"_fnv1a16: return "Metacity"; + case "monsterwm"_fnv1a16: return "monsterwm"; + case "muffin"_fnv1a16: return "Muffin"; + case "musca"_fnv1a16: return "musca"; + case "mwm"_fnv1a16: return "mwm"; + case "notion"_fnv1a16: return "notion"; + case "openbox"_fnv1a16: return "Openbox"; + case "pekwm"_fnv1a16: return "pekwm"; + case "qtile"_fnv1a16: return "Qtile"; + case "ratpoison"_fnv1a16: return "ratpoison"; + case "sawfish"_fnv1a16: return "sawfish"; + case "scrotwm"_fnv1a16: return "scrotwm"; + case "spectrwm"_fnv1a16: return "spectrwm"; + case "stumpwm"_fnv1a16: return "stumpwm"; + case "subtle"_fnv1a16: return "subtle"; + case "sway"_fnv1a16: return "sway"; + case "swm"_fnv1a16: return "swm"; + case "tinywm"_fnv1a16: return "tinywm"; + case "twin"_fnv1a16: return "twin"; + case "wayfire"_fnv1a16: return "wayfire"; + case "weston"_fnv1a16: return "weston"; + case "wmaker"_fnv1a16: return "wmaker"; + case "wmfs"_fnv1a16: return "wmfs"; + case "wmii"_fnv1a16: return "wmii"; + case "xfwm4"_fnv1a16: return "Xfwm4"; + case "xmonad"_fnv1a16: return "XMonad"; } return MAGIC_LINE; diff --git a/src/query/unix/utils/packages.cpp b/src/query/unix/utils/packages.cpp index 3a0017e..cca7cfe 100644 --- a/src/query/unix/utils/packages.cpp +++ b/src/query/unix/utils/packages.cpp @@ -1,8 +1,8 @@ #include "packages.hpp" +#include #include #include -#include #include #include "switch_fnv1a.hpp" diff --git a/src/util.cpp b/src/util.cpp index 725baa8..7adac19 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -141,6 +141,7 @@ byte_units_t auto_devide_bytes(const size_t num) bool is_file_image(const unsigned char* bytes) { + // clang-format off // https://stackoverflow.com/a/49683945 constexpr std::array jpeg = { 0xff, 0xd8, 0xff }; constexpr std::array png = { 0x89, 0x50, 0x4e, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }; @@ -150,16 +151,17 @@ bool is_file_image(const unsigned char* bytes) constexpr std::array tiffI = { 0x49, 0x49, 0x2A, 0x00 }; constexpr std::array tiffM = { 0x4D, 0x4D, 0x00, 0x2A }; - if (std::memcmp(bytes, png.data(), png.size()) == 0 || - std::memcmp(bytes, jpeg.data(), jpeg.size()) == 0 || - std::memcmp(bytes, gif89a.data(), gif89a.size()) == 0 || - std::memcmp(bytes, gif87a.data(), gif87a.size()) == 0 || - std::memcmp(bytes, tiffM.data(), tiffM.size()) == 0 || - std::memcmp(bytes, tiffI.data(), tiffI.size()) == 0 || - std::memcmp(bytes, bmp.data(), bmp.size()) == 0) - return true; + if (std::memcmp(bytes, png.data(), png.size()) == 0 || + std::memcmp(bytes, jpeg.data(), jpeg.size()) == 0 || + std::memcmp(bytes, gif89a.data(), gif89a.size()) == 0 || + std::memcmp(bytes, gif87a.data(), gif87a.size()) == 0 || + std::memcmp(bytes, tiffM.data(), tiffM.size()) == 0 || + std::memcmp(bytes, tiffI.data(), tiffI.size()) == 0 || + std::memcmp(bytes, bmp.data(), bmp.size()) == 0) + return true; return false; + // clang-format on } /**