diff options
| author | Tobias Pisani <topisani@hamsterpoison.com> | 2024-03-03 04:29:32 +0100 |
|---|---|---|
| committer | Tobias Pisani <topisani@hamsterpoison.com> | 2024-03-27 17:59:05 +0100 |
| commit | 5515383ae4683c3d691004cbc422ee1f6e36ee07 (patch) | |
| tree | b45f864897dd5ac6a3d531f79db1d019870dcf39 | |
| parent | 2f7568485ff6ac6aaf83f6ac5988de6a723083c4 (diff) | |
Add ClientRenamed hook
| -rw-r--r-- | doc/pages/hooks.asciidoc | 3 | ||||
| -rw-r--r-- | src/context.cc | 5 | ||||
| -rw-r--r-- | src/context.hh | 2 | ||||
| -rw-r--r-- | src/hook_manager.hh | 2 |
4 files changed, 11 insertions, 1 deletions
diff --git a/doc/pages/hooks.asciidoc b/doc/pages/hooks.asciidoc index 46de9133..d9c000eb 100644 --- a/doc/pages/hooks.asciidoc +++ b/doc/pages/hooks.asciidoc @@ -140,6 +140,9 @@ name. Hooks with no description will always use an empty string. *ClientClose* `client name`:: executed when a client is closed, after it was removed from the client list. + +*ClientRenamed* `<old name>:<new name>`:: + executed when a client is renamed using the `rename-client` command *RuntimeError* `error message`:: an error was encountered while executing a user command diff --git a/src/context.cc b/src/context.cc index 0c1b8aad..71a5becd 100644 --- a/src/context.cc +++ b/src/context.cc @@ -4,6 +4,7 @@ #include "client.hh" #include "face_registry.hh" #include "buffer_manager.hh" +#include "hook_manager.hh" #include "register_manager.hh" #include "window.hh" @@ -417,4 +418,8 @@ StringView Context::main_sel_register_value(StringView reg) const return RegisterManager::instance()[reg].get_main(*this, index); } +void Context::set_name(String name) { + String old_name = std::exchange(m_name, std::move(name)); + hooks().run_hook(Hook::ClientRenamed, format("{}:{}", old_name, m_name), *this); +} } diff --git a/src/context.hh b/src/context.hh index fca4ba06..7834bde4 100644 --- a/src/context.hh +++ b/src/context.hh @@ -110,7 +110,7 @@ public: StringView main_sel_register_value(StringView reg) const; const String& name() const { return m_name; } - void set_name(String name) { m_name = std::move(name); } + void set_name(String name); bool is_editing() const { return m_edition_level!= 0; } void disable_undo_handling() { m_edition_level = -1; } diff --git a/src/hook_manager.hh b/src/hook_manager.hh index 24e88e1a..4a5c85b3 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -30,6 +30,7 @@ enum class Hook BufSetOption, ClientCreate, ClientClose, + ClientRenamed, InsertChar, InsertDelete, InsertIdle, @@ -75,6 +76,7 @@ constexpr auto enum_desc(Meta::Type<Hook>) {Hook::BufSetOption, "BufSetOption"}, {Hook::ClientCreate, "ClientCreate"}, {Hook::ClientClose, "ClientClose"}, + {Hook::ClientRenamed, "ClientRenamed"}, {Hook::InsertChar, "InsertChar"}, {Hook::InsertDelete, "InsertDelete"}, {Hook::InsertIdle, "InsertIdle"}, |
