Skip to content

Commit

Permalink
keyboard_shortcut_manager: code cleanup and fix windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
bb1950328 committed Jan 3, 2024
1 parent befe16f commit e3d1220
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
24 changes: 6 additions & 18 deletions src/keyboard_shortcut_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace bricksim::keyboard_shortcut_manager {
}

namespace {
const uomap_t<key_t, const char*> MISC_KEY_DISPLAY_NAMES = {
const uomap_t<uint64_t, const char*> MISC_KEY_DISPLAY_NAMES = {
// NOLINT(cert-err58-cpp)
{GLFW_KEY_BACKSPACE, "Backspace"},
{GLFW_KEY_ENTER, "Enter"},
Expand Down Expand Up @@ -145,12 +145,12 @@ namespace bricksim::keyboard_shortcut_manager {
* @param keyFromGlfw for example `GLFW_KEY_Z`
* @return for example `GLFW_KEY_Y` on a machine with QWERTZ keyboard
*/
key_t translateKey(key_t keyFromGlfw) {
uint64_t translateKey(uint64_t keyFromGlfw) {
const char* keyName = glfwGetKeyName(keyFromGlfw, 0);
if (keyName == nullptr) {
return keyFromGlfw;
}
char charOnKeycap = static_cast<char>(std::tolower(static_cast<unsigned char>(keyName[0])));
const char charOnKeycap = static_cast<char>(std::tolower(static_cast<unsigned char>(keyName[0])));
if (GLFW_KEY_A <= keyFromGlfw && keyFromGlfw <= GLFW_KEY_Z) {
return charOnKeycap - 'a' + GLFW_KEY_A;
}
Expand All @@ -163,12 +163,12 @@ namespace bricksim::keyboard_shortcut_manager {
}

/**
* inverse function of translateKey(key_t)
* inverse function of translateKey(uint64_t)
* @param translatedKey
* @return
*/
key_t untranslateKey(key_t translatedKey) {
static uomap_t<key_t, key_t> keyTranslation;
uint64_t untranslateKey(uint64_t translatedKey) {
static uomap_t<uint64_t, uint64_t> keyTranslation;
if (keyTranslation.empty()) {
for (int i = GLFW_KEY_SPACE; i < GLFW_KEY_LAST; ++i) {
keyTranslation.emplace(translateKey(i), i);
Expand Down Expand Up @@ -222,18 +222,6 @@ namespace bricksim::keyboard_shortcut_manager {
}
}

/*std::vector<config::KeyboardShortcut>& getAllShortcuts() {
return config::get().keyboardShortcuts.shortcuts;
}*/

/*void replaceAllShortcuts(const std::vector<KeyboardShortcut>& newShortcuts) {
db::key_shortcuts::deleteAll();
for (const auto& shortcut: newShortcuts) {
db::key_shortcuts::saveShortcut({shortcut.action, shortcut.key, static_cast<uint8_t>(shortcut.modifiers), static_cast<uint8_t>(shortcut.event)});
}
shortcuts = newShortcuts;
}*/

void setCatchNextShortcut(bool doCatch) {
shouldCatchNextShortcut = doCatch;
}
Expand Down
2 changes: 0 additions & 2 deletions src/keyboard_shortcut_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace bricksim::keyboard_shortcut_manager {
using modifier_t = decltype(config::KeyboardShortcut::modifiers);
void initialize();
void shortcutPressed(int key, int keyAction, modifier_t modifiers, bool isCapturedByGui);
//std::vector<config::KeyboardShortcut>& getAllShortcuts();
//void replaceAllShortcuts(const std::vector<config::KeyboardShortcut>& newShortcuts);
void resetToDefault(config::KeyboardShortcuts& cfg);
const std::string& getShortcutForAction(user_actions::Action action);
std::string getDisplayName(const config::KeyboardShortcut& shortcut);
Expand Down

0 comments on commit e3d1220

Please sign in to comment.