From d3e9d7d63023a55af6a69862062596f7527194b8 Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Aug 14 2023 12:28:12 +0000 Subject: seems it is working --- diff --git a/app.c b/app.c index 6abd02b..a35983b 100644 --- a/app.c +++ b/app.c @@ -212,5 +212,6 @@ void appInvalidateRect(App *app, int x, int y, int w, int h) { LOGDBG("app: invalidate rect: x=%d, y=%d, w=%d, h=%d", x, y, w, h); rectIntersect(&x, &y, &w, &h, 0, 0, app->w, app->h); rectMerge(&app->irx, &app->iry, &app->irw, &app->irh, x, y, w, h); + LOGDBG("app: invalidate rect: summary x=%d, y=%d, w=%d, h=%d", app->irx, app->iry, app->irw, app->irh); } diff --git a/common.h b/common.h index 33d2537..b7c62ae 100644 --- a/common.h +++ b/common.h @@ -10,7 +10,7 @@ #include -//#define NOBORDER +#define NOBORDER #define COUNTOF(x) (sizeof(x)/sizeof((x)[0])) @@ -57,7 +57,7 @@ static inline void rectMerge(int *x, int *y, int *w, int *h, int xx, int yy, int if (*w <= 0 || *h <= 0) { *x = xx, *y = yy, *w = ww, *h = hh; return; } if (*x > xx) *w += *x - xx, *x = xx; - if (*x > xx) *h += *y - yy, *y = yy; + if (*y > yy) *h += *y - yy, *y = yy; ww += xx; hh += yy; if (*x + *w < ww) *w = ww - *x; if (*y + *h < hh) *h = hh - *y; diff --git a/graph.h b/graph.h index bce1f64..c3b55ff 100644 --- a/graph.h +++ b/graph.h @@ -5,7 +5,7 @@ #include "common.h" -#define TL_MAXLEN 16 +#define TL_MAXLEN 32 typedef enum { diff --git a/input.c b/input.c index 9783098..6fec9f1 100644 --- a/input.c +++ b/input.c @@ -246,5 +246,6 @@ void inputEvent(Input *in, int keycode, int press) { } XTestFakeKeyEvent(in->dpy, keycode, press, CurrentTime); XSync(in->dpy, False); + inputUpdateModifiers(in); } diff --git a/keyboard.c b/keyboard.c index 11a3027..aa11ed2 100644 --- a/keyboard.c +++ b/keyboard.c @@ -361,11 +361,11 @@ void keyboardSwitchLayout(Keyboard *kbd, int index) { if (index == LI_PREV) { index = kbd->current ? kbd->current - kbd->layouts - 1: 0; - if (index >= kbd->layoutsCount) index = 0; + if (index < 0) index = kbd->layoutsCount - 1; } else if (index == LI_NEXT) { - index = kbd->current ? kbd->current - kbd->layouts - 1: 0; - if (index < 0) index = kbd->layoutsCount - 1; + index = kbd->current ? kbd->current - kbd->layouts + 1: 0; + if (index >= kbd->layoutsCount) index = 0; } else if (index == LI_REVERT) { if (kbd->current && kbd->current->prev) diff --git a/keyboard.h b/keyboard.h index 074b9bc..178d77c 100644 --- a/keyboard.h +++ b/keyboard.h @@ -6,7 +6,7 @@ #include "input.h" -#define K_LBL_SIZE 16 +#define K_LBL_SIZE TL_MAXLEN // key flags diff --git a/layout.am.inc.c b/layout.am.inc.c new file mode 100644 index 0000000..535d383 --- /dev/null +++ b/layout.am.inc.c @@ -0,0 +1,73 @@ +#ifndef LAYOUT_AM_INC_C +#define LAYOUT_AM_INC_C + + +#include "layout.defs.h" + + +Key keysAm[] = { + HEADER + { 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_Armenian_full_stop, 0, "։", "…" }, + { N, 0, 0, 0, XK_Armenian_question, 0, "՞", "%" }, + { N, 0, 0, 0, XK_Armenian_ligature_ew, 0, "․", "և" }, + { N, 0, 0, 0, XK_Armenian_accent, 0, "՛", "՚" }, + { N, 0, 0, 0, XK_parenright, 0, ")", "(" }, + { N, 0, 0, 0, XK_Armenian_o, 0, "օ", "Օ" }, + { N, 0, 0, 0, XK_Armenian_e, 0, "է", "Է" }, + { N, 0, 0, 0, XK_Armenian_ghat, 0, "ղ", "Ղ" }, + { N, 0, W2, 0, XK_BackSpace, 0, "<-Bksp" }, + { S, N, W2, 0, XK_Tab, 0, "->|" }, + { N, 0, W, 0, XK_Armenian_tche, 0, "ճ", "Ճ" }, + { N, 0, 0, 0, XK_Armenian_pyur, 0, "փ", "Փ" }, + { N, 0, 0, 0, XK_Armenian_ben, 0, "բ", "Բ" }, + { N, 0, 0, 0, XK_Armenian_se, 0, "ս", "Ս" }, + { N, 0, 0, 0, XK_Armenian_men, 0, "մ", "Մ" }, + { N, 0, 0, 0, XK_Armenian_vo, 0, "ո", "Ո" }, + { N, 0, 0, 0, XK_Armenian_vyun, 0, "ւ", "Ւ" }, + { N, 0, 0, 0, XK_Armenian_ken, 0, "կ", "Կ" }, + { N, 0, 0, 0, XK_Armenian_at, 0, "ը", "Ը" }, + { N, 0, 0, 0, XK_Armenian_to, 0, "թ", "Թ" }, + { N, 0, 0, 0, XK_Armenian_tsa, 0, "ծ", "Ծ" }, + { N, 0, 0, 0, XK_Armenian_tso, 0, "ց", "Ց" }, + { N, 0, W2, H2, XK_Return, 0, "Return" }, + { S, Y3, W2, H, XK_Caps_Lock, 0, "Caps Lock", "", KF_MOD, IM_CAPSLOCK_BIT }, + { N, 0, W, 0, XK_Armenian_je, 0, "ջ", "Ջ" }, + { N, 0, 0, 0, XK_Armenian_vev, 0, "վ", "Վ" }, + { N, 0, 0, 0, XK_Armenian_gim, 0, "գ", "Գ" }, + { N, 0, 0, 0, XK_Armenian_yech, 0, "ե", "Ե" }, + { N, 0, 0, 0, XK_Armenian_ayb, 0, "ա", "Ա" }, + { N, 0, 0, 0, XK_Armenian_nu, 0, "ն", "Ն" }, + { N, 0, 0, 0, XK_Armenian_ini, 0, "ի", "Ի" }, + { N, 0, 0, 0, XK_Armenian_tyun, 0, "տ", "Տ" }, + { 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, "\\", "/" }, + { 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, "դ", "Դ" }, + { N, 0, 0, 0, XK_Armenian_cha, 0, "չ", "Չ" }, + { N, 0, 0, 0, XK_Armenian_hi, 0, "յ", "Յ" }, + { N, 0, 0, 0, XK_Armenian_za, 0, "զ", "Զ" }, + { N, 0, 0, 0, XK_Armenian_lyun, 0, "լ", "Լ" }, + { N, 0, 0, 0, XK_Armenian_ke, 0, "ք", "Ք" }, + { N, 0, 0, 0, XK_Armenian_khe, 0, "խ", "Խ" }, + { N, 0, 0, 0, XK_Armenian_sha, 0, "շ", "Շ" }, + { N, 0, 0, 0, XK_Armenian_ra, 0, "ռ", "Ռ" }, + { 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 +}; + +#endif diff --git a/layout.defs.h b/layout.defs.h new file mode 100644 index 0000000..02f3883 --- /dev/null +++ b/layout.defs.h @@ -0,0 +1,47 @@ +#ifndef LAYOUT_DEFS_H +#define LAYOUT_DEFS_H + + +#include "app.h" + + +#define S 10 // spacing + +#define W 50 // width +#define W2 70 // more width +#define W3 80 // more +#define W4 (W2+W+S) // and more +#define W5 (12*W+11*S-4*W2-4*S) // space bar width + +#define H 40 // height +#define H2 (H*2+S) // double height + +#define N (-S-1) // place key next to previos key + +#define FW (12*W+2*W2+13*S) // full width + + +#ifdef NOBORDER + #define HH 20 // header height + #define HEADER \ + { 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 Y (HH+2*S) +#else + #define Y S + #define HEADER + #define FOOTER +#endif + + +#define Y2 (Y+H+S) // row 2 +#define Y3 (Y+2*(H+S)) // row 3 +#define Y4 (Y+3*(H+S)) // row 4 +#define Y5 (Y+4*(H+S)) // row 5 +#define Y6 (Y+5*(H+S)) // row 6 + + + +#endif diff --git a/layout.en.inc.c b/layout.en.inc.c new file mode 100644 index 0000000..717865b --- /dev/null +++ b/layout.en.inc.c @@ -0,0 +1,73 @@ +#ifndef LAYOUT_EN_INC_C +#define LAYOUT_EN_INC_C + + +#include "layout.defs.h" + + +Key keysEn[] = { + HEADER + { S, Y, 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, Y3, 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 }, + FOOTER +}; + +#endif diff --git a/main.c b/main.c index c7dbf13..db38e55 100644 --- a/main.c +++ b/main.c @@ -7,44 +7,12 @@ #include "input.c" #include "keyboard.c" - -#define S 10 // spacing -#define W 50 // width -#define H 40 // height -#define N (-S-1) // place key next to previos key - -#ifdef NOBORDER - #define HEADER \ - { S, S, 200, 20, 0, 0, "::: coolkbd :::", "", KF_MOVE }, \ - { N, 0, 20, 20, 0, 0, "[X]", "", KF_CLOSE }, - #define FOOTER \ - { S, N, 220+S, 20, 0, 0, "resize", "", KF_SIZE }, - #define Y N -#else - #define Y S - #define HEADER - #define FOOTER -#endif - -Key keys[] = { - HEADER - { S, Y, 50, 40, XK_Armenian_vyun, XK_Armenian_VYUN, "ւ", "Ւ" }, - { N, 0, 0, 0, XK_b }, - { N, 0, 0, 0, XK_c, XK_X, "", "Iks" }, - { N, 0, 0, 0, XK_5, XK_percent, "5", "%" }, - { S, N, 0, 0, XK_Cyrillic_a, 0, "а", "А" }, - { N, 0, 0, 0, XK_Cyrillic_be }, - { N, 0, 0, 0, XK_Cyrillic_ve }, - { N, 0, 0, 0, XK_6, XK_exclam }, - { S, N, 0, 0, 0, 0, "[x]", "", KF_CLOSE }, - { N, 0, 0, 0, 0, 0, "[:::]", "", KF_MOVE }, - { N, 0, 0, 0, 0, 0, "[<]", "", KF_LAYOUT, LI_REVERT }, - { N, 0, 0, 0, 0, 0, "<:::>", "", KF_SIZE }, - FOOTER -}; +#include "layout.en.inc.c" +#include "layout.am.inc.c" Layout layouts[] = { - { keys, COUNTOF(keys) } }; + { keysEn, COUNTOF(keysEn) }, + { keysAm, COUNTOF(keysAm) } }; App app = { { layouts, COUNTOF(layouts) } }; // keyboard