Skip to content

Commit

Permalink
chore(linux): remove mcompile-specific km_types.h
Browse files Browse the repository at this point in the history
  • Loading branch information
SabineSIL committed Aug 13, 2024
1 parent dc97370 commit 58c1e50
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 156 deletions.
2 changes: 1 addition & 1 deletion linux/mcompile/keymap/keymap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, gui
* 0xFFFE in case a deadkey is out of range
* the keyval obtained from Keycode and shiftstate and caps;
*/
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, UINT shiftState, PKMX_WCHAR deadkey) {
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, KMX_DWORD shiftState, PKMX_WCHAR deadkey) {
GdkKeymapKey* maps;
guint* keyvals;
gint count;
Expand Down
40 changes: 37 additions & 3 deletions linux/mcompile/keymap/keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,40 @@ enum ShiftState {
ShftXxxx = Shft | Xxxx, // 9
};

#define VK_SPACE 0x20
#define VK_COLON 0xBA
#define VK_EQUAL 0xBB
#define VK_COMMA 0xBC
#define VK_HYPHEN 0xBD
#define VK_PERIOD 0xBE
#define VK_SLASH 0xBF
#define VK_ACCENT 0xC0
#define VK_LBRKT 0xDB
#define VK_BKSLASH 0xDC
#define VK_RBRKT 0xDD
#define VK_QUOTE 0xDE
#define VK_xDF 0xDF
#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd.

#define VK_DIVIDE 0x6F
#define VK_CANCEL 3
#define VK_DECIMAL 0x2E

#define VK_OEM_CLEAR 0xFE
#define VK_LSHIFT 0xA0
#define VK_RSHIFT 0xA1
#define VK_LCONTROL 0xA2
#define VK_RCONTROL 0xA3
#define VK_LMENU 0xA4
#define VK_RMENU 0xA5

#define VK_SHIFT 0x10
#define VK_CONTROL 0x11
#define VK_MENU 0x12
#define VK_PAUSE 0x13
#define VK_CAPITAL 0x14


// Map of all US English virtual key codes that we can translate
const KMX_DWORD KMX_VKMap[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
Expand Down Expand Up @@ -108,7 +142,7 @@ int append_underlying_ToVector(vec_dword_3D& all_vector, GdkKeymap* keymap);
/** @brief create a pointer to pointer of the current keymap for later use */
bool InitializeGDK(GdkKeymap** keymap, int argc, gchar* argv[]);

const UINT USVirtualKeyToScanCode[256] = {
const KMX_DWORD USVirtualKeyToScanCode[256] = {
0x00, // L"K_?00", // &H0
0x00, // L"K_LBUTTON", // &H1
0x00, // L"K_RBUTTON", // &H2
Expand Down Expand Up @@ -376,7 +410,7 @@ const UINT USVirtualKeyToScanCode[256] = {
0x00 // L"K_?FF" // &HFF
};

const UINT ScanCodeToUSVirtualKey[128] = {
const KMX_DWORD ScanCodeToUSVirtualKey[128] = {
0x01, // 0x00 => K_LBUTTON
0x1b, // 0x01 => K_ESC
0x31, // 0x02 => K_1
Expand Down Expand Up @@ -520,7 +554,7 @@ KMX_DWORD KMX_get_KeyVal_From_KeyCode(GdkKeymap* keymap, guint keycode, ShiftSta
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, int shiftState);

/** @brief return the keyvalue for a given Keycode and shiftstate of the currently used (underlying) keyboard layout. */
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, UINT shiftState, PKMX_WCHAR deadkey);
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyCodeUnderlying(GdkKeymap* keymap, guint keycode, KMX_DWORD shiftState, PKMX_WCHAR deadkey);

/** @brief return the keyvalue of a key of the the currently used (underlying) keyboard for a given keyvalue of the US keyboard */
KMX_DWORD KMX_get_KeyValUnderlying_From_KeyValUS(vec_dword_3D& all_vector, KMX_DWORD kv_us);
Expand Down
111 changes: 0 additions & 111 deletions linux/mcompile/keymap/km_types.h

This file was deleted.

46 changes: 23 additions & 23 deletions linux/mcompile/keymap/mc_import_rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ KMX_WCHAR KMX_DeadKeyMap(int index, std::vector<DeadKey*>* deadkeys, int deadkey
*/
class KMX_VirtualKey {
private:
UINT m_vk;
UINT m_sc;
KMX_DWORD m_vk;
KMX_DWORD m_sc;
bool m_rgfDeadKey[10][2];
std::u16string m_rgss[10][2];

public:
KMX_VirtualKey(UINT scanCode) {
KMX_VirtualKey(KMX_DWORD scanCode) {
this->m_vk = KMX_get_VKUS_From_KeyCodeUnderlying(scanCode);
this->m_sc = scanCode;
memset(this->m_rgfDeadKey, 0, sizeof(this->m_rgfDeadKey));
Expand All @@ -156,24 +156,24 @@ class KMX_VirtualKey {
/**
* @brief return member variable virtual key
*/
UINT VK() {
KMX_DWORD VK() {
return this->m_vk;
}

/**
* @brief return member variable scancode
*/
UINT SC() {
KMX_DWORD SC() {
return this->m_sc;
}

std::u16string KMX_GetShiftState(ShiftState shiftState, bool capsLock) {
return this->m_rgss[(UINT)shiftState][(capsLock ? 1 : 0)];
return this->m_rgss[(KMX_DWORD)shiftState][(capsLock ? 1 : 0)];
}

void KMX_SetShiftState(ShiftState shiftState, std::u16string value, bool isDeadKey, bool capsLock) {
this->m_rgfDeadKey[(UINT)shiftState][(capsLock ? 1 : 0)] = isDeadKey;
this->m_rgss[(UINT)shiftState][(capsLock ? 1 : 0)] = value;
this->m_rgfDeadKey[(KMX_DWORD)shiftState][(capsLock ? 1 : 0)] = isDeadKey;
this->m_rgss[(KMX_DWORD)shiftState][(capsLock ? 1 : 0)] = value;
}

bool KMX_IsSGCAPS() {
Expand Down Expand Up @@ -240,7 +240,7 @@ class KMX_VirtualKey {
return (this->m_vk >= 0x20 && this->m_vk <= 0x5F) || (this->m_vk >= 0x88);
}

UINT KMX_GetShiftStateValue(int capslock, int caps, ShiftState ss) {
KMX_DWORD KMX_GetShiftStateValue(int capslock, int caps, ShiftState ss) {
return KMX_ShiftStateMap[(int)ss] | (capslock ? (caps ? CAPITALFLAG : NOTCAPITALFLAG) : 0);
}

Expand Down Expand Up @@ -282,7 +282,7 @@ class KMX_VirtualKey {
return nkeys;
}

bool KMX_LayoutRow(int MaxShiftState, LPKMX_KEY key, std::vector<DeadKey*>* deadkeys, int deadkeyBase, BOOL bDeadkeyConversion, vec_dword_3D& all_vector, GdkKeymap* keymap) { // I4552
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) |
Expand Down Expand Up @@ -372,19 +372,19 @@ class KMX_VirtualKey {
class KMX_Loader {
private:
KMX_BYTE lpKeyStateNull[256];
UINT m_XxxxVk;
KMX_DWORD m_XxxxVk;

public:
KMX_Loader() {
m_XxxxVk = 0;
memset(lpKeyStateNull, 0, sizeof(lpKeyStateNull));
}

UINT Get_XxxxVk() {
KMX_DWORD Get_XxxxVk() {
return m_XxxxVk;
}

void Set_XxxxVk(UINT value) {
void Set_XxxxVk(KMX_DWORD value) {
m_XxxxVk = value;
}

Expand Down Expand Up @@ -440,7 +440,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** ke
// flag that the VK is valid, and it can store the SC value.

// Windows and Linux Keycodes start with 1; Mac keycodes start with 0
for (UINT sc = 0x01; sc <= 0x7f; sc++) {
for (KMX_DWORD sc = 0x01; sc <= 0x7f; sc++) {
/* HERE IS A BIG DIFFERENCE COMPARED TO MCOMPILE FOR WINDOWS:
* mcompile on Windows fills rgkey.m_vk with the VK of the Underlying keyboard
* mcompile for Linux fills rgkey.m_vk with the VK of the US keyboard
Expand All @@ -460,7 +460,7 @@ 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++) {
for (KMX_DWORD iKey = 0; iKey < rgKey.size(); iKey++) {
if (rgKey[iKey] != NULL) {
KMX_WCHAR sbBuffer[256]; // Scratchpad we use many places
for (ShiftState ss = Base; ss <= loader.KMX_MaxShiftState(); ss = (ShiftState)((int)ss + 1)) {
Expand Down Expand Up @@ -509,10 +509,10 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** ke
//

kp->dpGroupArray = gp;
for (UINT i = 0; i < kp->cxGroupArray; i++, gp++) {
for (KMX_DWORD i = 0; i < kp->cxGroupArray; i++, gp++) {
LPKMX_KEY kkp = gp->dpKeyArray;

for (UINT j = 0; j < gp->cxKeyArray; j++, kkp++) {
for (KMX_DWORD j = 0; j < gp->cxKeyArray; j++, kkp++) {
nDeadkey = std::max(nDeadkey, KMX_GetMaxDeadkeyIndex(kkp->dpContext));
nDeadkey = std::max(nDeadkey, KMX_GetMaxDeadkeyIndex(kkp->dpOutput));
}
Expand All @@ -523,8 +523,8 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** ke

// calculate the required size of `gp->dpKeyArray`

UINT nkeys = 0;
for (UINT iKey = 0; iKey < rgKey.size(); iKey++) {
KMX_DWORD nkeys = 0;
for (KMX_DWORD iKey = 0; iKey < rgKey.size(); iKey++) {
if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) {
nkeys += rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState());
}
Expand All @@ -543,7 +543,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** ke
// Fill in the new rules
//
nkeys = 0;
for (UINT iKey = 0; iKey < rgKey.size(); iKey++) {
for (KMX_DWORD iKey = 0; iKey < rgKey.size(); iKey++) {
if ((rgKey[iKey] != NULL) && rgKey[iKey]->KMX_IsKeymanUsedKey() && (!rgKey[iKey]->KMX_IsEmpty())) {
if (rgKey[iKey]->KMX_LayoutRow(loader.KMX_MaxShiftState(), &gp->dpKeyArray[nkeys], &alDead, nDeadkey, bDeadkeyConversion, all_vector, *keymap)) { // I4552
nkeys += rgKey[iKey]->KMX_GetKeyCount(loader.KMX_MaxShiftState());
Expand All @@ -557,7 +557,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** ke
// Add nomatch control to each terminating 'using keys' group // I4550
//
LPKMX_GROUP gp2 = kp->dpGroupArray;
for (UINT i = 0; i < kp->cxGroupArray - 1; i++, gp2++) {
for (KMX_DWORD i = 0; i < kp->cxGroupArray - 1; i++, gp2++) {
if (gp2->fUsingKeys && gp2->dpNoMatch == NULL) {
KMX_WCHAR* p = gp2->dpNoMatch = new KMX_WCHAR[4];
*p++ = UC_SENTINEL;
Expand All @@ -569,7 +569,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** ke
// the AltGr and ShiftAltGr combinations as rules to allow them to be matched as well. Yes, this
// loop is not very efficient but it's not worthy of optimisation.
//
UINT j;
KMX_DWORD j;
LPKMX_KEY kkp;
for (j = 0, kkp = gp->dpKeyArray; j < gp->cxKeyArray; j++, kkp++) {
if ((kkp->ShiftFlags & (K_CTRLFLAG | K_ALTFLAG | LCTRLFLAG | LALTFLAG | RCTRLFLAG | RALTFLAG)) != 0) {
Expand Down Expand Up @@ -624,7 +624,7 @@ bool KMX_ImportRules(LPKMX_KEYBOARD kp, vec_dword_3D& all_vector, GdkKeymap** ke
int nStoreBase = kp->cxStoreArray;
kp->cxStoreArray += alDead.size() * 2;

for (UINT i = 0; i < alDead.size(); i++) {
for (KMX_DWORD i = 0; i < alDead.size(); i++) {
DeadKey* dk = alDead[i];

sp->dpName = NULL;
Expand Down
6 changes: 3 additions & 3 deletions linux/mcompile/keymap/mc_kmxfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const int CODE__SIZE[] = {
};

/** @brief check if the file has correct version */
KMX_BOOL KMX_VerifyKeyboard(LPKMX_BYTE filebase, KMX_DWORD file_size);
KMX_BOOL KMX_VerifyKeyboard(PKMX_BYTE filebase, KMX_DWORD file_size);

/** @brief Fixup the keyboard by expanding pointers. */
LPKMX_KEYBOARD KMX_FixupKeyboard(PKMX_BYTE bufp, PKMX_BYTE base, KMX_DWORD dwFileSize);
Expand All @@ -65,7 +65,7 @@ KMX_DWORD KMX_WriteCompiledKeyboardToFile(LPKMX_KEYBOARD fk, FILE* hOutfile, KMX
PCOMP_KEY kp;
PKMX_BYTE buf;
KMX_DWORD size, offset;
DWORD i, j;
KMX_DWORD i, j;

// Calculate how much memory to allocate
size = sizeof(COMP_KEYBOARD) +
Expand Down Expand Up @@ -495,7 +495,7 @@ KMX_BOOL KMX_LoadKeyboard(KMX_CHAR* fileName, LPKMX_KEYBOARD* lpKeyboard) {
* @return true if successful;
* false if not
*/
KMX_BOOL KMX_VerifyKeyboard(LPKMX_BYTE filebase, KMX_DWORD file_size) {
KMX_BOOL KMX_VerifyKeyboard(PKMX_BYTE filebase, KMX_DWORD file_size) {
KMX_DWORD i;
PCOMP_KEYBOARD ckbp = (PCOMP_KEYBOARD)filebase;
PCOMP_STORE csp;
Expand Down
Loading

0 comments on commit 58c1e50

Please sign in to comment.