Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenBangla Keyboard should respect primary OS keyboard #39

Merged
merged 11 commits into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/openbangla.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<license>GPL 3</license>
<author>See AboutBox</author>
<icon>@PROJECT_DATADIR@/icons/OpenBangla-Keyboard.png</icon>
<layout>us</layout>
<layout>default</layout>
<longname>OpenBangla Keyboard</longname>
<description>OpenBangla Keyboard IME for iBus</description>
<rank>0</rank>
Expand Down
2 changes: 1 addition & 1 deletion src/engine/ibus/ibus_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void ibus_start_setup(bool ibus) {
"GPL 3",
"See About Dialog",
PKGDATADIR "/icons/OpenBangla-Keyboard.png",
"us"
"default"
));
ibus_bus_register_component(bus, component);

Expand Down
48 changes: 24 additions & 24 deletions src/engine/ibus/ibus_keycode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ std::map<guint,int> key;

void initKeycode() {
// Begin Alphanumeric Zone
key[IBUS_KEY_grave] = VC_BACKQUOTE;
key[IBUS_KEY_asciitilde] = VC_BACKQUOTE;
key[IBUS_KEY_grave] = VC_GRAVE;
key[IBUS_KEY_asciitilde] = VC_TILDE;

key[IBUS_KEY_0] = VC_0;
key[IBUS_KEY_1] = VC_1;
Expand All @@ -46,22 +46,22 @@ void initKeycode() {
key[IBUS_KEY_8] = VC_8;
key[IBUS_KEY_9] = VC_9;

key[IBUS_KEY_parenright] = VC_0;
key[IBUS_KEY_exclam] = VC_1;
key[IBUS_KEY_at] = VC_2;
key[IBUS_KEY_numbersign] = VC_3;
key[IBUS_KEY_dollar] = VC_4;
key[IBUS_KEY_percent] = VC_5;
key[IBUS_KEY_asciicircum] = VC_6;
key[IBUS_KEY_ampersand] = VC_7;
key[IBUS_KEY_asterisk] = VC_8;
key[IBUS_KEY_parenleft] = VC_9;
key[IBUS_KEY_parenright] = VC_PAREN_RIGHT;
key[IBUS_KEY_exclam] = VC_EXCLAM;
key[IBUS_KEY_at] = VC_AT;
key[IBUS_KEY_numbersign] = VC_HASH;
key[IBUS_KEY_dollar] = VC_DOLLAR;
key[IBUS_KEY_percent] = VC_PERCENT;
key[IBUS_KEY_asciicircum] = VC_CIRCUM;
key[IBUS_KEY_ampersand] = VC_AMPERSAND;
key[IBUS_KEY_asterisk] = VC_ASTERISK;
key[IBUS_KEY_parenleft] = VC_PAREN_LEFT;

key[IBUS_KEY_minus] = VC_MINUS;
key[IBUS_KEY_underscore] = VC_MINUS;
key[IBUS_KEY_underscore] = VC_UNDERSCORE;

key[IBUS_KEY_equal] = VC_EQUALS;
key[IBUS_KEY_plus] = VC_EQUALS;
key[IBUS_KEY_plus] = VC_PLUS;

key[IBUS_KEY_BackSpace] = VC_BACKSPACE;

Expand Down Expand Up @@ -121,28 +121,28 @@ void initKeycode() {
key[IBUS_KEY_y] = VC_Y;
key[IBUS_KEY_z] = VC_Z;

key[IBUS_KEY_bracketleft] = VC_OPEN_BRACKET;
key[IBUS_KEY_braceleft] = VC_OPEN_BRACKET;
key[IBUS_KEY_bracketleft] = VC_BRACKET_LEFT;
key[IBUS_KEY_braceleft] = VC_BRACE_LEFT;

key[IBUS_KEY_bracketright] = VC_CLOSE_BRACKET;
key[IBUS_KEY_braceright] = VC_CLOSE_BRACKET;
key[IBUS_KEY_bracketright] = VC_BRACKET_RIGHT;
key[IBUS_KEY_braceright] = VC_BRACE_RIGHT;

key[IBUS_KEY_backslash] = VC_BACK_SLASH;
key[IBUS_KEY_bar] = VC_BACK_SLASH;
key[IBUS_KEY_bar] = VC_BAR;

key[IBUS_KEY_slash] = VC_SLASH;
key[IBUS_KEY_question] = VC_SLASH;
key[IBUS_KEY_question] = VC_QUESTION;

key[IBUS_KEY_semicolon] = VC_SEMICOLON;
key[IBUS_KEY_colon] = VC_SEMICOLON;
key[IBUS_KEY_colon] = VC_COLON;

key[IBUS_KEY_comma] = VC_COMMA;
key[IBUS_KEY_less] = VC_COMMA;
key[IBUS_KEY_less] = VC_LESS;

key[IBUS_KEY_period] = VC_PERIOD;
key[IBUS_KEY_greater] = VC_PERIOD;
key[IBUS_KEY_greater] = VC_GREATER;

key[IBUS_KEY_apostrophe] = VC_QUOTE;
key[IBUS_KEY_apostrophe] = VC_APOSTROPHE;
key[IBUS_KEY_quotedbl] = VC_QUOTE;

key[IBUS_KEY_Return] = VC_ENTER;
Expand Down
209 changes: 142 additions & 67 deletions src/engine/libengine/FixedLayoutParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,10 @@ void FixedLayoutParser::setLayout(QJsonObject l) {
layout = l;
}

QString FixedLayoutParser::getCharForKey(int keyNum, bool shift, bool altgr, bool shiftaltgr) {
QString FixedLayoutParser::processAlphabetKey(int keyNum, bool shift, bool altgr, bool shiftaltgr) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just rename this to getCharForKey and be with it? 🤔

Copy link
Member Author

@mominul mominul Jun 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am also not very satisfied with this implementation. I had to do this because we now only check shift or other modifiers when the key is an alphabet key. But when the key is a metacharacter or numeric we need to handle them differently, if you look them closely.

Thanks!

QString key;
switch(keyNum) {
// Begin Alphanumeric Zone
case VC_BACKQUOTE:
key = "BackQuote";
break;

case VC_1:
key = "1";
break;
case VC_2:
key = "2";
break;
case VC_3:
key = "3";
break;
case VC_4:
key = "4";
break;
case VC_5:
key = "5";
break;
case VC_6:
key = "6";
break;
case VC_7:
key = "7";
break;
case VC_8:
key = "8";
break;
case VC_9:
key = "9";
break;
case VC_0:
key = "0";
break;
case VC_MINUS:
key = "Minus";
break;
case VC_EQUALS:
key = "Equals";
break;

// Begin Alphabet Zone
case VC_A:
key = "A";
break;
Expand Down Expand Up @@ -148,31 +107,158 @@ QString FixedLayoutParser::getCharForKey(int keyNum, bool shift, bool altgr, boo
key = "Z";
break;

case VC_OPEN_BRACKET:
key = "OpenBracket";
default:
return QString("");
}

QString mod;
if(!shift && !altgr && !shiftaltgr) {
mod = "Normal";
} else if(shift) {
mod = "Shift";
} else if(altgr) {
mod = "AltGr";
} else if(shiftaltgr) {
mod = "ShiftAltGr";
}

return QString("Key_%1_%2").arg(key).arg(mod);
}

QString FixedLayoutParser::getCharForKey(int keyNum, bool shift, bool altgr, bool shiftaltgr) {
QString result = processAlphabetKey(keyNum, shift, altgr, shiftaltgr);
if(result != "") {
return layout.value(result).toString();
}

QString key;
switch(keyNum) {
// Begin Alphanumeric Zone
case VC_GRAVE:
key = "BackQuote_Normal";
break;
case VC_CLOSE_BRACKET:
key = "CloseBracket";
case VC_TILDE:
key = "BackQuote_Shift";
break;
case VC_BACK_SLASH:
key = "BlackSlash";

case VC_1:
key = "1_Normal";
break;
case VC_EXCLAM:
key = "1_Shift";
break;
case VC_2:
key = "2_Normal";
break;
case VC_AT:
key = "2_Shift";
break;
case VC_3:
key = "3_Normal";
break;
case VC_HASH:
key = "3_Shift";
break;
case VC_4:
key = "4_Normal";
break;
case VC_DOLLAR:
key = "4_Shift";
break;
case VC_5:
key = "5_Normal";
break;
case VC_PERCENT:
key = "5_Shift";
break;
case VC_6:
key = "6_Normal";
break;
case VC_CIRCUM:
key = "6_Shift";
break;
case VC_7:
key = "7_Normal";
break;
case VC_AMPERSAND:
key = "7_Shift";
break;
case VC_8:
key = "8_Normal";
break;
case VC_ASTERISK:
key = "8_Shift";
break;
case VC_9:
key = "9_Normal";
break;
case VC_PAREN_LEFT:
key = "9_Shift";
break;
case VC_0:
key = "0_Normal";
break;
case VC_PAREN_RIGHT:
key = "0_Shift";
case VC_MINUS:
key = "Minus_Normal";
break;
case VC_UNDERSCORE:
key = "Minus_Shift";
case VC_EQUALS:
key = "Equals_Normal";
break;
case VC_PLUS:
key = "Equals_Shift";
break;

case VC_BRACKET_LEFT:
key = "OpenBracket_Normal";
break;
case VC_BRACE_LEFT:
key = "OpenBracket_Shift";
break;
case VC_BRACKET_RIGHT:
key = "CloseBracket_Normal";
break;
case VC_BRACE_RIGHT:
key = "CloseBracket_Shift";
break;
case VC_BACK_SLASH:
key = "BlackSlash_Normal";
break;
case VC_BAR:
key = "BlackSlash_Shift";
break;
case VC_SEMICOLON:
key = "Semicolon";
key = "Semicolon_Normal";
break;
case VC_COLON:
key = "Semicolon_Shift";
break;
case VC_APOSTROPHE:
key = "Quote_Normal";
break;
case VC_QUOTE:
key = "Quote";
case VC_QUOTE:
key = "Quote_Shift";
break;

case VC_COMMA:
key = "Comma";
key = "Comma_Normal";
break;
case VC_LESS:
key = "Comma_Shift";
break;
case VC_PERIOD:
key = "Period";
key = "Period_Normal";
break;
case VC_GREATER:
key = "Period_Shift";
case VC_SLASH:
key = "Slash";
key = "Slash_Normal";
break;
case VC_QUESTION:
key = "Slash_Shift";
break;
// End Alphanumeric Zone

Expand Down Expand Up @@ -230,20 +316,9 @@ QString FixedLayoutParser::getCharForKey(int keyNum, bool shift, bool altgr, boo
return QString("");
}

QString mod;
if(!shift && !altgr && !shiftaltgr) {
mod = "Normal";
} else if(shift) {
mod = "Shift";
} else if(altgr) {
mod = "AltGr";
} else if(shiftaltgr) {
mod = "ShiftAltGr";
}

QString keyName;
if(!key.contains("Num")) {
keyName = QString("Key_%1_%2").arg(key).arg(mod);
keyName = QString("Key_%1").arg(key);
} else {
if(gSettings->getNumberPadFixed()) {
keyName = key;
Expand Down
1 change: 1 addition & 0 deletions src/engine/libengine/FixedLayoutParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class FixedLayoutParser {
QJsonObject layout;
public:
void setLayout(QJsonObject l);
QString processAlphabetKey(int keyNum, bool shift, bool altgr, bool shiftaltgr);
QString getCharForKey(int keyNum, bool shift, bool altgr, bool shiftaltgr);
};

Expand Down
Loading