Skip to content

Commit

Permalink
French keyboard added #203
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Jan 4, 2025
1 parent f9adf14 commit 8563460
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
3 changes: 3 additions & 0 deletions app/include/keyboard_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <borealis.hpp>
#include <map>

enum KeyboardKeys
{
Expand All @@ -25,6 +26,7 @@ enum KeyboardKeys
struct KeyboardLocale {
std::string name;
std::string localization[_VK_KEY_MAX][2];
std::map<KeyboardKeys, KeyboardKeys> keyMapper;
};

struct KeyboardState {
Expand Down Expand Up @@ -56,6 +58,7 @@ class ButtonView : public brls::Box {
bool focusJustGained = false;

void applyTitle();
KeyboardLocale getCurrentLocale();
KeyboardView* keyboardView;
};

Expand Down
29 changes: 20 additions & 9 deletions app/src/keyboard_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,39 @@ void ButtonView::onFocusLost() {
}
}

void ButtonView::applyTitle() {
if (dummy)
return;

bool shifted = keysState[VK_RSHIFT];
KeyboardLocale ButtonView::getCurrentLocale() {
int selectedLang = keyboardView->keyboardLangLock != -1
? keyboardView->keyboardLangLock
: Settings::instance().get_keyboard_locale();
if (KeyboardView::getLocales().size() <= selectedLang) {
Settings::instance().set_keyboard_locale(0);
selectedLang = 0;
}
charLabel->setText(
KeyboardView::getLocales()[selectedLang].localization[key][shifted]);

return KeyboardView::getLocales()[selectedLang];
}

void ButtonView::applyTitle() {
if (dummy)
return;

bool shifted = keysState[VK_RSHIFT];
auto selectedLang = getCurrentLocale();
charLabel->setText(selectedLang.localization[key][shifted]);
}

void ButtonView::setKey(KeyboardKeys key) {
auto selectedLang = getCurrentLocale();
KeyboardKeys mappedKey = key;
if (selectedLang.keyMapper.contains(key)) {
mappedKey = selectedLang.keyMapper[key];
}

this->dummy = false;
this->key = key;
this->key = mappedKey;
this->applyTitle();

if (keysState[key])
if (keysState[mappedKey])
this->playClickAnimation(false, false, true);
}

Expand Down
18 changes: 18 additions & 0 deletions app/src/keyboards/keyboard_locales.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,23 @@ void KeyboardView::createLocales() {
}
});

locales.push_back(KeyboardLocale{
.name = "French",
.localization = {
{"Remove", "Remove"}, {"Esc", "Esc"}, {"à", "0"}, {"&", "1"}, {"é", "2"}, {"\"", "3"}, {"'", "4"}, {"(", "5"}, {"-", "6"},
{"è", "7"}, {"_", "8"}, {"ç", "9"}, {"a", "A"}, {"b", "B"}, {"c", "C"}, {"d", "D"}, {"e", "E"}, {"f", "F"}, {"g", "G"},
{"h", "H"}, {"i", "I"}, {"j", "J"}, {"k", "K"}, {"l", "L"}, {"m", "M"}, {"n", "N"}, {"o", "O"}, {"p", "P"}, {"q", "Q"},
{"r", "R"}, {"s", "S"}, {"t", "T"}, {"u", "U"}, {"v", "V"}, {"w", "W"}, {"x", "X"}, {"y", "Y"}, {"z", "Z"}, {"Return", "Return"}, {"Space", "Space"},
{"Ctrl", "Ctrl"}, {"Alt", "Alt"}, {"Shift", "Shift"}, {"Win", "Win"}, {",", "?"}, {";", "."}, {"F1", "F1"}, {"F2", "F2"}, {"F3", "F3"}, {"F4", "F4"},
{"F5", "F5"}, {"F6", "F6"}, {"F7", "F7"}, {"F8", "F8"}, {"F9", "F9"}, {"F10", "F10"}, {"F11", "F11"}, {"F12", "F12"}, {"Tab", "Tab"}, {"Delete", "Delete"},
{"!", "§"}, {":", "/"}, {"<", ">"}, {"ù", "%"}, {"*", "μ"}, {"=", "+"}, {")", "°"}, {"^", "¨"}, {"$", "£"}, {"\u2193", "\u2193"},
{"\u2190", "\u2190"}, {"\u2192", "\u2192"}, {"\u2191", "\u2191"}, {"CapsLock", "CapsLock"},
},
.keyMapper = {{VK_OEM_MINUS, VK_OEM_7}, {VK_OEM_PLUS, VK_OEM_6},
{VK_KEY_Q, VK_KEY_A}, {VK_KEY_W, VK_KEY_Z}, {VK_OEM_4, VK_OEM_MINUS}, {VK_OEM_6, VK_OEM_PLUS},
{VK_KEY_A, VK_KEY_Q}, {VK_OEM_1, VK_KEY_M}, {VK_OEM_7, VK_OEM_4},
{VK_KEY_Z, VK_KEY_W}, {VK_KEY_M, VK_OEM_PERIOD}, {VK_OEM_PERIOD, VK_OEM_2}, {VK_OEM_2, VK_OEM_1}}
});

// TODO: - Add more languages
}

0 comments on commit 8563460

Please sign in to comment.