Skip to content

Commit

Permalink
ui/Keys: add IsFKey()
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Sep 10, 2024
1 parent be80e46 commit c6ffc04
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
16 changes: 6 additions & 10 deletions src/KeyName.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ GetKeyName(int key) noexcept
{
static char buf[32];

for (int i = 0; i < 64; ++i) {
if (key == KEY_F(i)) {
snprintf(buf, sizeof(buf), "F%u", i);
return buf;
}
if (IsFKey(key)) {
snprintf(buf, sizeof(buf), "F%u", key - KEY_F0);
return buf;
}

const char *name = keyname(key);
Expand Down Expand Up @@ -132,11 +130,9 @@ GetLocalizedKeyName(int key) noexcept

static char buf[32];

for (int i = 0; i <= 63; i++) {
if (key == KEY_F(i)) {
snprintf(buf, sizeof(buf), "F%d", i );
return buf;
}
if (IsFKey(key)) {
snprintf(buf, sizeof(buf), "F%u", key - KEY_F0);
return buf;
}

const char *name = keyname(key);
Expand Down
8 changes: 2 additions & 6 deletions src/dialogs/TextInputDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,8 @@ TextInputDialog::OnKey(const Window window, int key)
}

/* check if key is a function key */
for (size_t i = 0; i < 63; i++)
if (key == (int)KEY_F(i)) {
key = KEY_F(1);
i = 64;
}
if (IsFKey(key))
return false;

switch (key) {
case KEY_TAB:
Expand Down Expand Up @@ -331,7 +328,6 @@ TextInputDialog::OnKey(const Window window, int key)
case KEY_IC:
case KEY_PPAGE:
case KEY_NPAGE:
case KEY_F(1):
/* ignore char */
break;
default:
Expand Down
6 changes: 6 additions & 0 deletions src/ui/Keys.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,9 @@ enum : int {
KEY_ESCAPE = 0x1b,
KEY_BACKSPACE3 = 0x7f,
};

constexpr bool
IsFKey(int key) noexcept
{
return key >= KEY_F(0) && key <= KEY_F(63);
}

0 comments on commit c6ffc04

Please sign in to comment.