Skip to content

Commit 8279965

Browse files
core: add show_apps_on_open config option (#147)
Add a new config option `general:show_apps_on_open` (default: 0) that displays desktop applications sorted by usage frequency when the launcher is opened, without requiring the user to type first. When disabled (default), the launcher opens with an empty list, preserving the original keyboard-first behavior.
1 parent e07f9cd commit 8279965

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

src/config/ConfigManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ CConfigManager::CConfigManager() : m_inotifyFd(inotify_init()) {
1414
m_config = makeUnique<Hyprlang::CConfig>(CFGPATH.c_str(), Hyprlang::SConfigOptions{.allowMissingConfig = true});
1515

1616
m_config->addConfigValue("general:grab_focus", Hyprlang::INT{1});
17+
m_config->addConfigValue("general:show_apps_on_open", Hyprlang::INT{0});
1718

1819
m_config->addConfigValue("locale:override", Hyprlang::STRING{""});
1920

src/finders/desktop/DesktopFinder.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,30 @@ std::vector<SFinderResult> CDesktopFinder::getResultsForQuery(const std::string&
279279

280280
std::vector<SFinderResult> results;
281281

282-
auto fuzzed = Fuzzy::getNResults(m_desktopEntryCacheGeneric, query, MAX_RESULTS_PER_FINDER);
282+
if (query.empty()) {
283+
// Return all entries sorted by frequency (most used first)
284+
auto sorted = m_desktopEntryCacheGeneric;
285+
std::stable_sort(sorted.begin(), sorted.end(), [](const SP<IFinderResult>& a, const SP<IFinderResult>& b) { return a->frequency() > b->frequency(); });
286+
287+
size_t count = std::min(sorted.size(), sc<size_t>(MAX_RESULTS_PER_FINDER));
288+
results.reserve(count);
289+
290+
for (size_t i = 0; i < count; ++i) {
291+
const auto p = reinterpretPointerCast<CDesktopEntry>(sorted[i]);
292+
if (!p)
293+
continue;
294+
results.emplace_back(SFinderResult{
295+
.label = p->m_name,
296+
.icon = *PICONSENABLED ? p->m_icon : "",
297+
.result = p,
298+
.hasIcon = true,
299+
});
300+
}
301+
302+
return results;
303+
}
304+
305+
auto fuzzed = Fuzzy::getNResults(m_desktopEntryCacheGeneric, query, MAX_RESULTS_PER_FINDER);
283306

284307
results.reserve(fuzzed.size());
285308

src/query/QueryProcessor.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ void CQueryProcessor::process() {
9797
bool eat = false;
9898

9999
if (!m_overrideFinder) {
100+
if (query.empty()) {
101+
// Only show apps on empty query if configured to do so
102+
static auto PSHOWONOPEN = Hyprlang::CSimpleConfigValue<Hyprlang::INT>(g_configManager->m_config.get(), "general:show_apps_on_open");
103+
if (*PSHOWONOPEN) {
104+
static auto PDEFAULTFINDER = Hyprlang::CSimpleConfigValue<Hyprlang::STRING>(g_configManager->m_config.get(), "finders:default_finder");
105+
FINDER = finderForName(*PDEFAULTFINDER);
106+
if (FINDER) {
107+
auto RESULTS = FINDER->getResultsForQuery("");
108+
if (g_ui && g_ui->m_backend)
109+
g_ui->m_backend->addIdle([r = std::move(RESULTS)] mutable { g_ui->updateResults(std::move(r)); });
110+
} else if (g_ui) {
111+
g_ui->m_backend->addIdle([] mutable { g_ui->updateResults({}); });
112+
}
113+
} else if (g_ui) {
114+
g_ui->m_backend->addIdle([] mutable { g_ui->updateResults({}); });
115+
}
116+
return;
117+
}
118+
100119
const auto [F, e] = finderForPrefix(query[0]);
101120

102121
if (e && query.size() == 1)
@@ -107,12 +126,6 @@ void CQueryProcessor::process() {
107126
} else
108127
FINDER = m_overrideFinder;
109128

110-
if (query.empty() && !m_overrideFinder) {
111-
if (g_ui)
112-
g_ui->m_backend->addIdle([] mutable { g_ui->updateResults({}); });
113-
return;
114-
}
115-
116129
auto RESULTS = FINDER ? FINDER->getResultsForQuery(eat ? query.substr(1) : query) : std::vector<SFinderResult>{};
117130

118131
if (g_ui && g_ui->m_backend)

0 commit comments

Comments
 (0)