Skip to content

Commit

Permalink
misc: format some code in src/ and include/
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Aug 31, 2024
1 parent 2c96c90 commit cbc074b
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 84 deletions.
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ SpaceInEmptyParentheses: false
SpacesInSquareBrackets: false
IndentAccessModifiers: false
AccessModifierOffset: -4
IndentCaseBlocks: false
IndentCaseLabels: true

# Control formatting of C++11 features
Cpp11BracedListStyle: false
Expand All @@ -62,7 +64,6 @@ ReflowComments: true
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
IndentCaseLabels: true

AlignConsecutiveShortCaseStatements:
Enabled: true
Expand Down
14 changes: 7 additions & 7 deletions include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include "config.hpp"
#include "util.hpp"

extern "C"
{
extern "C" {
#include <mntent.h>
#include <pwd.h>
#include <sys/stat.h>
Expand All @@ -22,7 +21,8 @@ extern "C"
#include <unistd.h>
}

using systemInfo_t = std::unordered_map<std::string, std::unordered_map<std::string, std::variant<std::string, size_t, float>>>;
using systemInfo_t =
std::unordered_map<std::string, std::unordered_map<std::string, std::variant<std::string, size_t, float>>>;
using variant = std::variant<std::string, size_t, float>;

namespace Query
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ std::vector<std::string> 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++)
Expand All @@ -167,7 +167,7 @@ std::vector<std::string> 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);

Expand Down
9 changes: 5 additions & 4 deletions src/gui.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifdef GUI_MODE

#define STB_IMAGE_IMPLEMENTATION
#include "gui.hpp"

#include <array>
#include <filesystem>
#include <fstream>
#include <array>

#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"
Expand Down Expand Up @@ -52,8 +53,8 @@ static std::vector<std::string> 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++)
{
Expand Down
120 changes: 60 additions & 60 deletions src/query/unix/utils/dewm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/query/unix/utils/packages.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "packages.hpp"

#include <algorithm>
#include <filesystem>
#include <fstream>
#include <algorithm>
#include <string>

#include "switch_fnv1a.hpp"
Expand Down
18 changes: 10 additions & 8 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char, 3> jpeg = { 0xff, 0xd8, 0xff };
constexpr std::array<unsigned char, 8> png = { 0x89, 0x50, 0x4e, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
Expand All @@ -150,16 +151,17 @@ bool is_file_image(const unsigned char* bytes)
constexpr std::array<unsigned char, 4> tiffI = { 0x49, 0x49, 0x2A, 0x00 };
constexpr std::array<unsigned char, 4> 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
}

/**
Expand Down

0 comments on commit cbc074b

Please sign in to comment.