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

feat(linux): add newest changes from mnemonic layout support-mac to mnemonic layout support-linux 🐘 #12837

Merged
merged 7 commits into from
Dec 19, 2024
60 changes: 27 additions & 33 deletions linux/mcompile/keymap/mcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ KMX_BOOL KMX_DoConvert(LPKMX_KEYBOARD kbd, KMX_BOOL bDeadkeyConversion, gint arg
/** @brief Collect the key data, translate it to kmx and append to the existing keyboard */
bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** keymap, std::vector<KMX_DeadkeyMapping>* KMX_FDeadkeys, KMX_BOOL bDeadkeyConversion); // I4353 // I4327

/** @brief return an array of [usvk, ch_out] pairs: all existing combinations of a deadkey + character for the underlying keyboard */
int KMX_GetDeadkeys(vec_dword_2D& dk_Table, KMX_WORD deadkey, KMX_WORD* outputPairs, GdkKeymap* keymap);
/** @brief return a vector of [usvk, ch_out] pairs: all existing combinations of a deadkey + character for the underlying keyboard */
int KMX_GetDeadkeys(vec_dword_2D& dk_Table, KMX_WORD deadkey, std::vector<KMX_WORD> &dk_vec, GdkKeymap* keymap);

std::vector<KMX_DeadkeyMapping> KMX_FDeadkeys; // I4353

Expand Down Expand Up @@ -94,7 +94,10 @@ std::vector<KMX_DeadkeyMapping> KMX_FDeadkeys; // I4353
}

if (KMX_DoConvert(kmxfile, bDeadkeyConversion, argc, (gchar**)argv)) { // I4552F
KMX_SaveKeyboard(kmxfile, outfile);
if(!KMX_SaveKeyboard(kmxfile, outfile)) {
KMX_LogError(L"Failed to save keyboard (%d)\n", errno);
return 3;
}
}

delete kmxfile;
Expand Down Expand Up @@ -358,9 +361,9 @@ KMX_WCHAR KMX_GetUniqueDeadkeyID(LPKMX_KEYBOARD kbd, KMX_WCHAR deadkey) {
return 0;
}

for (int i = 0; i < s_ndkids; i++) {
if (s_dkids[i].src_deadkey == deadkey) {
return s_dkids[i].dst_deadkey;
for (int xi = 0; xi < s_ndkids; xi++) {
if (s_dkids[xi].src_deadkey == deadkey) {
return s_dkids[xi].dst_deadkey;
}
}

Expand Down Expand Up @@ -399,8 +402,8 @@ KMX_WCHAR KMX_GetUniqueDeadkeyID(LPKMX_KEYBOARD kbd, KMX_WCHAR deadkey) {
* @param dk_Table a vector of all possible deadkey combinations for all Linux keyboards
*/
void KMX_ConvertDeadkey(LPKMX_KEYBOARD kbd, KMX_WORD vk_US, KMX_DWORD shift, KMX_WCHAR deadkey, vec_dword_3D& all_vector, GdkKeymap* keymap, vec_dword_2D dk_Table) {
KMX_WORD deadkeys[size_DK_array] = {0};
KMX_WORD* pdk;

std::vector<KMX_WORD> vec_deadkeys;

// Lookup the deadkey table for the deadkey in the physical keyboard
// Then for each character, go through and map it through
Expand All @@ -412,13 +415,14 @@ void KMX_ConvertDeadkey(LPKMX_KEYBOARD kbd, KMX_WORD vk_US, KMX_DWORD shift, KMX
KMX_FDeadkeys.push_back(KMX_deadkeyMapping); // dkid, vk, shift); // I4353
KMX_AddDeadkeyRule(kbd, dkid, vk_US, shift);

KMX_GetDeadkeys(dk_Table, deadkey, pdk = deadkeys, keymap); // returns array of [usvk, ch_out] pairs
KMX_GetDeadkeys(dk_Table, deadkey, vec_deadkeys, keymap); // returns vector of [usvk, ch_out] pairs

while (*pdk) {
int n=0;
while (n < (int)vec_deadkeys.size()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be

Suggested change
while (n < (int)vec_deadkeys.size()) {
while (n < (int)vec_deadkeys.size() - 2) {

since we're accessing vec_deadkeys[n+2] (and n+1)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, its the same thing since we work with a set of 3 elements each ( vec_deadkeys is always a multiple of 3 in size) and then we do n += 3; further down
vec_deadkeys.size()-2 and vec_deadkeys.size() would stop the loop after the same amount of loops

Copy link
Contributor

Choose a reason for hiding this comment

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

That is true, and it works. However, using vec_deadkeys.size() - 2 doesn't change anything in the way the current code works, but it would be a sign of defensive programming.

// Look up the ch
KMX_DWORD KeyValUnderlying = (KMX_DWORD) KMX_get_KeyValUnderlying_From_KeyValUS(all_vector, *pdk);
KMX_TranslateDeadkeyKeyboard(kbd, dkid, KeyValUnderlying, *(pdk + 1), *(pdk + 2));
pdk += 3;
KMX_DWORD KeyValUnderlying = (KMX_DWORD) KMX_get_KeyValUnderlying_From_KeyValUS(all_vector, vec_deadkeys[n]);
KMX_TranslateDeadkeyKeyboard(kbd, dkid, KeyValUnderlying, vec_deadkeys[n + 1], vec_deadkeys[n + 2]);
n += 3;
}
}

Expand Down Expand Up @@ -521,44 +525,34 @@ KMX_BOOL KMX_DoConvert(LPKMX_KEYBOARD kbd, KMX_BOOL bDeadkeyConversion, gint arg
}

/**
* @brief return an array of [usvk, ch_out] pairs: all existing combinations of a deadkey + character for the underlying keyboard
* @brief return a vector of [usvk, ch_out] pairs: all existing combinations of a deadkey + character for the underlying keyboard
* @param dk_Table shiftstate of the deadkey
* @param deadkey deadkey character
* @param[out] outputPairs pointer to array of [usvk, ch_out] pairs
* @param[out] dk_vec vector of [usvk, ch_out] pairs
* @param keymap pointer to the currently used (underlying) keyboard Layout
* @return size of array of [usvk, ch_out] pairs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* @return size of array of [usvk, ch_out] pairs
* @return size of vector of [usvk, ch_out] pairs

Although I think it's triplets, not pairs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

*/
int KMX_GetDeadkeys(vec_dword_2D& dk_Table, KMX_WORD deadkey, KMX_WORD* outputPairs, GdkKeymap* keymap) {
KMX_WORD* p = outputPairs;

int KMX_GetDeadkeys(vec_dword_2D& dk_Table, KMX_WORD deadkey, std::vector<KMX_WORD> &dk_vec, GdkKeymap* keymap) {

KMX_DWORD shift;
vec_dword_2D dk_SingleTable;
int no_dk_counter = 0;
int p_counter = 0;

query_dk_combinations_for_specific_dk(dk_Table, deadkey, dk_SingleTable);
for (int i = 0; i < (int)dk_SingleTable.size(); i++) {
KMX_WORD vk = KMX_change_keyname_to_capital(dk_SingleTable[i][1], shift, keymap);
if (vk != 0) {

if( p_counter < size_DK_array - 3) {
dk_vec.push_back(vk);
dk_vec.push_back(shift);
dk_vec.push_back(dk_SingleTable[i][2]);

*p++ = vk;
*p++ = shift;
*p++ = dk_SingleTable[i][2];

p_counter = p_counter+3;

} else {
no_dk_counter++;
}
} else {
KMX_LogError(L"Warning: complex deadkey not supported.");
}
}
if(p_counter >= size_DK_array -3)
KMX_LogError(L"Warning: %i deadkeys have not been processed.", no_dk_counter);
*p = 0;
return (p - outputPairs);

return dk_vec.size();
}

/**
Expand Down
Loading