From 9c4fdc98039ad516be6b301cc871c52346f44d8b Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 10 Feb 2024 00:47:23 +0100 Subject: [PATCH] Update hotkey name when description is changed This makes it easier to identify the hotkey in external tools --- plugins/base/utils/hotkey-helpers.cpp | 14 ++++++++++---- plugins/base/utils/hotkey-helpers.hpp | 1 + 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/base/utils/hotkey-helpers.cpp b/plugins/base/utils/hotkey-helpers.cpp index 8c775c17..41874196 100644 --- a/plugins/base/utils/hotkey-helpers.cpp +++ b/plugins/base/utils/hotkey-helpers.cpp @@ -5,7 +5,7 @@ namespace advss { std::vector> Hotkey::_registeredHotkeys = {}; -uint32_t Hotkey::_hotkeyCounter = 1; +uint32_t Hotkey::_hotkeyCounter = 0; static bool setup() { @@ -48,10 +48,9 @@ std::shared_ptr Hotkey::GetHotkey(const std::string &description, Hotkey::Hotkey(const std::string &description) : _description(description) { - std::string name = - "macro_condition_hotkey_" + std::to_string(_hotkeyCounter); _hotkeyID = obs_hotkey_register_frontend( - name.c_str(), _description.c_str(), Callback, this); + GetNameFromDescription(description).c_str(), + _description.c_str(), Callback, this); _hotkeyCounter++; } @@ -90,6 +89,8 @@ bool Hotkey::UpdateDescription(const std::string &descritpion) return false; } _description = descritpion; + obs_hotkey_set_name(_hotkeyID, + GetNameFromDescription(descritpion).c_str()); obs_hotkey_set_description(_hotkeyID, descritpion.c_str()); return true; } @@ -119,6 +120,11 @@ void Hotkey::Callback(void *data, obs_hotkey_id, obs_hotkey_t *, bool pressed) hotkey->_pressed = pressed; } +std::string Hotkey::GetNameFromDescription(const std::string &description) +{ + return "macro_condition_hotkey_" + description; +} + void Hotkey::ClearAllHotkeys() { _registeredHotkeys.clear(); diff --git a/plugins/base/utils/hotkey-helpers.hpp b/plugins/base/utils/hotkey-helpers.hpp index bedb7062..efbbded2 100644 --- a/plugins/base/utils/hotkey-helpers.hpp +++ b/plugins/base/utils/hotkey-helpers.hpp @@ -34,6 +34,7 @@ private: static bool DescriptionAvailable(const std::string &); static void Callback(void *data, obs_hotkey_id, obs_hotkey_t *, bool pressed); + static std::string GetNameFromDescription(const std::string &desc); static std::vector> _registeredHotkeys; static uint32_t _hotkeyCounter;