25 method reshape _ _
= ()
26 method mouse _ _ _ _ _
= ()
27 method motion _ _
= ()
28 method pmotion _ _
= ()
32 method winstate _
= ()
33 method quit
: 'a
. 'a
= exit
0
34 method scroll _ _
= ()
35 method zoom _ _ _
= ()
41 method map
: bool -> unit
43 method visible
: visiblestate
-> unit
44 method reshape
: int -> int -> unit
45 method mouse
: int -> bool -> int -> int -> int -> unit
46 method motion
: int -> int -> unit
47 method pmotion
: int -> int -> unit
48 method key
: int -> int -> unit
49 method enter
: int -> int -> unit
51 method winstate
: winstate list
-> unit
53 method scroll
: int -> int -> unit
54 method zoom
: float -> int -> int -> unit
55 method opendoc
: string -> unit
61 mutable fd
: Unix.file_descr
;
71 buf
= Bytes.create
512;
73 path
= Buffer.create
0;
76 external setcursor
: cursor
-> unit = "ml_setcursor"
77 external settitle
: string -> unit = "ml_settitle"
78 external swapb
: unit -> unit = "ml_swapb"
79 external reshape
: int -> int -> unit = "ml_reshape"
80 external makecurrentcontext
: unit -> unit = "ml_makecurrentcontext"
81 external getw
: unit -> int = "ml_getw"
82 external geth
: unit -> int = "ml_geth"
83 external get_server_fd
: unit -> Unix.file_descr
= "ml_get_server_fd"
84 external get_backing_scale_factor
: unit -> int = "ml_get_backing_scale_factor"
85 external fullscreen
: unit -> unit = "ml_fullscreen"
86 external mapwin
: unit -> unit = "ml_mapwin"
87 external nslog
: string -> unit = "ml_nslog"
90 Printf.ksprintf
nslog fmt
108 let handleresp resp
=
109 let opcode = r8 resp
0 in
112 let mapped = r8 resp
16 <> 0 in
113 vlog
"map %B" mapped;
119 let w = r16 resp
16 in
120 let h = r16 resp
18 in
121 vlog
"reshape width %d height %d" w h;
124 let down = r16 resp
10 <> 0 in
125 let b = r32 resp
12 in
126 let x = r16s resp
16 in
127 let y = r16s resp
20 in
128 let m = r32 resp
24 in
129 vlog
"mouse %s b %d x %d y %d m 0x%x" (if down then "down" else "up") b x y m;
130 state.t#mouse
b down x y m
132 let x = r16s resp
16 in
133 let y = r16s resp
20 in
134 let m = r32 resp
24 in
135 vlog
"motion x %d y %d m 0x%x" x y m;
138 let x = r16s resp
16 in
139 let y = r16s resp
20 in
140 let m = r32 resp
24 in
141 vlog
"pmotion x %d y %d m 0x%x" x y m;
144 let key = r32 resp
16 in
145 let mask = r32 resp
20 in
146 vlog
"keydown key %d mask %d" key mask;
149 let x = r16s resp
16 in
150 let y = r16s resp
20 in
151 vlog
"enter x %d y %d" x y;
157 let x = r32 resp
16 <> 0 in
158 vlog
"winstate %B" x;
159 state.t#winstate
(if x then [Fullscreen
] else []);
164 let dx = r32s resp
16 in
165 let dy = r32s resp
20 in
166 vlog
"scroll dx %d dy %d" dx dy;
169 let z = float (r32s resp
16) /. 1000.0 in
170 let x = r16s resp
20 in
171 let y = r16s resp
22 in
172 vlog
"zoom z %f x %d y %d" z x y;
175 begin match r16 resp
2 with
177 let path = Buffer.contents
state.path in
178 Buffer.reset
state.path;
179 if false then nslog "open %S" path;
182 if false then nslog "open-append %S" (Bytes.sub_string resp
4 chunk_len
);
183 Buffer.add_subbytes
state.path resp
4 chunk_len
186 vlog
"unknown server message %d" opcode
190 match Unix.read sock
state.buf
state.off
(Bytes.length
state.buf
- state.off
) with
191 | exception Unix.Unix_error
(Unix.EINTR
, _
, _
) -> state.off
196 (* vlog "loop off=%d len=%d\n%!" off len; *)
197 if off
+ 32 <= len then begin
198 let resp = Bytes.sub
state.buf off
32 in
201 end else if off
< len then begin
202 Bytes.blit
state.buf off
state.buf
0 (len - off
);
203 state.off
<- len - state.off
209 let fontsizefactor () =
210 get_backing_scale_factor
()
212 let init t
w h _platform
=
213 let fd = get_server_fd
() in
216 makecurrentcontext
();
220 let activatewin () = ()
222 let metamask = 1 lsl 19
224 let altmask = 1 lsl 19
226 let shiftmask = 1 lsl 17
228 let ctrlmask = 1 lsl 18
230 let withalt mask = mask land metamask != 0
232 let withctrl mask = mask land ctrlmask != 0
234 let withshift mask = mask land shiftmask != 0
236 let withmeta mask = mask land metamask != 0
238 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0
241 let t = Hashtbl.create
20
242 and f
= Hashtbl.create
20 in
244 List.iter
(fun s
-> Hashtbl.add t s k
) (n
::nl
);
248 let s = String.make
1 c
in
249 add s [] (Char.code c
)
252 let an = Char.code a
and bn
= Char.code
b in
253 for i
= an to bn
do addc (Char.chr i
) done;
258 String.iter
addc "`~!@#$%^&*()-_=+\\|[{]};:,./<>?";
259 for i
= 0 to 29 do add ("f" ^ string_of_int
(i
+1)) [] (0xf704 + i
) done;
261 add "ret" ["return"; "enter"] 13;
263 add "left" [] 0xff51;
264 add "right" [] 0xff53;
265 add "home" [] 0xf729;
267 add "ins" ["insert"] 0xf729;
268 add "del" ["delete"] 0x7f;
269 add "esc" ["escape"] 27;
270 add "pgup" ["pageup"] 0xf72c;
271 add "pgdown" ["pagedown"] 0xf72d;
272 add "backspace" [] 8;
274 add "down" [] 0xf701;
275 (* add "menu" [] 0xff67; *) (* ? *)
279 try Hashtbl.find xlatf k
280 with Not_found
-> Printf.sprintf
"%#x" k
283 try Hashtbl.find
xlatt name
285 if String.length name
= 1
286 then Char.code name
.[0]
287 else int_of_string name
296 | 0xf729 | 0xfff04 -> Home
297 | 0xf702 | 0xfff05 -> Left
298 | 0xfff0b | 0xf700 -> Up
299 | 0xfff0a | 0xF703 -> Right
300 | 0xfff01 | 0xf701-> Down
301 | 0xfff09 | 0xf72c -> Prior
302 | 0xf72d | 0xfff07 -> Next
303 | 0xfff02 | 0xf72b -> End
306 | 0xfff08 -> Ascii '
+'
307 | 0xfff06 -> Ascii '
-'
308 | code
when code
> 31 && code
< 128 -> Ascii
(Char.unsafe_chr code
)
309 | code
when code
>= 0xffb0 && code
<= 0xffb9 ->
310 Ascii
(Char.unsafe_chr
(code
- 0xffb0 + 0x30))
311 | code
when code
>= 0xf704 && code
<= 0xf70f -> Fn
(code
- 0xf704 + 1)
312 | code
when code
land 0xff00 = 0xff00 -> Ctrl code