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 setwinbgcol
: int -> unit = "ml_setwinbgcol"
88 external nslog
: string -> unit = "ml_nslog"
91 Printf.ksprintf
nslog fmt
109 let handleresp resp
=
110 let opcode = r8 resp
0 in
113 let mapped = r8 resp
16 <> 0 in
114 vlog
"map %B" mapped;
120 let w = r16 resp
16 in
121 let h = r16 resp
18 in
122 vlog
"reshape width %d height %d" w h;
125 let down = r16 resp
10 <> 0 in
126 let b = r32 resp
12 in
127 let x = r16s resp
16 in
128 let y = r16s resp
20 in
129 let m = r32 resp
24 in
130 vlog
"mouse %s b %d x %d y %d m 0x%x" (if down then "down" else "up") b x y m;
131 state.t#mouse
b down x y m
133 let x = r16s resp
16 in
134 let y = r16s resp
20 in
135 let m = r32 resp
24 in
136 vlog
"motion x %d y %d m 0x%x" x y m;
139 let x = r16s resp
16 in
140 let y = r16s resp
20 in
141 let m = r32 resp
24 in
142 vlog
"pmotion x %d y %d m 0x%x" x y m;
145 let key = r32 resp
16 in
146 let mask = r32 resp
20 in
147 vlog
"keydown key %d mask %d" key mask;
150 let x = r16s resp
16 in
151 let y = r16s resp
20 in
152 vlog
"enter x %d y %d" x y;
158 let x = r32 resp
16 <> 0 in
159 vlog
"winstate %B" x;
160 state.t#winstate
(if x then [Fullscreen
] else []);
165 let dx = r32s resp
16 in
166 let dy = r32s resp
20 in
167 vlog
"scroll dx %d dy %d" dx dy;
170 let z = float (r32s resp
16) /. 1000.0 in
171 let x = r16s resp
20 in
172 let y = r16s resp
22 in
173 vlog
"zoom z %f x %d y %d" z x y;
176 begin match r16 resp
2 with
178 let path = Buffer.contents
state.path in
179 Buffer.reset
state.path;
180 if false then nslog "open %S" path;
183 if false then nslog "open-append %S" (Bytes.sub_string resp
4 chunk_len
);
184 Buffer.add_subbytes
state.path resp
4 chunk_len
187 vlog
"unknown server message %d" opcode
191 match Unix.read sock
state.buf
state.off
(Bytes.length
state.buf
- state.off
) with
192 | exception Unix.Unix_error
(Unix.EINTR
, _
, _
) -> state.off
197 (* vlog "loop off=%d len=%d\n%!" off len; *)
198 if off
+ 32 <= len then begin
199 let resp = Bytes.sub
state.buf off
32 in
202 end else if off
< len then begin
203 Bytes.blit
state.buf off
state.buf
0 (len - off
);
204 state.off
<- len - state.off
210 let fontsizefactor () =
211 get_backing_scale_factor
()
213 let init t _
w h _platform
=
214 let fd = get_server_fd
() in
217 makecurrentcontext
();
221 let activatewin () = ()
223 let metamask = 1 lsl 19
225 let altmask = 1 lsl 19
227 let shiftmask = 1 lsl 17
229 let ctrlmask = 1 lsl 18
231 let withalt mask = mask land metamask != 0
233 let withctrl mask = mask land ctrlmask != 0
235 let withshift mask = mask land shiftmask != 0
237 let withmeta mask = mask land metamask != 0
239 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0
242 let t = Hashtbl.create
20
243 and f
= Hashtbl.create
20 in
245 List.iter
(fun s
-> Hashtbl.add t s k
) (n
::nl
);
249 let s = String.make
1 c
in
250 add s [] (Char.code c
)
253 let an = Char.code a
and bn
= Char.code
b in
254 for i
= an to bn
do addc (Char.chr i
) done;
259 String.iter
addc "`~!@#$%^&*()-_=+\\|[{]};:,./<>?";
260 for i
= 0 to 29 do add ("f" ^ string_of_int
(i
+1)) [] (0xf704 + i
) done;
262 add "ret" ["return"; "enter"] 13;
264 add "left" [] 0xff51;
265 add "right" [] 0xff53;
266 add "home" [] 0xf729;
268 add "ins" ["insert"] 0xf729;
269 add "del" ["delete"] 0x7f;
270 add "esc" ["escape"] 27;
271 add "pgup" ["pageup"] 0xf72c;
272 add "pgdown" ["pagedown"] 0xf72d;
273 add "backspace" [] 8;
275 add "down" [] 0xf701;
276 (* add "menu" [] 0xff67; *) (* ? *)
281 try Hashtbl.find xlatf k
282 with Not_found
-> Printf.sprintf
"%#x" k
;
286 try Hashtbl.find
xlatt name
288 if String.length name
= 1
289 then Char.code name
.[0]
290 else int_of_string name
;
300 | 0xf729 | 0xfff04 -> Home
301 | 0xf702 | 0xfff05 -> Left
302 | 0xfff0b | 0xf700 -> Up
303 | 0xfff0a | 0xF703 -> Right
304 | 0xfff01 | 0xf701-> Down
305 | 0xfff09 | 0xf72c -> Prior
306 | 0xf72d | 0xfff07 -> Next
307 | 0xfff02 | 0xf72b -> End
310 | 0xfff08 -> Ascii '
+'
311 | 0xfff06 -> Ascii '
-'
312 | code
when code
> 31 && code
< 128 -> Ascii
(Char.unsafe_chr code
)
313 | code
when code
>= 0xffb0 && code
<= 0xffb9 ->
314 Ascii
(Char.unsafe_chr
(code
- 0xffb0 + 0x30))
315 | code
when code
>= 0xf704 && code
<= 0xf70f -> Fn
(code
- 0xf704 + 1)
316 | code
when code
land 0xff00 = 0xff00 -> Ctrl code