feat(linux): work on 2nd round of comments on PR 11816

This commit is contained in:
Sabine 2024-06-20 17:44:21 +02:00
parent f22088c2d9
commit 404d888fde
6 changed files with 175 additions and 190 deletions

View file

@ -9,7 +9,7 @@ AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: trues
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never

View file

@ -621,8 +621,11 @@ int KMX_get_KeyVal_From_KeyCode(GdkKeymap *keymap, guint keycode, ShiftState ss,
if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count))
return 0;
if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(ss), count, keycode)))
if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(ss), count, keycode))){
g_free(keyvals);
g_free(maps);
return 0;
}
//BASE (shiftstate: 0)
if (( ss == Base ) && ( caps == 0 )) {
@ -710,8 +713,11 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap *keymap, gui
if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count))
return 0;
if (!(ensureValidInputForKeyboardTranslation( shift_state_pos, count, keycode)))
if (!(ensureValidInputForKeyboardTranslation( shift_state_pos, count, keycode))){
g_free(keyvals);
g_free(maps);
return 0;
}
kVal = (KMX_DWORD) KMX_get_KeyVal_From_KeyCode(keymap, keycode, (ShiftState) shift_state_pos, 0);
@ -732,8 +738,11 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap *keymap, UIN
if (!gdk_keymap_get_entries_for_keycode(keymap, kc_underlying, &maps, &keyvals, &count))
return 0;
if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(vk_ShiftState), count, kc_underlying)))
if (!(ensureValidInputForKeyboardTranslation( map_VKShiftState_to_LinModifier(vk_ShiftState), count, kc_underlying))){
g_free(keyvals);
g_free(maps);
return 0;
}
KMX_DWORD keyV = KMX_get_KeyVal_From_KeyCode(keymap, kc_underlying, ShiftState(map_VKShiftState_to_LinModifier(vk_ShiftState)), 0);

View file

@ -35,8 +35,7 @@ const int KMX_ShiftStateMap[] = {
ISVIRTUALKEY | RALTFLAG,
ISVIRTUALKEY | RALTFLAG | K_SHIFTFLAG,
0,
0
};
0};
DeadKey::DeadKey(KMX_WCHAR deadCharacter) {
this->m_deadchar = deadCharacter;
@ -66,6 +65,9 @@ int KMX_ToUnicodeEx(guint keycode, PKMX_WCHAR pwszBuff, int shift_state_pos, int
guint* keyvals;
gint count;
if (u16len(pwszBuff) < 1)
return 0;
if (!gdk_keymap_get_entries_for_keycode(keymap, keycode, &maps, &keyvals, &count))
return 0;
@ -76,10 +78,10 @@ int KMX_ToUnicodeEx(guint keycode, PKMX_WCHAR pwszBuff, int shift_state_pos, int
std::u16string str = convert_DeadkeyValues_To_U16str(keyVal);
pwszBuff[0] = *(PKMX_WCHAR)str.c_str();
g_free(keyvals);
g_free(maps);
if ((keyVal >= deadkey_min) && (keyVal <= deadkey_max)) // deadkeys
return -1;
else if (gdk_keyval_to_unicode(keyVal) == 0) // NO UNICODE
@ -88,7 +90,7 @@ int KMX_ToUnicodeEx(guint keycode, PKMX_WCHAR pwszBuff, int shift_state_pos, int
return 1;
}
int KMX_DeadKeyMap(int index, std::vector<DeadKey *> *deadkeys, int deadkeyBase, std::vector<KMX_DeadkeyMapping> *deadkeyMappings) { // I4327 // I4353
KMX_WCHAR KMX_DeadKeyMap( int index, std::vector<DeadKey*>* deadkeys, int deadkeyBase, std::vector<KMX_DeadkeyMapping>* deadkeyMappings) { // I4327 // I4353
for (size_t i = 0; i < deadkeyMappings->size(); i++) {
if ((*deadkeyMappings)[i].deadkey == index) {
return (*deadkeyMappings)[i].dkid;
@ -97,7 +99,7 @@ int KMX_DeadKeyMap(int index, std::vector<DeadKey *> *deadkeys, int deadkeyBase,
for (size_t i = 0; i < deadkeys->size(); i++) {
if ((*deadkeys)[i]->KMX_DeadCharacter() == index) {
return deadkeyBase + i;
return (KMX_WCHAR) (deadkeyBase + i);
}
}
return 0xFFFF;
@ -111,7 +113,6 @@ private:
std::u16string m_rgss[10][2];
public:
KMX_VirtualKey(UINT scanCode) {
this->m_vk = KMX_get_VKUS_From_KeyCodeUnderlying(scanCode);
this->m_sc = scanCode;
@ -141,45 +142,29 @@ public:
std::u16string stCaps = this->KMX_GetShiftState(Base, true);
std::u16string stShiftCaps = this->KMX_GetShiftState(Shft, true);
return (
((stCaps.size() > 0) &&
(stBase.compare(stCaps) != 0) &&
(stShift.compare(stCaps) != 0)) ||
((stShiftCaps.size() > 0) &&
(stBase.compare(stShiftCaps) != 0) &&
(stShift.compare(stShiftCaps) != 0)));
((stCaps.size() > 0) && (stBase.compare(stCaps) != 0) && (stShift.compare(stCaps) != 0)) ||
((stShiftCaps.size() > 0) && (stBase.compare(stShiftCaps) != 0) && (stShift.compare(stShiftCaps) != 0)));
}
bool KMX_IsCapsEqualToShift() {
std::u16string stBase = this->KMX_GetShiftState(Base, false);
std::u16string stShift = this->KMX_GetShiftState(Shft, false);
std::u16string stCaps = this->KMX_GetShiftState(Base, true);
return (
(stBase.size() > 0) &&
(stShift.size() > 0) &&
(stBase.compare(stShift) != 0) &&
(stShift.compare(stCaps) == 0));
return ((stBase.size() > 0) && (stShift.size() > 0) && (stBase.compare(stShift) != 0) && (stShift.compare(stCaps) == 0));
}
bool KMX_IsAltGrCapsEqualToAltGrShift() {
std::u16string stBase = this->KMX_GetShiftState(MenuCtrl, false);
std::u16string stShift = this->KMX_GetShiftState(ShftMenuCtrl, false);
std::u16string stCaps = this->KMX_GetShiftState(MenuCtrl, true);
return (
(stBase.size() > 0) &&
(stShift.size() > 0) &&
(stBase.compare(stShift) != 0) &&
(stShift.compare(stCaps) == 0));
return ((stBase.size() > 0) && (stShift.size() > 0) && (stBase.compare(stShift) != 0) && (stShift.compare(stCaps) == 0));
}
bool KMX_IsXxxxGrCapsEqualToXxxxShift() {
std::u16string stBase = this->KMX_GetShiftState(Xxxx, false);
std::u16string stShift = this->KMX_GetShiftState(ShftXxxx, false);
std::u16string stCaps = this->KMX_GetShiftState(Xxxx, true);
return (
(stBase.size() > 0) &&
(stShift.size() > 0) &&
(stBase.compare(stShift) != 0) &&
(stShift.compare(stCaps) == 0));
return ((stBase.size() > 0) && (stShift.size() > 0) && (stBase.compare(stShift) != 0) && (stShift.compare(stCaps) == 0));
}
bool KMX_IsEmpty() {
@ -211,7 +196,6 @@ public:
continue;
}
for (int caps = 0; caps <= 1; caps++) {
std::u16string st = this->KMX_GetShiftState((ShiftState)ss, (caps == 1));
if (st.size() == 0) {
@ -226,7 +210,8 @@ public:
isvalid = false;
wprintf(L"invalid for: %i\n", st[ich]);
break; }
break;
}
}
if (isvalid) {
nkeys++;
@ -239,11 +224,8 @@ public:
bool KMX_LayoutRow(int MaxShiftState, LPKMX_KEY key, std::vector<DeadKey*>* deadkeys, int deadkeyBase, BOOL bDeadkeyConversion, vec_dword_3D& all_vector, GdkKeymap* keymap) { // I4552
// Get the CAPSLOCK value
int capslock =
(this->KMX_IsCapsEqualToShift() ? 1 : 0) |
(this->KMX_IsSGCAPS() ? 2 : 0) |
(this->KMX_IsAltGrCapsEqualToAltGrShift() ? 4 : 0) |
(this->KMX_IsXxxxGrCapsEqualToXxxxShift() ? 8 : 0);
int capslock = (this->KMX_IsCapsEqualToShift() ? 1 : 0) | (this->KMX_IsSGCAPS() ? 2 : 0) |
(this->KMX_IsAltGrCapsEqualToAltGrShift() ? 4 : 0) | (this->KMX_IsXxxxGrCapsEqualToXxxxShift() ? 8 : 0);
for (int ss = 0; ss <= MaxShiftState; ss++) {
if (ss == Menu || ss == ShftMenu) {
@ -257,8 +239,7 @@ public:
if (st.size() == 0) {
// No character assigned here
}
else if (this->m_rgfDeadKey[(int)ss][caps]) {
} else if (this->m_rgfDeadKey[(int)ss][caps]) {
// It's a dead key, append an @ sign.
key->dpContext = new KMX_WCHAR[1];
*key->dpContext = 0;
@ -273,23 +254,21 @@ public:
*p++ = st[0];
*p = 0;
} else {
p = key->dpOutput = new KMX_WCHAR[4];
*p++ = UC_SENTINEL;
*p++ = CODE_DEADKEY;
// can convert since KMX_DeadKeyMap returns a small positive number
*p++ = (KMX_WCHAR) KMX_DeadKeyMap(st[0], deadkeys, deadkeyBase, &KMX_FDeadkeys); // I4353
*p++ = KMX_DeadKeyMap(st[0], deadkeys, deadkeyBase, &KMX_FDeadkeys); // I4353
*p = 0;
}
key++;
}
else {
} else {
bool isvalid = true;
for (size_t ich = 0; ich < st.size(); ich++) {
if (st[ich] < 0x20 || st[ich] == 0x7F) {
isvalid = false;
wprintf(L"invalid 16 for: %i\n", st[ich]);
break; }
break;
}
}
if (isvalid) {
// this is different to mcompile windows !!!!
@ -346,7 +325,6 @@ public:
bool KMX_IsControlChar(char16_t ch) {
return (ch < 0x0020) || (ch >= 0x007F && ch <= 0x009F);
}
};
int KMX_GetMaxDeadkeyIndex(KMX_WCHAR* p) {
@ -364,7 +342,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke
std::vector<KMX_VirtualKey*> rgKey; //= new VirtualKey[256];
std::vector<DeadKey*> alDead;
std::vector<DeadKey*> alDead_cpl = create_deadkeys_by_basechar();
std::vector<DeadKey*> alDead_byBasechar = create_deadkeys_by_basechar();
rgKey.resize(256);
@ -395,7 +373,6 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke
// in this part we skip shiftstates 4, 5, 8, 9
for (UINT iKey = 0; iKey < rgKey.size(); iKey++) {
if (rgKey[iKey] != NULL) {
KMX_WCHAR sbBuffer[256]; // Scratchpad we use many places
@ -413,20 +390,18 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke
if (rc > 0) {
if (*sbBuffer == 0) {
rgKey[iKey]->KMX_SetShiftState(ss, u"", false, (caps)); // different to windows since behavior on Linux is different
}
else {
} else {
if ((ss == Ctrl || ss == ShftCtrl)) {
continue;
}
sbBuffer[rc] = 0;
rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, false, (caps)); // different to windows since behavior on Linux is different
}
}
else if(rc < 0) {
} else if (rc < 0) {
sbBuffer[2] = 0;
rgKey[iKey]->KMX_SetShiftState(ss, sbBuffer, true, (caps)); // different to windows since behavior on Linux is different
refine_alDead(sbBuffer[0], alDead, alDead_cpl);
refine_alDead(sbBuffer[0], alDead, alDead_byBasechar);
}
}
}
@ -484,8 +459,6 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke
nDeadkey++; // ensure a 1-based index above the max deadkey value already in the keyboard
//
// Fill in the new rules
//
@ -596,8 +569,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap **ke
KMX_WCHAR* p = kkp->dpContext = new KMX_WCHAR[8];
*p++ = UC_SENTINEL;
*p++ = CODE_DEADKEY;
// can convert since KMX_DeadKeyMap returns a small positive number
*p++ = (KMX_WCHAR) KMX_DeadKeyMap(dk->KMX_DeadCharacter(), &alDead, nDeadkey, FDeadkeys); // I4353
*p++ = KMX_DeadKeyMap(dk->KMX_DeadCharacter(), &alDead, nDeadkey, FDeadkeys); // I4353
// *p++ = nDeadkey+i;
*p++ = UC_SENTINEL;
*p++ = CODE_ANY;

View file

@ -3,7 +3,7 @@
#define MC_KMXFILE_H
#include "km_types.h"
#include <../../../../common/include/kmx_file.h>
#include <kmx_file.h>
#include "filesystem.h"
#include "mcompile.h"

View file

@ -23,7 +23,7 @@
08 Apr 2015 - mcdurdin - I4651 - V9.0 - Mnemonic layout recompiler maps AltGr+VK_BKSLASH rather than VK_OEM_102
*/
//
// m-to-p.cpp : Defines the entry point for the console application.
// Defines the entry point for the console application.
//
// Note: this program deliberately leaks memory as it has a very short life cycle and managing the memory allocations
// for the subcomponents of the compiled keyboard is an unnecessary optimisation. Just so you know.
@ -499,4 +499,3 @@ void KMX_LogError(const wchar_t* fmt, ...) {
while(fmtbuf[j] != *end);
putwchar(*nl);
}

View file

@ -19,9 +19,14 @@ cpp_files = files(
'mc_import_rules.cpp',
'u16.cpp',)
comon_include_dir = [
include_directories('../../../../common/include'),
]
mcompile = executable(
'mcompile',
sources: [cpp_files],
dependencies: deps
dependencies: deps,
include_directories : comon_include_dir
)