Skip to content

Commit

Permalink
query: theme: add theme-gsettings
Browse files Browse the repository at this point in the history
also improve the version query
  • Loading branch information
Toni500github committed Oct 13, 2024
1 parent dbc93b4 commit 895ff98
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 30 deletions.
4 changes: 2 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 Config& config);
const std::string& theme_name_version, const Config& config, const bool gsettings_only = false);

Theme(systemInfo_t& queried_themes, const Config& config);
Theme(systemInfo_t& queried_themes, const Config& config, const bool gsettings_only = false);

std::string gtk_theme() noexcept;
std::string gtk_icon_theme() noexcept;
Expand Down
34 changes: 27 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ static void version()
fmt::println("customfetch {} branch {}", VERSION, BRANCH);

#ifdef GUI_MODE
fmt::println("GUI mode enabled");
fmt::print("GUI mode enabled\n\n");
#else
fmt::println("GUI mode IS NOT enabled");
fmt::print("GUI mode IS NOT enabled\n\n");
#endif

#if !(USE_DCONF)
fmt::println("NO flags were set");
#else
fmt::println("set flags:");
# if USE_DCONF
fmt::println("USE_DCONF");
# endif
#endif

// if only everyone would not return error when querying the program version :(
Expand Down Expand Up @@ -147,23 +156,34 @@ theme
cursor_name : cursor name [Bibata-Modern-Ice]
cursor_size : cursor size [16]
# If USE_DCONF flag is set, then we're going to use
# dconf, else backing up to gsettings
theme-gsettings
name : gsettings theme name [Decay-Green]
icons : gsettings icons theme name [Papirus-Dark]
font : gsettings font theme name [Cantarell 10]
cursor : gsettings cursor name with its size (auto add the size if queried) [Bibata-Modern-Ice (16px)]
cursor_name : gsettings cursor name [Bibata-Modern-Ice]
cursor_size : gsettings cursor size [16]
# the N stands for the gtk version number to query
# 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
# note: may be slow because of calling "gsettings" if couldn't read from configs.
# Read theme-gsettings module comments
theme-gtkN
name : gtk theme name [Arc-Dark]
icons : gtk icons theme name [Qogir-Dark]
font : gtk font theme name [Noto Sans 10]
# basically as like as the "theme-gtkN" module above
# but with gtk{{2,3,4}} and auto format gkt version
# note: may be slow because of calling "gsettings" if couldn't read from configs
# note: may be slow because of calling "gsettings" if couldn't read from configs.
# Read theme-gsettings module comments
theme-gtk-all
name : gtk theme name [Decay-Green [GTK2], Arc-Dark [GTK3/4]]
name : gtk theme name [Arc-Dark [GTK2/3/4]]
icons : gtk icons theme name [Papirus-Dark [GTK2/3], Qogir [GTK4]]
font : gtk font theme name [Cantarell 10 [GTK2], Noto Sans, 10 [GTK3], Noto Sans 10 [GTK4]]
font : gtk font theme name [Hack Nerd Font 13 [GTK2], Noto Sans 10 [GTK3/4]]
# note: these members are auto displayed in from B to YB (depending if using SI byte unit or not(IEC)).
# they all (except those that has the same name as the module or that ends with "_perc")
Expand Down
50 changes: 43 additions & 7 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ void addValueFromModule(const std::string& moduleName, const std::string& module

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

if (sysInfo.find(moduleName) == sysInfo.end())
sysInfo.insert({ moduleName, {} });
Expand All @@ -1107,13 +1107,49 @@ 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());
if (query_cursor.cursor_size() == UNKNOWN)
SYSINFO_INSERT(query_cursor.cursor());
else
SYSINFO_INSERT(fmt::format("{} ({}px)", query_theme.cursor(), query_theme.cursor_size()));
SYSINFO_INSERT(fmt::format("{} ({}px)", query_cursor.cursor(), query_cursor.cursor_size()));
break;
case "cursor_name"_fnv1a16: SYSINFO_INSERT(query_theme.cursor()); break;
case "cursor_size"_fnv1a16: SYSINFO_INSERT(query_theme.cursor_size()); break;
case "cursor_name"_fnv1a16: SYSINFO_INSERT(query_cursor.cursor()); break;
case "cursor_size"_fnv1a16: SYSINFO_INSERT(query_cursor.cursor_size()); break;
}
}
}

else if (moduleName == "theme-gsettings")
{

if (sysInfo.find(moduleName) == sysInfo.end())
sysInfo.insert({ moduleName, {} });

if (sysInfo.at(moduleName).find(moduleMemberName) == sysInfo.at(moduleName).end())
{
if (hasStart(moduleMemberName, "cursor"))
{
Query::Theme query_cursor(queried_themes, config, true);
switch (moduleMember_hash)
{
case "cursor"_fnv1a16:
if (query_cursor.cursor_size() == UNKNOWN)
SYSINFO_INSERT(query_cursor.cursor());
else
SYSINFO_INSERT(fmt::format("{} ({}px)", query_cursor.cursor(), query_cursor.cursor_size()));
break;
case "cursor_name"_fnv1a16: SYSINFO_INSERT(query_cursor.cursor()); break;
case "cursor_size"_fnv1a16: SYSINFO_INSERT(query_cursor.cursor_size()); break;
}
}
else
{
Query::Theme query_theme(0, queried_themes, queried_themes_names, "", config, true);
switch (moduleMember_hash)
{
case "name"_fnv1a16: SYSINFO_INSERT(query_theme.gtk_theme()); break;
case "icons"_fnv1a16: SYSINFO_INSERT(query_theme.gtk_icon_theme()); break;
case "font"_fnv1a16: SYSINFO_INSERT(query_theme.gtk_font()); break;
}
}
}
}
Expand All @@ -1124,7 +1160,7 @@ void addValueFromModule(const std::string& moduleName, const std::string& module
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 Down
29 changes: 15 additions & 14 deletions src/query/unix/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ static bool get_cursor_dconf(const std::string_view de_name, Theme::Theme_t& the

LOAD_LIBRARY("libdconf.so", return false);
LOAD_LIB_SYMBOL(DConfClient *, dconf_client_new, void);
LOAD_LIB_SYMBOL(GVariant *, dconf_client_read, DConfClient *client, const char *);
LOAD_LIB_SYMBOL(const gchar *, g_variant_get_string, GVariant *value, gsize *lenght);
LOAD_LIB_SYMBOL(GVariant *, dconf_client_read, DConfClient *, const char *);
LOAD_LIB_SYMBOL(const gchar *, g_variant_get_string, GVariant *, gsize *);
LOAD_LIB_SYMBOL(gint32, g_variant_get_int32, GVariant *);

debug("calling {}", __PRETTY_FUNCTION__);
DConfClient *client = dconf_client_new();
Expand Down Expand Up @@ -132,7 +133,7 @@ static bool get_cursor_dconf(const std::string_view de_name, Theme::Theme_t& the
{
variant = dconf_client_read(client, (interface + "cursor-size").c_str());
if (variant)
theme.cursor = g_variant_get_string(variant, NULL);
theme.cursor = g_variant_get_int32(variant);
}

return assert_cursor(theme);
Expand Down Expand Up @@ -439,20 +440,19 @@ static void get_de_gtk_theme(const std::string_view de_name, const std::uint8_t
}

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, const Config& config)
Theme::Theme_t& theme, const Config& config, const bool gsettings_only)
{
if (dont_query_dewm)
{
if (gsettings_only)
get_gtk_theme_gsettings(de_name, theme, config);
else if (dont_query_dewm)
get_gtk_theme_from_configs(ver, de_name, theme, config);
return;
}

get_de_gtk_theme(de_name, ver, theme, config);
else
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 Config& config)
const std::string& theme_name_version, const Config& config, const bool gsettings_only)
: m_queried_themes(queried_themes),
m_theme_name_version(theme_name_version),
m_Config(config)
Expand All @@ -472,7 +472,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, config);
get_gtk_theme(query_user.m_bDont_query_dewm, ver, m_wmde_name, m_theme_infos, config, gsettings_only);

if (m_theme_infos.gtk_theme_name.empty())
m_theme_infos.gtk_theme_name = MAGIC_LINE;
Expand All @@ -493,7 +493,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, const Config& config) : m_queried_themes(queried_themes), m_Config(config)
Theme::Theme(systemInfo_t& queried_themes, const Config& config, const bool gsettings_only) : m_queried_themes(queried_themes), m_Config(config)
{
static bool done = false;
if (hasStart(query_user.term_name(), "/dev") || done)
Expand All @@ -508,7 +508,8 @@ Theme::Theme(systemInfo_t& queried_themes, const Config& config) : m_queried_the
else
m_wmde_name = de_name;

if (get_de_cursor(m_wmde_name, m_theme_infos)){}
if (gsettings_only) { get_cursor_gsettings(m_wmde_name, m_theme_infos, config); }
else if (get_de_cursor(m_wmde_name, m_theme_infos)){}
else if (get_cursor_from_gtk_configs(4, m_theme_infos)){}
else if (get_cursor_from_gtk_configs(3, m_theme_infos)){}
else if (get_cursor_from_gtk_configs(2, m_theme_infos)){}
Expand Down

0 comments on commit 895ff98

Please sign in to comment.