Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/hop/blob/main/Linux/window.om # hop Hop: a small native macOS launcher. Clipboard history, find, on-device dictation and your coding agent behind one key. Brought by drakestapleton Sign in to star 1 stars 1 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `hop / Linux / window.om` 948 lines ยท 16921 bytes Raw Blame History 1 om2 2 note Hop Linux desktop boundary. X11 requests are emitted directly from Omega; no UI host library. 3 note X Consortium X11 protocol release 7.7, chapters 8/9/11 and Appendix B. 4 note X11 core fonts render Latin-1. Unicode input is retained as UTF-8; unrenderable glyphs show ?. Native Wayland is not implied. 5 note Color names below map to aienos-brand/reference/tokens.json dark theme. No display polling service is installed. 6 const lx_bg ulong 0x0a0a0f 7 const lx_card ulong 0x14141f 8 const lx_ink ulong 0xffffff 9 const lx_accent ulong 0x2563eb 10 const lx_muted ulong 0x88888b 11 global lx_query uchar * 12 global lx_rows uchar * 13 global lx_qn ulong 1 14 global lx_rn ulong 1 15 global lx_pick ulong 1 16 global lx_fd long 1 17 global lx_s ulong 32 18 global lx_buf uchar * 19 global lx_auth uchar * 20 global lx_keys uchar * 21 global lx_host uchar * 22 global lx_hn ulong 2 23 global lx_req uchar 512 24 global lx_env uchar 4096 25 global lx_path uchar 4096 26 global lx_addr uchar 110 27 global lx_piece uchar 256 28 text lx_display "DISPLAY=" 29 text lx_xauth "XAUTHORITY=" 30 text lx_home "HOME=" 31 text lx_local "/tmp/.X11-unix/X" 32 text lx_dotauth "/.Xauthority" 33 text lx_cookie "MIT-MAGIC-COOKIE-1" 34 text lx_hostname "/proc/sys/kernel/hostname" 35 text lx_name "Hop" 36 text lx_font "fixed" 37 text lx_wmp "WM_PROTOCOLS" 38 text lx_wmd "WM_DELETE_WINDOW" 39 text lx_hint "Type to find an app, a file, or ask a question" 40 text lx_help "Up / Down choose Enter opens Escape closes" 41 text lx_errdisp "Hop: open it from a Linux desktop (DISPLAY is missing or is not a local X11 display).\n" 42 text lx_errsock "Hop: cannot connect to the desktop display.\n" 43 text lx_errauth "Hop: the desktop refused its X11 login. Check DISPLAY and XAUTHORITY.\n" 44 text lx_errwire "Hop: the desktop connection ended or returned an invalid response.\n" 45 text lx_errmem "Hop: the system could not allocate memory for the desktop.\n" 46 47 fn lx_bad to void 48 k = write 2 lx_errwire 0 len lx_errwire 49 exit 1 50 end 51 fn lx_grow n ulong to void 52 r = enlarge lx_buf n 53 if lt r 0 54 k = write 2 lx_errmem 0 len lx_errmem 55 exit 1 56 end 57 end 58 fn lx_u16 o ulong to ulong 59 ret or ulong get lx_buf o shl ulong get lx_buf add o 1 8 60 end 61 fn lx_u32 o ulong to ulong 62 ret or lx_u16 o shl lx_u16 add o 2 16 63 end 64 fn lx_a16 o ulong to ulong 65 ret or shl ulong get lx_auth o 8 ulong get lx_auth add o 1 66 end 67 fn lx_p16 o ulong v ulong to void 68 put lx_req o uchar and v 255 69 put lx_req add o 1 uchar and shr v 8 255 70 end 71 fn lx_p32 o ulong v ulong to void 72 lx_p16 o v 73 lx_p16 add o 2 shr v 16 74 end 75 fn lx_request op uchar n ulong to void 76 for i ulong n bound 512 77 put lx_req i 0 78 end 79 put lx_req 0 op 80 lx_p16 2 div n 4 81 end 82 fn lx_send n ulong to void 83 p = ulong 0 84 while lt p n bound `9223372036854775807` 85 k = send int get lx_fd 0 lx_req p sub n p 0 86 if eq k -4 87 continue 88 end 89 if le k 0 90 lx_bad 91 end 92 p = add p ulong k 93 end 94 end 95 fn lx_read off ulong n ulong to void 96 lx_grow add off n 97 p = ulong 0 98 while lt p n bound `9223372036854775807` 99 k = read int get lx_fd 0 lx_buf add off p sub n p 100 if eq k -4 101 continue 102 end 103 if le k 0 104 lx_bad 105 end 106 p = add p ulong k 107 end 108 end 109 fn lx_reply to void 110 while true bound `9223372036854775807` 111 lx_read 0 32 112 kind = and get lx_buf 0 127 113 if eq kind 0 114 lx_bad 115 end 116 if eq kind 1 117 n = mul lx_u32 4 4 118 lx_read 32 n 119 ret 120 end 121 end 122 end 123 fn lx_envget key view uchar * to ulong 124 for i ulong ulong envcnt bound `9223372036854775807` 125 n = envread i lx_env 0 len lx_env 126 if ge n long len key 127 ok = true 128 for j ulong len key bound 4096 129 if ne get key j get lx_env j 130 ok = false 131 end 132 end 133 if ok 134 count = sub ulong n len key 135 for j ulong count bound 4096 136 put lx_path j get lx_env add len key j 137 end 138 ret count 139 end 140 end 141 end 142 ret 0 143 end 144 fn lx_number n ulong to ulong 145 v = ulong 0 146 i = ulong 0 147 if and ge n 5 eq get lx_path 0 117 148 note unix: and unix/: are local display spellings 149 if and eq get lx_path 1 110 eq get lx_path 2 105 150 if eq get lx_path 3 120 151 i = 4 152 if eq get lx_path 4 47 153 i = 5 154 end 155 end 156 end 157 end 158 if ge i n 159 ret 0 160 end 161 if ne get lx_path i 58 162 ret 0 163 end 164 i = add i 1 165 start = i 166 while lt i n bound 4096 167 c = get lx_path i 168 if eq c 46 169 break 170 end 171 if or lt c 48 gt c 57 172 ret 0 173 end 174 if gt v 999999 175 ret 0 176 end 177 v = add mul v 10 ulong sub c 48 178 i = add i 1 179 end 180 if eq start i 181 ret 0 182 end 183 put lx_s 24 v 184 put lx_s 25 sub i start 185 for j ulong sub i start bound 4096 186 put lx_piece j get lx_path add start j 187 end 188 screen = ulong 0 189 if lt i n 190 i = add i 1 191 if eq i n 192 ret 0 193 end 194 while lt i n bound 4096 195 c = get lx_path i 196 if or lt c 48 gt c 57 197 ret 0 198 end 199 if gt screen 999999 200 ret 0 201 end 202 screen = add mul screen 10 ulong sub c 48 203 i = add i 1 204 end 205 end 206 put lx_s 26 screen 207 ret 1 208 end 209 note FamilyLocal credentials name this machine, not merely a display number. The kernel hostname is read once per authority scan. 210 note FamilyWild explicitly bypasses the address match, as before; display and authentication-scheme checks remain in force. 211 fn lx_loadhost to void 212 put lx_hn 0 0 213 put lx_hn 1 0 214 fd = fopen lx_hostname 0 len lx_hostname 0 0 215 if lt fd 0 216 ret 217 end 218 used = ulong 0 219 while true bound `9223372036854775807` 220 r = enlarge lx_host add used 256 221 if lt r 0 222 k = fclose int fd 223 ret 224 end 225 k = read int fd lx_host used 256 226 if eq k -4 227 continue 228 end 229 if lt k 0 230 k = fclose int fd 231 ret 232 end 233 if eq k 0 234 break 235 end 236 used = add used ulong k 237 end 238 k = fclose int fd 239 note proc appends exactly one line feed; remove that delimiter, preserving any line feed in the hostname itself. 240 if gt used 0 241 if eq get lx_host sub used 1 10 242 used = sub used 1 243 end 244 end 245 put lx_hn 0 used 246 put lx_hn 1 1 247 end 248 fn lx_hostmatch offset ulong size ulong to bool 249 if eq get lx_hn 1 0 250 ret false 251 end 252 if ne size get lx_hn 0 253 ret false 254 end 255 for i ulong size bound 65536 256 if ne get lx_auth add offset i get lx_host i 257 ret false 258 end 259 end 260 ret true 261 end 262 fn lx_findauth n ulong to ulong 263 lx_loadhost 264 p = ulong 0 265 while lt p n bound `9223372036854775807` 266 if gt add p 2 n 267 ret 0 268 end 269 family = lx_a16 p 270 p = add p 2 271 ok = or eq family 256 eq family 65535 272 for fld ulong 4 bound 4 273 if gt add p 2 n 274 ret 0 275 end 276 size = lx_a16 p 277 p = add p 2 278 if gt add p size n 279 ret 0 280 end 281 if and eq fld 0 eq family 256 282 if not lx_hostmatch p size 283 ok = false 284 end 285 end 286 if eq fld 1 287 if ne size get lx_s 25 288 ok = false 289 else 290 for j ulong size bound 65536 291 if ne get lx_auth add p j get lx_piece j 292 ok = false 293 end 294 end 295 end 296 end 297 if eq fld 2 298 if ne size len lx_cookie 299 ok = false 300 else 301 for j ulong size bound 65536 302 if ne get lx_auth add p j get lx_cookie j 303 ok = false 304 end 305 end 306 end 307 end 308 if eq fld 3 309 if and ok eq size 16 310 put lx_s 27 p 311 ret size 312 end 313 end 314 p = add p size 315 end 316 end 317 ret 0 318 end 319 fn lx_authload to ulong 320 n = lx_envget lx_xauth 321 if eq n 0 322 n = lx_envget lx_home 323 if eq n 0 324 ret 0 325 end 326 if gt add n len lx_dotauth 4095 327 ret 0 328 end 329 for i ulong len lx_dotauth bound 32 330 put lx_path add n i get lx_dotauth i 331 end 332 n = add n len lx_dotauth 333 end 334 fd = fopen lx_path 0 n 0 0 335 if lt fd 0 336 ret 0 337 end 338 used = ulong 0 339 while true bound `9223372036854775807` 340 r = enlarge lx_auth add used 4096 341 if lt r 0 342 k = fclose int fd 343 ret 0 344 end 345 k = read int fd lx_auth used 4096 346 if eq k -4 347 continue 348 end 349 if le k 0 350 break 351 end 352 used = add used ulong k 353 end 354 k = fclose int fd 355 ret lx_findauth used 356 end 357 fn lx_setup to int 358 n = lx_envget lx_display 359 if eq n 0 360 k = write 2 lx_errdisp 0 len lx_errdisp 361 ret 1 362 end 363 if eq lx_number n 0 364 k = write 2 lx_errdisp 0 len lx_errdisp 365 ret 1 366 end 367 for i ulong len lx_local bound 32 368 put lx_addr add i 2 get lx_local i 369 end 370 for i ulong get lx_s 25 bound 16 371 put lx_addr add add 2 len lx_local i get lx_piece i 372 end 373 put lx_addr 0 1 374 n = add add 3 len lx_local get lx_s 25 375 fd = socknew 1 1 0 376 if lt fd 0 377 k = write 2 lx_errsock 0 len lx_errsock 378 ret 1 379 end 380 put lx_fd 0 fd 381 r = connect int fd lx_addr 0 n 382 if lt r 0 383 k = write 2 lx_errsock 0 len lx_errsock 384 k = fclose int fd 385 ret 1 386 end 387 an = lx_authload 388 lx_request 108 48 389 lx_p16 2 11 390 lx_p16 4 0 391 if gt an 0 392 lx_p16 6 len lx_cookie 393 lx_p16 8 an 394 for i ulong len lx_cookie bound 32 395 put lx_req add 12 i get lx_cookie i 396 end 397 for i ulong an bound 32 398 put lx_req add 32 i get lx_auth add get lx_s 27 i 399 end 400 lx_send 48 401 else 402 lx_send 12 403 end 404 lx_read 0 8 405 if ne get lx_buf 0 1 406 k = write 2 lx_errauth 0 len lx_errauth 407 k = fclose int fd 408 ret 1 409 end 410 n = mul lx_u16 6 4 411 lx_read 0 n 412 ret lx_screen n 413 end 414 fn lx_screen n ulong to int 415 if lt n 32 416 lx_bad 417 end 418 put lx_s 7 lx_u32 4 419 put lx_s 8 lx_u32 8 420 put lx_s 13 ulong get lx_buf 26 421 put lx_s 14 ulong get lx_buf 27 422 roots = ulong get lx_buf 20 423 if ge get lx_s 26 roots 424 lx_bad 425 end 426 p = add 32 mul div add lx_u16 16 3 4 4 427 p = add p mul ulong get lx_buf 21 8 428 for screen ulong add get lx_s 26 1 bound 65536 429 if gt add p 40 n 430 lx_bad 431 end 432 if eq screen get lx_s 26 433 put lx_s 4 lx_u32 p 434 put lx_s 16 lx_u16 add p 20 435 put lx_s 17 lx_u16 add p 22 436 ret 0 437 end 438 depths = ulong get lx_buf add p 39 439 p = add p 40 440 for j ulong depths bound 256 441 if gt add p 8 n 442 lx_bad 443 end 444 p = add add p 8 mul lx_u16 add p 2 24 445 end 446 end 447 ret 1 448 end 449 fn lx_id k ulong to ulong 450 v = get lx_s 7 451 mask = get lx_s 8 452 bit = ulong 1 453 for i ulong 32 bound 32 454 if ne and mask shl ulong 1 i 0 455 if ne and k bit 0 456 v = or v shl ulong 1 i 457 end 458 bit = shl bit 1 459 end 460 end 461 ret v 462 end 463 fn lx_atom name view uchar * to ulong 464 n = mul div add add 8 len name 3 4 4 465 lx_request 16 n 466 lx_p16 4 len name 467 for i ulong len name bound 256 468 put lx_req add 8 i get name i 469 end 470 lx_send n 471 lx_reply 472 ret lx_u32 8 473 end 474 fn lx_property atom ulong ty ulong fmt uchar data ulong n ulong to void 475 lx_request 18 28 476 lx_p32 4 get lx_s 1 477 lx_p32 8 atom 478 lx_p32 12 ty 479 put lx_req 16 fmt 480 lx_p32 20 n 481 lx_p32 24 data 482 lx_send 28 483 end 484 fn lx_color fg ulong bg ulong to void 485 lx_request 56 20 486 lx_p32 4 get lx_s 2 487 lx_p32 8 12 488 lx_p32 12 fg 489 lx_p32 16 bg 490 lx_send 20 491 end 492 fn lx_fill x ulong y ulong w ulong h ulong color ulong to void 493 lx_color color lx_bg 494 lx_request 70 20 495 lx_p32 4 get lx_s 1 496 lx_p32 8 get lx_s 2 497 lx_p16 12 x 498 lx_p16 14 y 499 lx_p16 16 w 500 lx_p16 18 h 501 lx_send 20 502 end 503 fn lx_text x ulong y ulong count ulong to void 504 note ImageText8 has an 8-bit glyph count. Split long strings in caller at the visible edge. 505 n = mul div add add 16 count 3 4 4 506 lx_request 76 n 507 put lx_req 1 uchar count 508 lx_p32 4 get lx_s 1 509 lx_p32 8 get lx_s 2 510 lx_p16 12 x 511 lx_p16 14 y 512 for i ulong count bound 256 513 put lx_req add 16 i get lx_piece i 514 end 515 lx_send n 516 end 517 fn lx_label textv view uchar * x ulong y ulong to void 518 n = len textv 519 if gt n 100 520 n = 100 521 end 522 for i ulong n bound 256 523 put lx_piece i get textv i 524 end 525 lx_text x y n 526 end 527 fn lx_querytext to void 528 n = get lx_qn 0 529 start = ulong 0 530 if gt n 90 531 start = sub n 90 532 while lt start n bound `9223372036854775807` 533 c = get lx_query start 534 if ne and c 192 128 535 break 536 end 537 start = add start 1 538 end 539 end 540 count = ulong 0 541 i = start 542 while and lt i n lt count 100 bound `9223372036854775807` 543 c = get lx_query i 544 if lt c 128 545 put lx_piece count c 546 count = add count 1 547 else 548 if ne and c 192 128 549 put lx_piece count 63 550 count = add count 1 551 end 552 end 553 i = add i 1 554 end 555 lx_text 24 78 count 556 end 557 fn lx_rowtext start ulong last ulong y ulong to void 558 count = ulong 0 559 i = start 560 while and lt i last lt count 92 bound `9223372036854775807` 561 c = get lx_rows i 562 if lt c 128 563 if ge c 32 564 put lx_piece count c 565 count = add count 1 566 end 567 else 568 if ne and c 192 128 569 put lx_piece count 63 570 count = add count 1 571 end 572 end 573 i = add i 1 574 end 575 lx_text 32 y count 576 end 577 fn lx_rowcount to ulong 578 n = get lx_rn 0 579 count = ulong 0 580 for i ulong n bound `9223372036854775807` 581 if eq get lx_rows i 10 582 count = add count 1 583 end 584 end 585 if gt n 0 586 if ne get lx_rows sub n 1 10 587 count = add count 1 588 end 589 end 590 ret count 591 end 592 fn lx_draw to void 593 put lx_s 19 lx_rowcount 594 if ge get lx_pick 0 get lx_s 19 595 put lx_pick 0 0 596 end 597 visible = div sub get lx_s 12 150 30 598 if lt get lx_pick 0 get lx_s 20 599 put lx_s 20 get lx_pick 0 600 end 601 if ge get lx_pick 0 add get lx_s 20 visible 602 put lx_s 20 add sub get lx_pick 0 visible 1 603 end 604 lx_request 61 16 605 lx_p32 4 get lx_s 1 606 lx_send 16 607 lx_color lx_ink lx_bg 608 lx_label lx_name 24 32 609 lx_color lx_muted lx_bg 610 if eq get lx_qn 0 0 611 lx_label lx_hint 24 78 612 else 613 lx_color lx_ink lx_bg 614 lx_querytext 615 end 616 lx_fill 24 96 sub get lx_s 11 48 1 lx_card 617 start = ulong 0 618 row = ulong 0 619 n = get lx_rn 0 620 i = ulong 0 621 while le i n bound `9223372036854775807` 622 last = eq i n 623 if lt i n 624 last = eq get lx_rows i 10 625 end 626 if last 627 if and ge row get lx_s 20 lt row add get lx_s 20 visible 628 if gt i start 629 y = add 126 mul sub row get lx_s 20 30 630 if eq row get lx_pick 0 631 lx_fill 24 sub y 18 sub get lx_s 11 48 28 lx_accent 632 lx_color lx_ink lx_accent 633 else 634 lx_color lx_ink lx_bg 635 end 636 lx_rowtext start i y 637 end 638 end 639 row = add row 1 640 start = add i 1 641 end 642 i = add i 1 643 end 644 lx_color lx_muted lx_bg 645 lx_label lx_help 24 sub get lx_s 12 20 646 end 647 fn lx_makewin to void 648 put lx_s 1 lx_id 1 649 put lx_s 2 lx_id 2 650 put lx_s 3 lx_id 3 651 put lx_s 11 640 652 put lx_s 12 440 653 lx_request 1 40 654 lx_p32 4 get lx_s 1 655 lx_p32 8 get lx_s 4 656 x = ulong 0 657 y = ulong 0 658 if gt get lx_s 16 640 659 x = div sub get lx_s 16 640 2 660 end 661 if gt get lx_s 17 440 662 y = div sub get lx_s 17 440 2 663 end 664 lx_p16 12 x 665 lx_p16 14 y 666 lx_p16 16 640 667 lx_p16 18 440 668 lx_p16 22 1 669 lx_p32 28 2050 670 lx_p32 32 lx_bg 671 lx_p32 36 or or ulong 1 4 or ulong 32768 131072 672 lx_send 40 673 put lx_s 9 lx_atom lx_wmp 674 put lx_s 10 lx_atom lx_wmd 675 lx_property get lx_s 9 4 32 get lx_s 10 1 676 lx_request 18 28 677 lx_p32 4 get lx_s 1 678 lx_p32 8 39 679 lx_p32 12 31 680 put lx_req 16 8 681 lx_p32 20 len lx_name 682 for i ulong len lx_name bound 16 683 put lx_req add 24 i get lx_name i 684 end 685 lx_send 28 686 lx_request 45 20 687 lx_p32 4 get lx_s 3 688 lx_p16 8 len lx_font 689 for i ulong len lx_font bound 16 690 put lx_req add 12 i get lx_font i 691 end 692 lx_send 20 693 lx_request 55 28 694 lx_p32 4 get lx_s 2 695 lx_p32 8 get lx_s 1 696 lx_p32 12 16396 697 lx_p32 16 lx_ink 698 lx_p32 20 lx_bg 699 lx_p32 24 get lx_s 3 700 lx_send 28 701 lx_request 101 8 702 put lx_req 4 uchar get lx_s 13 703 put lx_req 5 uchar add sub get lx_s 14 get lx_s 13 1 704 lx_send 8 705 lx_reply 706 put lx_s 15 ulong get lx_buf 1 707 n = mul lx_u32 4 4 708 r = enlarge lx_keys n 709 if lt r 0 710 lx_bad 711 end 712 for i ulong n bound `9223372036854775807` 713 put lx_keys i get lx_buf add 32 i 714 end 715 lx_request 8 8 716 lx_p32 4 get lx_s 1 717 lx_send 8 718 note SetInputFocus follows MapWindow; the window manager may override placement and focus according to user policy. 719 lx_request 42 12 720 put lx_req 1 1 721 lx_p32 4 get lx_s 1 722 lx_send 12 723 end 724 fn lx_keyvalue code ulong column ulong to ulong 725 if or lt code get lx_s 13 gt code get lx_s 14 726 ret 0 727 end 728 if ge column get lx_s 15 729 ret 0 730 end 731 p = mul add mul sub code get lx_s 13 get lx_s 15 column 4 732 if gt add p 4 len lx_keys 733 ret 0 734 end 735 v = ulong 0 736 for i ulong 4 bound 4 737 v = or v shl ulong get lx_keys add p i mul i 8 738 end 739 ret v 740 end 741 fn lx_append cp ulong to void 742 n = get lx_qn 0 743 r = enlarge lx_query add n 4 744 if lt r 0 745 lx_bad 746 end 747 if lt cp 128 748 put lx_query n uchar cp 749 n = add n 1 750 else 751 if lt cp 2048 752 put lx_query n uchar or 192 shr cp 6 753 put lx_query add n 1 uchar or 128 and cp 63 754 n = add n 2 755 else 756 if lt cp 65536 757 put lx_query n uchar or 224 shr cp 12 758 put lx_query add n 1 uchar or 128 and shr cp 6 63 759 put lx_query add n 2 uchar or 128 and cp 63 760 n = add n 3 761 else 762 put lx_query n uchar or 240 shr cp 18 763 put lx_query add n 1 uchar or 128 and shr cp 12 63 764 put lx_query add n 2 uchar or 128 and shr cp 6 63 765 put lx_query add n 3 uchar or 128 and cp 63 766 n = add n 4 767 end 768 end 769 end 770 put lx_qn 0 n 771 end 772 fn lx_changed to void 773 put lx_pick 0 0 774 put lx_s 20 0 775 hop_query 776 lx_draw 777 end 778 fn lx_key to void 779 code = ulong get lx_buf 1 780 state = lx_u16 28 781 key = lx_keyvalue code 0 782 if ne and state 1 0 783 other = lx_keyvalue code 1 784 if ne other 0 785 key = other 786 end 787 end 788 if ne and state 2 0 789 if and ge key 97 le key 122 790 key = sub key 32 791 else 792 if and ge key 65 le key 90 793 key = add key 32 794 end 795 end 796 end 797 if eq key 65307 798 put lx_s 18 1 799 ret 800 end 801 if eq key 65293 802 if eq hop_activate 1 803 put lx_s 18 1 804 else 805 lx_draw 806 end 807 ret 808 end 809 if eq key 65362 810 if gt get lx_pick 0 0 811 put lx_pick 0 sub get lx_pick 0 1 812 end 813 lx_draw 814 ret 815 end 816 if eq key 65364 817 if lt add get lx_pick 0 1 get lx_s 19 818 put lx_pick 0 add get lx_pick 0 1 819 end 820 lx_draw 821 ret 822 end 823 if eq key 65288 824 n = get lx_qn 0 825 if gt n 0 826 n = sub n 1 827 while gt n 0 bound `9223372036854775807` 828 if ne and get lx_query n 192 128 829 break 830 end 831 n = sub n 1 832 end 833 put lx_qn 0 n 834 lx_changed 835 end 836 ret 837 end 838 if eq key 65289 839 ret 840 end 841 if ne and state 4 0 842 if or eq key 117 eq key 85 843 put lx_qn 0 0 844 lx_changed 845 end 846 ret 847 end 848 if ne and state 72 0 849 ret 850 end 851 if and ge key 32 lt key 256 852 lx_append key 853 lx_changed 854 ret 855 end 856 if and ge key `16777248` le key `17891327` 857 cp = sub key `16777216` 858 if or lt cp 55296 gt cp 57343 859 lx_append cp 860 lx_changed 861 end 862 end 863 end 864 fn lx_click to void 865 button = get lx_buf 1 866 if eq button 4 867 if gt get lx_pick 0 0 868 put lx_pick 0 sub get lx_pick 0 1 869 end 870 lx_draw 871 ret 872 end 873 if eq button 5 874 if lt add get lx_pick 0 1 get lx_s 19 875 put lx_pick 0 add get lx_pick 0 1 876 end 877 lx_draw 878 ret 879 end 880 if ne button 1 881 ret 882 end 883 y = lx_u16 26 884 if lt y 108 885 ret 886 end 887 offset = div sub y 108 30 888 if ge offset div sub get lx_s 12 150 30 889 ret 890 end 891 row = add get lx_s 20 offset 892 if ge row get lx_s 19 893 ret 894 end 895 put lx_pick 0 row 896 if eq hop_activate 1 897 put lx_s 18 1 898 else 899 lx_draw 900 end 901 end 902 fn lx_main to int 903 if ne lx_setup 0 904 ret 1 905 end 906 lx_makewin 907 lx_changed 908 while eq get lx_s 18 0 bound `9223372036854775807` 909 lx_read 0 32 910 kind = and get lx_buf 0 127 911 if eq kind 0 912 lx_bad 913 end 914 if eq kind 1 915 lx_read 32 mul lx_u32 4 4 916 end 917 if eq kind 2 918 lx_key 919 end 920 if eq kind 4 921 lx_click 922 end 923 if eq kind 12 924 lx_draw 925 end 926 if eq kind 17 927 put lx_s 18 1 928 end 929 if eq kind 22 930 w = lx_u16 20 931 h = lx_u16 22 932 if and ge w 200 ge h 200 933 put lx_s 11 w 934 put lx_s 12 h 935 lx_draw 936 end 937 end 938 if eq kind 33 939 if eq lx_u32 8 get lx_s 9 940 if eq lx_u32 12 get lx_s 10 941 put lx_s 18 1 942 end 943 end 944 end 945 end 946 k = fclose int get lx_fd 0 947 ret 0 948 end