Skip to content

Commit aaf96e7

Browse files
authored
finders/desktop: use keywords for fuzzables as well (#151)
fixes #150
1 parent 033d365 commit aaf96e7

6 files changed

Lines changed: 53 additions & 32 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pkg_check_modules(
2626
hyprtoolkit
2727
pixman-1
2828
libdrm
29-
hyprutils>=0.10.2
29+
hyprutils>=0.12.0
3030
hyprwire
3131
icu-uc
3232
hyprlang

flake.lock

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nix/default.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
aquamarine,
1212
cairo,
1313
pixman,
14+
pango,
1415
hyprtoolkit,
1516
hyprgraphics,
1617
libqalculate,
18+
libGL,
1719
wayland,
1820
wayland-protocols,
1921
wayland-scanner,
@@ -48,6 +50,8 @@ stdenv.mkDerivation {
4850
aquamarine
4951
pixman
5052
cairo
53+
pango
54+
libGL
5155
];
5256

5357
cmakeFlags = lib.mapAttrsToList lib.cmakeFeature {

src/finders/Fuzzy.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ std::vector<SP<IFinderResult>> Fuzzy::getNResults(const std::vector<SP<IFinderRe
271271
return getBestResultsStable(scores, results);
272272
}
273273

274-
std::vector<std::string> Fuzzy::createFuzzableStrings(std::initializer_list<std::string_view> strings, bool toLowercase) {
274+
// NOLINTNEXTLINE SHUT THE FUCK UP
275+
std::vector<std::string> Fuzzy::createFuzzableStrings(std::vector<std::string_view>&& strings, bool toLowercase) {
275276
std::vector<std::string> fuzzables{};
276277
fuzzables.reserve(strings.size());
277278

src/finders/Fuzzy.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99

1010
namespace Fuzzy {
1111
std::vector<SP<IFinderResult>> getNResults(const std::vector<SP<IFinderResult>>& in, const std::string& query, size_t results);
12-
std::vector<std::string> createFuzzableStrings(std::initializer_list<std::string_view>, bool toLowercase = true);
12+
std::vector<std::string> createFuzzableStrings(std::vector<std::string_view>&&, bool toLowercase = true);
1313
};

src/finders/desktop/DesktopFinder.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <hyprutils/string/String.hpp>
1616
#include <hyprutils/os/Process.hpp>
1717
#include <hyprutils/string/ConstVarList.hpp>
18+
#include <hyprutils/string/VarList2.hpp>
1819

1920
using namespace Hyprutils::String;
2021
using namespace Hyprutils::OS;
@@ -60,7 +61,7 @@ class CDesktopEntry : public IFinderResult {
6061
const std::string_view TERMINAL_EXEC = *PTERMINALEXEC;
6162

6263
auto toExec = std::format("{}{}{}", LAUNCH_PREFIX.empty() ? std::string{""} : std::string{LAUNCH_PREFIX} + std::string{" "},
63-
m_terminal && !TERMINAL_EXEC.empty() ? std::string{TERMINAL_EXEC} + std::string{" "} : std::string{""}, m_exec);
64+
m_terminal && !TERMINAL_EXEC.empty() ? std::string{TERMINAL_EXEC} + std::string{" "} : std::string{""}, m_exec);
6465

6566
Debug::log(TRACE, "Running {}", toExec);
6667

@@ -265,10 +266,25 @@ void CDesktopFinder::cacheEntry(const std::filesystem::path& path) {
265266
e->m_exec = EXEC;
266267
e->m_icon = ICON;
267268
e->m_name = NAME;
268-
e->m_fuzzables = Fuzzy::createFuzzableStrings({NAME, GEN_NAME});
269269
e->m_stem = std::move(pathStem);
270270
e->m_terminal = TERMINAL;
271271
e->m_frequency = m_entryFrequencyCache->getCachedEntry(e->m_name);
272+
273+
// create fuzzable strings. Read: name, generic name, but also keywords.
274+
std::vector<std::string_view> strings = {NAME, GEN_NAME};
275+
const std::string_view KEYWORDS = extract("Keywords");
276+
if (!KEYWORDS.empty()) {
277+
CVarList2 keywords(KEYWORDS, 0, ';', true);
278+
for (const auto& k : keywords) {
279+
strings.emplace_back(k);
280+
}
281+
282+
// we need to emplace here because CVarList2 will be destroyed and the string_view
283+
// refs will become uafs
284+
e->m_fuzzables = Fuzzy::createFuzzableStrings(std::move(strings));
285+
} else
286+
e->m_fuzzables = Fuzzy::createFuzzableStrings(std::move(strings));
287+
272288
m_desktopEntryCacheGeneric.emplace_back(e);
273289

274290
Debug::log(TRACE, "desktop: cached {} with icon {} and exec line of \"{}\"", NAME, ICON, EXEC);

0 commit comments

Comments
 (0)