Do the right thing if some atoms are not interned
[llpp.git] / wsi.ml
blob41e052fbbc0abba564d7683a3336e6d96c489ef7
1 type cursor =
2 | CURSOR_INHERIT
3 | CURSOR_INFO
4 | CURSOR_CYCLE
5 | CURSOR_CROSSHAIR
6 | CURSOR_TEXT
7 ;;
9 external cloexec : Unix.file_descr -> unit = "ml_cloexec";;
10 external glx : int -> unit = "ml_glx";;
11 external swapb : unit -> unit = "ml_swapb";;
12 external hasdata : Unix.file_descr -> bool = "ml_hasdata";;
13 external toutf8 : int -> string = "ml_keysymtoutf8";;
15 let dolog fmt = Format.kprintf prerr_endline fmt;;
16 let vlog fmt = Format.kprintf ignore fmt;;
18 exception Quit;;
20 let onot = object
21 method display = ()
22 method reshape _ _ = ()
23 method mouse _ _ _ _ _ = ()
24 method motion _ _ = ()
25 method pmotion _ _ = ()
26 method key _ _ = ()
27 method enter _ _ = ()
28 method leave = ()
29 method quit = exit 0
30 end;;
32 class type t = object
33 method display : unit
34 method reshape : int -> int -> unit
35 method mouse : int -> bool -> int -> int -> int -> unit
36 method motion : int -> int -> unit
37 method pmotion : int -> int -> unit
38 method key : int -> int -> unit
39 method enter : int -> int -> unit
40 method leave : unit
41 method quit : unit
42 end;;
44 type state =
45 { mutable mink : int
46 ; mutable maxk : int
47 ; mutable keymap : int array array
48 ; fifo : (string -> unit) Queue.t
49 ; mutable seq : int
50 ; mutable protoatom : int
51 ; mutable deleatom : int
52 ; mutable idbase : int
53 ; mutable fullscreen : (int -> unit)
54 ; mutable stringatom : int
55 ; mutable t : t
56 ; mutable sock : Unix.file_descr
57 ; mutable w : int
58 ; mutable h : int
59 ; mutable fs : bool
60 ; mutable parent : int
64 let state =
65 { mink = max_int
66 ; maxk = min_int
67 ; keymap = [||]
68 ; fifo = Queue.create ()
69 ; seq = 0
70 ; protoatom = -1
71 ; deleatom = -1
72 ; idbase = -1
73 ; fullscreen = (fun _ -> ())
74 ; sock = Unix.stdin
75 ; t = onot
76 ; w = -1
77 ; h = -1
78 ; fs = false
79 ; stringatom = 31
80 ; parent = -1
84 let w8 s pos i = String.set s pos (Char.chr (i land 0xff));;
86 let w16 s pos i =
87 w8 s pos i;
88 w8 s (pos+1) (i lsr 8);
91 let w32 s pos i =
92 w16 s pos i;
93 w16 s (pos+2) (i lsr 16);
96 let r16 s pos =
97 let rb pos1 = Char.code (String.get s (pos + pos1)) in
98 (rb 0) lor ((rb 1) lsl 8)
101 let r16s s pos =
102 let i = r16 s pos in
103 i - ((i land 0x8000) lsl 1);
106 let r8 s pos = Char.code (String.get s pos);;
108 let r32 s pos =
109 let rb pos1 = Char.code (String.get s (pos + pos1)) in
110 let l = (rb 0) lor ((rb 1) lsl 8)
111 and u = (rb 2) lor ((rb 3) lsl 8) in
112 (u lsl 16) lor l
115 let error fmt = Printf.kprintf failwith fmt;;
117 let readstr sock n =
118 let s = String.create n in
119 let rec loop pos n =
120 let m = Unix.read sock s pos n in
121 if n != m
122 then (
123 ignore (Unix.select [sock] [] [] 0.01);
124 loop (pos + m) (n - m)
127 loop 0 n;
131 let sendstr1 s pos len sock =
132 vlog "%d => %S" state.seq s;
133 state.seq <- state.seq + 1;
134 let n = Unix.send sock s pos len [] in
135 if n != len
136 then error "send %d returned %d" len n;
139 let updkmap sock resp =
140 let syms = r8 resp 1 in
141 let len = r32 resp 4 in
142 let data =
143 if len > 0
144 then readstr sock (4*len)
145 else ""
147 let m = len / syms in
148 state.keymap <- Array.make_matrix
149 (state.maxk - state.mink) syms 0xffffff;
150 let rec loop i = if i = m then () else
151 let k = i*4*syms in
152 let rec loop2 k l = if l = syms then () else
153 let v = r32 data k in
154 state.keymap.(i).(l) <- v;
155 loop2 (k+4) (l+1)
157 loop2 k 0;
158 loop (i+1);
160 loop 0;
163 let sendwithrep sock s f =
164 Queue.push f state.fifo;
165 sendstr1 s 0 (String.length s) sock;
168 let padcatl ss =
169 let b = Buffer.create 16 in
170 List.iter (Buffer.add_string b) ss;
171 let bl = Buffer.length b in
172 let pl = bl land 3 in
173 if pl != 0
174 then (
175 let pad = "123" in
176 Buffer.add_substring b pad 0 (4 - pl);
178 Buffer.contents b;
181 let padcat s1 s2 = padcatl [s1; s2];;
183 let internreq name onlyifexists =
184 let s = "\016\000\000\000\000\000\000\000" in
185 let s = padcat s name in
186 w8 s 1 (if onlyifexists then 1 else 0);
187 w16 s 2 (String.length s / 4);
188 w16 s 4 (String.length name);
192 let sendintern sock s onlyifexists f =
193 let s = internreq s onlyifexists in
194 sendwithrep sock s f;
197 let createwindowreq wid parent x y w h bw mask =
198 let s = "\001\000\009\000wwwwppppxxyywwhhbwccvvvvmmmmeeee" in
199 w32 s 4 wid;
200 w32 s 8 parent;
201 w16 s 12 x;
202 w16 s 14 y;
203 w16 s 16 w;
204 w16 s 18 h;
205 w16 s 20 bw;
206 w16 s 22 1;
207 w32 s 24 0;
208 w32 s 28 0x800; (* eventmask *)
209 w32 s 32 mask;
213 let mapreq wid =
214 let s = "\008u\002\000wwww" in
215 w32 s 4 wid;
219 let getkeymapreq first count =
220 let s = "\101u\002\000fcuu" in
221 w8 s 4 first;
222 w8 s 5 count;
226 let changepropreq wid prop typ format props =
227 let s = "\018\000llwwwwppppttttfuuuLLLL" in
228 let s = padcat s props in
229 w16 s 2 (String.length s / 4);
230 w32 s 4 wid;
231 w32 s 8 prop;
232 w32 s 12 typ;
233 w8 s 16 format;
234 let ful = String.length props / (match format with
235 | 8 -> 1
236 | 16 -> 2
237 | 32 -> 4
238 | n -> error "no idea what %d means" n)
240 w32 s 20 ful;
244 let openfontreq fid name =
245 let s = "\045ullffffnnuu" in
246 let s = padcat s name in
247 w16 s 2 (String.length s / 4);
248 w32 s 4 fid;
249 w16 s 8 (String.length name);
253 let createglyphcursorreq fid cid cindex =
254 let s = "\094u\008\000ccccffffffffssmmrrggbbRRGGBB" in
255 w32 s 4 cid;
256 w32 s 8 fid;
257 w32 s 12 fid;
258 w16 s 16 cindex;
259 w16 s 18 (cindex+1);
260 w16 s 20 0;
261 w16 s 22 0;
262 w16 s 24 0;
263 w16 s 26 0xffff;
264 w16 s 28 0xffff;
265 w16 s 30 0xffff;
269 let mapwindowreq wid =
270 let s = "\008u\002\000wwww" in
271 w32 s 4 wid;
275 let changewindowattributesreq wid mask attrs =
276 let s = "\002ullwwwwmmmm" in
277 let s = padcat s attrs in
278 w16 s 2 (String.length s / 4);
279 w32 s 4 wid;
280 w32 s 8 mask;
284 let configurewindowreq wid mask values =
285 let s = "\012ullwwwwmmuu" in
286 let s = padcat s values in
287 w16 s 2 (String.length s / 4);
288 w32 s 4 wid;
289 w16 s 8 mask;
293 let s32 n =
294 let s = "1234" in
295 w32 s 0 n;
299 let clientmessage format seq wid typ data =
300 let s = "\033fsswwwwtttt" in
301 let s = padcat s data in
302 w8 s 1 format;
303 w16 s 2 seq;
304 w32 s 4 wid;
305 w32 s 8 typ;
309 let sendeventreq propagate destwid mask data =
310 let s = "\025p\011\000wwwwmmmm" in
311 let s = padcat s data in
312 w8 s 1 propagate;
313 w32 s 4 destwid;
314 w32 s 8 mask;
318 let getkeysym code mask =
319 let index = (mask land 1) lxor ((mask land 2) lsr 1) in
320 let keysym = state.keymap.(code-state.mink).(index) in
321 if index = 1 && keysym = 0
322 then state.keymap.(code-state.mink).(0)
323 else keysym
326 let readresp sock =
327 let resp = readstr sock 32 in
328 let opcode = r8 resp 0 in
329 match opcode land lnot 0x80 with
330 | 0 -> (* error *)
331 let s = resp in
332 let code = r8 s 1
333 and serial = r16 s 2
334 and resid = r32 resp 4
335 and min = r16 s 8
336 and maj = r8 s 10 in
337 error "code=%d serial=%d resid=%#x min=%d maj=%d\n%S"
338 code serial resid min maj resp;
340 | 1 -> (* response *)
341 let rep = Queue.pop state.fifo in
342 rep resp;
344 | 2 -> (* key press *)
345 if Array.length state.keymap > 0
346 then
347 let code = r8 resp 1 in
348 let mask = r16 resp 28 in
349 let keysym = getkeysym code mask in
350 vlog "keysym = %x %c" keysym (Char.unsafe_chr keysym);
351 state.t#key keysym mask;
353 | 3 -> (* key release *)
354 if Array.length state.keymap > 0
355 then
356 let code = r8 resp 1 in
357 let mask = r16 resp 28 in
358 let keysym = getkeysym code mask in
359 vlog "release keysym = %x %c mask %#x"
360 keysym (Char.unsafe_chr keysym) mask
362 | 4 -> (* buttonpress *)
363 let n = r8 resp 1
364 and x = r16s resp 24
365 and y = r16s resp 26
366 and m = r16 resp 28 in
367 state.t#mouse n true x y m;
368 vlog "press %d" n
370 | 5 -> (* buttonrelease *)
371 let n = r8 resp 1
372 and x = r16s resp 24
373 and y = r16s resp 26
374 and m = r16 resp 28 in
375 state.t#mouse n false x y m;
376 vlog "release %d %d %d" n x y
378 | 6 -> (* motion *)
379 let x = r16s resp 24 in
380 let y = r16s resp 26 in
381 let m = r16 resp 28 in
382 if m land 0x1f00 = 0
383 then state.t#pmotion x y
384 else state.t#motion x y;
385 vlog "move %dx%d => %d" x y m
387 | 7 -> (* enter *)
388 let x = r16s resp 24
389 and y = r16s resp 26 in
390 state.t#enter x y;
391 vlog "enter %d %d" x y
393 | 8 -> (* leave *)
394 state.t#leave
396 | 18 -> vlog "unmap";
398 | 19 -> (* map *)
399 if state.parent = -1 && state.w > 0 && state.h > 0
400 then state.t#reshape state.w state.h;
401 state.t#display;
402 vlog "map";
404 | 12 -> (* exposure *)
405 vlog "exposure";
406 state.t#display
408 | 15 -> (* visibility *)
409 let vis = r8 resp 8 in
410 if vis != 2 then state.t#display;
411 vlog "visibility %d" vis;
413 | 34 -> (* mapping *)
414 state.keymap <- [||];
415 let s = getkeymapreq state.mink (state.maxk-state.mink-1) in
416 sendwithrep sock s (updkmap sock);
418 | 33 -> (* clientmessage *)
419 let atom = r32 resp 8 in
420 if atom = state.protoatom
421 then (
422 let atom = r32 resp 12 in
423 if atom = state.deleatom
424 then raise Quit;
426 vlog "atom %#x" atom
428 | 21 -> (* reparent *)
429 state.parent <- r32 resp 24;
430 state.w <- -1;
431 state.h <- -1;
432 vlog "reparent"
434 | 22 -> (* configure *)
435 vlog "configure";
436 let w = r16 resp 20
437 and h = r16 resp 22 in
438 if w != state.w || h != state.h
439 then (
440 state.w <- w;
441 state.h <- h;
442 state.t#reshape w h;
445 | n ->
446 dolog "event %d %S" n resp
449 let readresp sock =
450 let rec loop () =
451 readresp sock;
452 if hasdata sock then loop ();
454 loop ();
457 let sendstr s ?(pos=0) ?(len=String.length s) sock =
458 sendstr1 s pos len sock;
459 if hasdata sock then readresp sock;
462 let hexstr s =
463 let b = Buffer.create 16 in
464 String.iter (fun c ->
465 Buffer.add_string b (Printf.sprintf "%02x" (Char.code c))) s;
466 Buffer.contents b;
469 let reshape w h =
470 if state.fs
471 then
472 state.fullscreen state.idbase
474 let s = "wwuuhhuu" in
475 w32 s 0 w;
476 w32 s 4 h;
477 let s = configurewindowreq state.idbase 0x000c s in
478 vlog "reshape %d %s %d" state.seq (hexstr s) (String.length s);
479 sendstr s state.sock;
482 let setup sock screennum w h =
483 let s = readstr sock 2 in
484 let n = String.length s in
485 if n != 2
486 then error "failed to read X connection setup response n=%d" n;
487 match s.[0] with
488 | '\000' ->
489 let reasonlen = r8 s 1 in
490 let s = readstr sock 6 in
491 let maj = r16 s 0
492 and min = r16 s 2
493 and add = r16 s 4 in
494 let len = add*4 in
495 let data = readstr sock len in
496 let reason = String.sub data 0 reasonlen in
497 error "X connection failed maj=%d min=%d reason=%S"
498 maj min reason
500 | '\002' -> failwith "X connection setup failed: authentication required";
502 | '\001' ->
503 let s = readstr sock 38 in
504 let maj = r16 s 0
505 and min = r16 s 2
506 and add = r16 s 4
507 and idbase = r32 s 10
508 and idmask = r32 s 14
509 and vlen = r16 s 22
510 and screens = r8 s 26
511 and formats = r8 s 27
512 and minkk = r8 s 32
513 and maxkk = r8 s 33 in
514 let data = readstr sock (4*add-32) in
515 let vendor = String.sub data 0 vlen in
516 let pos = ((vlen+3) land lnot 3) + formats*8 in
518 if screennum >= screens
519 then error "invalid screen %d, max %d" screennum (screens-1);
521 let pos =
522 let s = data in
523 let rec findscreen n pos = if n = screennum then pos else
524 let pos =
525 let ndepths = r8 s (pos+39) in
526 let rec skipdepths n pos = if n = ndepths then pos else
527 let pos =
528 let nvisiuals = r16 s (pos+2) in
529 pos + nvisiuals*24 + 8
531 skipdepths (n+1) pos
533 skipdepths n (pos+40)
535 findscreen (n+1) pos
537 findscreen 0 pos
539 let root = r32 data pos in
540 let rootw = r16 data (pos+20)
541 and rooth = r16 data (pos+22) in
542 state.mink <- minkk;
543 state.maxk <- maxkk;
544 state.idbase <- idbase;
545 vlog "vendor = %S, maj=%d min=%d" vendor maj min;
546 vlog "screens = %d formats = %d" screens formats;
547 vlog "minkk = %d maxkk = %d" minkk maxkk;
548 vlog "idbase = %#x idmask = %#x" idbase idmask;
549 vlog "root=%#x %dx%d" root rootw rooth;
551 let mask = 0
552 + 0x00000001 (* KeyPress *)
553 (* + 0x00000002 *) (* KeyRelease *)
554 + 0x00000004 (* ButtonPress *)
555 + 0x00000008 (* ButtonRelease *)
556 + 0x00000010 (* EnterWindow *)
557 + 0x00000020 (* LeaveWindow *)
558 + 0x00000040 (* PointerMotion *)
559 (* + 0x00000080 *) (* PointerMotionHint *)
560 (* + 0x00000100 *) (* Button1Motion *)
561 (* + 0x00000200 *) (* Button2Motion *)
562 (* + 0x00000400 *) (* Button3Motion *)
563 (* + 0x00000800 *) (* Button4Motion *)
564 (* + 0x00001000 *) (* Button5Motion *)
565 + 0x00002000 (* ButtonMotion *)
566 (* + 0x00004000 *) (* KeymapState *)
567 + 0x00008000 (* Exposure *)
568 + 0x00010000 (* VisibilityChange *)
569 + 0x00020000 (* StructureNotify *)
570 (* + 0x00040000 *) (* ResizeRedirect *)
571 (* + 0x00080000 *) (* SubstructureNotify *)
572 (* + 0x00100000 *) (* SubstructureRedirect *)
573 (* + 0x00200000 *) (* FocusChange *)
574 (* + 0x00400000 *) (* PropertyChange *)
575 (* + 0x00800000 *) (* ColormapChange *)
576 (* + 0x01000000 *) (* OwnerGrabButton *)
578 let wid = state.idbase in
579 state.w <- w;
580 state.h <- h;
581 let s = createwindowreq wid root 0 0 w h 0 mask in
582 sendstr s sock;
584 glx wid;
586 let s = mapreq wid in
587 sendstr s sock;
589 let s = getkeymapreq state.mink (state.maxk-state.mink) in
590 sendwithrep sock s (updkmap sock);
592 sendintern sock "WM_PROTOCOLS" false (fun resp ->
593 state.protoatom <- r32 resp 8;
594 sendintern sock "WM_DELETE_WINDOW" false (fun resp ->
595 state.deleatom <- r32 resp 8;
596 let s = s32 state.deleatom in
597 let s = changepropreq wid state.protoatom 4 32 s in
598 sendstr s sock;
602 sendintern sock "WM_CLASS" false (fun resp ->
603 let atom = r32 resp 8 in
604 let llpp = "llpp\000llpp\000" in
605 let s = changepropreq wid atom 31 8 llpp in
606 sendstr s sock;
609 let s = openfontreq (wid+1) "cursor" in
610 sendstr s sock;
612 Array.iteri (fun i glyphindex ->
613 let s = createglyphcursorreq (wid+1) (wid+2+i) glyphindex in
614 sendstr s sock;
615 ) [|34;48;50;58;128;152|];
617 sendintern sock "UTF8_STRING" true (fun resp ->
618 let atom = r32 resp 8 in
619 if atom != 0 then state.stringatom <- atom;
622 sendintern sock "_NET_WM_STATE" true (fun resp ->
623 let nwmsatom = r32 resp 8 in
624 if nwmsatom != 0
625 then
626 sendintern sock "_NET_WM_STATE_FULLSCREEN" true (fun resp ->
627 let fsatom = r32 resp 8 in
628 if fsatom != 0
629 then
630 state.fullscreen <-
631 (fun wid ->
632 let data = String.make 20 '\000' in
633 state.fs <- not state.fs;
634 w32 data 0 (if state.fs then 1 else 0);
635 w32 data 4 fsatom;
637 let cm = clientmessage 32 0 wid nwmsatom data in
638 let s = sendeventreq 0 root 0x180000 cm in
639 sendstr s sock;
645 | c ->
646 error "unknown conection setup response %d" (Char.code c)
649 let getauth haddr dnum =
650 let haddr =
651 if haddr = "localhost" || String.length haddr = 0
652 then
653 try Unix.gethostname ()
654 with exn ->
655 dolog "failed to resolve `%S': %s" haddr (Printexc.to_string exn);
656 haddr
657 else haddr
659 let readauth ic =
660 let input_string ic len =
661 let s = String.create len in
662 really_input ic s 0 len;
665 let r16 s =
666 let rb pos = Char.code (String.get s pos) in
667 (rb 1) lor ((rb 0) lsl 8)
669 let rec find () =
670 let rs () =
671 let s = input_string ic 2 in
672 let n = r16 s in
673 input_string ic n
675 let family = input_string ic 2 in
676 let addr = rs () in
677 let nums = rs () in
678 let num = int_of_string nums in
679 let name = rs () in
680 let data = rs () in
682 vlog "family %S addr %S(%S) num %d(%d) name %S data %S"
683 family addr haddr num dnum name data;
684 if addr = haddr && num = dnum
685 then name, data
686 else find ()
688 let name, data =
689 try find () with _ -> "", ""
691 close_in ic;
692 name, data;
694 let path =
695 try Sys.getenv "XAUTHORITY"
696 with Not_found -> Filename.concat (Sys.getenv "HOME") ".Xauthority"
698 let opt =
699 try Some (open_in_bin path)
700 with exn ->
701 dolog "failed to open X authority file `%S' : %s"
702 path
703 (Printexc.to_string exn);
704 None
706 match opt with
707 | None -> "", ""
708 | Some ic -> readauth ic
711 let init t w h =
712 let d =
713 try Sys.getenv "DISPLAY"
714 with exn ->
715 error "Could not get DISPLAY evironment variable: %s"
716 (Printexc.to_string exn)
718 let colonpos = String.index d ':' in
719 let host = String.sub d 0 colonpos in
720 let dispnum, screennum =
722 let dotpos = String.index_from d (colonpos + 1) '.' in
723 let disp = String.sub d (colonpos + 1) (dotpos - colonpos - 1) in
724 let screen = String.sub d (dotpos + 1) (String.length d - dotpos - 1) in
725 int_of_string disp, int_of_string screen
726 with Not_found ->
727 let disp = String.sub d (colonpos + 1) (String.length d - colonpos - 1) in
728 int_of_string disp, 0
730 let aname, adata = getauth host dispnum in
731 let fd =
732 if String.length host = 0 || host = "unix"
733 then
734 let addr = Unix.ADDR_UNIX ("/tmp/.X11-unix/X" ^ string_of_int dispnum) in
735 let fd = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
736 Unix.connect fd addr;
738 else
739 let h = Unix.gethostbyname host in
740 let addr = h.Unix.h_addr_list.(0) in
741 let port = 6000 + dispnum in
742 let fd = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
743 Unix.connect fd (Unix.ADDR_INET (addr, port));
746 cloexec fd;
747 let s = "luMMmmnndduu" in
748 let s = padcat s aname in
749 let s = padcat s adata in
750 w16 s 2 11;
751 w16 s 4 0;
752 w16 s 6 (String.length aname);
753 w16 s 8 (String.length adata);
754 sendstr1 s 0 (String.length s) fd;
755 state.sock <- fd;
756 setup fd screennum w h;
757 state.t <- t;
761 let settitle s =
762 let s = changepropreq state.idbase 39 state.stringatom 8 s in
763 sendstr s state.sock;
766 let setcursor cursor =
767 let n =
768 match cursor with
769 | CURSOR_INHERIT -> -1
770 | CURSOR_INFO -> 3
771 | CURSOR_CYCLE -> 2
772 | CURSOR_CROSSHAIR -> 0
773 | CURSOR_TEXT -> 5
775 let s = s32 (if n = -1 then 0 else state.idbase+2+n) in
776 let s = changewindowattributesreq state.idbase (*cursor*)0x4000 s in
777 sendstr s state.sock;
780 let fullscreen () =
781 state.fullscreen state.idbase;
784 let metamask = 0x40;;
785 let altmask = 8;;
786 let shiftmask = 1;;
787 let ctrlmask = 4;;
789 let withalt mask = mask land altmask != 0;;
790 let withctrl mask = mask land ctrlmask != 0;;
791 let withshift mask = mask land shiftmask != 0;;
792 let withmeta mask = mask land metamask != 0;;
793 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0;;
795 let xlatt, xlatf =
796 let t = Hashtbl.create 20
797 and f = Hashtbl.create 20 in
798 let add n nl k =
799 List.iter (fun s -> Hashtbl.add t s k) (n::nl);
800 Hashtbl.add f k n
802 let addc c =
803 let s = String.create 1 in
804 s.[0] <- c;
805 add s [] (Char.code c)
807 let addcr a b =
808 let an = Char.code a and bn = Char.code b in
809 for i = an to bn do addc (Char.chr i) done;
811 addcr '0' '9';
812 addcr 'a' 'z';
813 addcr 'A' 'Z';
814 String.iter addc "`~!@#$%^&*()-_=+\\|[{]};:,./?";
815 for i = 0 to 29 do add ("f" ^ string_of_int (i+1)) [] (0xffbe + i) done;
816 add "space" [] 0x20;
817 add "return" ["ret"; "enter"] 0xff0d;
818 add "tab" [] 0xff09;
819 add "left" [] 0xff51;
820 add "right" [] 0xff53;
821 add "home" [] 0xff50;
822 add "end" [] 0xff57;
823 add "insert" ["ins"] 0xff63;
824 add "delete" ["del"] 0xffff;
825 add "escape" ["esc"] 0xff1b;
826 add "pgup" ["pageup"] 0xff55;
827 add "pgdown" ["pagedown"] 0xff56;
828 add "backspace" [] 0xff08;
829 add "up" [] 0xff52;
830 add "down" [] 0xff54;
831 t, f;
834 let keyname k =
835 try Hashtbl.find xlatf k
836 with Not_found -> Printf.sprintf "%#x" k;
839 let namekey name =
840 try Hashtbl.find xlatt name
841 with Not_found ->
842 if String.length name = 1
843 then Char.code name.[0]
844 else error "can not find keysym for %S" name;