Skip to content

Commit

Permalink
misc: add theme.colors + some query code changes
Browse files Browse the repository at this point in the history
sorry for being away for 3 days, kinda busy and also contributing a little to Hyprland
  • Loading branch information
Toni500github committed Oct 9, 2024
1 parent 03b3765 commit 69625a1
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 36 deletions.
2 changes: 1 addition & 1 deletion include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Disk
std::string mountdir;
};

Disk(const std::string_view path, std::vector<std::string_view>& paths);
Disk(const std::string_view path, std::vector<std::string>& paths);

float& total_amount() noexcept;
float& free_amount() noexcept;
Expand Down
14 changes: 6 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "config.hpp"
#include "display.hpp"
#include "fmt/compile.h"
#include "gui.hpp"
#include "switch_fnv1a.hpp"
#include "util.hpp"
Expand All @@ -19,14 +18,10 @@
: (optarg != NULL))

using namespace std::string_view_literals;
using namespace fmt::literals;

static void version()
{
// {fmt} lib doesn't like fmt::println()
// why? I know that "just put the newline \n and shut up" (nobody said it)
// but would be nice :)
fmt::print("customfetch {} branch {}\n"_cf, VERSION, BRANCH);
fmt::println("customfetch {} branch {}", VERSION, BRANCH);

#ifdef GUI_MODE
fmt::println("GUI mode enabled");
Expand Down Expand Up @@ -134,6 +129,8 @@ user
terminal_name : Terminal name [alacritty]
terminal_version: Terminal version [0.13.2]
# with `symb` I mean a symbol to be used for the
# view of the color palette
builtin
title : user and hostname colored with ${{auto2}} [toni@arch2]
title_sep : separator between the title and the system infos (with the title lenght) [--------]
Expand All @@ -146,12 +143,13 @@ builtin
# such as indeed cursor
# because it is not GTK-Qt specific
theme
cursor : cursor name with its size (auto add the size if queried) [Bibata-Modern-Ice (16px)]
cursor_name : cursor name [Bibata-Modern-Ice]
cursor_size : cursor size [16]
# the N stands for the gtk version number to query
# so for example if you want to query the gtk3 theme version
# write it like "theme.gtk3"
# so for example if you want to query the gtk3 theme name
# write it like "theme-gtk3.name"
# note: they may be inaccurate if didn't find anything in the config files
# thus because of using as last resort the `gsettings` exacutable
theme-gtkN
Expand Down
16 changes: 11 additions & 5 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,11 +862,11 @@ void addValueFromModule(const std::string& moduleName, const std::string& module
const Config& config = parse_args.config;
systemInfo_t& sysInfo = parse_args.systemInfo;

const auto& moduleMember_hash = fnv1a16::hash(moduleMemberName);
static std::vector<std::uint16_t> queried_gpus;
static std::vector<std::string_view> queried_disks;
static std::vector<std::string> queried_themes_names;
static systemInfo_t queried_themes;
const auto& moduleMember_hash = fnv1a16::hash(moduleMemberName);
static std::vector<std::uint16_t> queried_gpus;
static std::vector<std::string> queried_disks;
static std::vector<std::string> queried_themes_names;
static systemInfo_t queried_themes;

if (moduleName == "os")
{
Expand Down Expand Up @@ -1092,6 +1092,12 @@ void addValueFromModule(const std::string& moduleName, const std::string& module
{
switch (moduleMember_hash)
{
case "cursor"_fnv1a16:
if (query_theme.cursor_size() == UNKNOWN)
SYSINFO_INSERT(query_theme.cursor());
else
SYSINFO_INSERT(fmt::format("{} ({}px)", query_theme.cursor(), query_theme.cursor_size()));
break;
case "cursor_name"_fnv1a16: SYSINFO_INSERT(query_theme.cursor()); break;
case "cursor_size"_fnv1a16: SYSINFO_INSERT(query_theme.cursor_size()); break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/query/unix/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

using namespace Query;

Disk::Disk(const std::string_view path, std::vector<std::string_view>& paths)
Disk::Disk(const std::string_view path, std::vector<std::string>& paths)
{
if (std::find(paths.begin(), paths.end(), path) == paths.end())
paths.push_back(path);
paths.push_back(path.data());
else
return;

Expand Down
16 changes: 8 additions & 8 deletions src/query/unix/gpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

using namespace Query;

static std::string _get_name(const std::string_view m_vendor_id_s, const std::string_view m_device_id_s)
static std::string get_name(const std::string_view m_vendor_id_s, const std::string_view m_device_id_s)
{
std::string name = binarySearchPCIArray(m_vendor_id_s, m_device_id_s);
debug("GPU binarySearchPCIArray name = {}", name);
size_t first_bracket = name.find('[');
size_t last_bracket = name.rfind(']');
const size_t first_bracket = name.find('[');
const size_t last_bracket = name.rfind(']');

// remove the chips name "TU106 [GeForce GTX 1650]"
// This should work for AMD and Intel too.
Expand All @@ -29,7 +29,7 @@ static std::string _get_name(const std::string_view m_vendor_id_s, const std::st
return name;
}

static std::string _get_vendor(const std::string_view m_vendor_id_s)
static std::string get_vendor(const std::string_view m_vendor_id_s)
{ return binarySearchPCIArray(m_vendor_id_s); }

static GPU::GPU_t get_gpu_infos(const std::string_view m_vendor_id_s, const std::string_view m_device_id_s)
Expand All @@ -41,8 +41,8 @@ static GPU::GPU_t get_gpu_infos(const std::string_view m_vendor_id_s, const std:
if (m_device_id_s == UNKNOWN || m_vendor_id_s == UNKNOWN)
return ret;

ret.name = _get_name(m_vendor_id_s, m_device_id_s);
ret.vendor = _get_vendor(m_vendor_id_s);
ret.name = get_name(m_vendor_id_s, m_device_id_s);
ret.vendor = get_vendor(m_vendor_id_s);

return ret;
}
Expand All @@ -54,8 +54,8 @@ GPU::GPU(const std::uint16_t id, std::vector<std::uint16_t>& queried_gpus)
else
return;

const u_short max_iter = 10;
u_short id_iter = id;
const std::uint16_t max_iter = 10;
std::uint16_t id_iter = id;
std::string sys_path;
int i = 0;
for (; i <= max_iter; i++)
Expand Down
18 changes: 9 additions & 9 deletions src/query/unix/ram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ using namespace Query;
SRECLAIMABLE
};*/

static size_t get_from_text(std::string& line, u_short& iter_index)
static size_t get_from_text(std::string& line, u_short& iter_index, const std::uint16_t len)
{
std::string amount = line.substr(line.find(':') + 1);
std::string amount = line.substr(len + 1);
strip(amount);
++iter_index;
return std::stoi(amount);
Expand All @@ -40,16 +40,16 @@ static RAM::RAM_t get_amount() noexcept
while (std::getline(file, line) && iter_index < 4)
{
if (hasStart(line, "MemAvailable:"))
memory_infos.free_amount = get_from_text(line, iter_index);
memory_infos.free_amount = get_from_text(line, iter_index, "MemAvailable:"_len);

if (hasStart(line, "MemTotal:"))
memory_infos.total_amount = get_from_text(line, iter_index);
else if (hasStart(line, "MemTotal:"))
memory_infos.total_amount = get_from_text(line, iter_index, "MemTotal:"_len);

if (hasStart(line, "SwapFree:"))
memory_infos.swap_free_amount = get_from_text(line, iter_index);
else if (hasStart(line, "SwapFree:"))
memory_infos.swap_free_amount = get_from_text(line, iter_index, "SwapFree:"_len);

if (hasStart(line, "SwapTotal:"))
memory_infos.swap_total_amount = get_from_text(line, iter_index);
else if (hasStart(line, "SwapTotal:"))
memory_infos.swap_total_amount = get_from_text(line, iter_index, "SwapTotal:"_len);

/*if (line.find("Shmem:") != std::string::npos)
extra_mem_info.at(SHMEM) = get_from_text(line);
Expand Down
8 changes: 5 additions & 3 deletions src/query/unix/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <array>
#include <cerrno>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <filesystem>
Expand Down Expand Up @@ -36,12 +37,13 @@ static void get_host_paths(System::System_t& paths)
{
// everyone does it like "KVM/QEMU Standard PC (...) (host_version)" so why not
paths.host_vendor = "KVM/QEMU";
paths.host_version = fmt::format("({})", read_by_syspath(syspath + "/product_version"));
paths.host_version = std::string_view('(' + read_by_syspath(syspath + "/product_version") + ')').data();
}
else
paths.host_version = read_by_syspath(syspath + "/product_version");
}

// idfk why it has a newline
if (paths.host_version.back() == '\n')
paths.host_version.pop_back();
}
Expand Down Expand Up @@ -70,8 +72,8 @@ static System::System_t get_system_infos_lsb_releases()
}

// get OS /etc/lsb-release infos
u_short iter_index = 0;
std::string line;
std::uint16_t iter_index = 0;
std::string line;
while (std::getline(os_release_file, line) && iter_index < 3)
{
if (hasStart(line, "DISTRIB_DESCRIPTION="))
Expand Down

0 comments on commit 69625a1

Please sign in to comment.