From fe3453e36806fd72386e165c0fa0cea2a734da3c Mon Sep 17 00:00:00 2001 From: Kristofer Berggren Date: Sun, 24 Mar 2024 15:38:16 +0800 Subject: [PATCH] fixes #193 - custom key bindings may stop working after using dialog --- lib/common/src/version.h | 2 +- src/nchat.1 | 2 +- src/uikeyconfig.cpp | 20 +++++++++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/common/src/version.h b/lib/common/src/version.h index bfb48a80..d78a130b 100644 --- a/lib/common/src/version.h +++ b/lib/common/src/version.h @@ -7,4 +7,4 @@ #pragma once -#define NCHAT_VERSION "4.43" +#define NCHAT_VERSION "4.44" diff --git a/src/nchat.1 b/src/nchat.1 index 5803d2ac..9056b748 100644 --- a/src/nchat.1 +++ b/src/nchat.1 @@ -1,5 +1,5 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man. -.TH NCHAT "1" "March 2024" "nchat v4.43" "User Commands" +.TH NCHAT "1" "March 2024" "nchat v4.44" "User Commands" .SH NAME nchat \- ncurses chat .SH SYNOPSIS diff --git a/src/uikeyconfig.cpp b/src/uikeyconfig.cpp index 3694d699..1a481dd0 100644 --- a/src/uikeyconfig.cpp +++ b/src/uikeyconfig.cpp @@ -1,6 +1,6 @@ // uikeyconfig.cpp // -// Copyright (c) 2019-2023 Kristofer Berggren +// Copyright (c) 2019-2024 Kristofer Berggren // All rights reserved. // // nchat is distributed under the MIT license, see LICENSE for details. @@ -332,10 +332,20 @@ int UiKeyConfig::GetKeyCode(const std::string& p_KeyName) int UiKeyConfig::GetVirtualKeyCodeFromOct(const std::string& p_KeyOct) { - int keyCode = ReserveVirtualKeyCode(); - std::string keyStr = StrUtil::StrFromOct(p_KeyOct); - define_key(keyStr.c_str(), keyCode); - return keyCode; + static std::map reservedVirtualKeyCodes; + auto it = reservedVirtualKeyCodes.find(p_KeyOct); + if (it != reservedVirtualKeyCodes.end()) + { + return it->second; + } + else + { + int keyCode = ReserveVirtualKeyCode(); + std::string keyStr = StrUtil::StrFromOct(p_KeyOct); + define_key(keyStr.c_str(), keyCode); + reservedVirtualKeyCodes[p_KeyOct] = keyCode; + return keyCode; + } } int UiKeyConfig::ReserveVirtualKeyCode()