Skip to content

Commit

Permalink
parse: prettify DE name
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni500github committed Aug 26, 2024
1 parent 752b7f4 commit 56ee3ba
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
43 changes: 37 additions & 6 deletions src/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ std::string parse(const std::string_view input, systemInfo_t& systemInfo, std::s
getInfoFromName(systemInfo, moduleName, moduleValueName));
}
break;
case '}': // please pay very attention when reading this unreadable code
case '}': // please pay very attention when reading this unreadable and godawful code
if (!config.m_arg_colors_name.empty())
{
const auto& it_name = std::find(config.m_arg_colors_name.begin(), config.m_arg_colors_name.end(), command);
Expand Down Expand Up @@ -468,6 +468,37 @@ static std::string prettify_term_name(const std::string_view term_name)
return term_name.data();
}

static std::string prettify_de_name(const std::string_view de_name)
{
switch (fnv1a16::hash(str_tolower(de_name.data())))
{
case "kde"_fnv1a16:
case "plasma"_fnv1a16:
case "plasmashell"_fnv1a16:
case "plasmawayland"_fnv1a16:
return "KDE Plasma";

case "gnome"_fnv1a16:
case "gnome-shell"_fnv1a16:
return "GNOME";

case "xfce"_fnv1a16:
case "xfce4"_fnv1a16:
case "xfce4-session"_fnv1a16:
return "Xfce4";

case "mate"_fnv1a16:
case "mate-session"_fnv1a16:
return "Mate";

case "lxqt"_fnv1a16:
case "lxqt-session"_fnv1a16:
return "LXQt";
}

return de_name.data();
}

void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, const std::string& moduleValueName,
const Config& config)
{
Expand Down Expand Up @@ -581,14 +612,14 @@ void addValueFromModule(systemInfo_t& sysInfo, const std::string& moduleName, co

case "de_name"_fnv1a16:
SYSINFO_INSERT(
query_user.de_name(query_user.m_bDont_query_dewm, query_user.term_name(),
query_user.wm_name(query_user.m_bDont_query_dewm, query_user.term_name())));
prettify_de_name(query_user.de_name(query_user.m_bDont_query_dewm, query_user.term_name(),
query_user.wm_name(query_user.m_bDont_query_dewm, query_user.term_name()))));
break;

case "de_version"_fnv1a16:
SYSINFO_INSERT(query_user.de_version(
query_user.de_name(query_user.m_bDont_query_dewm, query_user.term_name(),
query_user.wm_name(query_user.m_bDont_query_dewm, query_user.term_name()))));
SYSINFO_INSERT(
query_user.de_version(query_user.de_name(query_user.m_bDont_query_dewm, query_user.term_name(),
query_user.wm_name(query_user.m_bDont_query_dewm, query_user.term_name()))));
break;

case "wm_name"_fnv1a16:
Expand Down
2 changes: 2 additions & 0 deletions src/query/unix/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static std::string get_wm_name()
if ((pos = proc_name.rfind('/')) != std::string::npos)
proc_name.erase(pos);

debug("proc_name after = {}", proc_name);

if ((wm_name = prettify_wm_name(proc_name)) == MAGIC_LINE)
continue;

Expand Down

0 comments on commit 56ee3ba

Please sign in to comment.