diff --git a/src/hook_manager.cc b/src/hook_manager.cc index e55eb89e..c5698c18 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -63,12 +63,26 @@ CandidateList HookManager::complete_hook_group(StringView prefix, ByteCount pos_ void HookManager::run_hook(Hook hook, StringView param, Context& context) { + auto& hook_list = m_hooks[to_underlying(hook)]; + const bool only_always = context.hooks_disabled(); + auto& disabled_hooks = context.options()["disabled_hooks"].get(); + + struct ToRun { HookData* hook; MatchResults captures; }; + Vector hooks_to_run; // The m_hooks_trash vector ensure hooks wont die during this method + for (auto& hook : hook_list) + { + MatchResults captures; + if ((not only_always or (hook->flags & HookFlags::Always)) and + (hook->group.empty() or disabled_hooks.empty() or + not regex_match(hook->group.begin(), hook->group.end(), disabled_hooks)) + and regex_match(param.begin(), param.end(), captures, hook->filter)) + hooks_to_run.push_back({ hook.get(), std::move(captures) }); + } if (m_parent) m_parent->run_hook(hook, param, context); - auto& hook_list = m_hooks[to_underlying(hook)]; auto hook_name = enum_desc(Meta::Type{})[to_underlying(hook)].name; if (contains(m_running_hooks, std::make_pair(hook, param))) { @@ -88,20 +102,6 @@ void HookManager::run_hook(Hook hook, StringView param, Context& context) const bool profile = debug_flags & DebugFlags::Profile; auto start_time = profile ? Clock::now() : TimePoint{}; - auto& disabled_hooks = context.options()["disabled_hooks"].get(); - - struct ToRun { HookData* hook; MatchResults captures; }; - Vector hooks_to_run; // The m_hooks_trash vector ensure hooks wont die during this method - for (auto& hook : hook_list) - { - MatchResults captures; - if ((not only_always or (hook->flags & HookFlags::Always)) and - (hook->group.empty() or disabled_hooks.empty() or - not regex_match(hook->group.begin(), hook->group.end(), disabled_hooks)) - and regex_match(param.begin(), param.end(), captures, hook->filter)) - hooks_to_run.push_back({ hook.get(), std::move(captures) }); - } - bool hook_error = false; for (auto& to_run : hooks_to_run) { diff --git a/test/compose/do-not-run-hooks-added-by-parent/cmd b/test/compose/do-not-run-hooks-added-by-parent/cmd new file mode 100644 index 00000000..ebd87f60 --- /dev/null +++ b/test/compose/do-not-run-hooks-added-by-parent/cmd @@ -0,0 +1 @@ + diff --git a/test/compose/do-not-run-hooks-added-by-parent/in b/test/compose/do-not-run-hooks-added-by-parent/in new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/compose/do-not-run-hooks-added-by-parent/in @@ -0,0 +1 @@ + diff --git a/test/compose/do-not-run-hooks-added-by-parent/out b/test/compose/do-not-run-hooks-added-by-parent/out new file mode 100644 index 00000000..257cc564 --- /dev/null +++ b/test/compose/do-not-run-hooks-added-by-parent/out @@ -0,0 +1 @@ +foo diff --git a/test/compose/do-not-run-hooks-added-by-parent/rc b/test/compose/do-not-run-hooks-added-by-parent/rc new file mode 100644 index 00000000..039cffa3 --- /dev/null +++ b/test/compose/do-not-run-hooks-added-by-parent/rc @@ -0,0 +1,5 @@ +hook global NormalKey %{ + hook window NormalKey %{ + exec -draft ifoo + } +}