diff --git a/CHANGELOG.md b/CHANGELOG.md index 948bf03b..93431c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,10 @@ is missing or empty. - Every iPad, iPhone and iPod touch screen now starts at the size it has under iOS. Before, only the iPad 6, iPad 7 and iPhone 7 did; on the others, such as the iPod touch 6, everything was drawn at half size. +- On a phone held upright, the on-screen keyboard has ten keys across as on + iOS, under a short row of Esc, Tab, Ctrl, Alt and the arrows. 123 holds the + digits and common symbols, and #+= the rest, plus Home, End, Page Up/Down + and Delete. - A new launcher replaces the app grid: Home, Super and the bar's logo open apps, actions and (on a phone) the system controls in swipeable tabs, with search, recent apps and files, long-press app menus and full keyboard diff --git a/desktop/keyboard/friendly-layout.py b/desktop/keyboard/friendly-layout.py index 195ed26b..c0a669ed 100644 --- a/desktop/keyboard/friendly-layout.py +++ b/desktop/keyboard/friendly-layout.py @@ -15,8 +15,10 @@ import sys -def key(label, code, width=1, shifted=None, kind="Code", special=False): - return (label, shifted if shifted is not None else label, width, kind, code, special) +def key(label, code, width=1, shifted=None, kind="Code", special=False, forced=None, target=None): + # forced: a modifier the key always sends ("$" is Shift+4); target: the + # layout a Layout key opens. + return (label, shifted if shifted is not None else label, width, kind, code, special, forced, target) def mod(label, code, width=1): @@ -101,6 +103,78 @@ def more(wide=False): return [row1, row2, row3, row4, row5] +# A phone held upright: ten keys across, as on iOS, under a short row of the +# keys a terminal needs. 123 and #+= hold the symbols, each sent as the key +# (and Shift) that types it on a US keyboard, so they work in every app. +PHONE_WIDTH = 10 + + +def typed(text): + plain = {"-": "MINUS", "/": "SLASH", ";": "SEMICOLON", "'": "APOSTROPHE", ".": "DOT", + ",": "COMMA", "[": "LEFTBRACE", "]": "RIGHTBRACE", "=": "EQUAL", "\\": "BACKSLASH", + "`": "GRAVE"} + shifted = {":": "SEMICOLON", "(": "9", ")": "0", "$": "4", "&": "7", "@": "2", '"': "APOSTROPHE", + "?": "SLASH", "!": "1", "_": "MINUS", "|": "BACKSLASH", "{": "LEFTBRACE", + "}": "RIGHTBRACE", "#": "3", "%": "5", "^": "6", "*": "8", "+": "EQUAL", "~": "GRAVE", + "<": "COMMA", ">": "DOT"} + if text in plain: + return "KEY_" + plain[text], None + return "KEY_" + shifted[text], "Shift" + + +def sym(text, width=1): + code, forced = typed(text) + return key(text, code, width, forced=forced) + + +def go(label, target, width): + return key(label, "0", width, kind="Layout", special=True, target=target) + + +phone_tools = [key(label, "KEY_" + code, 1.25, special=True) for label, code in + [("Esc", "ESC"), ("Tab", "TAB")]] + \ + [mod("Ctrl", "Ctrl", 1.25), mod("Alt", "Alt", 1.25)] + \ + [key(label, "KEY_" + code, 1.25, special=True) for label, code in + [("←", "LEFT"), ("↓", "DOWN"), ("↑", "UP"), ("→", "RIGHT")]] +phone_backspace = key("⌫", "KEY_BACKSPACE", 1.5, special=True) +phone_enter = key("Enter", "KEY_ENTER", 2, special=True) +pad = key("", "0", .5, kind="Pad") + + +def phone_bottom(switch, left, right): + return [switch, mod("Super", "Super", 1.25), left, key("space", "KEY_SPACE", 3.5), right, phone_enter] + + +phone = [ + phone_tools, + letters("qwertyuiop"), + [pad] + letters("asdfghjkl") + [pad], + [key("⇧", "Shift", 1.5, shifted="⇫", kind="Mod", special=True)] + letters("zxcvbnm") + [phone_backspace], + phone_bottom(go("123", "PhoneNum", 1.25), sym(","), sym(".")), +] +phone_punctuation = [sym(c, 1.4) for c in ".,?!'"] + [phone_backspace] +phone_num = [ + phone_tools, + [key(c, "KEY_" + c) for c in "1234567890"], + [sym(c) for c in '-/:;()$&@"'], + [go("#+=", "PhoneSym", 1.5)] + phone_punctuation, + phone_bottom(go("ABC", "Phone", 1.25), sym("_"), sym("|")), +] +phone_sym = [ + phone_tools, + [sym(c) for c in "[]{}#%^*+="], + [sym(c) for c in "\\~<>`"] + [key(label, "KEY_" + code, special=True) for label, code in + [("Home", "HOME"), ("End", "END"), ("PgUp", "PAGEUP"), ("PgDn", "PAGEDOWN"), + ("Del", "DELETE")]], + [go("123", "PhoneNum", 1.5)] + phone_punctuation, + phone_bottom(go("ABC", "Phone", 1.25), sym("_"), sym("|")), +] +# Each new layout: its enum name, wvkbd's name for it (-l), and whether it is +# a letters layout. +PHONE_LAYOUTS = {"keys_phone": ("Phone", "phone", True, phone), + "keys_phone_num": ("PhoneNum", "phonenum", False, phone_num), + "keys_phone_sym": ("PhoneSym", "phonesym", False, phone_sym)} + LAYOUTS = {"keys_full": portrait, "keys_special": more(), "keys_landscape": landscape, "keys_landscape_special": more(True)} @@ -136,12 +210,28 @@ def validate(): "Ctrl", "Alt", "Super", "Shift"} <= codes +def validate_phone(): + for name, (_, _, _, rows) in PHONE_LAYOUTS.items(): + assert len(rows) == 5, name + assert rows[0] == phone_tools, name + for row in rows: + assert abs(sum(k[2] for k in row) - PHONE_WIDTH) < .0001, (name, row) + assert rows[-1][-1][4] == "KEY_ENTER" and rows[-1][3][4] == "KEY_SPACE", name + targets = {k[7] for row in rows for k in row if k[3] == "Layout"} + assert targets <= {v[0] for v in PHONE_LAYOUTS.values()}, (name, targets) + codes = {k[4] for rows in (phone, phone_num) for row in rows for k in row} + assert {"KEY_" + c.upper() for c in "abcdefghijklmnopqrstuvwxyz0123456789"} <= codes + assert {"KEY_ESC", "KEY_TAB", "Ctrl", "Alt", "Super", "Shift", "KEY_BACKSPACE", "KEY_ENTER", + "KEY_UP", "KEY_DOWN", "KEY_LEFT", "KEY_RIGHT"} <= codes + + def render(name, rows): lines = ["static struct key " + name + "[] = {"] for row_index, row in enumerate(rows): - for label, shifted, width, kind, code, special in row: + for label, shifted, width, kind, code, special, forced, layout in row: # Index links preserve upstream's international/compose chooser. - target = ", .layout = &layouts[Index]" if kind == "Layout" else "" + target = ", .layout = &layouts[%s]" % (layout or "Index") if kind == "Layout" else "" + target += ", .code_mod = " + forced if forced else "" scheme = (", .scheme = 2" if kind == "Mod" and code == "Super" else ", .scheme = 4" if code in ("KEY_BACKSPACE", "KEY_UP", "KEY_DOWN", "KEY_LEFT", "KEY_RIGHT") else ", .scheme = 3" if code == "KEY_SPACE" else @@ -156,6 +246,69 @@ def render(name, rows): return "\n".join(lines) +# The phone's short top row: this share of a full row's height. +TOOLBAR_ROW = .55 + + +def add_phone(text): + """The phone layouts are new to wvkbd: name them, declare them, list them + and add their keys after the landscape ones.""" + validate_phone() + names = list(PHONE_LAYOUTS) + enum = "".join("\t%s,\n" % PHONE_LAYOUTS[n][0] for n in names) + assert text.count("\tLandscapeSpecial,\n") == 1 + text = text.replace("\tLandscapeSpecial,\n", "\tLandscapeSpecial,\n" + enum) + assert text.count("keys_landscape_special[],") == 1 + text = text.replace("keys_landscape_special[],", "keys_landscape_special[], " + + ", ".join(n + "[]" for n in names) + ",") + marker = ' [LandscapeSpecial] = {keys_landscape_special, "latin", "landscapespecial", true},\n' + assert text.count(marker) == 1 + # The last field: the layout's first row is the short row (add_toolbar_row). + entries = "".join(' [%s] = {%s, "latin", "%s", %s, 0, true},\n' % + (PHONE_LAYOUTS[n][0], n, PHONE_LAYOUTS[n][1], "true" if PHONE_LAYOUTS[n][2] else "false") + for n in names) + text = text.replace(marker, marker + entries) + start = text.index("static struct key keys_landscape_special[] = {") + end = text.index("\n};", start) + len("\n};") + rendered = "\n\n".join(render(n, PHONE_LAYOUTS[n][3]) for n in names) + return text[:end] + "\n\n" + rendered + text[end:] + + +def add_toolbar_row(source): + header = source / "keyboard.h" + text = header.read_text() + marker = "\tuint32_t keyheight; // absolute height (pixels)\n" + assert text.count(marker) == 1 + header.write_text(text.replace(marker, marker + "\tbool toolbar; // Orchard: the first row is a short row\n")) + code = source / "keyboard.c" + text = code.read_text() + old = """ l->keyheight = height / rows; + + struct key *k = l->keys; + double rowlength = kbd_get_row_length(k); + double rowwidth = 0.0; + while (k->type != Last) { + if (k->type == EndRow) { + y += l->keyheight;""" + new = """ /* Orchard: a toolbar layout's first row is %s of a row's height. */ + double units = rows - (l->toolbar ? 1 - %s : 0); + l->keyheight = height / units; + uint32_t rowheight = l->toolbar ? (uint32_t)(l->keyheight * %s) : l->keyheight; + + struct key *k = l->keys; + double rowlength = kbd_get_row_length(k); + double rowwidth = 0.0; + while (k->type != Last) { + if (k->type == EndRow) { + y += rowheight; + rowheight = l->keyheight;""" % (TOOLBAR_ROW, TOOLBAR_ROW, TOOLBAR_ROW) + assert text.count(old) == 1 + text = text.replace(old, new) + old = " k->h = l->keyheight;\n k++;" + assert text.count(old) == 1 + code.write_text(text.replace(old, " k->h = rowheight;\n k++;")) + + def apply(source): validate() layout = source / "layout.mobintl.h" @@ -167,7 +320,9 @@ def apply(source): end = text.index("\n};", start) + len("\n};") text = text[:start] + render(name, rows) + text[end:] text = text.replace("#define KBD_KEY_BORDER 2", "#define KBD_KEY_BORDER 3") + text = add_phone(text) layout.write_text(text) + add_toolbar_row(source) config = source / "config.mobintl.h" text = config.read_text().replace("#define SHIFT_SPACE_IS_TAB", "/* Shift+Space remains a space; Tab has its own key. */") text = text.replace("#define DEFAULT_ROUNDING 5", "#define DEFAULT_ROUNDING 7") @@ -221,6 +376,9 @@ def apply(source): assert '"\ue900", "\ue900"' in rendered assert "Mod, Super, .scheme = 2" in rendered assert "Code, KEY_SPACE, .scheme = 3" in rendered - print("Four five-row layouts: row separators, widths, letters, digits, modifiers and arrows OK") + validate_phone() + for name, (_, _, _, rows) in PHONE_LAYOUTS.items(): + assert render(name, rows).count("EndRow") == 4 + print("Four five-row layouts and three phone layouts: row separators, widths, letters, digits, modifiers and arrows OK") else: apply(Path(sys.argv[1])) diff --git a/desktop/keyboard/wvkbd-0.20-layout.patch b/desktop/keyboard/wvkbd-0.20-layout.patch index a8d59877..91d9261c 100644 --- a/desktop/keyboard/wvkbd-0.20-layout.patch +++ b/desktop/keyboard/wvkbd-0.20-layout.patch @@ -38,7 +38,37 @@ diff -ruN a/keyboard.c b/keyboard.c kb->mods ^= Shift; } else { // normal behaviour: switch to the next layout in the layer sequence -@@ -406,6 +406,9 @@ +@@ -207,14 +207,18 @@ + uint32_t x = 0, y = 0; + uint8_t rows = kbd_get_rows(l); + +- l->keyheight = height / rows; ++ /* Orchard: a toolbar layout's first row is 0.55 of a row's height. */ ++ double units = rows - (l->toolbar ? 1 - 0.55 : 0); ++ l->keyheight = height / units; ++ uint32_t rowheight = l->toolbar ? (uint32_t)(l->keyheight * 0.55) : l->keyheight; + + struct key *k = l->keys; + double rowlength = kbd_get_row_length(k); + double rowwidth = 0.0; + while (k->type != Last) { + if (k->type == EndRow) { +- y += l->keyheight; ++ y += rowheight; ++ rowheight = l->keyheight; + x = 0; + rowwidth = 0.0; + rowlength = kbd_get_row_length(k + 1); +@@ -229,7 +233,7 @@ + x++; + } + } +- k->h = l->keyheight; ++ k->h = rowheight; + k++; + } + } +@@ -406,6 +410,9 @@ void kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) { @@ -48,7 +78,7 @@ diff -ruN a/keyboard.c b/keyboard.c if ((kb->compose == 1) && (k->type != Compose) && (k->type != Mod)) { if ((k->type == NextLayer) || (k->type == BackLayer) || ((k->type == Code) && (k->code == KEY_SPACE))) { -@@ -461,6 +464,19 @@ +@@ -461,6 +468,19 @@ } break; case Mod: @@ -68,7 +98,7 @@ diff -ruN a/keyboard.c b/keyboard.c kb->mods ^= k->code; if (kb->mods & k->code) { if (kb->debug) -@@ -631,6 +647,8 @@ +@@ -631,6 +651,8 @@ { const char *label = ((kb->mods & Shift)||((kb->mods & CapsLock) && strlen(k->label) == 1 && isalpha(k->label[0]))) ? k->shift_label : k->label; @@ -77,7 +107,7 @@ diff -ruN a/keyboard.c b/keyboard.c if (kb->debug) fprintf(stderr, "Draw key +%d+%d %dx%d -> %s\n", k->x, k->y, k->w, k->h, label); -@@ -702,6 +720,7 @@ +@@ -702,6 +724,7 @@ continue; } if ((next_key->type == Mod && kb->mods & next_key->code) || @@ -96,7 +126,15 @@ diff -ruN a/keyboard.h b/keyboard.h enum key_type; enum key_modifier_type; -@@ -108,6 +109,7 @@ +@@ -89,6 +90,7 @@ + const char *name; + bool abc; //is this an alphabetical/abjad layout or not? (i.e. something that is a primary input layout) + uint32_t keyheight; // absolute height (pixels) ++ bool toolbar; // Orchard: the first row is a short row + }; + + struct kbd { +@@ -108,6 +110,7 @@ bool shift_space_is_tab; bool exclusive; uint8_t mods; @@ -116,7 +154,36 @@ diff -ruN a/layout.mobintl.h b/layout.mobintl.h /* layout declarations */ enum layout_id { -@@ -173,75 +173,72 @@ +@@ -26,6 +26,9 @@ + Nav, + Landscape, + LandscapeSpecial, ++ Phone, ++ PhoneNum, ++ PhoneSym, + ComposeA, + ComposeE, + ComposeY, +@@ -70,7 +73,7 @@ + + static struct key keys_full[], keys_full_wide[], keys_special[], keys_specialpad[], keys_simple[], + keys_cyrillic[], keys_arabic[], keys_persian[], keys_georgian[], keys_greek[], keys_hebrew[], +- keys_emoji[], keys_nav[], keys_landscape[], keys_landscape_special[], keys_compose_a[], ++ keys_emoji[], keys_nav[], keys_landscape[], keys_landscape_special[], keys_phone[], keys_phone_num[], keys_phone_sym[], keys_compose_a[], + keys_compose_e[], keys_compose_y[], keys_compose_u[], keys_compose_i[], + keys_compose_o[], keys_compose_w[], keys_compose_r[], keys_compose_t[], + keys_compose_p[], keys_compose_s[], keys_compose_d[], keys_compose_f[], +@@ -102,6 +105,9 @@ + [Nav] = {keys_nav, "latin", "nav", false}, + [Landscape] = {keys_landscape, "latin", "landscape", true}, + [LandscapeSpecial] = {keys_landscape_special, "latin", "landscapespecial", true}, ++ [Phone] = {keys_phone, "latin", "phone", true, 0, true}, ++ [PhoneNum] = {keys_phone_num, "latin", "phonenum", false, 0, true}, ++ [PhoneSym] = {keys_phone_sym, "latin", "phonesym", false, 0, true}, + [ComposeA] = {keys_compose_a, "latin"}, + [ComposeE] = {keys_compose_e, "latin"}, + [ComposeY] = {keys_compose_y, "latin"}, +@@ -173,75 +179,72 @@ * - layout: layout to switch to when key is pressed */ static struct key keys_full[] = { @@ -258,7 +325,7 @@ diff -ruN a/layout.mobintl.h b/layout.mobintl.h }; static struct key keys_full_wide[] = { -@@ -319,62 +316,58 @@ +@@ -319,62 +322,58 @@ }; static struct key keys_special[] = { @@ -373,7 +440,7 @@ diff -ruN a/layout.mobintl.h b/layout.mobintl.h }; static struct key keys_specialpad[] = { -@@ -1102,122 +1095,129 @@ +@@ -1102,122 +1101,279 @@ }; static struct key keys_landscape[] = { @@ -548,18 +615,6 @@ diff -ruN a/layout.mobintl.h b/layout.mobintl.h - {"", "", 0.5, Pad, .scheme = 1}, - {"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1}, - {"", "", 0.0, EndRow}, -- -- {"Abc", "Abc", 1.0, BackLayer, .scheme = 1}, -- {"⌨͕", "⌨͔", 1.0, NextLayer, .scheme = 1}, -- {"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1}, -- {"Sup", "Sup", 1.0, Mod, Super, .scheme = 1}, -- {"", "Tab", 5.0, Code, KEY_SPACE}, -- {"Alt", "Alt", 1.0, Mod, Alt, .scheme = 1}, -- {"AGr", "AGr", 1.0, Mod, AltGr, .scheme = 1}, -- {"Enter", "Enter", 2.0, Code, KEY_ENTER, .scheme = 1}, -- -- /* end of layout */ -- {"", "", 0.0, Last}, + {"F1", "F1", 1.25, Code, KEY_F1, .scheme = 1}, + {"F2", "F2", 1.25, Code, KEY_F2, .scheme = 1}, + {"F3", "F3", 1.25, Code, KEY_F3, .scheme = 1}, @@ -612,6 +667,166 @@ diff -ruN a/layout.mobintl.h b/layout.mobintl.h + {"←", "←", 1, Code, KEY_LEFT, .scheme = 4}, + {"↓", "↓", 1, Code, KEY_DOWN, .scheme = 4}, + {"→", "→", 1, Code, KEY_RIGHT, .scheme = 4}, ++ {"", "", 0, Last}, ++}; ++ ++static struct key keys_phone[] = { ++ {"Esc", "Esc", 1.25, Code, KEY_ESC, .scheme = 1}, ++ {"Tab", "Tab", 1.25, Code, KEY_TAB, .scheme = 1}, ++ {"Ctrl", "Ctrl", 1.25, Mod, Ctrl, .scheme = 1}, ++ {"Alt", "Alt", 1.25, Mod, Alt, .scheme = 1}, ++ {"←", "←", 1.25, Code, KEY_LEFT, .scheme = 4}, ++ {"↓", "↓", 1.25, Code, KEY_DOWN, .scheme = 4}, ++ {"↑", "↑", 1.25, Code, KEY_UP, .scheme = 4}, ++ {"→", "→", 1.25, Code, KEY_RIGHT, .scheme = 4}, ++ {"", "", 0, EndRow}, ++ {"q", "Q", 1, Code, KEY_Q}, ++ {"w", "W", 1, Code, KEY_W}, ++ {"e", "E", 1, Code, KEY_E}, ++ {"r", "R", 1, Code, KEY_R}, ++ {"t", "T", 1, Code, KEY_T}, ++ {"y", "Y", 1, Code, KEY_Y}, ++ {"u", "U", 1, Code, KEY_U}, ++ {"i", "I", 1, Code, KEY_I}, ++ {"o", "O", 1, Code, KEY_O}, ++ {"p", "P", 1, Code, KEY_P}, ++ {"", "", 0, EndRow}, ++ {"", "", 0.5, Pad, 0}, ++ {"a", "A", 1, Code, KEY_A}, ++ {"s", "S", 1, Code, KEY_S}, ++ {"d", "D", 1, Code, KEY_D}, ++ {"f", "F", 1, Code, KEY_F}, ++ {"g", "G", 1, Code, KEY_G}, ++ {"h", "H", 1, Code, KEY_H}, ++ {"j", "J", 1, Code, KEY_J}, ++ {"k", "K", 1, Code, KEY_K}, ++ {"l", "L", 1, Code, KEY_L}, ++ {"", "", 0.5, Pad, 0}, ++ {"", "", 0, EndRow}, ++ {"⇧", "⇫", 1.5, Mod, Shift, .scheme = 1}, ++ {"z", "Z", 1, Code, KEY_Z}, ++ {"x", "X", 1, Code, KEY_X}, ++ {"c", "C", 1, Code, KEY_C}, ++ {"v", "V", 1, Code, KEY_V}, ++ {"b", "B", 1, Code, KEY_B}, ++ {"n", "N", 1, Code, KEY_N}, ++ {"m", "M", 1, Code, KEY_M}, ++ {"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 4}, ++ {"", "", 0, EndRow}, ++ {"123", "123", 1.25, Layout, 0, .layout = &layouts[PhoneNum], .scheme = 1}, ++ {"", "", 1.25, Mod, Super, .scheme = 2}, ++ {",", ",", 1, Code, KEY_COMMA}, ++ {"space", "space", 3.5, Code, KEY_SPACE, .scheme = 3}, ++ {".", ".", 1, Code, KEY_DOT}, ++ {"Enter", "Enter", 2, Code, KEY_ENTER, .scheme = 1}, ++ {"", "", 0, Last}, ++}; + +- {"Abc", "Abc", 1.0, BackLayer, .scheme = 1}, +- {"⌨͕", "⌨͔", 1.0, NextLayer, .scheme = 1}, +- {"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1}, +- {"Sup", "Sup", 1.0, Mod, Super, .scheme = 1}, +- {"", "Tab", 5.0, Code, KEY_SPACE}, +- {"Alt", "Alt", 1.0, Mod, Alt, .scheme = 1}, +- {"AGr", "AGr", 1.0, Mod, AltGr, .scheme = 1}, +- {"Enter", "Enter", 2.0, Code, KEY_ENTER, .scheme = 1}, ++static struct key keys_phone_num[] = { ++ {"Esc", "Esc", 1.25, Code, KEY_ESC, .scheme = 1}, ++ {"Tab", "Tab", 1.25, Code, KEY_TAB, .scheme = 1}, ++ {"Ctrl", "Ctrl", 1.25, Mod, Ctrl, .scheme = 1}, ++ {"Alt", "Alt", 1.25, Mod, Alt, .scheme = 1}, ++ {"←", "←", 1.25, Code, KEY_LEFT, .scheme = 4}, ++ {"↓", "↓", 1.25, Code, KEY_DOWN, .scheme = 4}, ++ {"↑", "↑", 1.25, Code, KEY_UP, .scheme = 4}, ++ {"→", "→", 1.25, Code, KEY_RIGHT, .scheme = 4}, ++ {"", "", 0, EndRow}, ++ {"1", "1", 1, Code, KEY_1}, ++ {"2", "2", 1, Code, KEY_2}, ++ {"3", "3", 1, Code, KEY_3}, ++ {"4", "4", 1, Code, KEY_4}, ++ {"5", "5", 1, Code, KEY_5}, ++ {"6", "6", 1, Code, KEY_6}, ++ {"7", "7", 1, Code, KEY_7}, ++ {"8", "8", 1, Code, KEY_8}, ++ {"9", "9", 1, Code, KEY_9}, ++ {"0", "0", 1, Code, KEY_0}, ++ {"", "", 0, EndRow}, ++ {"-", "-", 1, Code, KEY_MINUS}, ++ {"/", "/", 1, Code, KEY_SLASH}, ++ {":", ":", 1, Code, KEY_SEMICOLON, .code_mod = Shift}, ++ {";", ";", 1, Code, KEY_SEMICOLON}, ++ {"(", "(", 1, Code, KEY_9, .code_mod = Shift}, ++ {")", ")", 1, Code, KEY_0, .code_mod = Shift}, ++ {"$", "$", 1, Code, KEY_4, .code_mod = Shift}, ++ {"&", "&", 1, Code, KEY_7, .code_mod = Shift}, ++ {"@", "@", 1, Code, KEY_2, .code_mod = Shift}, ++ {"\"", "\"", 1, Code, KEY_APOSTROPHE, .code_mod = Shift}, ++ {"", "", 0, EndRow}, ++ {"#+=", "#+=", 1.5, Layout, 0, .layout = &layouts[PhoneSym], .scheme = 1}, ++ {".", ".", 1.4, Code, KEY_DOT}, ++ {",", ",", 1.4, Code, KEY_COMMA}, ++ {"?", "?", 1.4, Code, KEY_SLASH, .code_mod = Shift}, ++ {"!", "!", 1.4, Code, KEY_1, .code_mod = Shift}, ++ {"'", "'", 1.4, Code, KEY_APOSTROPHE}, ++ {"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 4}, ++ {"", "", 0, EndRow}, ++ {"ABC", "ABC", 1.25, Layout, 0, .layout = &layouts[Phone], .scheme = 1}, ++ {"", "", 1.25, Mod, Super, .scheme = 2}, ++ {"_", "_", 1, Code, KEY_MINUS, .code_mod = Shift}, ++ {"space", "space", 3.5, Code, KEY_SPACE, .scheme = 3}, ++ {"|", "|", 1, Code, KEY_BACKSLASH, .code_mod = Shift}, ++ {"Enter", "Enter", 2, Code, KEY_ENTER, .scheme = 1}, ++ {"", "", 0, Last}, ++}; + +- /* end of layout */ +- {"", "", 0.0, Last}, ++static struct key keys_phone_sym[] = { ++ {"Esc", "Esc", 1.25, Code, KEY_ESC, .scheme = 1}, ++ {"Tab", "Tab", 1.25, Code, KEY_TAB, .scheme = 1}, ++ {"Ctrl", "Ctrl", 1.25, Mod, Ctrl, .scheme = 1}, ++ {"Alt", "Alt", 1.25, Mod, Alt, .scheme = 1}, ++ {"←", "←", 1.25, Code, KEY_LEFT, .scheme = 4}, ++ {"↓", "↓", 1.25, Code, KEY_DOWN, .scheme = 4}, ++ {"↑", "↑", 1.25, Code, KEY_UP, .scheme = 4}, ++ {"→", "→", 1.25, Code, KEY_RIGHT, .scheme = 4}, ++ {"", "", 0, EndRow}, ++ {"[", "[", 1, Code, KEY_LEFTBRACE}, ++ {"]", "]", 1, Code, KEY_RIGHTBRACE}, ++ {"{", "{", 1, Code, KEY_LEFTBRACE, .code_mod = Shift}, ++ {"}", "}", 1, Code, KEY_RIGHTBRACE, .code_mod = Shift}, ++ {"#", "#", 1, Code, KEY_3, .code_mod = Shift}, ++ {"%", "%", 1, Code, KEY_5, .code_mod = Shift}, ++ {"^", "^", 1, Code, KEY_6, .code_mod = Shift}, ++ {"*", "*", 1, Code, KEY_8, .code_mod = Shift}, ++ {"+", "+", 1, Code, KEY_EQUAL, .code_mod = Shift}, ++ {"=", "=", 1, Code, KEY_EQUAL}, ++ {"", "", 0, EndRow}, ++ {"\\", "\\", 1, Code, KEY_BACKSLASH}, ++ {"~", "~", 1, Code, KEY_GRAVE, .code_mod = Shift}, ++ {"<", "<", 1, Code, KEY_COMMA, .code_mod = Shift}, ++ {">", ">", 1, Code, KEY_DOT, .code_mod = Shift}, ++ {"`", "`", 1, Code, KEY_GRAVE}, ++ {"Home", "Home", 1, Code, KEY_HOME, .scheme = 1}, ++ {"End", "End", 1, Code, KEY_END, .scheme = 1}, ++ {"PgUp", "PgUp", 1, Code, KEY_PAGEUP, .scheme = 1}, ++ {"PgDn", "PgDn", 1, Code, KEY_PAGEDOWN, .scheme = 1}, ++ {"Del", "Del", 1, Code, KEY_DELETE, .scheme = 1}, ++ {"", "", 0, EndRow}, ++ {"123", "123", 1.5, Layout, 0, .layout = &layouts[PhoneNum], .scheme = 1}, ++ {".", ".", 1.4, Code, KEY_DOT}, ++ {",", ",", 1.4, Code, KEY_COMMA}, ++ {"?", "?", 1.4, Code, KEY_SLASH, .code_mod = Shift}, ++ {"!", "!", 1.4, Code, KEY_1, .code_mod = Shift}, ++ {"'", "'", 1.4, Code, KEY_APOSTROPHE}, ++ {"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 4}, ++ {"", "", 0, EndRow}, ++ {"ABC", "ABC", 1.25, Layout, 0, .layout = &layouts[Phone], .scheme = 1}, ++ {"", "", 1.25, Mod, Super, .scheme = 2}, ++ {"_", "_", 1, Code, KEY_MINUS, .code_mod = Shift}, ++ {"space", "space", 3.5, Code, KEY_SPACE, .scheme = 3}, ++ {"|", "|", 1, Code, KEY_BACKSLASH, .code_mod = Shift}, ++ {"Enter", "Enter", 2, Code, KEY_ENTER, .scheme = 1}, + {"", "", 0, Last}, }; diff --git a/desktop/shell/bin/omarchy-keyboard b/desktop/shell/bin/omarchy-keyboard index 857a211e..67ea0b1c 100644 --- a/desktop/shell/bin/omarchy-keyboard +++ b/desktop/shell/bin/omarchy-keyboard @@ -265,6 +265,23 @@ def listen(): policy.tick() +def phone(): + """A phone: the screen's short side under 480 logical pixels, the width + under which the shell lays itself out as on a phone too.""" + import json + try: + outputs = json.loads(subprocess.run(["wlr-randr", "--json"], capture_output=True, + text=True, timeout=5).stdout) + except (OSError, ValueError, subprocess.SubprocessError): + return False + for output in outputs: + mode = next((m for m in output.get("modes", []) if m.get("current")), None) + scale = output.get("scale") or 1 + if output.get("enabled") and mode and scale > 0: + return min(mode["width"], mode["height"]) / scale < 480 + return False + + def run(): import tomllib if (pid := live_pid()) and pid != os.getpid(): @@ -280,6 +297,10 @@ def run(): "--fg-sp", color("selection"), "--press", color("accent"), "--press-sp", color("accent"), "--text", color("foreground"), "--text-sp", color("bright_foreground", "foreground")] + # Upright on a phone: ten keys across under a short row of terminal keys, + # and 123 and #+= for the rest (desktop/keyboard/friendly-layout.py). + if phone(): + args += ["-l", "phone,phonenum,phonesym"] state_file.write_text("0\n") pid_file.write_text(str(os.getpid()) + "\n") os.environ["WVKBD_STATE_FILE"] = str(state_file) diff --git a/tests/test_keyboard_policy.py b/tests/test_keyboard_policy.py index aeebb4c3..f8a6fbaa 100644 --- a/tests/test_keyboard_policy.py +++ b/tests/test_keyboard_policy.py @@ -267,5 +267,33 @@ def test_a_bad_line_is_ignored(self): self.assertEqual(self.calls, []) +class PhoneLayoutTests(unittest.TestCase): + """A phone-width screen starts the keyboard with the phone layers.""" + + def phone(self, width, height, scale): + module = load() + import json + import subprocess + output = [{'name': 'DSI-1', 'enabled': True, 'scale': scale, + 'modes': [{'width': width, 'height': height, 'current': True}]}] + from unittest import mock + result = subprocess.CompletedProcess([], 0, stdout=json.dumps(output)) + with mock.patch.object(module.subprocess, 'run', return_value=result): + return module.phone() + + def test_phone_width_screens_are_phones(self): + self.assertTrue(self.phone(640, 1136, 2)) # iPod touch 6 + self.assertTrue(self.phone(1334, 750, 2)) # iPhone 7, turned + self.assertTrue(self.phone(1125, 2436, 3)) # iPhone X + self.assertFalse(self.phone(1536, 2048, 2)) # iPad + self.assertFalse(self.phone(750, 1334, 1)) # a phone at scale 1 is as wide as a small tablet + + def test_the_layers_exist_in_the_layout(self): + layout = (PROJECT / 'desktop/keyboard/wvkbd-0.20-layout.patch').read_text() + for name in ('phone', 'phonenum', 'phonesym'): + self.assertIn('"latin", "%s"' % name, layout) + self.assertIn('"-l", "phone,phonenum,phonesym"', SCRIPT.read_text()) + + if __name__ == '__main__': unittest.main()