From 569832792a45e28fbf621d7af42f40568410e264 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Aug 14 2023 14:46:37 +0000 Subject: add layouts --- diff --git a/common.c b/common.c index aaf6deb..3370f6f 100644 --- a/common.c +++ b/common.c @@ -318,7 +318,7 @@ int keysymString(unsigned int keySym, char *buf5bytes) { } if (uc <= 0x0007ff) { buf5bytes[0] = 0xc0 | (uc >> 6); - buf5bytes[1] = 0x80 | (uc & 0x1f); + buf5bytes[1] = 0x80 | (uc & 0x3f); buf5bytes[2] = 0; return 2; } diff --git a/input.c b/input.c index 6fec9f1..c8a1cdb 100644 --- a/input.c +++ b/input.c @@ -20,7 +20,6 @@ void inputPrepareKeysyms(unsigned int *ks0, unsigned int *ks1, int *isLetter, in if (*ks0) { KeySym kl = 0, ku = 0; XConvertCase(*ks0, &kl, &ku); - LOGDBG("XConvertCase %x %lx %lx", *ks0, kl, ku); if (*ks0 == kl && ku && kl != ku) { if (!*ks1) *ks1 = ku; *isLetter = 1; @@ -45,8 +44,8 @@ int inputChooseKeysym(unsigned int modifiers, unsigned int ks0, unsigned int ks1 if (capsLock) // capsLock priority shiftLock = 0; - if (numLock && isKeypad) - return shift || shiftLock; + if (isKeypad) + return numLock; if (!shift && !capsLock && !shiftLock) return 0; if (!shift && capsLock) @@ -111,7 +110,8 @@ void inputUpdateLayout(Input *in) { XK_Caps_Lock, XK_Shift_Lock, XK_Num_Lock, - XK_Mode_switch }; + XK_Mode_switch, + XK_Scroll_Lock }; in->updated = 0; memset(in->masks, 0, sizeof(in->masks)); diff --git a/input.h b/input.h index 22635fb..d725202 100644 --- a/input.h +++ b/input.h @@ -17,6 +17,7 @@ enum { IM_SHIFTLOCK, IM_NUMLOCK, IM_GROUP, + IM_SCRLOCK, IM_COUNT }; enum { @@ -24,7 +25,8 @@ enum { IM_CAPSLOCK_BIT = 1 << IM_CAPSLOCK, IM_SHIFTLOCK_BIT = 1 << IM_SHIFTLOCK, IM_NUMLOCK_BIT = 1 << IM_NUMLOCK, - IM_GROUP_BIT = 1 << IM_GROUP }; + IM_GROUP_BIT = 1 << IM_GROUP, + IM_SCRLOCK_BIT = 1 << IM_SCRLOCK }; typedef struct Input { diff --git a/keyboard.c b/keyboard.c index aa11ed2..d09a1f8 100644 --- a/keyboard.c +++ b/keyboard.c @@ -36,7 +36,7 @@ void keyDraw(Key *k, int cx, int cy, int cw, int ch) { App *app = k->l->kbd->app; int active = k->down; - if (k->flags & KF_MOD) + if (!active && (k->flags & KF_MOD)) active = (app->input.modifiers & (unsigned int)k->optValue); graphDrawButton(&k->l->kbd->app->graph, k->x, k->y, k->w, k->h, active); @@ -50,12 +50,10 @@ void keyDraw(Key *k, int cx, int cy, int cw, int ch) { lx = lx2 = k->x + k->w/2; ly = ly2 = k->y + k->h/2; if (!k->isLetter && k->label2[0]) { - int dx = k->w/6; - int dy = k->h/6; - lx -= dx; - ly += dy; - lx2 += dx; - ly2 -= dy; + lx -= k->w/8; + ly += k->h/8; + lx2 += k->w/4; + ly2 -= k->h/4; } textLayoutDraw(tl, lx, ly, active); @@ -358,6 +356,7 @@ void keyboardSwitchLayout(Keyboard *kbd, int index) { LOGDBG("keyboard: switch layout"); if (!kbd->layoutsCount) return; + keyboardRelaseHeld(kbd); if (index == LI_PREV) { index = kbd->current ? kbd->current - kbd->layouts - 1: 0; diff --git a/layout.am.inc.c b/layout.am.inc.c index 535d383..15d6fa5 100644 --- a/layout.am.inc.c +++ b/layout.am.inc.c @@ -6,12 +6,12 @@ Key keysAm[] = { - HEADER + HEADER(FW) { S, Y, W2, H, XK_Armenian_exclam, 0, "՝", "՜" }, { N, 0, W, 0, XK_Armenian_fe, 0, "ֆ", "Ֆ" }, { N, 0, 0, 0, XK_Armenian_dza, 0, "ձ", "Ձ" }, { N, 0, 0, 0, XK_Armenian_hyphen, 0, "֊", "—" }, - { N, 0, 0, 0, XK_comma, 0, "," }, + { N, 0, 0, 0, XK_comma }, { N, 0, 0, 0, XK_Armenian_full_stop, 0, "։", "…" }, { N, 0, 0, 0, XK_Armenian_question, 0, "՞", "%" }, { N, 0, 0, 0, XK_Armenian_ligature_ew, 0, "․", "և" }, @@ -47,7 +47,7 @@ Key keysAm[] = { { N, 0, 0, 0, XK_Armenian_ho, 0, "հ", "Հ" }, { N, 0, 0, 0, XK_Armenian_pe, 0, "պ", "Պ" }, { N, 0, 0, 0, XK_Armenian_re, 0, "ր", "Ր" }, - { N, 0, 0, 0, XK_backslash, 0, "\\", "/" }, + { N, 0, 0, 0, XK_backslash, XK_slash, "\\", "/" }, { S, N, W4, 0, XK_Shift_L, 0, "Shift", "", KF_HOLD }, { N, 0, W, 0, XK_Armenian_zhe, 0, "ժ", "Ժ" }, { N, 0, 0, 0, XK_Armenian_da, 0, "դ", "Դ" }, @@ -67,7 +67,7 @@ Key keysAm[] = { { N, 0, W2, 0, 0, 0, "-->", "", KF_LAYOUT, LI_NEXT }, { N, 0, W2, 0, XK_Alt_R, 0, "Alt", "", KF_HOLD }, { N, 0, W2, 0, XK_Control_R, 0, "Ctrl", "", KF_HOLD }, - FOOTER + FOOTER(FW) }; #endif diff --git a/layout.defs.h b/layout.defs.h index 02f3883..14ab49a 100644 --- a/layout.defs.h +++ b/layout.defs.h @@ -23,16 +23,16 @@ #ifdef NOBORDER #define HH 20 // header height - #define HEADER \ - { S, S, FW-S-HH, HH, 0, 0, "::: coolkbd :::", "", KF_MOVE }, \ + #define HEADER(fw) \ + { S, S, fw-S-HH, HH, 0, 0, "::: coolkbd :::", "", KF_MOVE }, \ { N, 0, HH, 0, 0, 0, "[X]", "", KF_CLOSE }, - #define FOOTER \ - { S, N, FW, HH, 0, 0, "::: resize handle :::", "", KF_SIZE }, + #define FOOTER(fw) \ + { S, N, fw, HH, 0, 0, "::: resize handle :::", "", KF_SIZE }, #define Y (HH+2*S) #else #define Y S - #define HEADER - #define FOOTER + #define HEADER(fw) + #define FOOTER(fw) #endif diff --git a/layout.en.full.inc.c b/layout.en.full.inc.c new file mode 100644 index 0000000..d9a0b49 --- /dev/null +++ b/layout.en.full.inc.c @@ -0,0 +1,120 @@ +#ifndef LAYOUT_EN_FULL_INC_C +#define LAYOUT_EN_FULL_INC_C + + +#include "layout.defs.h" + + +#define LEF_COL2 (FW+S+W/2) +#define LEF_COL3 (LEF_COL2+3*S+3*W+W/2) +#define LEF_FW (LEF_COL3+2*S+4*W) + +Key keysEnFull[] = { + HEADER(LEF_FW) + { S, Y, W, H, XK_Escape, 0, "Esc" }, + { N-W, 0, 0, 0, XK_F1, 0, "F1" }, + { N, 0, 0, 0, XK_F2, 0, "F2" }, + { N, 0, 0, 0, XK_F3, 0, "F3" }, + { N, 0, 0, 0, XK_F4, 0, "F4" }, + { N-W/2, 0, 0, 0, XK_F5, 0, "F5" }, + { N, 0, 0, 0, XK_F6, 0, "F6" }, + { N, 0, 0, 0, XK_F7, 0, "F7" }, + { N, 0, 0, 0, XK_F8, 0, "F8" }, + { N-W/2, 0, 0, 0, XK_F9, 0, "F9" }, + { N, 0, 0, 0, XK_F10, 0, "F10" }, + { N, 0, 0, 0, XK_F11, 0, "F11" }, + { N, 0, 0, 0, XK_F12, 0, "F12" }, + { S, N-S, W2, H, XK_grave, XK_asciitilde }, + { N, 0, W, 0, XK_1, XK_exclam }, + { N, 0, 0, 0, XK_2, XK_at }, + { N, 0, 0, 0, XK_3, XK_numbersign }, + { N, 0, 0, 0, XK_4, XK_dollar }, + { N, 0, 0, 0, XK_5, XK_percent }, + { N, 0, 0, 0, XK_6, XK_asciicircum }, + { N, 0, 0, 0, XK_7, XK_ampersand }, + { N, 0, 0, 0, XK_8, XK_asterisk }, + { N, 0, 0, 0, XK_9, XK_parenleft }, + { N, 0, 0, 0, XK_0, XK_parenright }, + { N, 0, 0, 0, XK_minus, XK_underscore }, + { N, 0, 0, 0, XK_equal, XK_plus }, + { N, 0, W2, 0, XK_BackSpace, 0, "<-Bksp" }, + { S, N, W2, 0, XK_Tab, 0, "->|" }, + { N, 0, W, 0, XK_q }, + { N, 0, 0, 0, XK_w }, + { N, 0, 0, 0, XK_e }, + { N, 0, 0, 0, XK_r }, + { N, 0, 0, 0, XK_t }, + { N, 0, 0, 0, XK_y }, + { N, 0, 0, 0, XK_u }, + { N, 0, 0, 0, XK_i }, + { N, 0, 0, 0, XK_o }, + { N, 0, 0, 0, XK_p }, + { N, 0, 0, 0, XK_bracketleft, XK_braceleft }, + { N, 0, 0, 0, XK_bracketright, XK_braceright }, + { N, 0, W2, H2, XK_Return, 0, "Enter" }, + { S, Y4+S, W2, H, XK_Caps_Lock, 0, "Caps Lock", "", KF_MOD, IM_CAPSLOCK_BIT }, + { N, 0, W, 0, XK_a }, + { N, 0, 0, 0, XK_s }, + { N, 0, 0, 0, XK_d }, + { N, 0, 0, 0, XK_f }, + { N, 0, 0, 0, XK_g }, + { N, 0, 0, 0, XK_h }, + { N, 0, 0, 0, XK_j }, + { N, 0, 0, 0, XK_k }, + { N, 0, 0, 0, XK_l }, + { N, 0, 0, 0, XK_semicolon, XK_colon }, + { N, 0, 0, 0, XK_apostrophe, XK_quotedbl }, + { N, 0, 0, 0, XK_backslash, XK_bar }, + { S, N, W4, 0, XK_Shift_L, 0, "Shift", "", KF_HOLD }, + { N, 0, W, 0, XK_z }, + { N, 0, 0, 0, XK_x }, + { N, 0, 0, 0, XK_c }, + { N, 0, 0, 0, XK_v }, + { N, 0, 0, 0, XK_b }, + { N, 0, 0, 0, XK_n }, + { N, 0, 0, 0, XK_m }, + { N, 0, 0, 0, XK_comma, XK_less }, + { N, 0, 0, 0, XK_period, XK_greater }, + { N, 0, 0, 0, XK_slash, XK_question }, + { N, 0, W4, 0, XK_Shift_R, 0, "Shift", "", KF_HOLD }, + { S, N, W2, 0, XK_Control_L, 0, "Ctrl", "", KF_HOLD }, + { N, 0, W2, 0, XK_Alt_L, 0, "Alt", "", KF_HOLD }, + { N, 0, W2, 0, 0, 0, "<--", "", KF_LAYOUT, LI_PREV }, + { N, 0, W5, 0, XK_space }, + { N, 0, W2, 0, 0, 0, "-->", "", KF_LAYOUT, LI_NEXT }, + { N, 0, W2, 0, XK_Alt_R, 0, "Alt", "", KF_HOLD }, + { N, 0, W2, 0, XK_Control_R, 0, "Ctrl", "", KF_HOLD }, + { LEF_COL2, Y, W, 0, XK_Print, 0, "PrtScr" }, + { N, 0, 0, 0, XK_Scroll_Lock, 0, "ScrLk", "", KF_MOD, IM_SCRLOCK_BIT }, + { N, 0, 0, 0, XK_Pause, 0, "Pause" }, + { LEF_COL2, N-S, 0, 0, XK_Insert, 0, "Ins" }, + { N, 0, 0, 0, XK_Home, 0, "Home" }, + { N, 0, 0, 0, XK_Page_Up, 0, "PgUp" }, + { LEF_COL2, N, 0, 0, XK_Delete, 0, "Del" }, + { N, 0, 0, 0, XK_End, 0, "End" }, + { N, 0, 0, 0, XK_Page_Down, 0, "PgDn" }, + { LEF_COL2+W+S, N-H-S, 0, 0, XK_Up, 0, "↑" }, + { LEF_COL2, N, 0, 0, XK_Left, 0, "←" }, + { N, 0, 0, 0, XK_Down, 0, "↓" }, + { N, 0, 0, 0, XK_Right, 0, "→" }, + { LEF_COL3, Y+H+2*S, 0, 0, XK_Num_Lock, 0, "NumLk", "", KF_MOD, IM_NUMLOCK_BIT }, + { N, 0, 0, 0, XK_KP_Divide, 0, "/" }, + { N, 0, 0, 0, XK_KP_Multiply, 0, "*" }, + { N, 0, 0, 0, XK_KP_Subtract, 0, "-" }, + { LEF_COL3, N, 0, 0, XK_KP_Home, XK_KP_7, "Home", "7" }, + { N, 0, 0, 0, XK_KP_Up, XK_KP_8, "↑", "8" }, + { N, 0, 0, 0, XK_KP_Page_Down, XK_KP_9, "PgDn", "9" }, + { N, 0, 0, H2, XK_KP_Add, 0, "+" }, + { LEF_COL3, Y4+S, 0, H, XK_KP_Left, XK_KP_4, "←", "4" }, + { N, 0, 0, 0, 0, XK_KP_5, "", "5" }, + { N, 0, 0, 0, XK_KP_Right, XK_KP_6, "→", "6" }, + { LEF_COL3, N, 0, 0, XK_KP_End, XK_KP_1, "End", "1" }, + { N, 0, 0, 0, XK_KP_Down, XK_KP_2, "↓", "2" }, + { N, 0, 0, 0, XK_KP_Page_Down, XK_KP_3, "PgDn", "2" }, + { N, 0, 0, H2, XK_KP_Enter, 0, "Enter" }, + { LEF_COL3, Y6+S, 2*W+S, H, XK_KP_Insert, XK_KP_0, "Ins", "0" }, + { N, 0, W, 0, XK_KP_Delete, XK_KP_Decimal, "Del", "." }, + FOOTER(LEF_FW) +}; + +#endif diff --git a/layout.en.inc.c b/layout.en.inc.c index 717865b..145937f 100644 --- a/layout.en.inc.c +++ b/layout.en.inc.c @@ -6,7 +6,7 @@ Key keysEn[] = { - HEADER + HEADER(FW) { S, Y, W2, H, XK_grave, XK_asciitilde }, { N, 0, W, 0, XK_1, XK_exclam }, { N, 0, 0, 0, XK_2, XK_at }, @@ -32,8 +32,8 @@ Key keysEn[] = { { N, 0, 0, 0, XK_i }, { N, 0, 0, 0, XK_o }, { N, 0, 0, 0, XK_p }, - { N, 0, 0, 0, XK_bracketleft, XK_braceleft, "[", "{" }, - { N, 0, 0, 0, XK_bracketright, XK_braceright, "]", "}" }, + { N, 0, 0, 0, XK_bracketleft, XK_braceleft }, + { N, 0, 0, 0, XK_bracketright, XK_braceright }, { N, 0, W2, H2, XK_Return, 0, "Enter" }, { S, Y3, W2, H, XK_Caps_Lock, 0, "Caps Lock", "", KF_MOD, IM_CAPSLOCK_BIT }, { N, 0, W, 0, XK_a }, @@ -45,9 +45,9 @@ Key keysEn[] = { { N, 0, 0, 0, XK_j }, { N, 0, 0, 0, XK_k }, { N, 0, 0, 0, XK_l }, - { N, 0, 0, 0, XK_semicolon, XK_colon, ";", ":" }, - { N, 0, 0, 0, XK_apostrophe, XK_quotedbl, "'", "\"" }, - { N, 0, 0, 0, XK_backslash, XK_bar, "\\", "|" }, + { N, 0, 0, 0, XK_semicolon, XK_colon }, + { N, 0, 0, 0, XK_apostrophe, XK_quotedbl }, + { N, 0, 0, 0, XK_backslash, XK_bar }, { S, N, W4, 0, XK_Shift_L, 0, "Shift", "", KF_HOLD }, { N, 0, W, 0, XK_z }, { N, 0, 0, 0, XK_x }, @@ -56,9 +56,9 @@ Key keysEn[] = { { N, 0, 0, 0, XK_b }, { N, 0, 0, 0, XK_n }, { N, 0, 0, 0, XK_m }, - { N, 0, 0, 0, XK_comma, XK_less, ",", "<" }, - { N, 0, 0, 0, XK_period, XK_greater, ".", ">" }, - { N, 0, 0, 0, XK_slash, XK_question, "/", "?" }, + { N, 0, 0, 0, XK_comma, XK_less }, + { N, 0, 0, 0, XK_period, XK_greater }, + { N, 0, 0, 0, XK_slash, XK_question }, { N, 0, W4, 0, XK_Shift_R, 0, "Shift", "", KF_HOLD }, { S, N, W2, 0, XK_Control_L, 0, "Ctrl", "", KF_HOLD }, { N, 0, W2, 0, XK_Alt_L, 0, "Alt", "", KF_HOLD }, @@ -67,7 +67,7 @@ Key keysEn[] = { { N, 0, W2, 0, 0, 0, "-->", "", KF_LAYOUT, LI_NEXT }, { N, 0, W2, 0, XK_Alt_R, 0, "Alt", "", KF_HOLD }, { N, 0, W2, 0, XK_Control_R, 0, "Ctrl", "", KF_HOLD }, - FOOTER + FOOTER(FW) }; #endif diff --git a/layout.ru.inc.c b/layout.ru.inc.c new file mode 100644 index 0000000..6eaddd1 --- /dev/null +++ b/layout.ru.inc.c @@ -0,0 +1,72 @@ +#ifndef LAYOUT_RU_INC_C +#define LAYOUT_RU_INC_C + + +#include "layout.defs.h" + +Key keysRu[] = { + HEADER(FW) + { S, Y, W2, H, XK_Cyrillic_io }, + { N, 0, W, 0, XK_1, XK_exclam }, + { N, 0, 0, 0, XK_2, XK_quotedbl }, + { N, 0, 0, 0, XK_3, XK_numerosign }, + { N, 0, 0, 0, XK_4, XK_semicolon }, + { N, 0, 0, 0, XK_5, XK_percent }, + { N, 0, 0, 0, XK_6, XK_colon }, + { N, 0, 0, 0, XK_7, XK_question }, + { N, 0, 0, 0, XK_8, XK_asterisk }, + { N, 0, 0, 0, XK_9, XK_parenleft }, + { N, 0, 0, 0, XK_0, XK_parenright }, + { N, 0, 0, 0, XK_minus, XK_underscore }, + { N, 0, 0, 0, XK_equal, XK_plus }, + { N, 0, W2, 0, XK_BackSpace, 0, "<-Bksp" }, + { S, N, W2, 0, XK_Tab, 0, "->|" }, + { N, 0, W, 0, XK_Cyrillic_shorti }, + { N, 0, 0, 0, XK_Cyrillic_tse }, + { N, 0, 0, 0, XK_Cyrillic_u }, + { N, 0, 0, 0, XK_Cyrillic_ka }, + { N, 0, 0, 0, XK_Cyrillic_ie }, + { N, 0, 0, 0, XK_Cyrillic_en }, + { N, 0, 0, 0, XK_Cyrillic_ghe }, + { N, 0, 0, 0, XK_Cyrillic_sha }, + { N, 0, 0, 0, XK_Cyrillic_shcha }, + { N, 0, 0, 0, XK_Cyrillic_ze }, + { N, 0, 0, 0, XK_Cyrillic_ha }, + { N, 0, 0, 0, XK_Cyrillic_hardsign }, + { N, 0, W2, H2, XK_Return, 0, "Enter" }, + { S, Y3, W2, H, XK_Caps_Lock, 0, "Caps Lock", "", KF_MOD, IM_CAPSLOCK_BIT }, + { N, 0, W, 0, XK_Cyrillic_ef }, + { N, 0, 0, 0, XK_Cyrillic_yeru }, + { N, 0, 0, 0, XK_Cyrillic_ve }, + { N, 0, 0, 0, XK_Cyrillic_a }, + { N, 0, 0, 0, XK_Cyrillic_pe }, + { N, 0, 0, 0, XK_Cyrillic_er }, + { N, 0, 0, 0, XK_Cyrillic_o }, + { N, 0, 0, 0, XK_Cyrillic_el }, + { N, 0, 0, 0, XK_Cyrillic_de }, + { N, 0, 0, 0, XK_Cyrillic_zhe }, + { N, 0, 0, 0, XK_Cyrillic_e }, + { N, 0, 0, 0, XK_backslash, XK_slash }, + { S, N, W4, 0, XK_Shift_L, 0, "Shift", "", KF_HOLD }, + { N, 0, W, 0, XK_Cyrillic_ya }, + { N, 0, 0, 0, XK_Cyrillic_che }, + { N, 0, 0, 0, XK_Cyrillic_es }, + { N, 0, 0, 0, XK_Cyrillic_em }, + { N, 0, 0, 0, XK_Cyrillic_i }, + { N, 0, 0, 0, XK_Cyrillic_te }, + { N, 0, 0, 0, XK_Cyrillic_softsign }, + { N, 0, 0, 0, XK_Cyrillic_be }, + { N, 0, 0, 0, XK_Cyrillic_yu }, + { N, 0, 0, 0, XK_comma, XK_period }, + { N, 0, W4, 0, XK_Shift_R, 0, "Shift", "", KF_HOLD }, + { S, N, W2, 0, XK_Control_L, 0, "Ctrl", "", KF_HOLD }, + { N, 0, W2, 0, XK_Alt_L, 0, "Alt", "", KF_HOLD }, + { N, 0, W2, 0, 0, 0, "<--", "", KF_LAYOUT, LI_PREV }, + { N, 0, W5, 0, XK_space }, + { N, 0, W2, 0, 0, 0, "-->", "", KF_LAYOUT, LI_NEXT }, + { N, 0, W2, 0, XK_Alt_R, 0, "Alt", "", KF_HOLD }, + { N, 0, W2, 0, XK_Control_R, 0, "Ctrl", "", KF_HOLD }, + FOOTER(FW) +}; + +#endif diff --git a/main.c b/main.c index db38e55..dd5a3c6 100644 --- a/main.c +++ b/main.c @@ -9,10 +9,15 @@ #include "layout.en.inc.c" #include "layout.am.inc.c" +#include "layout.ru.inc.c" +#include "layout.en.full.inc.c" Layout layouts[] = { { keysEn, COUNTOF(keysEn) }, - { keysAm, COUNTOF(keysAm) } }; + { keysAm, COUNTOF(keysAm) }, + { keysRu, COUNTOF(keysRu) }, + { keysEnFull, COUNTOF(keysEnFull) }, +}; App app = { { layouts, COUNTOF(layouts) } }; // keyboard