Skip to content

Commit

Permalink
misc: add code comments in headers instead of source
Browse files Browse the repository at this point in the history
also add new CPU ID for the GPU in android
  • Loading branch information
Toni500github committed Dec 26, 2024
1 parent 0115673 commit 95d25ba
Show file tree
Hide file tree
Showing 10 changed files with 335 additions and 133 deletions.
61 changes: 52 additions & 9 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "toml++/toml.hpp"
#include "util.hpp"

// config colors
// those without gui_ prefix are for the terminal
struct colors_t
{
std::string black;
Expand All @@ -57,9 +59,10 @@ struct colors_t
class Config
{
public:
// Create .config directories and files and load the config file (args or default)
Config(const std::string_view configFile, const std::string_view configDir, colors_t& colors);

// config file
// Variables of config file in [config] table
std::vector<std::string> layout;
std::vector<std::string> percentage_colors;
std::vector<std::string> colors_name, colors_value;
Expand All @@ -81,12 +84,14 @@ class Config
bool use_SI_unit = false;
bool wrap_lines = false;

// modules specific config
// Variables of config file for
// modules specific configs, e.g [uptime]
std::string uptime_d_fmt;
std::string uptime_h_fmt;
std::string uptime_m_fmt;
std::string uptime_s_fmt;

// [pkgs]
std::vector<std::string> pkgs_managers;
std::vector<std::string> pacman_dirs;
std::vector<std::string> flatpak_dirs;
Expand All @@ -102,12 +107,37 @@ class Config
bool m_display_distro = true;
bool m_print_logo_only = false;

void loadConfigFile(const std::string_view filename, colors_t& colors);
std::string getThemeValue(const std::string_view value, const std::string_view fallback) const;
void generateConfig(const std::string_view filename);
void addAliasColors(const std::string& str);
std::vector<std::string> getValueArrayStr(const std::string_view value, const std::vector<std::string>& fallback);
/**
* Load config file and parse every config variables
* @param filename The config file path
* @param colors The colors struct where we'll put the default config colors.
* It doesn't include the colors in config.alias-colors
*/
void loadConfigFile(const std::string_view filename, colors_t& colors);

/**
* Generate a config file
* @param filename The config file path
*/
void generateConfig(const std::string_view filename);

/**
* Add alias values to colors_name and colors_value.
* @param str The alias color to add.
* Must have a '=' for separating color name and value,
* E.g "pink=!#FFC0CB"
*/
void addAliasColors(const std::string& str);

private:
// Parsed config from loadConfigFile()
toml::table tbl;

/**
* Get value of config variables
* @param value The config variable "path" (e.g "config.source-path")
* @param fallback Default value if couldn't retrive value
*/
template <typename T>
T getValue(const std::string_view value, const T&& fallback) const
{
Expand All @@ -118,10 +148,23 @@ class Config
return ret.value_or(fallback);
}

private:
toml::table tbl;
/**
* getValue() but don't want to specify the template, so it's std::string,
* and because of the name, only used when retriving the colors for terminal and GUI
* @param value The config variable "path" (e.g "config.gui-red")
* @param fallback Default value if couldn't retrive value
*/
std::string getThemeValue(const std::string_view value, const std::string_view fallback) const;

/**
* Get value of config array of string variables
* @param value The config variable "path" (e.g "config.gui-red")
* @param fallback Default value if couldn't retrive value
*/
std::vector<std::string> getValueArrayStr(const std::string_view value, const std::vector<std::string>& fallback);
};

// default config
inline constexpr std::string_view AUTOCONFIG = R"#([config]
# customfetch is designed with customizability in mind
# here is how it works:
Expand Down
4 changes: 2 additions & 2 deletions include/display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Display
{

/*
* Render the layout along side the ASCII art and return the vector
* Render the layout along side the source file and return the vector
* @param config The config class
* @param colors The colors
* @param already_analyzed_path If already checked that the source path is not a binary file
Expand All @@ -45,7 +45,7 @@ std::vector<std::string> render(const Config& config, const colors_t& colors, co
const std::string_view path);

/*
* Display the ascii art and layout
* Display the rendered result (or just display a normal vector of strings)
* @param renderResult The rendered vector usually by Display::render()
*/
void display(const std::vector<std::string>& renderResult);
Expand Down
19 changes: 16 additions & 3 deletions include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ namespace GUI
class Window : public Gtk::Window
{
public:

/**
* Initialize and create everything and parse layout with source path.
* @param config The config class
* @param colors The non-alias colors struct
* @param path The logo source path
*/
Window(const Config& config, const colors_t& colors, const std::string_view path);
// Destroy the window, handled by GTK
virtual ~Window();

private:
Expand All @@ -59,19 +67,22 @@ class Window : public Gtk::Window
Glib::RefPtr<Gdk::Pixbuf> m_bg_static_image;
int m_width, m_height;

void on_window_resize(Gtk::Allocation& allocation)
// Update background image size (gif or static)
// on window resize
void on_window_resize(const Gtk::Allocation& allocation)
{
m_width = allocation.get_width();
m_height = allocation.get_height();

if (m_bg_static_image)
// static image: Update to fit the new window size
// static image: update to fit the new window size
update_static_image();
else if (m_iter)
// animated image: Update the current frame
// gif: update the current frame
update_frame();
}

// Update background gif size
bool on_update_animation()
{
if (!m_iter)
Expand All @@ -83,13 +94,15 @@ class Window : public Gtk::Window
return true; // continue the timer
}

// Update background image size
void update_static_image()
{
// scale the static image to fit the window size
const Glib::RefPtr<Gdk::Pixbuf> scaled_image = m_bg_static_image->scale_simple(m_width, m_height, Gdk::INTERP_BILINEAR);
m_bg_image.set(scaled_image);
}

// Update background gif size in the current frame
void update_frame()
{
// scale the current frame of the animation to fit the window size
Expand Down
7 changes: 5 additions & 2 deletions include/parse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
#include "config.hpp"
#include "query.hpp"

/* the additional args that parse() needs for getting the necessary infos/configs.
* only used for making the argument passing more clear.
/* The additional args that parse() needs for getting the necessary infos/configs.
* Only used for making the argument passing more clear.
* Always pass it non-const and by reference
*/
struct parse_args_t
Expand Down Expand Up @@ -84,6 +84,9 @@ void addValueFromModule(const std::string& moduleName, parse_args_t& parse_args)

/*
* Return a module member value
* @param systemInfo The systemInfo_t map
* @param moduleName The module name
* @param moduleMemberName The module member name
*/
std::string getInfoFromName(const systemInfo_t& systemInfo, const std::string_view moduleName,
const std::string_view moduleMemberName);
Expand Down
2 changes: 2 additions & 0 deletions include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ extern "C" {
#include <unistd.h>
}

// Special variable for storing info modules values
using systemInfo_t =
std::unordered_map<std::string, std::unordered_map<std::string, std::variant<std::string, size_t, double>>>;
// used in systemInfo_t most of the time
using variant = std::variant<std::string, size_t, double>;

namespace Query
Expand Down
Loading

0 comments on commit 95d25ba

Please sign in to comment.