Kill commented out line
[llpp.git] / wsi.ml
blob1d63a47f590449ee93163e1654c657133f5f148a
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 end;;
31 class type t = object
32 method display : unit
33 method reshape : int -> int -> unit
34 method mouse : int -> bool -> int -> int -> int -> unit
35 method motion : int -> int -> unit
36 method pmotion : int -> int -> unit
37 method key : int -> int -> unit
38 method enter : int -> int -> unit
39 method leave : unit
40 end;;
42 type state =
43 { mutable mink : int
44 ; mutable maxk : int
45 ; mutable keymap : int array array
46 ; fifo : (string -> unit) Queue.t
47 ; mutable seq : int
48 ; mutable protoatom : int
49 ; mutable deleatom : int
50 ; mutable idbase : int
51 ; mutable fullscreen : (int -> unit)
52 ; mutable stringatom : int
53 ; mutable t : t
54 ; mutable sock : Unix.file_descr
55 ; mutable w : int
56 ; mutable h : int
57 ; mutable fs : bool
58 ; mutable parent : int
62 let state =
63 { mink = max_int
64 ; maxk = min_int
65 ; keymap = [||]
66 ; fifo = Queue.create ()
67 ; seq = 0
68 ; protoatom = -1
69 ; deleatom = -1
70 ; idbase = -1
71 ; fullscreen = (fun _ -> ())
72 ; sock = Unix.stdin
73 ; t = onot
74 ; w = -1
75 ; h = -1
76 ; fs = false
77 ; stringatom = 31
78 ; parent = -1
82 let w8 s pos i = String.set s pos (Char.chr (i land 0xff));;
84 let w16 s pos i =
85 w8 s pos i;
86 w8 s (pos+1) (i lsr 8);
89 let w32 s pos i =
90 w16 s pos i;
91 w16 s (pos+2) (i lsr 16);
94 let r16 s pos =
95 let rb pos1 = Char.code (String.get s (pos + pos1)) in
96 (rb 0) lor ((rb 1) lsl 8)
99 let r16s s pos =
100 let i = r16 s pos in
101 i - ((i land 0x8000) lsl 1);
104 let r8 s pos = Char.code (String.get s pos);;
106 let r32 s pos =
107 let rb pos1 = Char.code (String.get s (pos + pos1)) in
108 let l = (rb 0) lor ((rb 1) lsl 8)
109 and u = (rb 2) lor ((rb 3) lsl 8) in
110 (u lsl 16) lor l
113 let error fmt = Printf.kprintf failwith fmt;;
115 let readstr sock n =
116 let s = String.create n in
117 let rec loop pos n =
118 let m = Unix.read sock s pos n in
119 if n != m
120 then (
121 ignore (Unix.select [sock] [] [] 0.01);
122 loop (pos + m) (n - m)
125 loop 0 n;
129 let sendstr s ?(pos=0) ?(len=String.length s) sock =
130 vlog "%d => %S" state.seq s;
131 state.seq <- state.seq + 1;
132 let n = Unix.send sock s pos len [] in
133 if n != len
134 then error "send %d returned %d" len n;
137 let updkmap sock resp =
138 let syms = r8 resp 1 in
139 let len = r32 resp 4 in
140 let data =
141 if len > 0
142 then readstr sock (4*len)
143 else ""
145 let m = len / syms in
146 state.keymap <- Array.make_matrix
147 (state.maxk - state.mink) syms 0xffffff;
148 let rec loop i = if i = m then () else
149 let k = i*4*syms in
150 let rec loop2 k l = if l = syms then () else
151 let v = r32 data k in
152 state.keymap.(i).(l) <- v;
153 loop2 (k+4) (l+1)
155 loop2 k 0;
156 loop (i+1);
158 loop 0;
161 let sendwithrep sock s f =
162 Queue.push f state.fifo;
163 sendstr s sock;
166 let padcatl ss =
167 let b = Buffer.create 16 in
168 List.iter (Buffer.add_string b) ss;
169 let bl = Buffer.length b in
170 let pl = bl land 3 in
171 if pl != 0
172 then (
173 let pad = "123" in
174 Buffer.add_substring b pad 0 (4 - pl);
176 Buffer.contents b;
179 let padcat s1 s2 = padcatl [s1; s2];;
181 let internreq name onlyifexists =
182 let s = "\016\000\000\000\000\000\000\000" in
183 let s = padcat s name in
184 w8 s 1 (if onlyifexists then 1 else 0);
185 w16 s 2 (String.length s / 4);
186 w16 s 4 (String.length name);
190 let sendintern sock s onlyifexists f =
191 let s = internreq s onlyifexists in
192 sendwithrep sock s f;
195 let createwindowreq wid parent x y w h bw mask =
196 let s = "\001\000\009\000wwwwppppxxyywwhhbwccvvvvmmmmeeee" in
197 w32 s 4 wid;
198 w32 s 8 parent;
199 w16 s 12 x;
200 w16 s 14 y;
201 w16 s 16 w;
202 w16 s 18 h;
203 w16 s 20 bw;
204 w16 s 22 1;
205 w32 s 24 0;
206 w32 s 28 0x800; (* eventmask *)
207 w32 s 32 mask;
211 let mapreq wid =
212 let s = "\008u\002\000wwww" in
213 w32 s 4 wid;
217 let getkeymapreq first count =
218 let s = "\101u\002\000fcuu" in
219 w8 s 4 first;
220 w8 s 5 count;
224 let changepropreq wid prop typ format props =
225 let s = "\018\000llwwwwppppttttfuuuLLLL" in
226 let s = padcat s props in
227 w16 s 2 (String.length s / 4);
228 w32 s 4 wid;
229 w32 s 8 prop;
230 w32 s 12 typ;
231 w8 s 16 format;
232 let ful = String.length props / (match format with
233 | 8 -> 1
234 | 16 -> 2
235 | 32 -> 4
236 | n -> error "no idea what %d means" n)
238 w32 s 20 ful;
242 let openfontreq fid name =
243 let s = "\045ullffffnnuu" in
244 let s = padcat s name in
245 w16 s 2 (String.length s / 4);
246 w32 s 4 fid;
247 w16 s 8 (String.length name);
251 let createglyphcursorreq fid cid cindex =
252 let s = "\094u\008\000ccccffffffffssmmrrggbbRRGGBB" in
253 w32 s 4 cid;
254 w32 s 8 fid;
255 w32 s 12 fid;
256 w16 s 16 cindex;
257 w16 s 18 (cindex+1);
258 w16 s 20 0;
259 w16 s 22 0;
260 w16 s 24 0;
261 w16 s 26 0xffff;
262 w16 s 28 0xffff;
263 w16 s 30 0xffff;
267 let mapwindowreq wid =
268 let s = "\008u\002\000wwww" in
269 w32 s 4 wid;
273 let changewindowattributesreq wid mask attrs =
274 let s = "\002ullwwwwmmmm" in
275 let s = padcat s attrs in
276 w16 s 2 (String.length s / 4);
277 w32 s 4 wid;
278 w32 s 8 mask;
282 let configurewindowreq wid mask values =
283 let s = "\012ullwwwwmmuu" in
284 let s = padcat s values in
285 w16 s 2 (String.length s / 4);
286 w32 s 4 wid;
287 w16 s 8 mask;
291 let s32 n =
292 let s = "1234" in
293 w32 s 0 n;
297 let clientmessage format seq wid typ data =
298 let s = "\033fsswwwwtttt" in
299 let s = padcat s data in
300 w8 s 1 format;
301 w16 s 2 seq;
302 w32 s 4 wid;
303 w32 s 8 typ;
307 let sendeventreq propagate destwid mask data =
308 let s = "\025p\011\000wwwwmmmm" in
309 let s = padcat s data in
310 w8 s 1 propagate;
311 w32 s 4 destwid;
312 w32 s 8 mask;
316 let getkeysym code mask =
317 let index = (mask land 1) lxor ((mask land 2) lsr 1) in
318 let keysym = state.keymap.(code-state.mink).(index) in
319 if index = 1 && keysym = 0
320 then state.keymap.(code-state.mink).(0)
321 else keysym
324 let readresp sock =
325 let resp = readstr sock 32 in
326 let opcode = r8 resp 0 in
327 match opcode land lnot 0x80 with
328 | 0 -> (* error *)
329 let s = resp in
330 let code = r8 s 1
331 and serial = r16 s 2
332 and resid = r32 resp 4
333 and min = r16 s 8
334 and maj = r8 s 10 in
335 error "code=%d serial=%d resid=%#x min=%d maj=%d\n%S"
336 code serial resid min maj resp;
338 | 1 -> (* response *)
339 let rep = Queue.pop state.fifo in
340 rep resp;
342 | 2 -> (* key press *)
343 if Array.length state.keymap > 0
344 then
345 let code = r8 resp 1 in
346 let mask = r16 resp 28 in
347 let keysym = getkeysym code mask in
348 vlog "keysym = %x %c" keysym (Char.unsafe_chr keysym);
349 state.t#key keysym mask;
351 | 3 -> (* key release *)
352 if Array.length state.keymap > 0
353 then
354 let code = r8 resp 1 in
355 let mask = r16 resp 28 in
356 let keysym = getkeysym code mask in
357 vlog "release keysym = %x %c mask %#x"
358 keysym (Char.unsafe_chr keysym) mask
360 | 4 -> (* buttonpress *)
361 let n = r8 resp 1
362 and x = r16s resp 24
363 and y = r16s resp 26
364 and m = r16 resp 28 in
365 state.t#mouse n true x y m;
366 vlog "press %d" n
368 | 5 -> (* buttonrelease *)
369 let n = r8 resp 1
370 and x = r16s resp 24
371 and y = r16s resp 26
372 and m = r16 resp 28 in
373 state.t#mouse n false x y m;
374 vlog "release %d %d %d" n x y
376 | 6 -> (* motion *)
377 let x = r16s resp 24 in
378 let y = r16s resp 26 in
379 let m = r16 resp 28 in
380 if m land 0x1f00 = 0
381 then state.t#pmotion x y
382 else state.t#motion x y;
383 vlog "move %dx%d => %d" x y m
385 | 7 -> (* enter *)
386 let x = r16s resp 24
387 and y = r16s resp 26 in
388 state.t#enter x y;
389 vlog "enter %d %d" x y
391 | 8 -> (* leave *)
392 state.t#leave
394 | 18 -> vlog "unmap";
396 | 19 -> (* map *)
397 if state.parent = -1 && state.w > 0 && state.h > 0
398 then state.t#reshape state.w state.h;
399 state.t#display;
400 vlog "map";
402 | 12 -> (* exposure *)
403 vlog "exposure";
404 state.t#display
406 | 15 -> (* visibility *)
407 let vis = r8 resp 8 in
408 if vis != 2 then state.t#display;
409 vlog "visibility %d" vis;
411 | 34 -> (* mapping *)
412 state.keymap <- [||];
413 let s = getkeymapreq state.mink (state.maxk-state.mink-1) in
414 sendwithrep sock s (updkmap sock);
416 | 33 -> (* clientmessage *)
417 let atom = r32 resp 8 in
418 if atom = state.protoatom
419 then (
420 let atom = r32 resp 12 in
421 if atom = state.deleatom
422 then raise Quit;
424 vlog "atom %#x" atom
426 | 21 -> (* reparent *)
427 state.parent <- r32 resp 24;
428 state.w <- -1;
429 state.h <- -1;
430 vlog "reparent"
432 | 22 -> (* configure *)
433 vlog "configure";
434 let w = r16 resp 20
435 and h = r16 resp 22 in
436 if w != state.w || h != state.h
437 then (
438 state.w <- w;
439 state.h <- h;
440 state.t#reshape w h;
443 | n ->
444 dolog "event %d %S" n resp
447 let readresp sock =
448 let rec loop () =
449 readresp sock;
450 if hasdata sock then loop ();
452 loop ();
455 let hexstr s =
456 let b = Buffer.create 16 in
457 String.iter (fun c ->
458 Buffer.add_string b (Printf.sprintf "%02x" (Char.code c))) s;
459 Buffer.contents b;
462 let reshape w h =
463 if state.fs
464 then
465 state.fullscreen state.idbase
467 let s = "wwuuhhuu" in
468 w32 s 0 w;
469 w32 s 4 h;
470 let s = configurewindowreq state.idbase 0x000c s in
471 vlog "reshape %d %s %d" state.seq (hexstr s) (String.length s);
472 sendstr s state.sock;
475 let setup sock screennum w h =
476 let s = readstr sock 2 in
477 let n = String.length s in
478 if n != 2
479 then error "failed to read X connection setup response n=%d" n;
480 match s.[0] with
481 | '\000' ->
482 let reasonlen = r8 s 1 in
483 let s = readstr sock 6 in
484 let maj = r16 s 0
485 and min = r16 s 2
486 and add = r16 s 4 in
487 let len = add*4 in
488 let data = readstr sock len in
489 let reason = String.sub data 0 reasonlen in
490 error "X connection failed maj=%d min=%d reason=%S"
491 maj min reason
493 | '\002' -> failwith "X connection setup failed: authentication required";
495 | '\001' ->
496 let s = readstr sock 38 in
497 let maj = r16 s 0
498 and min = r16 s 2
499 and add = r16 s 4
500 and idbase = r32 s 10
501 and idmask = r32 s 14
502 and vlen = r16 s 22
503 and screens = r8 s 26
504 and formats = r8 s 27
505 and minkk = r8 s 32
506 and maxkk = r8 s 33 in
507 let data = readstr sock (4*add-32) in
508 let vendor = String.sub data 0 vlen in
509 let pos = ((vlen+3) land lnot 3) + formats*8 in
511 if screennum >= screens
512 then error "invalid screen %d, max %d" screennum (screens-1);
514 let pos =
515 let s = data in
516 let rec findscreen n pos = if n = screennum then pos else
517 let pos =
518 let ndepths = r8 s (pos+39) in
519 let rec skipdepths n pos = if n = ndepths then pos else
520 let pos =
521 let nvisiuals = r16 s (pos+2) in
522 pos + nvisiuals*24 + 8
524 skipdepths (n+1) pos
526 skipdepths n (pos+40)
528 findscreen (n+1) pos
530 findscreen 0 pos
532 let root = r32 data pos in
533 let rootw = r16 data (pos+20)
534 and rooth = r16 data (pos+22) in
535 state.mink <- minkk;
536 state.maxk <- maxkk;
537 state.idbase <- idbase;
538 vlog "vendor = %S, maj=%d min=%d" vendor maj min;
539 vlog "screens = %d formats = %d" screens formats;
540 vlog "minkk = %d maxkk = %d" minkk maxkk;
541 vlog "idbase = %#x idmask = %#x" idbase idmask;
542 vlog "root=%#x %dx%d" root rootw rooth;
544 let mask = 0
545 + 0x00000001 (* KeyPress *)
546 (* + 0x00000002 *) (* KeyRelease *)
547 + 0x00000004 (* ButtonPress *)
548 + 0x00000008 (* ButtonRelease *)
549 + 0x00000010 (* EnterWindow *)
550 + 0x00000020 (* LeaveWindow *)
551 + 0x00000040 (* PointerMotion *)
552 (* + 0x00000080 *) (* PointerMotionHint *)
553 (* + 0x00000100 *) (* Button1Motion *)
554 (* + 0x00000200 *) (* Button2Motion *)
555 (* + 0x00000400 *) (* Button3Motion *)
556 (* + 0x00000800 *) (* Button4Motion *)
557 (* + 0x00001000 *) (* Button5Motion *)
558 + 0x00002000 (* ButtonMotion *)
559 (* + 0x00004000 *) (* KeymapState *)
560 + 0x00008000 (* Exposure *)
561 + 0x00010000 (* VisibilityChange *)
562 + 0x00020000 (* StructureNotify *)
563 (* + 0x00040000 *) (* ResizeRedirect *)
564 (* + 0x00080000 *) (* SubstructureNotify *)
565 (* + 0x00100000 *) (* SubstructureRedirect *)
566 (* + 0x00200000 *) (* FocusChange *)
567 (* + 0x00400000 *) (* PropertyChange *)
568 (* + 0x00800000 *) (* ColormapChange *)
569 (* + 0x01000000 *) (* OwnerGrabButton *)
571 let wid = state.idbase in
572 state.w <- w;
573 state.h <- h;
574 let s = createwindowreq wid root 0 0 w h 0 mask in
575 sendstr s sock;
577 let s = mapreq wid in
578 sendstr s sock;
580 let s = getkeymapreq state.mink (state.maxk-state.mink) in
581 sendwithrep sock s (updkmap sock);
583 sendintern sock "WM_PROTOCOLS" false (fun resp ->
584 state.protoatom <- r32 resp 8;
585 sendintern sock "WM_DELETE_WINDOW" false (fun resp ->
586 state.deleatom <- r32 resp 8;
587 let s = s32 state.deleatom in
588 let s = changepropreq wid state.protoatom 4 32 s in
589 sendstr s sock;
593 sendintern sock "WM_CLASS" false (fun resp ->
594 let atom = r32 resp 8 in
595 let llpp = "llpp\000llpp\000" in
596 let s = changepropreq wid atom 31 8 llpp in
597 sendstr s sock;
600 let s = openfontreq (wid+1) "cursor" in
601 sendstr s sock;
603 Array.iteri (fun i glyphindex ->
604 let s = createglyphcursorreq (wid+1) (wid+2+i) glyphindex in
605 sendstr s sock;
606 ) [|34;48;50;58;128;152|];
608 sendintern sock "UTF8_STRING" false (fun resp ->
609 state.stringatom <- r32 resp 8;
612 sendintern sock "_NET_WM_STATE" true (fun resp ->
613 let nwmsatom = r32 resp 8 in
614 sendintern sock "_NET_WM_STATE_FULLSCREEN" true (fun resp ->
615 let fsatom = r32 resp 8 in
617 state.fullscreen <-
618 (fun wid ->
619 let data = String.make 20 '\000' in
620 state.fs <- not state.fs;
621 w32 data 0 (if state.fs then 1 else 0);
622 w32 data 4 fsatom;
624 let cm = clientmessage 32 0 wid nwmsatom data in
625 let s = sendeventreq 0 root 0x180000 cm in
626 sendstr s sock;
631 glx wid
633 | c ->
634 error "unknown conection setup response %d" (Char.code c)
637 let getauth haddr dnum =
638 let haddr =
639 if haddr = "localhost"
640 then
641 try Unix.gethostname ()
642 with exn ->
643 dolog "failed to resolve `%S': %s" haddr (Printexc.to_string exn);
644 haddr
645 else haddr
647 let readauth ic =
648 let input_string ic len =
649 let s = String.create len in
650 really_input ic s 0 len;
653 let r16 s =
654 let rb pos = Char.code (String.get s pos) in
655 (rb 1) lor ((rb 0) lsl 8)
657 let rec find () =
658 let rs () =
659 let s = input_string ic 2 in
660 let n = r16 s in
661 input_string ic n
663 let family = input_string ic 2 in
664 let addr = rs () in
665 let nums = rs () in
666 let num = int_of_string nums in
667 let name = rs () in
668 let data = rs () in
670 vlog "family %S addr %S(%S) num %d(%d) name %S data %S"
671 family addr haddr num dnum name data;
672 if addr = haddr && num = dnum
673 then name, data
674 else find ()
676 let name, data =
677 try find () with _ -> "", ""
679 close_in ic;
680 name, data;
682 let path =
683 try Sys.getenv "XAUTHORITY"
684 with Not_found -> Filename.concat (Sys.getenv "HOME") ".Xauthority"
686 let opt =
687 try Some (open_in_bin path)
688 with exn ->
689 dolog "failed to open X authority file `%S' : %s"
690 path
691 (Printexc.to_string exn);
692 None
694 match opt with
695 | None -> "", ""
696 | Some ic -> readauth ic
699 let init t w h =
700 let d =
701 try Sys.getenv "DISPLAY"
702 with exn ->
703 error "Could not get DISPLAY evironment variable: %s"
704 (Printexc.to_string exn)
706 let colonpos = String.index d ':' in
707 let host = String.sub d 0 colonpos in
708 let dispnum, screennum =
710 let dotpos = String.index_from d (colonpos + 1) '.' in
711 let disp = String.sub d (colonpos + 1) (dotpos - colonpos - 1) in
712 let screen = String.sub d (dotpos + 1) (String.length d - dotpos - 1) in
713 int_of_string disp, int_of_string screen
714 with Not_found ->
715 let disp = String.sub d (colonpos + 1) (String.length d - colonpos - 1) in
716 int_of_string disp, 0
718 let aname, adata = getauth host dispnum in
719 let fd =
720 if String.length host = 0 || host = "unix"
721 then
722 let addr = Unix.ADDR_UNIX ("/tmp/.X11-unix/X" ^ string_of_int dispnum) in
723 let fd = Unix.socket Unix.PF_UNIX Unix.SOCK_STREAM 0 in
724 Unix.connect fd addr;
726 else
727 let h = Unix.gethostbyname host in
728 let addr = h.Unix.h_addr_list.(0) in
729 let port = 6000 + dispnum in
730 let fd = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
731 Unix.connect fd (Unix.ADDR_INET (addr, port));
734 cloexec fd;
735 let s = "luMMmmnndduu" in
736 let s = padcat s aname in
737 let s = padcat s adata in
738 w16 s 2 11;
739 w16 s 4 0;
740 w16 s 6 (String.length aname);
741 w16 s 8 (String.length adata);
742 sendstr s fd;
743 state.sock <- fd;
744 setup fd screennum w h;
745 state.t <- t;
749 let settitle s =
750 let s = changepropreq state.idbase 39 state.stringatom 8 s in
751 sendstr s state.sock;
754 let setcursor cursor =
755 let n =
756 match cursor with
757 | CURSOR_INHERIT -> -1
758 | CURSOR_INFO -> 3
759 | CURSOR_CYCLE -> 2
760 | CURSOR_CROSSHAIR -> 0
761 | CURSOR_TEXT -> 5
763 let s = s32 (if n = -1 then 0 else state.idbase+2+n) in
764 let s = changewindowattributesreq state.idbase (*cursor*)0x4000 s in
765 sendstr s state.sock;
768 let fullscreen () =
769 state.fullscreen state.idbase;
772 let metamask = 0x40;;
773 let altmask = 8;;
774 let shiftmask = 1;;
775 let ctrlmask = 4;;
777 let withalt mask = mask land altmask != 0;;
778 let withctrl mask = mask land ctrlmask != 0;;
779 let withshift mask = mask land shiftmask != 0;;
780 let withmeta mask = mask land metamask != 0;;
781 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0;;
783 let xlatt, xlatf =
784 let t = Hashtbl.create 20
785 and f = Hashtbl.create 20 in
786 let add n nl k =
787 List.iter (fun s -> Hashtbl.add t s k) (n::nl);
788 Hashtbl.add f k n
790 let addc c =
791 let s = String.create 1 in
792 s.[0] <- c;
793 add s [] (Char.code c)
795 let addcr a b =
796 let an = Char.code a and bn = Char.code b in
797 for i = an to bn do addc (Char.chr i) done;
799 addcr '0' '9';
800 addcr 'a' 'z';
801 addcr 'A' 'Z';
802 String.iter addc "`~!@#$%^&*()-_=+\\|[{]};:,./?";
803 for i = 0 to 29 do add ("f" ^ string_of_int (i+1)) [] (0xffbe + i) done;
804 add "space" [] 0x20;
805 add "return" ["ret"; "enter"] 0xff0d;
806 add "tab" [] 0xff09;
807 add "left" [] 0xff51;
808 add "right" [] 0xff53;
809 add "home" [] 0xff50;
810 add "end" [] 0xff57;
811 add "delete" ["del"] 0xffff;
812 add "escape" ["esc"] 0xff1b;
813 add "pgup" ["pageup"] 0xff55;
814 add "pgdown" ["pagedown"] 0xff56;
815 add "backspace" [] 0xff08;
816 add "up" [] 0xff52;
817 add "down" [] 0xff54;
818 t, f;
821 let keyname k =
822 try Hashtbl.find xlatf k
823 with Not_found -> Printf.sprintf "%#x" k;
826 let namekey name =
827 try Hashtbl.find xlatt name
828 with Not_found ->
829 if String.length name = 1
830 then Char.code name.[0]
831 else error "can not find keysym for %S" name;