3 let (~
>) = Bytes.unsafe_of_string
;;
25 type wid
= int and screenno
= int and vid
= int and atom
= int;;
27 external glxinit
: string -> wid
-> screenno
-> vid
= "ml_glxinit";;
28 external glxcompleteinit
: unit -> unit = "ml_glxcompleteinit";;
29 external swapb
: unit -> unit = "ml_swapb";;
31 let vlog fmt
= Format.ksprintf ignore fmt
;;
38 method reshape _ _
= ()
39 method mouse _ _ _ _ _
= ()
40 method motion _ _
= ()
41 method pmotion _ _
= ()
45 method winstate _
= ()
51 method map
: bool -> unit
53 method visible
: visiblestate
-> unit
54 method reshape
: int -> int -> unit
55 method mouse
: int -> bool -> int -> int -> int -> unit
56 method motion
: int -> int -> unit
57 method pmotion
: int -> int -> unit
58 method key
: int -> int -> unit
59 method enter
: int -> int -> unit
61 method winstate
: winstate list
-> unit
68 ; mutable keymap
: int array array
69 ; fifo
: (bytes
-> unit) Queue.t
71 ; mutable protoatom
: atom
72 ; mutable deleatom
: atom
73 ; mutable nwmsatom
: atom
74 ; mutable maxvatom
: atom
75 ; mutable maxhatom
: atom
76 ; mutable fulsatom
: atom
77 ; mutable idbase
: int
80 ; mutable fullscreen
: (int -> unit)
81 ; mutable setwmname
: (bytes
-> unit)
82 ; mutable actwin
: (unit -> unit)
83 ; mutable stringatom
: int
85 ; mutable sock
: Unix.file_descr
91 ; mutable curcurs
: cursor
92 ; mutable capslmask
: int
93 ; mutable numlmask
: int
94 ; mutable levl3mask
: int
95 ; mutable levl5mask
: int
99 | Fs
of (int * int * int * int)
106 ; fifo
= Queue.create
()
117 ; fullscreen
= (fun _
-> ())
118 ; setwmname
= (fun _
-> ())
119 ; actwin
= (fun _
-> ())
128 ; curcurs
= CURSOR_INHERIT
138 let makereq opcode len reqlen
=
139 let s = Bytes.create len
in
145 let recv fd
s pos len
=
146 Unix.read fd
s pos len
;
150 let s = Bytes.create n
in
152 let m = tempfailureretry
(recv sock
s pos
) n
in
157 ignore
(tempfailureretry
(Unix.select
[sock
] [] []) 0.01);
158 loop (pos
+ m) (n
- m)
165 let sendstr1 s pos len sock
=
166 let s = Bytes.unsafe_to_string
s in
167 vlog "%d <= %S" state.seq
s;
168 state.seq
<- state.seq
+ 1;
169 let n = tempfailureretry
(Unix.write_substring sock
s pos
) len
in
171 then error
"send %d returned %d" len
n;
174 let updkmap sock resp
=
175 let syms = r8 resp
1 in
176 let len = r32 resp
4 in
179 then readstr sock
(4*len)
182 let m = len / syms in
183 state.keymap
<- Array.make_matrix
184 (state.maxk
- state.mink
) syms 0xffffff;
185 let rec loop i
= if i
= m then () else
187 let rec loop2 k l
= if l
= syms then () else
188 let v = r32
data k in
189 state.keymap
.(i
).(l
) <- v;
198 let updmodmap sock resp
=
200 let len = r16 resp
4 in
203 then readstr sock
(len*4)
206 if len > 0 then (*???*)
207 let modmap = Array.make_matrix
8 n 0xffffff in
208 let rec loop l
= if l
= 8 then () else
210 let rec loop1 m = if m = n then () else
212 let code = r8
data p in
213 modmap.(l
).(m) <- code;
216 let ki = code - state.mink
in
219 let a = state.keymap
.(ki) in
220 let rec capsloop i
= if i
= Array.length
a || i
> 3 then () else
223 then state.capslmask
<- 2
231 let ki = code - state.mink
in
234 let a = state.keymap
.(ki) in
235 let rec lloop i
= if i
= Array.length
a || i
> 3 then () else
238 | 0xfe03 -> state.levl3mask
<- 1 lsl l
239 | 0xfe11 -> state.levl5mask
<- 1 lsl l
240 | 0xff7f -> state.numlmask
<- 1 lsl l
254 let sendwithrep sock
s f
=
255 Queue.push f
state.fifo
;
256 sendstr1 s 0 (Bytes.length
s) sock
;
262 let b = Buffer.create
16 in
263 List.iter
(Buffer.add_bytes
b) ss
;
264 let bl = Buffer.length
b in
265 let pl = bl land 3 in
268 Buffer.add_substring
b pad 0 (4 - pl);
273 let padcat s1 s2
= padcatl [s1
; s2
];;
275 let internreq name onlyifexists
=
276 let s = makereq 16 8 8 in
277 let s = padcat s name
in
278 w8
s 1 (if onlyifexists
then 1 else 0);
279 w16
s 2 (Bytes.length
s / 4);
280 w16
s 4 (Bytes.length name
);
284 let sendintern sock
s onlyifexists f
=
285 let s = internreq s onlyifexists
in
286 sendwithrep sock
s f
;
289 let createwindowreq wid parent x y w h bw eventmask vid depth mid
=
290 let s = makereq 1 48 12 in
299 w16
s 22 0; (* inputoutput *)
300 w32
s 24 vid
; (* visual *)
301 w32
s 28 0x280a; (* eventmask*)
309 let createcolormapreq mid wid vid
=
310 let s = makereq 78 16 4 in
318 let getgeometryreq wid
=
319 let s = makereq 14 8 2 in
325 let s = makereq 8 8 2 in
330 let getkeymapreq first count
=
331 let s = makereq 101 8 2 in
337 let changepropreq wid prop typ format props
=
338 let s = makereq 18 24 0 in
339 let s = padcat s props
in
341 w16
s 2 (Bytes.length
s / 4);
346 let ful = Bytes.length props
/ (match format
with
350 | n -> error
"no idea what %d means" n)
356 let getpropreq delete wid prop typ
=
357 let s = makereq 20 24 6 in
358 w8
s 1 (if delete
then 1 else 0);
367 let openfontreq fid name
=
368 let s = makereq 45 12 0 in
369 let s = padcat s name
in
370 w16
s 2 (Bytes.length
s / 4);
372 w16
s 8 (Bytes.length name
);
376 let createglyphcursorreq fid cid cindex
=
377 let s = makereq 94 32 8 in
392 let changewindowattributesreq wid mask attrs
=
393 let s = makereq 2 12 0 in
394 let s = padcat s attrs
in
395 w16
s 2 (Bytes.length
s / 4);
401 let configurewindowreq wid mask values
=
402 let s = makereq 12 12 0 in
403 let s = padcat s values
in
404 w16
s 2 (Bytes.length
s / 4);
411 let s = Bytes.create
4 in
416 let clientmessage format seq wid typ
data =
417 let s = makereq 33 12 0 in
418 let s = padcat s data in
426 let sendeventreq propagate destwid mask
data =
427 let s = makereq 25 12 11 in
428 let s = padcat s data in
436 let getmodifiermappingreq () =
440 let getkeysym code mask
=
441 let pkpk = state.keymap
.(code-state.mink
).(0) in
442 if (pkpk >= 0xff80 && pkpk <= 0xffbd)
443 || (pkpk >= 0x11000000 && pkpk <= 0x1100ffff)
445 if mask
land state.numlmask
!= 0
447 let keysym = state.keymap
.(code-state.mink
).(1) in
448 if keysym = 0 then pkpk else keysym
453 if pkpk land 0xf000 = 0xf000
455 else (mask
land 1) lxor ((mask
land state.capslmask
) lsr 1)
458 let l3 = (mask
land state.levl3mask
) != 0 in
459 let l4 = (mask
land state.levl5mask
) != 0 in
461 if l3 then (if l4 then 8 else 4) else (if l4 then 6 else 0)
463 let keysym = state.keymap
.(code-state.mink
).(index) in
464 if index land 1 = 1 && keysym = 0
465 then state.keymap
.(code-state.mink
).(index - 1)
471 let resp = readstr sock
32 in
472 let opcode = r8
resp 0 in
473 match opcode land lnot
0x80 with
478 and resid
= r32
resp 4
481 error
"code=%d serial=%d resid=%#x min=%d maj=%d\n%S"
482 code serial resid min maj
(Bytes.unsafe_to_string
resp);
484 | 1 -> (* response *)
485 let rep = Queue.pop
state.fifo
in
488 | 2 -> (* key press *)
489 if Array.length
state.keymap
> 0
491 let code = r8
resp 1 in
492 let mask = r16
resp 28 in
493 let keysym = getkeysym code mask in
494 vlog "keysym = %x %c mask %#x code %d"
495 keysym (Char.unsafe_chr
keysym) mask code;
496 state.t#key
keysym mask;
498 | 3 -> (* key release *)
499 if Array.length
state.keymap
> 0
501 let code = r8
resp 1 in
502 let mask = r16
resp 28 in
503 let keysym = getkeysym code mask in
504 vlog "release keysym = %x %c mask %#x code %#d"
505 keysym (Char.unsafe_chr
keysym) mask code
507 | 4 -> (* buttonpress *)
511 and m = r16
resp 28 in
512 state.t#mouse
n true x y
m;
515 | 5 -> (* buttonrelease *)
519 and m = r16
resp 28 in
520 state.t#mouse
n false x y
m;
521 vlog "release %d %d %d" n x y
524 let x = r16s
resp 24 in
525 let y = r16s
resp 26 in
526 let m = r16
resp 28 in
528 then state.t#pmotion
x y
529 else state.t#motion
x y;
530 vlog "move %dx%d => %d" x y m
534 and y = r16s
resp 26 in
536 vlog "enter %d %d" x y
549 | 12 -> (* exposure *)
553 | 15 -> (* visibility *)
558 | 1 -> PartiallyObscured
561 dolog
"unknown visibility %d" v;
565 vlog "visibility %d" v;
567 | 34 -> (* mapping *)
569 let s = getkeymapreq state.mink
(state.maxk
-state.mink
-1) in
570 sendwithrep sock
s (updkmap sock
);
571 state.capslmask
<- 0;
572 state.levl3mask
<- 0;
573 state.levl5mask
<- 0;
575 let s = getmodifiermappingreq () in
576 sendwithrep sock
s (updmodmap sock
);
578 | 33 -> (* clientmessage *)
579 let atom = r32
resp 8 in
580 if atom = state.protoatom
582 let atom = r32
resp 12 in
583 if atom = state.deleatom
588 | 21 -> (* reparent *)
591 | 22 -> (* configure *)
595 and h
= r16
resp 22 in
596 vlog "configure cur [%d %d %d %d] conf [%d %d %d %d]"
597 state.x state.y state.w
state.h
600 if w
!= state.w
|| h
!= state.h
611 let atom = r32
resp 8 in
612 if atom = state.nwmsatom
614 let s = getpropreq false state.wid
atom 4 in
615 sendwithrep sock
s (fun resp ->
616 let len = r32
resp 4 in
617 let nitems = r32
resp 16 in
622 let s = readstr sock
(len*4) in
623 let rec loop wsl i
= if i
= nitems then wsl else
624 let atom = r32
s (i
*4) in
626 if atom = state.maxhatom
629 if atom = state.maxvatom
632 if atom = state.fulsatom
634 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
644 state.t#winstate
(List.sort compare
wsl)
648 dolog
"event %d %S" n (Bytes.unsafe_to_string
resp)
654 if hasdata sock
then loop ();
659 let sendstr s ?
(pos
=0) ?
(len=Bytes.length
s) sock
=
660 sendstr1 s pos
len sock
;
661 if hasdata sock
then readresp sock
;
667 let s = Bytes.create
8 in
670 let s = configurewindowreq state.wid
0x000c s in
671 sendstr s state.sock
;
672 else state.fullscreen
state.wid
679 let syncsendwithrep sock secstowait
s f
=
680 let completed = ref false in
681 sendwithrep sock
s (fun resp -> f
resp; completed := true);
682 let now = Unix.gettimeofday
in
683 let deadline = now () +. secstowait
in
684 let rec readtillcompletion () =
686 let timeout = deadline -. now () in
689 else Unix.select
[sock
] [] [] timeout
691 let r, _
, _
= tempfailureretry
sf deadline in
693 | [] -> error
"didn't get X response in %f seconds, aborting" secstowait
697 then readtillcompletion ()
699 readtillcompletion ();
703 let s = mapreq state.wid
in
704 sendstr s state.sock
;
707 let syncsendintern sock secstowait
s onlyifexists f
=
708 let s = internreq s onlyifexists
in
709 syncsendwithrep sock secstowait
s f
;
712 let setup disp sock rootwid screennum w h
=
713 let s = readstr sock
2 in
714 let n = Bytes.length
s in
716 then error
"failed to read X connection setup response n=%d" n;
717 match Bytes.get
s 0 with
719 let reasonlen = r8
s 1 in
720 let s = readstr sock
6 in
725 let data = readstr sock
len in
726 let reason = Bytes.sub
data 0 reasonlen in
727 error
"X connection failed maj=%d min=%d reason=%S"
728 maj min
(Bytes.unsafe_to_string
reason)
730 | '
\002'
-> failwith
"X connection setup failed: authentication required";
733 let s = readstr sock
38 in
737 and idbase
= r32
s 10
738 and idmask
= r32
s 14
740 and screens
= r8
s 26
741 and formats
= r8
s 27
743 and maxkk
= r8
s 33 in
744 let data = readstr sock
(4*add
-32) in
745 let vendor = Bytes.sub
data 0 vlen
in
746 let pos = ((vlen
+3) land lnot
3) + formats
*8 in
748 if screennum
>= screens
749 then error
"invalid screen %d, max %d" screennum
(screens
-1);
752 let rec findscreen n pos = if n = screennum
then pos else
754 let ndepths = r8
data (pos+39) in
755 let rec skipdepths n pos = if n = ndepths then pos else
757 let nvisiuals = r16
data (pos+2) in
758 pos + nvisiuals*24 + 8
762 skipdepths n (pos+40)
768 let root = if rootwid
= 0 then r32
data pos else rootwid
in
769 let rootw = r16
data (pos+20)
770 and rooth
= r16
data (pos+22)
771 and rootdepth
= r8
data (pos+38)in
775 state.idbase
<- idbase
;
776 vlog "vendor = %S, maj=%d min=%d" (Bytes.unsafe_to_string
vendor) maj min
;
777 vlog "screens = %d formats = %d" screens formats
;
778 vlog "minkk = %d maxkk = %d" minkk maxkk
;
779 vlog "idbase = %#x idmask = %#x" idbase idmask
;
780 vlog "root=%#x %dx%d" root rootw rooth
;
781 vlog "wmm = %d, hmm = %d" (r16
data (pos+24)) (r16
data (pos+26));
782 vlog "visualid = %#x " (r32
data (pos+32));
783 vlog "root depth = %d" rootdepth
;
785 let wid = state.idbase
in
792 let vid = glxinit disp
wid screennum
in
793 let ndepths = r8
data (pos+39) in
794 let rec finddepth n'
pos =
796 then error
"couldn't find depth for visual %#x" vid;
797 let depth = r8
data pos in
798 let nvisuals = r16
data (pos+2) in
799 let rec findvisual n pos =
801 then finddepth (n'
+1) pos
803 let id = r32
data pos in
806 else findvisual (n+1) (pos+24)
810 let depth = finddepth 0 (pos+40) in
812 let s = createcolormapreq mid root vid in
816 + 0x00000001 (* KeyPress *)
817 (* + 0x00000002 *) (* KeyRelease *)
818 + 0x00000004 (* ButtonPress *)
819 + 0x00000008 (* ButtonRelease *)
820 + 0x00000010 (* EnterWindow *)
821 + 0x00000020 (* LeaveWindow *)
822 + 0x00000040 (* PointerMotion *)
823 (* + 0x00000080 *) (* PointerMotionHint *)
824 (* + 0x00000100 *) (* Button1Motion *)
825 (* + 0x00000200 *) (* Button2Motion *)
826 (* + 0x00000400 *) (* Button3Motion *)
827 (* + 0x00000800 *) (* Button4Motion *)
828 (* + 0x00001000 *) (* Button5Motion *)
829 + 0x00002000 (* ButtonMotion *)
830 (* + 0x00004000 *) (* KeymapState *)
831 + 0x00008000 (* Exposure *)
832 + 0x00010000 (* VisibilityChange *)
833 + 0x00020000 (* StructureNotify *)
834 (* + 0x00040000 *) (* ResizeRedirect *)
835 (* + 0x00080000 *) (* SubstructureNotify *)
836 (* + 0x00100000 *) (* SubstructureRedirect *)
837 (* + 0x00200000 *) (* FocusChange *)
838 + 0x00400000 (* PropertyChange *)
839 (* + 0x00800000 *) (* ColormapChange *)
840 (* + 0x01000000 *) (* OwnerGrabButton *)
843 let s = createwindowreq wid root 0 0 w h
0 mask vid depth mid in
846 sendintern sock
(~
> "WM_PROTOCOLS") false (fun resp ->
847 state.protoatom
<- r32
resp 8;
849 sock
(~
> "WM_DELETE_WINDOW") false (fun resp ->
850 state.deleatom
<- r32
resp 8;
851 let s = s32 state.deleatom
in
852 let s = changepropreq wid state.protoatom
4 32 s in
857 sendintern sock
(~
> "WM_CLIENT_MACHINE") false (fun resp ->
858 let atom = r32
resp 8 in
861 try Unix.gethostname
()
863 dolog
"error getting host name: %s" (exntos exn
);
868 let s = changepropreq wid atom state.stringatom
8
871 sendintern sock
(~
> "_NET_WM_PID") false (fun resp ->
872 let atom = r32
resp 8 in
873 let pid = Unix.getpid
() in
875 let s = changepropreq wid atom 6(*cardinal*) 32 s in
880 state.actwin
<- (fun () ->
881 let s = Bytes.create
4 in
882 let s = configurewindowreq wid 0x40 s in
883 sendstr s state.sock
;
884 let s = mapreq wid in
885 sendstr s state.sock
;
888 sendintern sock
(~
> "_NET_ACTIVE_WINDOW") true (fun resp ->
889 let atom = r32
resp 8 in
890 state.actwin
<- (fun () ->
891 let data = Bytes.make
20 '
\000'
in
892 let cm = clientmessage 32 0 wid atom data in
893 let s = sendeventreq 0 root 0x180000 cm in
894 sendstr s state.sock
;
898 syncsendintern sock
2.0 (~
> "WM_CLASS") false (fun resp ->
899 let atom = r32
resp 8 in
900 let llpp = ~
> "llpp\000llpp\000" in
901 let s = changepropreq wid atom 31 8 llpp in
905 let s = getkeymapreq state.mink
(state.maxk
-state.mink
) in
906 sendwithrep sock
s (updkmap sock
);
908 let s = getmodifiermappingreq () in
909 sendwithrep sock
s (updmodmap sock
);
911 let s = openfontreq fid (~
> "cursor") in
914 Array.iteri
(fun i glyphindex
->
915 let s = createglyphcursorreq fid (fid+1+i
) glyphindex
in
917 ) [|34;48;50;58;128;152|];
919 sendintern sock
(~
> "UTF8_STRING") true (fun resp ->
920 let atom = r32
resp 8 in
922 then state.stringatom
<- atom;
926 let s = changepropreq wid 39 state.stringatom
8 s in
927 sendstr s state.sock
;
929 state.setwmname <- setwmname;
930 sendintern sock
(~
> "_NET_WM_NAME") true (fun resp ->
931 let atom = r32
resp 8 in
933 then state.setwmname <- (fun s ->
935 let s = changepropreq wid atom state.stringatom
8 s in
936 sendstr s state.sock
;
940 state.fullscreen
<- (fun wid ->
941 let s = Bytes.create
16 in
948 let s = configurewindowreq wid 0x000f s in
949 sendstr s state.sock
;
950 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
957 let s = configurewindowreq wid 0x000f s in
958 sendstr s state.sock
;
962 sendintern sock
(~
> "_NET_WM_STATE") true (fun resp ->
963 state.nwmsatom
<- r32
resp 8;
964 if state.nwmsatom
!= 0
966 sendintern sock
(~
> "_NET_WM_STATE_MAXIMIZED_VERT") true (fun resp ->
967 state.maxvatom
<- r32
resp 8;
969 sendintern sock
(~
> "_NET_WM_STATE_MAXIMIZED_HORZ") true (fun resp ->
970 state.maxhatom
<- r32
resp 8;
972 sendintern sock
(~
> "_NET_WM_STATE_FULLSCREEN") true (fun resp ->
973 state.fulsatom
<- r32
resp 8;
974 if state.fulsatom
!= 0
978 let data = Bytes.make
20 '
\000'
in
981 | NoFs
-> Fs
(-1, -1, -1, -1), 1
985 w32
data 4 state.fulsatom
;
987 let cm = clientmessage 32 0 wid state.nwmsatom
data in
988 let s = sendeventreq 0 root 0x180000 cm in
995 let s = getgeometryreq wid in
996 syncsendwithrep sock
2.0 s (fun resp ->
999 and h
= r16
resp 18 in
1005 error
"unknown conection setup response %d" (Char.code c
)
1008 let getauth haddr dnum
=
1010 if haddr = "localhost" || String.length
haddr = 0
1012 try Unix.gethostname
()
1014 dolog
"failed to resolve `%S': %s" haddr (exntos exn
);
1019 try Sys.getenv
"XAUTHORITY"
1021 try Filename.concat
(Sys.getenv
"HOME") ".Xauthority"
1022 with Not_found
-> E.s
1026 let rb pos = Char.code (Bytes.get
s pos) in
1027 (rb 1) lor ((rb 0) lsl 8)
1031 let s = really_input_string ic
2 in
1032 let n = r16be (~
> s) in
1033 really_input_string ic
n
1035 let family = really_input_string ic
2 in
1039 try Some
(int_of_string
nums)
1042 "display number(%S) is not an integer (corrupt %S?): %s"
1043 nums path (exntos exn
);
1049 vlog "family %S addr %S(%S) num %S(%d) name %S data %S"
1050 family addr haddr nums dnum
name data;
1052 | Some num
when addr = haddr && num
= dnum
->
1059 | End_of_file
-> E.s, E.s
1061 dolog
"exception while reading X authority data (%S): %s"
1070 if String.length
path = 0
1072 else Some
(open_in_bin
path)
1074 if Sys.file_exists
path
1076 dolog
"failed to open X authority file `%S' : %s"
1082 | Some ic
-> readauth ic
1085 let init t rootwid
w h osx
=
1087 try Sys.getenv
"DISPLAY"
1089 error
"could not get DISPLAY evironment variable: %s"
1094 then error
"invalid DISPLAY(%s) %S" w d
1096 let s = String.sub
d b (e
- b) in
1099 error
"invalid DISPLAY %S can not parse %s(%S): %s"
1103 if pos = String.length
d
1104 then error
"invalid DISPLAY %S no display number specified" d
1108 let rec pdispnum pos1
=
1109 if pos1
= String.length
d
1110 then getnum "display number" (pos+1) pos1
, 0
1114 let dispnum = getnum "display number" (pos+1) pos1
in
1115 let rec pscreennum pos2
=
1116 if pos2
= String.length
d
1117 then getnum "screen number" (pos1
+1) pos2
1120 | '
0'
.. '
9'
-> pscreennum (pos2
+1)
1122 error
"invalid DISPLAY %S, cannot parse screen number" d
1124 dispnum, pscreennum (pos1
+1)
1125 | '
0'
.. '
9'
-> pdispnum (pos1
+1)
1127 error
"invalid DISPLAY %S, cannot parse display number" d
1129 String.sub
d 0 pos, pdispnum (pos+1)
1133 let host, (dispnum, screennum
) = phost 0 in
1134 let aname, adata
= getauth host dispnum in
1137 if osx
|| String.length
host = 0 || host = "unix"
1141 then Unix.ADDR_UNIX
d
1142 else Unix.ADDR_UNIX
("/tmp/.X11-unix/X" ^ string_of_int
dispnum)
1144 let fd = Unix.socket
Unix.PF_UNIX
Unix.SOCK_STREAM
0 in
1148 try Unix.gethostbyname
host
1150 error
"cannot resolve %S: %s" host (exntos exn
)
1152 let addr = h.Unix.h_addr_list
.(0) in
1153 let port = 6000 + dispnum in
1154 let fd = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
1155 fd, (Unix.ADDR_INET
(addr, port))
1157 try Unix.connect
fd addr; fd
1159 error
"failed to connect to X: %s" (exntos exn
)
1162 let s = Bytes.create
12 in
1163 let s = padcat s (~
> aname) in
1164 let s = padcat s (~
> adata
) in
1165 Bytes.set
s 0 ordermagic
;
1168 w16
s 6 (String.length
aname);
1169 w16
s 8 (String.length adata
);
1170 sendstr1 s 0 (Bytes.length
s) fd;
1172 setup d fd rootwid screennum
w h;
1174 fd, state.w, state.h;
1178 state.setwmname (~
> s);
1181 let setcursor cursor
=
1182 if cursor
!= state.curcurs
1186 | CURSOR_INHERIT
-> -1
1189 | CURSOR_CROSSHAIR
-> 0
1192 let s = s32 (if n = -1 then 0 else state.fid+1+n) in
1193 let s = changewindowattributesreq state.wid 0x4000(*cursor*) s in
1194 sendstr s state.sock
;
1195 state.curcurs
<- cursor
;
1199 state.fullscreen state.wid;
1202 let metamask = 0x40;;
1207 let withalt mask = mask land altmask != 0;;
1208 let withctrl mask = mask land ctrlmask != 0;;
1209 let withshift mask = mask land shiftmask != 0;;
1210 let withmeta mask = mask land metamask != 0;;
1211 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0;;
1214 let t = Hashtbl.create
20
1215 and f
= Hashtbl.create
20 in
1217 List.iter
(fun s -> Hashtbl.add t s k) (n::nl
);
1221 let s = String.make
1 c
in
1222 add s [] (Char.code c
)
1225 let an = Char.code a and bn
= Char.code b in
1226 for i
= an to bn
do addc (Char.chr i
) done;
1231 String.iter
addc "`~!@#$%^&*()-_=+\\|[{]};:,./<>?";
1232 for i
= 0 to 29 do add ("f" ^ string_of_int
(i
+1)) [] (0xffbe + i
) done;
1233 add "space" [] 0x20;
1234 add "ret" ["return"; "enter"] 0xff0d;
1235 add "tab" [] 0xff09;
1236 add "left" [] 0xff51;
1237 add "right" [] 0xff53;
1238 add "home" [] 0xff50;
1239 add "end" [] 0xff57;
1240 add "ins" ["insert"] 0xff63;
1241 add "del" ["delete"] 0xffff;
1242 add "esc" ["escape"] 0xff1b;
1243 add "pgup" ["pageup"] 0xff55;
1244 add "pgdown" ["pagedown"] 0xff56;
1245 add "backspace" [] 0xff08;
1247 add "down" [] 0xff54;
1248 add "menu" [] 0xff67;
1253 try Hashtbl.find xlatf
k
1254 with Not_found
-> Printf.sprintf
"%#x" k;
1258 try Hashtbl.find xlatt name
1260 if String.length
name = 1
1261 then Char.code name.[0]
1262 else int_of_string
name;