Skip to content

Commit

Permalink
Correction of 5822.2, refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Jun 16, 2021
1 parent 9530d5f commit bb9d2a6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 49 deletions.
7 changes: 7 additions & 0 deletions far/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
--------------------------------------------------------------------------------
drkns 16.06.2021 18:22:16 +0100 - build 5823

1. Correction of 5822.2.

2. Refactoring.

--------------------------------------------------------------------------------
drkns 15.06.2021 22:01:42 +0100 - build 5822

Expand Down
1 change: 0 additions & 1 deletion far/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,6 @@ bool Edit::ProcessKey(const Manager::Key& Key)

if (
!IntKeyState.ShiftPressed() &&
!Global->CtrlObject->Macro.IsExecuting() &&
!Recurse &&
is_clear_selection_key(LocalKey)
)
Expand Down
60 changes: 25 additions & 35 deletions far/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ static const TFKey ModifKeyName[]
{ KEY_ALT, lng::MKeyAlt, L"Alt"sv, },
{ KEY_RALT, lng::MKeyRAlt, L"RAlt"sv, },
{ KEY_SHIFT, lng::MKeyShift, L"Shift"sv, },
{ KEY_M_SPEC, lng(-1), L"Spec"sv, },
{ KEY_M_OEM, lng(-1), L"Oem"sv, },
};

static auto& Layout()
Expand Down Expand Up @@ -1382,19 +1380,21 @@ int KeyNameToKey(string_view Name)
if (Chr)
Name.remove_prefix(1);
}
else if (
Name.size() == 5 && any_of(Key, KEY_M_SPEC, KEY_M_OEM) &&
std::all_of(ALL_CONST_RANGE(Name), std::iswdigit)
) // Варианты (3) и (4)
else
{
const auto K = from_string<unsigned>(Name);

if (Key == KEY_M_SPEC) // Вариант (3)
Key = (Key & ~KEY_M_SPEC) | (K + KEY_VK_0xFF_BEGIN);
else // Вариант (4)
Key = (Key & ~KEY_M_OEM) | (K + KEY_FKEY_BEGIN);
const auto
OemPrefix = L"Oem"sv,
SpecPrefix = L"Spec"sv;

Name = {};
if (const auto IsOem = starts_with(Name, OemPrefix); IsOem || starts_with(Name, SpecPrefix))
{
const auto Tail = Name.substr(IsOem? OemPrefix.size() : SpecPrefix.size());
if (Tail.size() == 5 && std::all_of(ALL_CONST_RANGE(Tail), std::iswdigit)) // Варианты (3) и (4)
{
Key |= (IsOem? KEY_FKEY_BEGIN : KEY_VK_0xFF_BEGIN) | from_string<unsigned>(Tail);
Name = {};
}
}
}
// Вариант (5). Уже "собран".
}
Expand Down Expand Up @@ -1762,34 +1762,24 @@ int TranslateKeyToVK(int Key, INPUT_RECORD* Rec)
}


int IsNavKey(DWORD Key)
bool IsNavKey(DWORD const Key)
{
static const std::pair<DWORD, DWORD> NavKeysMap[] =
static const DWORD Keys[]
{
{0,KEY_CTRLC},
{0,KEY_RCTRLC},
{0,KEY_INS}, {0,KEY_NUMPAD0},
{0,KEY_CTRLINS}, {0,KEY_CTRLNUMPAD0},
{0,KEY_RCTRLINS}, {0,KEY_RCTRLNUMPAD0},

{1,KEY_LEFT}, {1,KEY_NUMPAD4},
{1,KEY_RIGHT}, {1,KEY_NUMPAD6},
{1,KEY_HOME}, {1,KEY_NUMPAD7},
{1,KEY_END}, {1,KEY_NUMPAD1},
{1,KEY_UP}, {1,KEY_NUMPAD8},
{1,KEY_DOWN}, {1,KEY_NUMPAD2},
{1,KEY_PGUP}, {1,KEY_NUMPAD9},
{1,KEY_PGDN}, {1,KEY_NUMPAD3},
//!!!!!!!!!!!
KEY_LEFT, KEY_NUMPAD4,
KEY_RIGHT, KEY_NUMPAD6,
KEY_HOME, KEY_NUMPAD7,
KEY_END, KEY_NUMPAD1,
KEY_UP, KEY_NUMPAD8,
KEY_DOWN, KEY_NUMPAD2,
KEY_PGUP, KEY_NUMPAD9,
KEY_PGDN, KEY_NUMPAD3,
};

return std::any_of(CONST_RANGE(NavKeysMap, i)
{
return (!i.first && Key==i.second) || (i.first && (Key&0x00FFFFFF) == (i.second&0x00FFFFFF));
});
return contains(Keys, Key & ~KEY_CTRLMASK);
}

int IsShiftKey(DWORD Key)
bool IsShiftKey(DWORD Key)
{
static const DWORD ShiftKeys[] =
{
Expand Down
4 changes: 2 additions & 2 deletions far/keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ unsigned int CalcKeyCode(INPUT_RECORD* rec, bool RealKey, bool* NotMacros = null
DWORD WaitKey(DWORD KeyWait = static_cast<DWORD>(-1), DWORD delayMS = 0, bool ExcludeMacro = true);
int SetFLockState(unsigned vkKey, int State);
bool WriteInput(int Key);
int IsNavKey(DWORD Key);
int IsShiftKey(DWORD Key);
bool IsNavKey(DWORD Key);
bool IsShiftKey(DWORD Key);
bool IsModifKey(DWORD Key);
bool IsInternalKeyReal(unsigned int Key);
bool IsCharKey(unsigned int Key);
Expand Down
20 changes: 10 additions & 10 deletions far/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,24 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

//----------------------------------------------------------------------------

#define EXTENDED_KEY_BASE 0x00010000
#define INTERNAL_KEY_BASE 0x00020000
#define INTERNAL_KEY_BASE_2 0x00030000
#define INTERNAL_MACRO_BASE 0x00080000
constexpr unsigned int
KEY_CTRLMASK = 0xFF000000,
EXTENDED_KEY_BASE = 0x00010000,
INTERNAL_KEY_BASE = 0x00020000,
INTERNAL_KEY_BASE_2 = 0x00030000,
INTERNAL_MACRO_BASE = 0x00080000;

enum far_key_code: unsigned int
{
NO_KEY = 0,

KEY_CTRLMASK =0xFFF00000,
KEY_M_OEM =0x00100000,
KEY_M_SPEC =0x00200000,
//
//
KEY_CTRL =0x01000000,
KEY_ALT =0x02000000,
KEY_SHIFT =0x04000000,
//
KEY_RCTRL =0x10000000,
KEY_RALT =0x20000000,
KEY_RSHIFT =0x80000000,
KEY_RSHIFT =0x40000000,

KEY_BRACKET ='[',
KEY_BACKBRACKET =']',
Expand All @@ -89,6 +86,7 @@ enum far_key_code: unsigned int

KEY_MASKF =0x0001FFFF,

// 0x00010000
KEY_FKEY_BEGIN =EXTENDED_KEY_BASE,

KEY_BREAK =EXTENDED_KEY_BASE+VK_CANCEL,
Expand Down Expand Up @@ -201,6 +199,7 @@ enum far_key_code: unsigned int

KEY_END_FKEY =0x0001FFFF,

// 0x00020000
KEY_MSWHEEL_UP =INTERNAL_KEY_BASE+3,
KEY_MSWHEEL_DOWN =INTERNAL_KEY_BASE+4,

Expand Down Expand Up @@ -246,6 +245,7 @@ enum far_key_code: unsigned int
KEY_LAST_BASE =KEY_END_SKEY,

// см macroopcode.hpp
// 0x00080000
KEY_MACRO_BASE =INTERNAL_MACRO_BASE,
KEY_MACRO_C_BASE =INTERNAL_MACRO_BASE+0x0400, // булевые условия 0x00080400 - 0x000807FF
KEY_MACRO_V_BASE =INTERNAL_MACRO_BASE+0x0800, // разные переменные 0x00080800 - 0x00080BFF
Expand Down
2 changes: 1 addition & 1 deletion far/vbuild.m4
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5822
5823

0 comments on commit bb9d2a6

Please sign in to comment.