code wiki / _hdl_build / nx_x11_keyboard_gate.nx
nx_x11_keyboard_gate.nx source
↩ module page · 101 lines · 4877 B
1// nx_x11_keyboard_gate.nx -- proves the keysym -> browser-vk fold (the codes nx_input_abstract
2// binds), the GetKeyboardMapping request bytes, and the SendEvent(Key) frame layout -- all pure,
3// no server. The live keymap fetch + synthetic-key round trip are proven by nx_desktop_breeders
4// --selftest against the real X server.
5// license_tier: ORIGINAL expect_exit: 0
6import "nx_x11_keyboard.nx"
7import "nx_gate_verdict.nx"
8
9func vw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
10func vn(v: i64) -> i64 {
11 let t: *u8 = sys_mmap(32) as *u8
12 var m: i64 = v; var w: i64 = 0
13 if m<0 { t[w]=45 as u8; w=w+1; m=0-m }
14 if m==0 { t[w]=48 as u8; sys_write(1,t,w+1); return 0 }
15 let d: *u8 = sys_mmap(32) as *u8
16 var k: i64=0
17 while m>0 { d[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
18 var j: i64=0
19 while j<k { t[w]=d[k-1-j]; w=w+1; j=j+1 }
20 sys_write(1,t,w); return 0
21}
22
23func main() -> i64 {
24 var pass: i64 = 0
25 let total: i64 = 5
26 vw("=== nx_x11_keyboard gate (keysym fold + wire frames) ===\n" as *u8)
27
28 // T1 letter fold: lowercase keysyms land on the vk codes the input layer binds
29 var t1: i64 = 0
30 if nx_keysym_to_vk(0x77) == 87 { t1 = t1 + 1 } // w -> W
31 if nx_keysym_to_vk(0x61) == 65 { t1 = t1 + 1 } // a -> A
32 if nx_keysym_to_vk(0x73) == 83 { t1 = t1 + 1 } // s -> S
33 if nx_keysym_to_vk(0x64) == 68 { t1 = t1 + 1 } // d -> D
34 if nx_keysym_to_vk(0x65) == 69 { t1 = t1 + 1 } // e -> E (interact)
35 if nx_keysym_to_vk(0x62) == 66 { t1 = t1 + 1 } // b -> B (breed)
36 if nx_keysym_to_vk(0x57) == 87 { t1 = t1 + 1 } // already-uppercase W
37 vw("T1 letters: " as *u8); vn(t1); vw("/7\n" as *u8)
38 if t1 == 7 { pass = pass + 1 }
39
40 // T2 specials: arrows / space / enter / escape / digits
41 var t2: i64 = 0
42 if nx_keysym_to_vk(0xFF51) == 37 { t2 = t2 + 1 }
43 if nx_keysym_to_vk(0xFF52) == 38 { t2 = t2 + 1 }
44 if nx_keysym_to_vk(0xFF53) == 39 { t2 = t2 + 1 }
45 if nx_keysym_to_vk(0xFF54) == 40 { t2 = t2 + 1 }
46 if nx_keysym_to_vk(0x20) == 32 { t2 = t2 + 1 }
47 if nx_keysym_to_vk(0xFF0D) == 13 { t2 = t2 + 1 }
48 if nx_keysym_to_vk(0xFF1B) == 27 { t2 = t2 + 1 }
49 if nx_keysym_to_vk(0x30) == 48 { t2 = t2 + 1 }
50 if nx_keysym_to_vk(0x39) == 57 { t2 = t2 + 1 }
51 vw("T2 specials+digits: " as *u8); vn(t2); vw("/9\n" as *u8)
52 if t2 == 9 { pass = pass + 1 }
53
54 // T3 unmapped keysyms are 0, never a garbage vk (Shift_L, comma, F1)
55 var t3: i64 = 0
56 if nx_keysym_to_vk(0xFFE1) == 0 { t3 = t3 + 1 }
57 if nx_keysym_to_vk(0x2C) == 0 { t3 = t3 + 1 }
58 if nx_keysym_to_vk(0xFFBE) == 0 { t3 = t3 + 1 }
59 vw("T3 unmapped->0: " as *u8); vn(t3); vw("/3\n" as *u8)
60 if t3 == 3 { pass = pass + 1 }
61
62 // T4 GetKeyboardMapping request bytes exact
63 let req: *u8 = sys_mmap(16)
64 nx_x11_keymap_req(req, 8, 248)
65 var t4: i64 = 0
66 if (req[0] & 0xff) == 101 { t4 = t4 + 1 }
67 if (req[2] & 0xff) == 2 { if (req[3] & 0xff) == 0 { t4 = t4 + 1 } }
68 if (req[4] & 0xff) == 8 { t4 = t4 + 1 }
69 if (req[5] & 0xff) == 248 { t4 = t4 + 1 }
70 vw("T4 keymap request: " as *u8); vn(t4); vw("/4\n" as *u8)
71 if t4 == 4 { pass = pass + 1 }
72
73 // T5 SendEvent(Key) frame: opcode/len/destination/type/detail/same-screen, press vs release
74 let sk: *u8 = sys_mmap(64)
75 let n: i64 = nx_x11_send_key_req(sk, 0x0A0B0C0D, 0x01020304, 40, 1)
76 var t5: i64 = 0
77 if n == 44 { t5 = t5 + 1 }
78 if (sk[0] & 0xff) == 25 { t5 = t5 + 1 }
79 if (sk[2] & 0xff) == 11 { if (sk[3] & 0xff) == 0 { t5 = t5 + 1 } }
80 if (sk[4] & 0xff) == 0x04 { if (sk[7] & 0xff) == 0x01 { t5 = t5 + 1 } }
81 if (sk[12] & 0xff) == 2 { t5 = t5 + 1 } // KeyPress
82 if (sk[13] & 0xff) == 40 { t5 = t5 + 1 } // keycode
83 if (sk[20] & 0xff) == 0x0D { t5 = t5 + 1 } // root LE
84 if (sk[24] & 0xff) == 0x04 { t5 = t5 + 1 } // event window LE
85 if (sk[42] & 0xff) == 1 { t5 = t5 + 1 } // same-screen
86 nx_x11_send_key_req(sk, 0x0A0B0C0D, 0x01020304, 40, 0)
87 if (sk[12] & 0xff) == 3 { t5 = t5 + 1 } // KeyRelease
88 vw("T5 SendEvent frame: " as *u8); vn(t5); vw("/10\n" as *u8)
89 if t5 == 10 { pass = pass + 1 }
90
91 vw("nx_x11_keyboard_gate: " as *u8); vn(pass); vw("/" as *u8); vn(total); vw("\n" as *u8)
92 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
93 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
94 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
95 let ctr__dry: *i64 = gv_ctr()
96 ctr__dry[0] = pass
97 ctr__dry[1] = total
98 let rc__dry: i64 = gv_verdict("X11-KEYBOARD-GATE" as *u8, ctr__dry, "keysym fold + keyboard wire frames spec-exact" as *u8)
99 sys_exit(rc__dry)
100 return rc__dry
101}