Skip to content

Commit

Permalink
general: add support for gtkrc-v.0-kde and gtkrc-v.0-kde4
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntRanch committed Sep 14, 2024
1 parent b3a8238 commit 0f9f888
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 32 deletions.
24 changes: 12 additions & 12 deletions assets/ascii/fedora.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ ${blue} .',;::::;,'.
${blue} .';:cccccccccccc:;,.
${blue} .;cccccccccccccccccccccc;.
${blue} .:cccccccccccccccccccccccccc:.
${blue} .;ccccccccccccc;${1}.:dddl:.${blue};ccccccc;.
${blue} .:ccccccccccccc;${1}OWMKOOXMWd${blue};ccccccc:.
${blue}.:ccccccccccccc;${1}KMMc${blue};cc;${1}xMMc${blue};ccccccc:.
${blue},cccccccccccccc;${1}MMM.${blue};cc;${1};WW:${blue};cccccccc,
${blue}:cccccccccccccc;${1}MMM.${blue};cccccccccccccccc:
${blue}:ccccccc;${1}oxOOOo${blue};${1}MMM0OOk.${blue};cccccccccccc:
${blue}cccccc;${1}0MMKxdd:${blue};${1}MMMkddc.${blue};cccccccccccc;
${blue}ccccc;${1}XM0'${blue};cccc;${1}MMM.${blue};cccccccccccccccc'
${blue}ccccc;${1}MMo${blue};ccccc;${1}MMW.${blue};ccccccccccccccc;
${blue}ccccc;${1}0MNc.${blue}ccc${1}.xMMd${blue};ccccccccccccccc;
${blue}cccccc;${1}dNMWXXXWM0:${blue};cccccccccccccc:,
${blue}cccccccc;${1}.:odl:.${blue};cccccccccccccc:,.
${blue} .;ccccccccccccc;${0}.:dddl:.${blue};ccccccc;.
${blue} .:ccccccccccccc;${0}OWMKOOXMWd${blue};ccccccc:.
${blue}.:ccccccccccccc;${0}KMMc${blue};cc;${0}xMMc${blue};ccccccc:.
${blue},cccccccccccccc;${0}MMM.${blue};cc;${0};WW:${blue};cccccccc,
${blue}:cccccccccccccc;${0}MMM.${blue};cccccccccccccccc:
${blue}:ccccccc;${0}oxOOOo${blue};${0}MMM0OOk.${blue};cccccccccccc:
${blue}cccccc;${0}0MMKxdd:${blue};${0}MMMkddc.${blue};cccccccccccc;
${blue}ccccc;${0}XM0'${blue};cccc;${0}MMM.${blue};cccccccccccccccc'
${blue}ccccc;${0}MMo${blue};ccccc;${0}MMW.${blue};ccccccccccccccc;
${blue}ccccc;${0}0MNc.${blue}ccc${0}.xMMd${blue};ccccccccccccccc;
${blue}cccccc;${0}dNMWXXXWM0:${blue};cccccccccccccc:,
${blue}cccccccc;${0}.:odl:.${blue};cccccccccccccc:,.
${blue}:cccccccccccccccccccccccccccc:'.
${blue}.:cccccccccccccccccccccc:;,..
${blue} '::cccccccccccccc::;,.
7 changes: 7 additions & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Config
Config(const std::string_view configFile, const std::string_view configDir, colors_t& colors);

// config file
bool slow_query_warnings = true;
std::vector<std::string> layout;
std::string source_path;
std::string font;
Expand Down Expand Up @@ -151,6 +152,12 @@ inline constexpr std::string_view AUTOCONFIG = R"#([config]
#
# Read the manual cufetch.1 for more infos with $() tag
# cufetch behavioural settings
# Warn against tradeoffs between slower queries for availability
# e.g. falling back to gsettings when we can't find the config file for GTK
slow-query-warnings = true
layout = [
"$<builtin.title>",
"$<builtin.title_sep>",
Expand Down
5 changes: 3 additions & 2 deletions include/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class Theme
};

Theme(const std::uint8_t ver, systemInfo_t& queried_themes, std::vector<std::string>& queried_themes_names,
const std::string& theme_name_version);
const std::string& theme_name_version, const Config &config);

Theme(systemInfo_t& queried_themes);
Theme(systemInfo_t& queried_themes, const Config &config);

std::string gtk_theme() noexcept;
std::string gtk_icon_theme() noexcept;
Expand All @@ -140,6 +140,7 @@ class Theme
systemInfo_t& m_queried_themes;
const std::string m_theme_name_version;
std::string m_wmde_name;
const Config& m_Config;
};

class CPU
Expand Down
7 changes: 7 additions & 0 deletions include/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ void warn(const std::string_view fmt, Args&&... args) noexcept
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
}

template <typename... Args>
void info(const std::string_view fmt, Args&&... args) noexcept
{
fmt::println(BOLD_COLOR((fmt::rgb(fmt::color::cyan))), "INFO: {}",
fmt::format(fmt::runtime(fmt), std::forward<Args>(args)...));
}

/** Ask the user a yes or no question.
* @param def The default result
* @param fmt The format string
Expand Down
10 changes: 5 additions & 5 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co

else if (moduleName == "theme")
{
Query::Theme query_theme(queried_themes);
Query::Theme query_theme(queried_themes, config);

if (sysInfo.find(moduleName) == sysInfo.end())
sysInfo.insert({ moduleName, {} });
Expand All @@ -894,9 +894,9 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co

else if (moduleName == "theme-gtk-all")
{
Query::Theme gtk2(2, queried_themes, queried_themes_names, "gtk2");
Query::Theme gtk3(3, queried_themes, queried_themes_names, "gtk3");
Query::Theme gtk4(4, queried_themes, queried_themes_names, "gtk4");
Query::Theme gtk2(2, queried_themes, queried_themes_names, "gtk2", config);
Query::Theme gtk3(3, queried_themes, queried_themes_names, "gtk3", config);
Query::Theme gtk4(4, queried_themes, queried_themes_names, "gtk4", config);

if (sysInfo.find(moduleName) == sysInfo.end())
sysInfo.insert({ moduleName, {} });
Expand All @@ -922,7 +922,7 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co
"Syntax should be like 'theme_gtkN' which N stands for the version of gtk to query (single number)",
moduleName);

Query::Theme query_theme(ver, queried_themes, queried_themes_names, fmt::format("gtk{}", ver));
Query::Theme query_theme(ver, queried_themes, queried_themes_names, fmt::format("gtk{}", ver), config);

if (sysInfo.find(moduleName) == sysInfo.end())
sysInfo.insert({ moduleName, {} });
Expand Down
46 changes: 33 additions & 13 deletions src/query/unix/theme.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <algorithm>
#include <cstdint>

#include "config.hpp"
#include "parse.hpp"
#include "query.hpp"
#include "rapidxml-1.13/rapidxml.hpp"
Expand Down Expand Up @@ -122,6 +123,12 @@ static bool get_cursor_from_gtk_configs(const std::uint8_t ver, Theme::Theme_t&
if (get_gtk_cursor_config(fmt::format("{}/.gtkrc-{}.0", std::getenv("HOME"), ver), theme))
return true;

if (get_gtk_cursor_config(fmt::format("{}/.gtkrc-{}.0-kde", std::getenv("HOME"), ver), theme))
return true;

if (get_gtk_cursor_config(fmt::format("{}/.gtkrc-{}.0-kde4", std::getenv("HOME"), ver), theme))
return true;

return false;
}

Expand Down Expand Up @@ -208,7 +215,7 @@ static bool get_gtk_theme_config(const std::string_view path, Theme::Theme_t& th
return true;
}

static void get_gtk_theme_settings(const std::string_view de_name, Theme::Theme_t& theme)
static void get_gtk_theme_settings(const std::string_view de_name, Theme::Theme_t& theme, const Config &config)
{
debug("calling {}", __PRETTY_FUNCTION__);

Expand All @@ -220,6 +227,12 @@ static void get_gtk_theme_settings(const std::string_view de_name, Theme::Theme_
theme.gtk_theme_name = gtk_theme_env;
}

if (config.slow_query_warnings) {
warn("cufetch could not detect a gtk configuration file. cufetch will use the much-slower gsettings.");
warn("If there's a file in a standard location that we aren't detecting, please file an issue on our GitHub.");
info("You can disable this warning by disabling slow-query-warnings in your config.toml file.");
}

const char* interface;
switch(fnv1a16::hash(str_tolower(de_name.data())))
{
Expand Down Expand Up @@ -256,7 +269,7 @@ static void get_gtk_theme_settings(const std::string_view de_name, Theme::Theme_
theme.gtk_font.erase(std::remove(theme.gtk_font.begin(), theme.gtk_font.end(), '\''), theme.gtk_font.end());
}

static void get_gtk_theme_from_configs(const std::uint8_t ver, const std::string_view de_name, Theme::Theme_t& theme)
static void get_gtk_theme_from_configs(const std::uint8_t ver, const std::string_view de_name, Theme::Theme_t& theme, const Config &config)
{
if (get_gtk_theme_config(fmt::format("{}/gtk-{}.0/settings.ini", configDir, ver), theme))
return;
Expand All @@ -270,10 +283,16 @@ static void get_gtk_theme_from_configs(const std::uint8_t ver, const std::string
if (get_gtk_theme_config(fmt::format("{}/.gtkrc-{}.0", std::getenv("HOME"), ver), theme))
return;

get_gtk_theme_settings(de_name, theme);
if (get_gtk_theme_config(fmt::format("{}/.gtkrc-{}.0-kde", std::getenv("HOME"), ver), theme))
return;

if (get_gtk_theme_config(fmt::format("{}/.gtkrc-{}.0-kde4", std::getenv("HOME"), ver), theme))
return;

get_gtk_theme_settings(de_name, theme, config);
}

static void get_de_gtk_theme(const std::string_view de_name, const std::uint8_t ver, Theme::Theme_t& theme)
static void get_de_gtk_theme(const std::string_view de_name, const std::uint8_t ver, Theme::Theme_t& theme, const Config &config)
{
switch (fnv1a16::hash(str_tolower(de_name.data())))
{
Expand All @@ -285,7 +304,7 @@ static void get_de_gtk_theme(const std::string_view de_name, const std::uint8_t
std::ifstream f(path, std::ios::in);
if (!f.is_open())
{
get_gtk_theme_from_configs(ver, de_name, theme);
get_gtk_theme_from_configs(ver, de_name, theme, config);
return;
}

Expand Down Expand Up @@ -331,27 +350,28 @@ static void get_de_gtk_theme(const std::string_view de_name, const std::uint8_t
}
break;
default:
get_gtk_theme_from_configs(ver, de_name, theme);
get_gtk_theme_from_configs(ver, de_name, theme, config);
}
}

static void get_gtk_theme(const bool dont_query_dewm, const std::uint8_t ver, const std::string_view de_name,
Theme::Theme_t& theme)
Theme::Theme_t& theme, const Config &config)
{
if (dont_query_dewm)
{
get_gtk_theme_from_configs(ver, de_name, theme);
get_gtk_theme_from_configs(ver, de_name, theme, config);
return;
}

get_de_gtk_theme(de_name, ver, theme);
get_de_gtk_theme(de_name, ver, theme, config);
}

// clang-format off
Theme::Theme(const std::uint8_t ver, systemInfo_t& queried_themes, std::vector<std::string>& queried_themes_names,
const std::string& theme_name_version)
const std::string& theme_name_version, const Config &config)
: m_queried_themes(queried_themes),
m_theme_name_version(theme_name_version)
m_theme_name_version(theme_name_version),
m_Config(config)
{
if (std::find(queried_themes_names.begin(), queried_themes_names.end(), m_theme_name_version)
== queried_themes_names.end())
Expand All @@ -368,7 +388,7 @@ Theme::Theme(const std::uint8_t ver, systemInfo_t& queried_themes, std::vector<s
else
m_wmde_name = de_name;

get_gtk_theme(query_user.m_bDont_query_dewm, ver, m_wmde_name, m_theme_infos);
get_gtk_theme(query_user.m_bDont_query_dewm, ver, m_wmde_name, m_theme_infos, config);

if (m_theme_infos.gtk_theme_name.empty())
m_theme_infos.gtk_theme_name = MAGIC_LINE;
Expand All @@ -389,7 +409,7 @@ Theme::Theme(const std::uint8_t ver, systemInfo_t& queried_themes, std::vector<s
}

// only use it for cursor
Theme::Theme(systemInfo_t& queried_themes) : m_queried_themes(queried_themes)
Theme::Theme(systemInfo_t& queried_themes, const Config &config) : m_queried_themes(queried_themes), m_Config(config)
{
static bool done = false;
if (hasStart(query_user.term_name(), "/dev") || done)
Expand Down

0 comments on commit 0f9f888

Please sign in to comment.