15 let tempfailureretry f a
=
17 try f a
with Unix.Unix_error
(Unix.EINTR
, _
, _
) -> g ()
21 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
22 external glx
: int -> unit = "ml_glx";;
23 external glxsync
: unit -> unit = "ml_glxsync";;
24 external swapb
: unit -> unit = "ml_swapb";;
25 external hasdata
: Unix.file_descr
-> bool = "ml_hasdata";;
26 external toutf8
: int -> string = "ml_keysymtoutf8";;
28 let dolog fmt
= Format.kprintf prerr_endline fmt
;;
29 let vlog fmt
= Format.kprintf ignore fmt
;;
34 method reshape _ _
= ()
35 method mouse _ _ _ _ _
= ()
36 method motion _ _
= ()
37 method pmotion _ _
= ()
41 method winstate _
= ()
48 method reshape
: int -> int -> unit
49 method mouse
: int -> bool -> int -> int -> int -> unit
50 method motion
: int -> int -> unit
51 method pmotion
: int -> int -> unit
52 method key
: int -> int -> unit
53 method enter
: int -> int -> unit
55 method winstate
: winstate list
-> unit
62 ; mutable keymap
: int array array
63 ; fifo
: (string -> unit) Queue.t
65 ; mutable protoatom
: int
66 ; mutable deleatom
: int
67 ; mutable nwmsatom
: int
68 ; mutable maxvatom
: int
69 ; mutable maxhatom
: int
70 ; mutable fulsatom
: int
71 ; mutable idbase
: int
72 ; mutable fullscreen
: (int -> unit)
73 ; mutable setwmname
: (string -> unit)
74 ; mutable actwin
: (unit -> unit)
75 ; mutable stringatom
: int
77 ; mutable sock
: Unix.file_descr
83 ; mutable curcurs
: cursor
84 ; mutable capslmask
: int
85 ; mutable numlmask
: int
86 ; mutable levl3mask
: int
87 ; mutable levl5mask
: int
91 | Fs
of (int * int * int * int)
98 ; fifo
= Queue.create
()
107 ; fullscreen
= (fun _
-> ())
108 ; setwmname
= (fun _
-> ())
109 ; actwin
= (fun _
-> ())
118 ; curcurs
= CURSOR_INHERIT
126 let w8 s pos i
= String.set s pos
(Char.chr
(i
land 0xff));;
130 w8 s
(pos
+1) (i
lsr 8);
135 w16 s
(pos
+2) (i
lsr 16);
139 let rb pos1
= Char.code
(String.get s
(pos
+ pos1
)) in
140 (rb 0) lor ((rb 1) lsl 8)
145 i - ((i land 0x8000) lsl 1);
148 let r8 s pos
= Char.code
(String.get s pos
);;
151 let rb pos1
= Char.code
(String.get s
(pos
+ pos1
)) in
152 let l = (rb 0) lor ((rb 1) lsl 8)
153 and u
= (rb 2) lor ((rb 3) lsl 8) in
157 let exntos = function
158 | Unix.Unix_error
(e
, s
, a
) -> Printf.sprintf
"%s(%s):%s(%d)"
159 s a
(Unix.error_message e
) (Obj.magic e
)
160 | exn
-> Printexc.to_string exn
;
163 let error fmt
= Printf.kprintf failwith fmt
;;
166 let s = String.create n
in
168 let m = tempfailureretry (Unix.read sock
s pos
) n
in
173 ignore
(tempfailureretry (Unix.select
[sock
] [] []) 0.01);
174 loop (pos
+ m) (n
- m)
181 let sendstr1 s pos len sock
=
182 vlog "%d => %S" state.seq
s;
183 state.seq
<- state.seq
+ 1;
184 let n = tempfailureretry (Unix.send sock
s pos len
) [] in
186 then error "send %d returned %d" len
n;
189 let updkmap sock resp
=
190 let syms = r8 resp
1 in
191 let len = r32 resp
4 in
194 then readstr sock
(4*len)
197 let m = len / syms in
198 state.keymap
<- Array.make_matrix
199 (state.maxk
- state.mink
) syms 0xffffff;
200 let rec loop i = if i = m then () else
202 let rec loop2 k l = if l = syms then () else
203 let v = r32 data k in
204 state.keymap
.(i).(l) <- v;
213 let updmodmap sock resp
=
215 let len = r16 resp
4 in
218 then readstr sock
(len*4)
221 let modmap = Array.make_matrix
8 n 0xffffff in
222 let rec loop l = if l = 8 then () else
224 let rec loop1 m = if m = n then () else
226 let code = r8 data p in
227 modmap.(l).(m) <- code;
230 let ki = code - state.mink
in
233 let a = state.keymap
.(ki) in
234 let rec capsloop i = if i = Array.length
a || i > 3 then () else
237 then state.capslmask
<- 2
245 let ki = code - state.mink
in
248 let a = state.keymap
.(ki) in
249 let rec lloop i = if i = Array.length
a || i > 3 then () else
252 | 0xfe03 -> state.levl3mask
<- 1 lsl l
253 | 0xfe11 -> state.levl5mask
<- 1 lsl l
254 | 0xff7f -> state.numlmask
<- 1 lsl l
268 let sendwithrep sock
s f
=
269 Queue.push f
state.fifo
;
270 sendstr1 s 0 (String.length
s) sock
;
274 let b = Buffer.create
16 in
275 List.iter
(Buffer.add_string
b) ss
;
276 let bl = Buffer.length
b in
277 let pl = bl land 3 in
281 Buffer.add_substring
b pad 0 (4 - pl);
286 let padcat s1 s2
= padcatl [s1
; s2
];;
288 let internreq name onlyifexists
=
289 let s = "\016\000\000\000\000\000\000\000" in
290 let s = padcat s name
in
291 if onlyifexists
then w8 s 1 1;
292 w16 s 2 (String.length
s / 4);
293 w16 s 4 (String.length name
);
297 let sendintern sock
s onlyifexists f
=
298 let s = internreq s onlyifexists
in
299 sendwithrep sock
s f
;
302 let createwindowreq wid parent x y w h bw mask
=
303 let s = "\001\000\009\000wwwwppppxxyywwhhbwccvvvvmmmmeeee" in
313 w32 s 28 0x800; (* eventmask *)
318 let getgeometryreq wid
=
319 let s = "\014u\002\000dddd" in
325 let s = "\008u\002\000wwww" in
330 let getkeymapreq first count
=
331 let s = "\101u\002\000fcuu" in
337 let changepropreq wid prop typ format props
=
338 let s = "\018\000llwwwwppppttttfuuuLLLL" in
339 let s = padcat s props
in
340 w16 s 2 (String.length
s / 4);
345 let ful = String.length props
/ (match format
with
349 | n -> error "no idea what %d means" n)
355 let getpropreq delete wid prop typ
=
356 let s = "\020\000\006\000wwwwppppttttooooLLLL" in
357 if delete
then w8 s 1 1;
366 let openfontreq fid name
=
367 let s = "\045ullffffnnuu" in
368 let s = padcat s name
in
369 w16 s 2 (String.length
s / 4);
371 w16 s 8 (String.length name
);
375 let createglyphcursorreq fid cid cindex
=
376 let s = "\094u\008\000ccccffffffffssmmrrggbbRRGGBB" in
391 let changewindowattributesreq wid mask attrs
=
392 let s = "\002ullwwwwmmmm" in
393 let s = padcat s attrs
in
394 w16 s 2 (String.length
s / 4);
400 let configurewindowreq wid mask values
=
401 let s = "\012ullwwwwmmuu" in
402 let s = padcat s values
in
403 w16 s 2 (String.length
s / 4);
415 let clientmessage format seq wid typ
data =
416 let s = "\033fsswwwwtttt" in
417 let s = padcat s data in
425 let sendeventreq propagate destwid mask
data =
426 let s = "\025p\011\000wwwwmmmm" in
427 let s = padcat s data in
434 let getmodifiermappingreq () =
435 let s = "\119u\001\000" in
439 let getkeysym code mask
=
440 let pkpk = state.keymap
.(code-state.mink
).(0) in
441 if (pkpk >= 0xff80 && pkpk <= 0xffbd)
442 || (pkpk >= 0x11000000 && pkpk <= 0x1100ffff)
444 if mask
land state.numlmask
!= 0
446 let keysym = state.keymap
.(code-state.mink
).(1) in
447 if keysym = 0 then pkpk else keysym
451 let shift = (mask
land 1) lxor ((mask
land state.capslmask
) lsr 1) in
453 let l3 = (mask
land state.levl3mask
) != 0 in
454 let l4 = (mask
land state.levl5mask
) != 0 in
456 if l3 then (if l4 then 8 else 4) else (if l4 then 6 else 0)
458 let keysym = state.keymap
.(code-state.mink
).(index) in
459 if index land 1 = 1 && keysym = 0
460 then state.keymap
.(code-state.mink
).(index - 1)
466 let resp = readstr sock
32 in
467 let opcode = r8 resp 0 in
468 match opcode land lnot
0x80 with
473 and resid
= r32 resp 4
476 error "code=%d serial=%d resid=%#x min=%d maj=%d\n%S"
477 code serial resid min maj
resp;
479 | 1 -> (* response *)
480 let rep = Queue.pop
state.fifo
in
483 | 2 -> (* key press *)
484 if Array.length
state.keymap
> 0
486 let code = r8 resp 1 in
487 let mask = r16 resp 28 in
488 let keysym = getkeysym code mask in
489 vlog "keysym = %x %c mask %#x code %d"
490 keysym (Char.unsafe_chr
keysym) mask code;
491 state.t#key
keysym mask;
493 | 3 -> (* key release *)
494 if Array.length
state.keymap
> 0
496 let code = r8 resp 1 in
497 let mask = r16 resp 28 in
498 let keysym = getkeysym code mask in
499 vlog "release keysym = %x %c mask %#x code %#d"
500 keysym (Char.unsafe_chr
keysym) mask code
502 | 4 -> (* buttonpress *)
506 and m = r16 resp 28 in
507 state.t#mouse
n true x y
m;
510 | 5 -> (* buttonrelease *)
514 and m = r16 resp 28 in
515 state.t#mouse
n false x y
m;
516 vlog "release %d %d %d" n x y
519 let x = r16s resp 24 in
520 let y = r16s resp 26 in
521 let m = r16 resp 28 in
523 then state.t#pmotion
x y
524 else state.t#motion
x y;
525 vlog "move %dx%d => %d" x y m
529 and y = r16s resp 26 in
531 vlog "enter %d %d" x y
536 | 18 -> vlog "unmap";
541 | 12 -> (* exposure *)
545 | 15 -> (* visibility *)
546 let vis = r8 resp 8 in
547 if vis != 2 then state.t#expose
;
548 vlog "visibility %d" vis;
550 | 34 -> (* mapping *)
551 state.keymap
<- [||];
552 let s = getkeymapreq state.mink
(state.maxk
-state.mink
-1) in
553 sendwithrep sock
s (updkmap sock
);
554 state.capslmask
<- 0;
555 state.levl3mask
<- 0;
556 state.levl5mask
<- 0;
558 let s = getmodifiermappingreq () in
559 sendwithrep sock
s (updmodmap sock
);
562 | 33 -> (* clientmessage *)
563 let atom = r32 resp 8 in
564 if atom = state.protoatom
566 let atom = r32 resp 12 in
567 if atom = state.deleatom
572 | 21 -> (* reparent *)
575 | 22 -> (* configure *)
579 and h
= r16 resp 22 in
580 vlog "configure cur [%d %d %d %d] conf [%d %d %d %d]"
581 state.x state.y state.w
state.h
585 if w
!= state.w
|| h
!= state.h
596 let atom = r32 resp 8 in
597 if atom = state.nwmsatom
599 let s = getpropreq false state.idbase
atom 4 in
600 sendwithrep sock
s (fun resp ->
601 let len = r32 resp 4 in
602 let nitems = r32 resp 16 in
607 let s = readstr sock
(len*4) in
608 let rec loop wsl i = if i = nitems then wsl else
609 let atom = r32 s (i*4) in
611 if atom = state.maxhatom
614 if atom = state.maxvatom
617 if atom = state.fulsatom
619 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
629 state.t#winstate
(List.sort compare
wsl)
633 dolog "event %d %S" n resp
639 if hasdata sock
then loop ();
644 let sendstr s ?
(pos
=0) ?
(len=String.length
s) sock
=
645 sendstr1 s pos
len sock
;
646 if hasdata sock
then readresp sock
;
652 let s = "wwuuhhuu" in
655 let s = configurewindowreq state.idbase
0x000c s in
656 sendstr s state.sock
;
657 else state.fullscreen
state.idbase
664 let syncsendwithrep sock secstowait
s f
=
665 let completed = ref false in
666 sendwithrep sock
s (fun resp -> f
resp; completed := true);
667 let now = Unix.gettimeofday
in
668 let deadline = now () +. secstowait
in
669 let rec readtillcompletion () =
671 let timeout = deadline -. now () in
674 else Unix.select
[sock
] [] [] timeout
676 let r, _
, _
= tempfailureretry sf deadline in
678 | [] -> error "didn't get X response in %f seconds, aborting" secstowait
682 then readtillcompletion ()
684 readtillcompletion ();
687 let syncsendintern sock secstowait
s onlyifexists f
=
688 let s = internreq s onlyifexists
in
689 syncsendwithrep sock secstowait
s f
;
692 let setup sock screennum w h
=
693 let s = readstr sock
2 in
694 let n = String.length
s in
696 then error "failed to read X connection setup response n=%d" n;
699 let reasonlen = r8 s 1 in
700 let s = readstr sock
6 in
705 let data = readstr sock
len in
706 let reason = String.sub
data 0 reasonlen in
707 error "X connection failed maj=%d min=%d reason=%S"
710 | '
\002'
-> failwith
"X connection setup failed: authentication required";
713 let s = readstr sock
38 in
717 and idbase
= r32 s 10
718 and idmask
= r32 s 14
720 and screens
= r8 s 26
721 and formats
= r8 s 27
723 and maxkk
= r8 s 33 in
724 let data = readstr sock
(4*add
-32) in
725 let vendor = String.sub
data 0 vlen
in
726 let pos = ((vlen
+3) land lnot
3) + formats
*8 in
728 if screennum
>= screens
729 then error "invalid screen %d, max %d" screennum
(screens
-1);
733 let rec findscreen n pos = if n = screennum
then pos else
735 let ndepths = r8 s (pos+39) in
736 let rec skipdepths n pos = if n = ndepths then pos else
738 let nvisiuals = r16 s (pos+2) in
739 pos + nvisiuals*24 + 8
743 skipdepths n (pos+40)
749 let root = r32 data pos in
750 let rootw = r16 data (pos+20)
751 and rooth
= r16 data (pos+22) in
754 state.idbase
<- idbase
;
755 vlog "vendor = %S, maj=%d min=%d" vendor maj min
;
756 vlog "screens = %d formats = %d" screens formats
;
757 vlog "minkk = %d maxkk = %d" minkk maxkk
;
758 vlog "idbase = %#x idmask = %#x" idbase idmask
;
759 vlog "root=%#x %dx%d" root rootw rooth
;
762 + 0x00000001 (* KeyPress *)
763 (* + 0x00000002 *) (* KeyRelease *)
764 + 0x00000004 (* ButtonPress *)
765 + 0x00000008 (* ButtonRelease *)
766 + 0x00000010 (* EnterWindow *)
767 + 0x00000020 (* LeaveWindow *)
768 + 0x00000040 (* PointerMotion *)
769 (* + 0x00000080 *) (* PointerMotionHint *)
770 (* + 0x00000100 *) (* Button1Motion *)
771 (* + 0x00000200 *) (* Button2Motion *)
772 (* + 0x00000400 *) (* Button3Motion *)
773 (* + 0x00000800 *) (* Button4Motion *)
774 (* + 0x00001000 *) (* Button5Motion *)
775 + 0x00002000 (* ButtonMotion *)
776 (* + 0x00004000 *) (* KeymapState *)
777 + 0x00008000 (* Exposure *)
778 + 0x00010000 (* VisibilityChange *)
779 + 0x00020000 (* StructureNotify *)
780 (* + 0x00040000 *) (* ResizeRedirect *)
781 (* + 0x00080000 *) (* SubstructureNotify *)
782 (* + 0x00100000 *) (* SubstructureRedirect *)
783 (* + 0x00200000 *) (* FocusChange *)
784 + 0x00400000 (* PropertyChange *)
785 (* + 0x00800000 *) (* ColormapChange *)
786 (* + 0x01000000 *) (* OwnerGrabButton *)
788 let wid = state.idbase
in
789 let s = createwindowreq wid root 0 0 w h
0 mask in
792 sendintern sock
"WM_PROTOCOLS" false (fun resp ->
793 state.protoatom
<- r32 resp 8;
794 sendintern sock
"WM_DELETE_WINDOW" false (fun resp ->
795 state.deleatom
<- r32 resp 8;
796 let s = s32 state.deleatom
in
797 let s = changepropreq wid state.protoatom
4 32 s in
802 sendintern sock
"WM_CLIENT_MACHINE" false (fun resp ->
803 let atom = r32 resp 8 in
806 try Unix.gethostname
()
808 dolog "error getting host name: %s" (exntos exn
);
813 let s = changepropreq wid atom state.stringatom
8 hostname in
815 sendintern sock
"_NET_WM_PID" false (fun resp ->
816 let atom = r32 resp 8 in
817 let pid = Unix.getpid
() in
819 let s = changepropreq wid atom (* cardinal *)6 32 s in
824 state.actwin
<- (fun () ->
826 let s = configurewindowreq state.idbase
0x40 s in
827 sendstr s state.sock
;
828 let s = mapreq state.idbase
in
829 sendstr s state.sock
;
832 sendintern sock
"_NET_ACTIVE_WINDOW" true (fun resp ->
833 let atom = r32 resp 8 in
834 state.actwin
<- (fun () ->
835 let data = String.make
20 '
\000'
in
836 let cm = clientmessage 32 0 wid atom data in
837 let s = sendeventreq 0 root 0x180000 cm in
838 sendstr s state.sock
;
842 syncsendintern sock
2.0 "WM_CLASS" false (fun resp ->
843 let atom = r32 resp 8 in
844 let llpp = "llpp\000llpp\000" in
845 let s = changepropreq wid atom 31 8 llpp in
849 let s = mapreq wid in
852 let s = getkeymapreq state.mink
(state.maxk
-state.mink
) in
853 sendwithrep sock
s (updkmap sock
);
855 let s = getmodifiermappingreq () in
856 sendwithrep sock
s (updmodmap sock
);
858 let s = openfontreq (wid+1) "cursor" in
861 Array.iteri
(fun i glyphindex
->
862 let s = createglyphcursorreq (wid+1) (wid+2+i) glyphindex
in
864 ) [|34;48;50;58;128;152|];
866 sendintern sock
"UTF8_STRING" true (fun resp ->
867 let atom = r32 resp 8 in
869 then state.stringatom
<- atom;
873 let s = changepropreq state.idbase
39 state.stringatom
8 s in
874 sendstr s state.sock
;
876 state.setwmname <- setwmname;
877 sendintern sock
"_NET_WM_NAME" true (fun resp ->
878 let atom = r32 resp 8 in
880 then state.setwmname <- (fun s ->
882 let s = changepropreq state.idbase
atom state.stringatom
8 s in
883 sendstr s state.sock
;
887 state.fullscreen
<- (fun wid ->
888 let s = "xxuuyyuuwwuuhhuu" in
895 let s = configurewindowreq wid 0x000f s in
896 sendstr s state.sock
;
897 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
904 let s = configurewindowreq wid 0x000f s in
905 sendstr s state.sock
;
909 sendintern sock
"_NET_WM_STATE" true (fun resp ->
910 state.nwmsatom
<- r32 resp 8;
911 if state.nwmsatom
!= 0
913 sendintern sock
"_NET_WM_STATE_MAXIMIZED_VERT" true (fun resp ->
914 state.maxvatom
<- r32 resp 8;
916 sendintern sock
"_NET_WM_STATE_MAXIMIZED_HORZ" true (fun resp ->
917 state.maxhatom
<- r32 resp 8;
919 sendintern sock
"_NET_WM_STATE_FULLSCREEN" true (fun resp ->
920 state.fulsatom
<- r32 resp 8;
921 if state.fulsatom
!= 0
925 let data = String.make
20 '
\000'
in
928 | NoFs
-> Fs
(-1, -1, -1, -1), 1
932 w32 data 4 state.fulsatom
;
934 let cm = clientmessage 32 0 wid state.nwmsatom
data in
935 let s = sendeventreq 0 root 0x180000 cm in
942 let s = getgeometryreq wid in
943 syncsendwithrep sock
2.0 s (fun resp ->
946 and h
= r16 resp 18 in
952 error "unknown conection setup response %d" (Char.code c
)
955 let getauth haddr dnum
=
957 if haddr = "localhost" || String.length
haddr = 0
959 try Unix.gethostname
()
961 dolog "failed to resolve `%S': %s" haddr (exntos exn
);
966 try Sys.getenv
"XAUTHORITY"
968 try Filename.concat
(Sys.getenv
"HOME") ".Xauthority"
972 let input_string ic
len =
973 let s = String.create
len in
974 really_input ic
s 0 len;
978 let rb pos = Char.code (String.get
s pos) in
979 (rb 1) lor ((rb 0) lsl 8)
983 let s = input_string ic
2 in
987 let family = input_string ic
2 in
991 try Some
(int_of_string
nums)
994 "display number(%S) is not an integer (corrupt %S?): %s"
995 nums path (exntos exn
);
1001 vlog "family %S addr %S(%S) num %S(%d) name %S data %S"
1002 family addr haddr nums dnum
name data;
1004 | Some num
when addr = haddr && num
= dnum
->
1011 | End_of_file
-> "", ""
1013 dolog "exception while reading X authority data (%S): %s"
1022 if String.length
path = 0
1024 else Some
(open_in_bin
path)
1026 if Sys.file_exists
path
1028 dolog "failed to open X authority file `%S' : %s"
1034 | Some ic
-> readauth ic
1037 let init t
w h osx
=
1039 try Sys.getenv
"DISPLAY"
1041 error "could not get DISPLAY evironment variable: %s"
1046 then error "invalid DISPLAY(%s) %S" w d
1048 let s = String.sub
d b (e
- b) in
1051 error "invalid DISPLAY %S can not parse %s(%S): %s"
1055 if pos = String.length
d
1056 then error "invalid DISPLAY %S no display number specified" d
1060 let rec pdispnum pos1
=
1061 if pos1
= String.length
d
1062 then getnum "display number" (pos+1) pos1
, 0
1066 let dispnum = getnum "display number" (pos+1) pos1
in
1067 let rec pscreennum pos2
=
1068 if pos2
= String.length
d
1069 then getnum "screen number" (pos1
+1) pos2
1072 | '
0'
.. '
9'
-> pscreennum (pos2
+1)
1074 error "invalid DISPLAY %S, cannot parse screen number" d
1076 dispnum, pscreennum (pos1
+1)
1077 | '
0'
.. '
9'
-> pdispnum (pos1
+1)
1079 error "invalid DISPLAY %S, cannot parse display number" d
1081 String.sub
d 0 pos, pdispnum (pos+1)
1085 let host, (dispnum, screennum
) = phost 0 in
1086 let aname, adata
= getauth host dispnum in
1089 if osx
|| String.length
host = 0 || host = "unix"
1093 then Unix.ADDR_UNIX
d
1094 else Unix.ADDR_UNIX
("/tmp/.X11-unix/X" ^ string_of_int
dispnum)
1096 let fd = Unix.socket
Unix.PF_UNIX
Unix.SOCK_STREAM
0 in
1100 try Unix.gethostbyname
host
1102 error "cannot resolve %S: %s" host (exntos exn
)
1104 let addr = h.Unix.h_addr_list
.(0) in
1105 let port = 6000 + dispnum in
1106 let fd = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
1107 fd, (Unix.ADDR_INET
(addr, port))
1109 try Unix.connect
fd addr; fd
1111 error "failed to connect to X: %s" (exntos exn
)
1114 let s = "luMMmmnndduu" in
1115 let s = padcat s aname in
1116 let s = padcat s adata
in
1119 w16 s 6 (String.length
aname);
1120 w16 s 8 (String.length adata
);
1121 sendstr1 s 0 (String.length
s) fd;
1123 setup fd screennum
w h;
1125 fd, state.w, state.h;
1132 let setcursor cursor
=
1133 if cursor
!= state.curcurs
1137 | CURSOR_INHERIT
-> -1
1140 | CURSOR_CROSSHAIR
-> 0
1143 let s = s32 (if n = -1 then 0 else state.idbase
+2+n) in
1144 let s = changewindowattributesreq state.idbase
(*cursor*)0x4000 s in
1145 sendstr s state.sock
;
1146 state.curcurs
<- cursor
;
1150 state.fullscreen state.idbase
;
1153 let metamask = 0x40;;
1158 let withalt mask = mask land altmask != 0;;
1159 let withctrl mask = mask land ctrlmask != 0;;
1160 let withshift mask = mask land shiftmask != 0;;
1161 let withmeta mask = mask land metamask != 0;;
1162 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0;;
1165 let t = Hashtbl.create
20
1166 and f
= Hashtbl.create
20 in
1168 List.iter
(fun s -> Hashtbl.add t s k) (n::nl
);
1172 let s = String.create
1 in
1174 add s [] (Char.code c
)
1177 let an = Char.code a and bn
= Char.code b in
1178 for i = an to bn
do addc (Char.chr
i) done;
1183 String.iter
addc "`~!@#$%^&*()-_=+\\|[{]};:,./<>?";
1184 for i = 0 to 29 do add ("f" ^ string_of_int
(i+1)) [] (0xffbe + i) done;
1185 add "space" [] 0x20;
1186 add "ret" ["return"; "enter"] 0xff0d;
1187 add "tab" [] 0xff09;
1188 add "left" [] 0xff51;
1189 add "right" [] 0xff53;
1190 add "home" [] 0xff50;
1191 add "end" [] 0xff57;
1192 add "ins" ["insert"] 0xff63;
1193 add "del" ["delete"] 0xffff;
1194 add "esc" ["escape"] 0xff1b;
1195 add "pgup" ["pageup"] 0xff55;
1196 add "pgdown" ["pagedown"] 0xff56;
1197 add "backspace" [] 0xff08;
1199 add "down" [] 0xff54;
1204 try Hashtbl.find xlatf
k
1205 with Not_found
-> Printf.sprintf
"%#x" k;
1209 try Hashtbl.find xlatt name
1211 if String.length
name = 1
1212 then Char.code name.[0]
1213 else int_of_string
name;