From db2d0446e17665d53cb7be6c76fb5aeee91df59b Mon Sep 17 00:00:00 2001 From: Ivan Mahonin Date: Aug 18 2023 14:45:34 +0000 Subject: improve layout --- diff --git a/app.c b/app.c index 020f6d7..d11c021 100644 --- a/app.c +++ b/app.c @@ -294,7 +294,8 @@ void appStop(App *app, int err) { void appMove(App *app, int x, int y, int w, int h) { LOGDBG("app: move: x=%d, y=%d, w=%d, h=%d", x, y, w, h); - if (w < MIN_WIDTH || h < MIN_HEIGHT) return; + if (w < MIN_WIDTH) w = MIN_WIDTH; + if (h < MIN_HEIGHT) h = MIN_HEIGHT; unsigned int mask = 0; XWindowChanges ch = {}; @@ -305,6 +306,7 @@ void appMove(App *app, int x, int y, int w, int h) { if (!mask) return; XConfigureWindow(app->dpy, app->win, mask, &ch); + XFlush(app->dpy); } diff --git a/build.sh b/build.sh index 2659160..fd14353 100755 --- a/build.sh +++ b/build.sh @@ -10,6 +10,7 @@ else FLAGS="$FLAGS -O3 -DNDEBUG" fi -cc main.c $FLAGS -o coolkbd +echo cc main.c $FLAGS -o coolkbd + cc main.c $FLAGS -o coolkbd echo done diff --git a/config.h b/config.h index 5421ed1..cd17771 100644 --- a/config.h +++ b/config.h @@ -14,5 +14,7 @@ #define LABEL_MAXLEN 32 +#define KEY_BORDER 2 // see also S in layout.defs.h + #endif diff --git a/graph.c b/graph.c index f80073c..d848cca 100644 --- a/graph.c +++ b/graph.c @@ -121,7 +121,7 @@ void textLayoutInit(TextLayout *tl, Graph *g, const char *text) { int desc = tl->g->fonts[i]->descent; int w = e.width; int minw = asc + asc/3; - int h = asc + 2*desc; + int h = asc + desc; // proper value is: asc + 2*desc tl->sizes[i].x = e.x - w/2; tl->sizes[i].y = asc/2; diff --git a/keyboard.c b/keyboard.c index 6a77d72..3900174 100644 --- a/keyboard.c +++ b/keyboard.c @@ -53,7 +53,9 @@ void keyDraw(Key *k, int cx, int cy, int cw, int ch) { 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); + int w = k->w - 2*KEY_BORDER; + int h = k->h - 2*KEY_BORDER; + graphDrawButton(&k->l->kbd->app->graph, k->x + KEY_BORDER, k->y + KEY_BORDER, w, h, active); TextLayout *tl = &k->tl; TextLayout *tl2 = &k->tl2; @@ -61,20 +63,20 @@ void keyDraw(Key *k, int cx, int cy, int cw, int ch) { tl = tl2, tl2 = &k->tl; // swap labels int lx, lx2, ly, ly2, lw, lw2, lh, lh2; - lx = lx2 = k->x + k->w/2; - ly = ly2 = k->y + k->h/2; - lw = lw2 = k->w - k->w/8; - lh = lh2 = k->h - k->h/8; + lx = lx2 = k->x + w/2; + ly = ly2 = k->y + h/2; + lw = lw2 = w - w/8; + lh = lh2 = h - h/8; if (!k->isLetter && k->label2[0]) { - lx -= k->w/8; - ly += k->h/8; - lw -= k->w/4; - lh -= k->h/4; + lx -= w/8; + ly += h/8; + lw -= w/4; + lh -= h/4; - lx2 += k->w/4; - ly2 -= k->h/4; - lw2 -= k->w/2; - lh2 -= k->h/2; + lx2 += w/4; + ly2 -= h/4; + lw2 -= w/2; + lh2 -= h/2; } textLayoutDraw(tl, lx, ly, lw, lh, active); diff --git a/layout.am.inc.c b/layout.am.inc.c index 15d6fa5..0d6babe 100644 --- a/layout.am.inc.c +++ b/layout.am.inc.c @@ -7,7 +7,7 @@ Key keysAm[] = { HEADER(FW) - { S, Y, W2, H, XK_Armenian_exclam, 0, "՝", "՜" }, + { X0, Y1, 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, "֊", "—" }, @@ -20,8 +20,8 @@ Key keysAm[] = { { 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, W2, 0, XK_BackSpace, 0, "⌫" }, + { X0, 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, "բ", "Բ" }, @@ -35,7 +35,7 @@ Key keysAm[] = { { 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 }, + { X0, 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, "գ", "Գ" }, @@ -48,7 +48,7 @@ Key keysAm[] = { { N, 0, 0, 0, XK_Armenian_pe, 0, "պ", "Պ" }, { N, 0, 0, 0, XK_Armenian_re, 0, "ր", "Ր" }, { N, 0, 0, 0, XK_backslash, XK_slash, "\\", "/" }, - { S, N, W4, 0, XK_Shift_L, 0, "Shift", "", KF_HOLD }, + { X0, 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, "չ", "Չ" }, @@ -60,7 +60,7 @@ Key keysAm[] = { { 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 }, + { X0, 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 }, diff --git a/layout.defs.h b/layout.defs.h index 6e77c8b..355b6d7 100644 --- a/layout.defs.h +++ b/layout.defs.h @@ -5,8 +5,11 @@ #include "app.h" -#define S 5 // spacing -#define S2 15 // spacing +#define X0 5 // left top corner +#define Y0 5 + +#define S 0 // spacing +#define S2 10 #define W 50 // width #define W2 70 // more width @@ -26,23 +29,22 @@ #ifdef NOBORDER #define HH 30 // header height #define HEADER(fw) \ - { S, S, fw-S-HH, HH, 0, 0, "::: coolkbd :::", "", KF_MOVE }, \ + { X0, Y0, fw-S-HH, HH, 0, 0, "::: coolkbd :::", "", KF_MOVE }, \ { N, 0, HH, 0, 0, 0, "[X]", "", KF_CLOSE }, #define FOOTER(fw) \ - { S, N2, fw, HH, 0, 0, "::: resize handle :::", "", KF_SIZE }, - #define Y (HH+S+S2) + { X0, N2, fw, HH, 0, 0, "::: resize handle :::", "", KF_SIZE }, + #define Y1 (Y0+HH+S2) #else - #define Y S + #define Y1 Y0 #define HEADER(fw) #define FOOTER(fw) #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 +#define Y2 (Y1+H+S) // row 2 +#define Y3 (Y1+2*(H+S)) // row 3 +#define Y4 (Y1+3*(H+S)) // row 4 +#define Y5 (Y1+4*(H+S)) // row 5 +#define Y6 (Y1+5*(H+S)) // row 6 diff --git a/layout.en.full.inc.c b/layout.en.full.inc.c index 21eda9c..6c6adc5 100644 --- a/layout.en.full.inc.c +++ b/layout.en.full.inc.c @@ -5,16 +5,16 @@ #include "layout.defs.h" -#define LEF_COL2 (FW+S+W/2) +#define LEF_COL2 (X0+FW+S+W/2) #define LEF_COL3 (LEF_COL2+3*S+3*W+W/2) -#define LEF_FW (LEF_COL3+2*S+4*W) -#define LEF_N (-(FW-14*W-11*S)-1) +#define LEF_FW (LEF_COL3-X0+3*S+4*W) +#define LEF_N (-1-(FW-14*W-11*S)) Key keysEnFull[] = { HEADER(LEF_FW) - { S, Y, W, H, XK_Escape, 0, "Esc" }, + { X0, Y1, W, H, XK_Escape, 0, "Esc" }, { LEF_N, 0, 0, 0, XK_F1, 0, "F1" }, { N, 0, 0, 0, XK_F2, 0, "F2" }, { N, 0, 0, 0, XK_F3, 0, "F3" }, @@ -28,7 +28,7 @@ Key keysEnFull[] = { { N, 0, 0, 0, XK_F11, 0, "F11" }, { N, 0, 0, 0, XK_F12, 0, "F12" }, - { S, N2, W2, H, XK_grave, XK_asciitilde }, + { X0, N2, 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 }, @@ -41,9 +41,9 @@ Key keysEnFull[] = { { 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" }, + { N, 0, W2, 0, XK_BackSpace, 0, "⌫" }, - { S, N, W2, 0, XK_Tab, 0, "->|" }, + { X0, N, W2, 0, XK_Tab, 0, "⇥" }, { N, 0, W, 0, XK_q }, { N, 0, 0, 0, XK_w }, { N, 0, 0, 0, XK_e }, @@ -58,7 +58,7 @@ Key keysEnFull[] = { { N, 0, 0, 0, XK_bracketright, XK_braceright }, { N, 0, W2, H2, XK_Return, 0, "Enter" }, - { S, Y4+S2-S, W2, H, XK_Caps_Lock, 0, "Caps Lock", "", KF_MOD, IM_CAPSLOCK_BIT }, + { X0, Y4+S2-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 }, @@ -72,7 +72,7 @@ Key keysEnFull[] = { { 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 }, + { X0, 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 }, @@ -85,7 +85,7 @@ Key keysEnFull[] = { { 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 }, + { X0, 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 }, @@ -95,7 +95,7 @@ Key keysEnFull[] = { // col 2 - { LEF_COL2, Y, W, 0, XK_Print, 0, "PrtScr" }, + { LEF_COL2, Y1, 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" }, @@ -114,7 +114,7 @@ Key keysEnFull[] = { // col3 - { LEF_COL3, Y+H+2*S, 0, 0, XK_Num_Lock, 0, "NumLk", "", KF_MOD, IM_NUMLOCK_BIT }, + { LEF_COL3, Y1+H+S2, 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, "-" }, @@ -124,7 +124,7 @@ Key keysEnFull[] = { { 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" }, + { LEF_COL3, Y4+S2-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" }, @@ -133,7 +133,7 @@ Key keysEnFull[] = { { 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" }, + { LEF_COL3, Y6+S2-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) diff --git a/layout.en.inc.c b/layout.en.inc.c index 145937f..8d2a1b9 100644 --- a/layout.en.inc.c +++ b/layout.en.inc.c @@ -7,7 +7,7 @@ Key keysEn[] = { HEADER(FW) - { S, Y, W2, H, XK_grave, XK_asciitilde }, + { X0, Y1, 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 }, @@ -20,8 +20,8 @@ Key keysEn[] = { { 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, W2, 0, XK_BackSpace, 0, "⌫" }, + { X0, N, W2, 0, XK_Tab, 0, "⇥" }, { N, 0, W, 0, XK_q }, { N, 0, 0, 0, XK_w }, { N, 0, 0, 0, XK_e }, @@ -35,7 +35,7 @@ Key keysEn[] = { { 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 }, + { X0, 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 }, @@ -48,7 +48,7 @@ Key keysEn[] = { { 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 }, + { X0, 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 }, @@ -60,7 +60,7 @@ Key keysEn[] = { { 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 }, + { X0, 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 }, diff --git a/layout.ru.inc.c b/layout.ru.inc.c index 6eaddd1..f5c6319 100644 --- a/layout.ru.inc.c +++ b/layout.ru.inc.c @@ -6,7 +6,7 @@ Key keysRu[] = { HEADER(FW) - { S, Y, W2, H, XK_Cyrillic_io }, + { X0, Y1, 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 }, @@ -19,8 +19,8 @@ Key keysRu[] = { { 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, W2, 0, XK_BackSpace, 0, "⌫" }, + { X0, 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 }, @@ -34,7 +34,7 @@ Key keysRu[] = { { 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 }, + { X0, 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 }, @@ -47,7 +47,7 @@ Key keysRu[] = { { 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 }, + { X0, 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 }, @@ -59,7 +59,7 @@ Key keysRu[] = { { 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 }, + { X0, 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 },