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";;
30 external setcursor
: cursor
-> unit = "ml_setcursor";;
37 method reshape _ _
= ()
38 method mouse _ _ _ _ _
= ()
39 method motion _ _
= ()
40 method pmotion _ _
= ()
44 method winstate _
= ()
45 method quit
: 'a
. 'a
= exit
0
46 method scroll _ _
= ()
47 method zoom _ _ _
= ()
54 method map
: bool -> unit
56 method visible
: visiblestate
-> unit
57 method reshape
: int -> int -> unit
58 method mouse
: int -> bool -> int -> int -> int -> unit
59 method motion
: int -> int -> unit
60 method pmotion
: int -> int -> unit
61 method key
: int -> int -> unit
62 method enter
: int -> int -> unit
64 method winstate
: winstate list
-> unit
66 method scroll
: int -> int -> unit
67 method zoom
: float -> int -> int -> unit
68 method opendoc
: string -> unit
74 ; mutable keymap
: int array array
75 ; fifo
: (bytes
-> unit) Queue.t
77 ; mutable protoatom
: atom
78 ; mutable deleatom
: atom
79 ; mutable nwmsatom
: atom
80 ; mutable maxvatom
: atom
81 ; mutable maxhatom
: atom
82 ; mutable fulsatom
: atom
83 ; mutable idbase
: int
86 ; mutable fullscreen
: (int -> unit)
87 ; mutable setwmname
: (bytes
-> unit)
88 ; mutable actwin
: (unit -> unit)
89 ; mutable stringatom
: int
91 ; mutable sock
: Unix.file_descr
97 ; mutable curcurs
: cursor
98 ; mutable capslmask
: int
99 ; mutable numlmask
: int
100 ; mutable levl3mask
: int
101 ; mutable levl5mask
: int
106 | Fs
of (int * int * int * int)
113 ; fifo
= Queue.create
()
124 ; fullscreen
= (fun _
-> ())
125 ; setwmname
= (fun _
-> ())
126 ; actwin
= (fun _
-> ())
135 ; curcurs
= CURSOR_TEXT
144 let ordermagic = 'l'
;;
146 let makereq opcode len reqlen
=
147 let s = Bytes.create len
in
154 let s = Bytes.create n
in
156 let m = tempfailureretry
(Unix.read sock
s pos
) n
in
161 ignore
(tempfailureretry
(Unix.select
[sock
] [] []) 0.01);
162 loop (pos
+ m) (n
- m)
169 let sendstr1 s pos len sock
=
170 let s = Bytes.unsafe_to_string
s in
171 vlog
"%d <= %S" state.seq
s;
172 state.seq
<- state.seq
+ 1;
173 let n = tempfailureretry
(Unix.write_substring sock
s pos
) len
in
175 then error
"send %d returned %d" len
n;
178 let updkmap sock resp
=
179 let syms = r8 resp
1 in
180 let len = r32 resp
4 in
183 then readstr sock
(4*len)
186 let m = len / syms in
187 state.keymap
<- Array.make_matrix
state.maxk
syms 0xffffff;
195 let v = r32
data k in
196 state.keymap
.(i
).(l
) <- v;
205 let updmodmap sock resp
=
207 let len = r16 resp
4 in
210 then readstr sock
(len*4)
215 let modmap = Array.make_matrix
8 n 0xffffff in
225 let code = r8
data p in
226 modmap.(l
).(m) <- code;
229 let ki = code - state.mink
in
232 let a = state.keymap
.(ki) in
234 if i
= Array.length
a || i
> 3
239 then state.capslmask
<- 2
247 let ki = code - state.mink
in
250 let a = state.keymap
.(ki) in
252 if i
= Array.length
a || i
> 3
257 | 0xfe03 -> state.levl3mask
<- 1 lsl l
258 | 0xfe11 -> state.levl5mask
<- 1 lsl l
259 | 0xff7f -> state.numlmask
<- 1 lsl l
272 let sendwithrep sock
s f
=
273 Queue.push f
state.fifo
;
274 sendstr1 s 0 (Bytes.length
s) sock
;
280 let b = Buffer.create
16 in
281 List.iter
(Buffer.add_bytes
b) ss
;
282 let bl = Buffer.length
b in
283 let pl = bl land 3 in
285 then Buffer.add_substring
b pad 0 (4 - pl);
289 let padcat s1 s2
= padcatl [s1
; s2
];;
291 let internreq name onlyifexists
=
292 let s = makereq 16 8 8 in
293 let s = padcat s name
in
294 w8
s 1 (if onlyifexists
then 1 else 0);
295 w16
s 2 (Bytes.length
s / 4);
296 w16
s 4 (Bytes.length name
);
300 let sendintern sock
s onlyifexists f
=
301 let s = internreq s onlyifexists
in
302 sendwithrep sock
s f
;
305 let createwindowreq wid parent x y w h bw eventmask vid depth mid
=
306 let s = makereq 1 44 11 in
315 w16
s 22 0; (* copyfromparent *)
316 w32
s 24 vid
; (* visual *)
317 w32
s 28 0x2808; (* valuemask =
321 w32
s 32 0; (* border pixel*)
327 let createcolormapreq mid wid vid
=
328 let s = makereq 78 16 4 in
336 let getgeometryreq wid
=
337 let s = makereq 14 8 2 in
343 let s = makereq 8 8 2 in
348 let getkeymapreq first count
=
349 let s = makereq 101 8 2 in
355 let changepropreq wid prop typ format props
=
356 let s = makereq 18 24 0 in
357 let s = padcat s props
in
359 w16
s 2 (Bytes.length
s / 4);
364 let ful = Bytes.length props
/ (match format
with
368 | n -> error
"no idea what %d means" n)
374 let getpropreq delete wid prop typ
=
375 let s = makereq 20 24 6 in
376 w8
s 1 (if delete
then 1 else 0);
385 let configurewindowreq wid mask values
=
386 let s = makereq 12 12 0 in
387 let s = padcat s values
in
388 w16
s 2 (Bytes.length
s / 4);
395 let s = Bytes.create
4 in
400 let clientmessage format seq wid typ
data =
401 let s = makereq 33 12 0 in
402 let s = padcat s data in
410 let sendeventreq propagate destwid mask
data =
411 let s = makereq 25 12 11 in
412 let s = padcat s data in
420 let getmodifiermappingreq () =
424 let queryextensionreq name
=
425 let s = makereq 98 8 0 in
426 let s = padcat s name
in
427 w16
s 2 (Bytes.length
s / 4);
428 w16
s 4 (Bytes.length name
);
432 let getkeysym pkpk
code mask
=
433 if (pkpk
>= 0xff80 && pkpk
<= 0xffbd)
434 || (pkpk
>= 0x11000000 && pkpk
<= 0x1100ffff)
436 if mask
land state.numlmask
!= 0
438 let keysym = state.keymap
.(code-state.mink
).(1) in
439 if keysym = 0 then pkpk
else keysym
444 if pkpk
land 0xf000 = 0xf000
446 else (mask
land 1) lxor ((mask
land state.capslmask
) lsr 1)
449 if state.xkb
&& mask
land 0x2000 != 0
452 let l3 = (mask
land state.levl3mask
) != 0 in
453 let l4 = (mask
land state.levl5mask
) != 0 in
455 if l3 then (if l4 then 8 else 4) else (if l4 then 6 else 0)
457 let keysym = state.keymap
.(code-state.mink
).(index) in
458 if index land 1 = 1 && keysym = 0
459 then state.keymap
.(code-state.mink
).(index - 1)
464 let getkeysym code mask
=
465 let pkpk = state.keymap
.(code-state.mink
).(0) in
466 if state.xkb
&& pkpk lsr 8 = 0xfe (* XKB *)
468 else getkeysym pkpk code mask
472 let resp = readstr sock
32 in
473 let opcode = r8
resp 0 in
474 match opcode land lnot
0x80 with
479 and resid
= r32
resp 4
482 error
"code=%d serial=%d resid=%#x min=%d maj=%d\n%S"
483 code serial resid min maj
(Bytes.unsafe_to_string
resp);
485 | 1 -> (* response *)
486 let rep = Queue.pop
state.fifo
in
489 | 2 -> (* key press *)
490 if Array.length
state.keymap
> 0
492 let code = r8
resp 1 in
493 let mask = r16
resp 28 in
494 let keysym = getkeysym code mask in
495 vlog
"keysym = %x %c mask %#x code %d"
496 keysym (Char.unsafe_chr
keysym) mask code;
498 then state.t#key
keysym mask
500 | 3 -> (* key release *)
501 if Array.length
state.keymap
> 0
503 let code = r8
resp 1 in
504 let mask = r16
resp 28 in
505 let keysym = getkeysym code mask in
506 vlog
"release keysym = %x %c mask %#x code %d"
507 keysym (Char.unsafe_chr
keysym) mask code
509 | 4 -> (* buttonpress *)
513 and m = r16
resp 28 in
514 state.t#mouse
n true x y
m;
517 | 5 -> (* buttonrelease *)
521 and m = r16
resp 28 in
522 state.t#mouse
n false x y
m;
523 vlog
"release %d %d %d" n x y
526 let x = r16s
resp 24 in
527 let y = r16s
resp 26 in
528 let m = r16
resp 28 in
530 then state.t#pmotion
x y
531 else state.t#motion
x y;
532 vlog
"move %dx%d => %d" x y m
536 and y = r16s
resp 26 in
538 vlog
"enter %d %d" x y
551 | 12 -> (* exposure *)
555 | 15 -> (* visibility *)
560 | 1 -> PartiallyObscured
563 dolog
"unknown visibility %d" v;
567 vlog
"visibility %d" v;
569 | 34 -> (* mapping *)
571 let s = getkeymapreq state.mink
(state.maxk
-state.mink
-1) in
572 sendwithrep sock
s (updkmap sock
);
573 state.capslmask
<- 0;
574 state.levl3mask
<- 0;
575 state.levl5mask
<- 0;
577 let s = getmodifiermappingreq () in
578 sendwithrep sock
s (updmodmap sock
);
580 | 33 -> (* clientmessage *)
581 let atom = r32
resp 8 in
582 if atom = state.protoatom
584 let atom = r32
resp 12 in
585 if atom = state.deleatom
589 | 21 -> (* reparent *)
592 | 22 -> (* configure *)
596 and h
= r16
resp 22 in
597 vlog
"configure cur [%d %d %d %d] conf [%d %d %d %d]"
598 state.x state.y state.w
state.h
600 if w
!= state.w
|| h
!= state.h
601 then state.t#reshape w h
;
607 | 24 -> (* Gravity notify *)
610 | 28 -> (* Property notify *)
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 ->
617 let len = r32
resp 4 in
618 let nitems = r32
resp 16 in
623 let s = readstr sock
(len*4) in
628 let atom = r32
s (i
*4) in
630 if atom = state.maxhatom
633 if atom = state.maxvatom
636 if atom = state.fulsatom
638 state.fs
<- Fs
(state.x, state.y,
649 state.t#winstate
(List.sort compare
wsl)
653 dolog
"event %d %S" n (Bytes.unsafe_to_string
resp)
659 if hasdata sock
then loop ();
664 let sendstr s ?
(pos
=0) ?
(len=Bytes.length
s) sock
=
665 sendstr1 s pos
len sock
;
666 if hasdata sock
then readresp sock
;
672 let s = Bytes.create
8 in
675 let s = configurewindowreq state.wid
0x000c s in
676 sendstr s state.sock
;
677 else state.fullscreen
state.wid
684 let syncsendwithrep sock secstowait
s f
=
685 let completed = ref false in
686 sendwithrep sock
s (fun resp -> f
resp; completed := true);
687 let now = Unix.gettimeofday
in
688 let deadline = now () +. secstowait
in
689 let rec readtillcompletion () =
691 let timeout = deadline -. now () in
694 else Unix.select
[sock
] [] [] timeout
696 let r, _
, _
= tempfailureretry
sf deadline in
698 | [] -> error
"didn't get X response in %f seconds, aborting" secstowait
702 then readtillcompletion ()
704 readtillcompletion ();
708 let s = mapreq state.wid
in
709 sendstr s state.sock
;
712 let syncsendintern sock secstowait
s onlyifexists f
=
713 let s = internreq s onlyifexists
in
714 syncsendwithrep sock secstowait
s f
;
717 let setup disp sock rootwid screennum w h
=
718 let s = readstr sock
2 in
719 let n = Bytes.length
s in
721 then error
"failed to read X connection setup response n=%d" n;
722 match Bytes.get
s 0 with
724 let reasonlen = r8
s 1 in
725 let s = readstr sock
6 in
730 let data = readstr sock
len in
731 let reason = Bytes.sub
data 0 reasonlen in
732 error
"X connection failed maj=%d min=%d reason=%S"
733 maj min
(Bytes.unsafe_to_string
reason)
735 | '
\002'
-> error
"X connection setup failed: authentication required";
738 let s = readstr sock
38 in
742 and idbase
= r32
s 10
743 and idmask
= r32
s 14
745 and screens
= r8
s 26
746 and formats
= r8
s 27
748 and maxkk
= r8
s 33 in
749 let data = readstr sock
(4*add
-32) in
750 let vendor = Bytes.sub
data 0 vlen
in
751 let pos = ((vlen
+3) land lnot
3) + formats
*8 in
753 if screennum
>= screens
754 then error
"invalid screen %d, max %d" screennum
(screens
-1);
757 let rec findscreen n pos =
762 let ndepths = r8
data (pos+39) in
763 let rec skipdepths n pos =
768 let nvisiuals = r16
data (pos+2) in
769 pos + nvisiuals*24 + 8
773 skipdepths n (pos+40)
779 let root = if rootwid
= 0 then r32
data pos else rootwid
in
780 let rootw = r16
data (pos+20)
781 and rooth
= r16
data (pos+22)
782 and rootdepth
= r8
data (pos+38)in
786 state.idbase
<- idbase
;
787 vlog
"vendor = %S, maj=%d min=%d" (Bytes.unsafe_to_string
vendor) maj min
;
788 vlog
"screens = %d formats = %d" screens formats
;
789 vlog
"minkk = %d maxkk = %d" minkk maxkk
;
790 vlog
"idbase = %#x idmask = %#x" idbase idmask
;
791 vlog
"root=%#x %dx%d" root rootw rooth
;
792 vlog
"wmm = %d, hmm = %d" (r16
data (pos+24)) (r16
data (pos+26));
793 vlog
"visualid = %#x" (r32
data (pos+32));
794 vlog
"root depth = %d" rootdepth
;
796 let wid = state.idbase
in
803 let vid = glxinit disp
wid screennum
in
804 let ndepths = r8
data (pos+39) in
805 let rec finddepth n'
pos =
807 then error
"cannot find depth for visual %#x" vid;
808 let depth = r8
data pos in
809 let nvisuals = r16
data (pos+2) in
810 let rec findvisual n pos =
812 then finddepth (n'
+1) pos
814 let id = r32
data pos in
817 else findvisual (n+1) (pos+24)
821 let depth = finddepth 0 (pos+40) in
823 let s = createcolormapreq mid root vid in
827 + 0x00000001 (* KeyPress *)
828 (* + 0x00000002 *) (* KeyRelease *)
829 + 0x00000004 (* ButtonPress *)
830 + 0x00000008 (* ButtonRelease *)
831 + 0x00000010 (* EnterWindow *)
832 + 0x00000020 (* LeaveWindow *)
833 + 0x00000040 (* PointerMotion *)
834 (* + 0x00000080 *) (* PointerMotionHint *)
835 (* + 0x00000100 *) (* Button1Motion *)
836 (* + 0x00000200 *) (* Button2Motion *)
837 (* + 0x00000400 *) (* Button3Motion *)
838 (* + 0x00000800 *) (* Button4Motion *)
839 (* + 0x00001000 *) (* Button5Motion *)
840 + 0x00002000 (* ButtonMotion *)
841 (* + 0x00004000 *) (* KeymapState *)
842 + 0x00008000 (* Exposure *)
843 + 0x00010000 (* VisibilityChange *)
844 + 0x00020000 (* StructureNotify *)
845 (* + 0x00040000 *) (* ResizeRedirect *)
846 (* + 0x00080000 *) (* SubstructureNotify *)
847 (* + 0x00100000 *) (* SubstructureRedirect *)
848 (* + 0x00200000 *) (* FocusChange *)
849 + 0x00400000 (* PropertyChange *)
850 (* + 0x00800000 *) (* ColormapChange *)
851 (* + 0x01000000 *) (* OwnerGrabButton *)
854 let s = createwindowreq wid root 0 0 w h
0 mask vid depth mid in
858 sock
(~
> "WM_PROTOCOLS") false (fun resp ->
859 state.protoatom
<- r32
resp 8;
861 sock
(~
> "WM_DELETE_WINDOW") false (fun resp ->
862 state.deleatom
<- r32
resp 8;
863 let s = s32 state.deleatom
in
864 let s = changepropreq wid state.protoatom
4 32 s in
870 sock
(~
> "WM_CLIENT_MACHINE") false (fun resp ->
871 let atom = r32
resp 8 in
874 try Unix.gethostname
()
876 dolog
"error getting host name: %s" @@ exntos exn
;
881 let s = changepropreq wid atom state.stringatom
8
885 sock
(~
> "_NET_WM_PID") false (fun resp ->
886 let atom = r32
resp 8 in
887 let pid = Unix.getpid
() in
889 let s = changepropreq wid atom 6(*cardinal*) 32 s in
894 state.actwin
<- (fun () ->
895 let s = Bytes.create
4 in
896 let s = configurewindowreq wid 0x40 s in
897 sendstr s state.sock
;
898 let s = mapreq wid in
899 sendstr s state.sock
;
903 sock
(~
> "_NET_ACTIVE_WINDOW") true (fun resp ->
904 let atom = r32
resp 8 in
905 state.actwin
<- (fun () ->
906 let data = Bytes.make
20 '
\000'
in
907 let cm = clientmessage 32 0 wid atom data in
908 let s = sendeventreq 0 root 0x180000 cm in
909 sendstr s state.sock
;
914 sock
2.0 (~
> "WM_CLASS") false (fun resp ->
915 let atom = r32
resp 8 in
916 let llpp = ~
> "llpp\000llpp\000" in
917 let s = changepropreq wid atom 31 8 llpp in
921 let s = getkeymapreq state.mink
(state.maxk
-state.mink
) in
922 sendwithrep sock
s (updkmap sock
);
924 let s = getmodifiermappingreq () in
925 sendwithrep sock
s (updmodmap sock
);
928 sock
(~
> "UTF8_STRING") true (fun resp ->
929 let atom = r32
resp 8 in
931 then state.stringatom
<- atom;
935 let s = changepropreq wid 39 state.stringatom
8 s in
936 sendstr s state.sock
;
938 state.setwmname <- setwmname;
940 sock
(~
> "_NET_WM_NAME") true (fun resp ->
941 let atom = r32
resp 8 in
943 then state.setwmname <- (fun s ->
945 let s = changepropreq wid atom state.stringatom
8 s in
946 sendstr s state.sock
;
950 state.fullscreen
<- (fun wid ->
951 let s = Bytes.create
16 in
958 let s = configurewindowreq wid 0x000f s in
959 sendstr s state.sock
;
960 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
967 let s = configurewindowreq wid 0x000f s in
968 sendstr s state.sock
;
973 sock
(~
> "_NET_WM_STATE") true (fun resp ->
974 state.nwmsatom
<- r32
resp 8;
975 if state.nwmsatom
!= 0
977 sendintern sock
(~
> "_NET_WM_STATE_MAXIMIZED_VERT") true (fun resp ->
978 state.maxvatom
<- r32
resp 8;
980 sendintern sock
(~
> "_NET_WM_STATE_MAXIMIZED_HORZ") true (fun resp ->
981 state.maxhatom
<- r32
resp 8;
984 sock
(~
> "_NET_WM_STATE_FULLSCREEN") true (fun resp ->
985 state.fulsatom
<- r32
resp 8;
986 if state.fulsatom
!= 0
990 let data = Bytes.make
20 '
\000'
in
993 | NoFs
-> Fs
(-1, -1, -1, -1), 1
997 w32
data 4 state.fulsatom
;
999 let cm = clientmessage 32 0 wid state.nwmsatom
data in
1000 let s = sendeventreq 0 root 0x180000 cm in
1007 let s = queryextensionreq (~
> "XKEYBOARD") in
1010 let present = r8
resp 8 in
1013 let maj = r8
resp 9 in
1014 let s = Bytes.create
8 in
1015 w8
s 0 maj; (* XKB *)
1016 w8
s 1 0; (* XKBUseExtension *)
1017 w16
s 2 2; (* request-length *)
1018 w16
s 4 1; (* wantedMajor *)
1019 w16
s 6 0; (* watnedMinor *)
1023 let supported = r8
resp 1 in
1024 state.xkb
<- supported != 0
1028 let s = getgeometryreq wid in
1029 syncsendwithrep sock
2.0 s (fun resp ->
1032 and h
= r16
resp 18 in
1038 error
"unknown connection setup response %d" (Char.code c
)
1041 let getauth haddr dnum
=
1043 if emptystr
haddr || haddr = "localhost"
1045 try Unix.gethostname
()
1047 dolog
"failed to resolve `%S': %s" haddr @@ exntos exn
;
1052 try Sys.getenv
"XAUTHORITY"
1054 try Filename.concat
(Sys.getenv
"HOME") ".Xauthority"
1055 with Not_found
-> E.s
1059 let rb pos = Char.code (Bytes.get
s pos) in
1060 (rb 1) lor ((rb 0) lsl 8)
1064 let s = really_input_string ic
2 in
1065 let n = r16be (~
> s) in
1066 really_input_string ic
n
1068 let family = really_input_string ic
2 in
1072 try Some
(int_of_string
nums)
1075 "display number(%S) is not an integer (corrupt %S?): %s"
1076 nums path @@ exntos exn
;
1082 vlog
"family %S addr %S(%S) num %S(%d) name %S data %S"
1083 family addr haddr nums dnum
name data;
1085 | Some num
when addr = haddr && num
= dnum
->
1092 | End_of_file
-> E.s, E.s
1094 dolog
"exception while reading X authority data (%S): %s"
1104 match open_in_bin
path with
1107 dolog
"failed to open X authority file `%S' : %s" path @@ exntos exn
;
1111 let init t
w h platform
=
1113 try Sys.getenv
"DISPLAY"
1115 error
"cannot get DISPLAY evironment variable: %s" @@ exntos exn
1119 then error
"invalid DISPLAY(%s) %S" w d
1121 let s = String.sub
d b (e
- b) in
1124 error
"invalid DISPLAY %S can not parse %s(%S): %s"
1128 if pos = String.length
d
1129 then error
"invalid DISPLAY %S no display number specified" d
1133 let rec pdispnum pos1
=
1134 if pos1
= String.length
d
1135 then getnum "display number" (pos+1) pos1
, 0
1139 let dispnum = getnum "display number" (pos+1) pos1
in
1140 let rec pscreennum pos2
=
1141 if pos2
= String.length
d
1142 then getnum "screen number" (pos1
+1) pos2
1145 | '
0'
.. '
9'
-> pscreennum (pos2
+1)
1147 error
"invalid DISPLAY %S, cannot parse screen number" d
1149 dispnum, pscreennum (pos1
+1)
1150 | '
0'
.. '
9'
-> pdispnum (pos1
+1)
1152 error
"invalid DISPLAY %S, cannot parse display number" d
1154 String.sub
d 0 pos, pdispnum (pos+1)
1158 let host, (dispnum, screennum
) = phost 0 in
1159 let aname, adata
= getauth host dispnum in
1162 if emptystr
host || host.[0] = '
/'
|| host = "unix"
1166 | Utils.Pmacos
-> Unix.ADDR_UNIX
d
1168 Unix.ADDR_UNIX
("\000/tmp/.X11-unix/X" ^ string_of_int
dispnum)
1169 | Utils.Punknown
| Utils.Pbsd
->
1170 Unix.ADDR_UNIX
("/tmp/.X11-unix/X" ^ string_of_int
dispnum)
1172 Unix.socket
Unix.PF_UNIX
Unix.SOCK_STREAM
0, addr
1175 try Unix.gethostbyname
host
1176 with exn
-> error
"cannot resolve %S: %s" host @@ exntos exn
1178 let addr = h.Unix.h_addr_list
.(0) in
1179 let port = 6000 + dispnum in
1180 let fd = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
1181 fd, (Unix.ADDR_INET
(addr, port))
1183 try Unix.connect
fd addr; fd
1184 with exn
-> error
"failed to connect to X: %s" @@ exntos exn
1187 let s = Bytes.create
12 in
1188 let s = padcat s (~
> aname) in
1189 let s = padcat s (~
> adata
) in
1190 Bytes.set
s 0 ordermagic;
1193 w16
s 6 (String.length
aname);
1194 w16
s 8 (String.length adata
);
1195 sendstr1 s 0 (Bytes.length
s) fd;
1197 setup d fd 0 screennum
w h;
1199 fd, state.w, state.h;
1203 state.setwmname (~
> s);
1206 let setcursor cursor
=
1207 if cursor
!= state.curcurs
1210 state.curcurs
<- cursor
;
1215 state.fullscreen state.wid;
1218 let metamask = 0x40;;
1223 let withalt mask = mask land altmask != 0;;
1224 let withctrl mask = mask land ctrlmask != 0;;
1225 let withshift mask = mask land shiftmask != 0;;
1226 let withmeta mask = mask land metamask != 0;;
1227 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0;;
1230 let t = Hashtbl.create
20
1231 and f
= Hashtbl.create
20 in
1233 List.iter
(fun s -> Hashtbl.add t s k) (n::nl
);
1237 let s = String.make
1 c
in
1238 add s [] (Char.code c
)
1241 let an = Char.code a and bn
= Char.code b in
1242 for i
= an to bn
do addc (Char.chr i
) done;
1247 String.iter
addc "`~!@#$%^&*()-_=+\\|[{]};:,./<>?";
1248 for i
= 0 to 29 do add ("f" ^ string_of_int
(i
+1)) [] (0xffbe + i
) done;
1249 add "space" [] 0x20;
1250 add "ret" ["return"; "enter"] 0xff0d;
1251 add "tab" [] 0xff09;
1252 add "left" [] 0xff51;
1253 add "right" [] 0xff53;
1254 add "home" [] 0xff50;
1255 add "end" [] 0xff57;
1256 add "ins" ["insert"] 0xff63;
1257 add "del" ["delete"] 0xffff;
1258 add "esc" ["escape"] 0xff1b;
1259 add "pgup" ["pageup"] 0xff55;
1260 add "pgdown" ["pagedown"] 0xff56;
1261 add "backspace" [] 0xff08;
1263 add "down" [] 0xff54;
1264 add "menu" [] 0xff67;
1269 try Hashtbl.find xlatf
k
1270 with Not_found
-> Printf.sprintf
"%#x" k;
1274 try Hashtbl.find xlatt name
1276 if String.length
name = 1
1277 then Char.code name.[0]
1278 else int_of_string
name;
1284 | 0xff08 -> Backspace
1306 | 0xffab -> Ascii '
+'
1307 | 0xffad -> Ascii '
-'
1309 | code when code > 31 && code < 128 -> Ascii
(Char.unsafe_chr
code)
1310 | code when code >= 0xffb0 && code <= 0xffb9 ->
1311 Ascii
(Char.unsafe_chr
(code - 0xffb0 + 0x30))
1312 | code when code >= 0xffbe && code <= 0xffc8 -> Fn
(code - 0xffbe + 1)
1313 | code when code land 0xff00 = 0xff00 -> Ctrl
code
1317 let fontsizefactor () = 1;;