4 | Ulinkgoto
of (int * int)
6 | Uunexpected
of string
10 and facename
= string;;
12 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
13 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* wmclasshack
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and wmclasshack
= bool
39 and irect
= (int * int * int * int)
40 and trimparams
= (trimmargins
* irect
)
41 and colorspace
= | Rgb
| Bgr
| Gray
44 type platform
= | Punknown
| Plinux
| Pwindows
| Posx
| Psun
45 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
48 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
49 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
50 external copysel
: string -> opaque
-> unit = "ml_copysel";;
51 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
52 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
53 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
54 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
55 external measurestr
: int -> string -> float = "ml_measure_string";;
56 external getmaxw
: unit -> float = "ml_getmaxw";;
57 external postprocess
: opaque
-> bool -> int -> int -> unit = "ml_postprocess";;
58 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
59 external platform
: unit -> platform
= "ml_platform";;
60 external setaalevel
: int -> unit = "ml_setaalevel";;
61 external realloctexts
: int -> bool = "ml_realloctexts";;
63 let platform_to_string = function
64 | Punknown
-> "unknown"
66 | Pwindows
-> "Windows"
69 | Pfreebsd
-> "FreeBSD"
70 | Pdragonflybsd
-> "DragonflyBSD"
71 | Popenbsd
-> "OpenBSD"
77 let platform = platform ();;
81 | Pwindows
| Pmingw
-> true
89 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
92 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
96 | Msel
of (mpos
* mpos
)
99 | Mzoom
of (int * int)
100 | Mzoomrect
of (mpos
* mpos
)
104 type textentry
= string * string * onhist
option * onkey
* ondone
105 and onkey
= string -> int -> te
106 and ondone
= string -> unit
107 and histcancel
= unit -> unit
108 and onhist
= ((histcmd
-> string) * histcancel
)
109 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
114 | TEswitch
of textentry
125 let bound v minv maxv
=
126 max minv
(min maxv v
);
130 { store
= Array.create n v
137 let drawstring size x y s
=
139 Gl.enable `texture_2d
;
140 ignore
(drawstr size x y s
);
142 Gl.disable `texture_2d
;
145 let drawstring1 size x y s
=
149 let drawstring2 size x y fmt
=
150 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
153 let cbcap b
= Array.length b
.store
;;
158 b
.wc
<- (b
.wc
+ 1) mod cap;
160 b
.len
<- min
(b
.len
+ 1) cap;
163 let cbempty b
= b
.len
= 0;;
165 let cbgetg b circular dir
=
169 let rc = b
.rc + dir
in
181 else max
0 (min
rc (b
.len
-1))
187 let cbget b
= cbgetg b
false;;
188 let cbgetc b
= cbgetg b
true;;
205 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
206 dolog " WxH %dx%d" l
.pagew l
.pageh
;
207 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
208 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
209 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
213 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
215 dolog " x0,y0=(% f, % f)" x0 y0
;
216 dolog " x1,y1=(% f, % f)" x1 y1
;
217 dolog " x2,y2=(% f, % f)" x2 y2
;
218 dolog " x3,y3=(% f, % f)" x3 y3
;
223 multicol
* ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
224 and multicol
= columncount
* covercount
* covercount
226 and columncount
= int
227 and covercount
= int;;
230 { mutable scrollbw
: int
231 ; mutable scrollh
: int
232 ; mutable icase
: bool
233 ; mutable preload
: bool
234 ; mutable pagebias
: int
235 ; mutable verbose
: bool
236 ; mutable debug
: bool
237 ; mutable scrollstep
: int
238 ; mutable maxhfit
: bool
239 ; mutable crophack
: bool
240 ; mutable autoscrollstep
: int
241 ; mutable maxwait
: float option
242 ; mutable hlinks
: bool
243 ; mutable underinfo
: bool
244 ; mutable interpagespace
: interpagespace
245 ; mutable zoom
: float
246 ; mutable presentation
: bool
247 ; mutable angle
: angle
250 ; mutable savebmarks
: bool
251 ; mutable proportional
: proportional
252 ; mutable trimmargins
: trimmargins
253 ; mutable trimfuzz
: irect
254 ; mutable memlimit
: memsize
255 ; mutable texcount
: texcount
256 ; mutable sliceheight
: sliceheight
257 ; mutable thumbw
: width
258 ; mutable jumpback
: bool
259 ; mutable bgcolor
: float * float * float
260 ; mutable bedefault
: bool
261 ; mutable scrollbarinpm
: bool
262 ; mutable tilew
: int
263 ; mutable tileh
: int
264 ; mutable mustoresize
: memsize
265 ; mutable checkers
: bool
266 ; mutable aalevel
: int
267 ; mutable urilauncher
: string
268 ; mutable colorspace
: colorspace
269 ; mutable invert
: bool
270 ; mutable colorscale
: float
271 ; mutable redirectstderr
: bool
272 ; mutable ghyllscroll
: (int * int * int) option
273 ; mutable columns
: columns
option
274 ; mutable beyecolumns
: columncount
option
275 ; mutable selcmd
: string
279 type anchor
= pageno
* top
;;
281 type outline
= string * int * anchor
;;
283 type rect
= float * float * float * float * float * float * float * float;;
285 type tile
= opaque
* pixmapsize
* elapsed
286 and elapsed
= float;;
287 type pagemapkey
= pageno
* gen
;;
288 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
292 let emptyanchor = (0, 0.0);;
294 type infochange
= | Memused
| Docinfo
| Pdim
;;
296 class type uioh
= object
297 method display
: unit
298 method key
: int -> uioh
299 method special
: Glut.special_key_t
-> uioh
301 Glut.button_t
-> Glut.mouse_button_state_t
-> int -> int -> uioh
302 method motion
: int -> int -> uioh
303 method pmotion
: int -> int -> uioh
304 method infochanged
: infochange
-> unit
305 method scrollpw
: (int * float * float)
306 method scrollph
: (int * float * float)
310 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
311 | Textentry
of (textentry
* onleave
)
313 and onleave
= leavetextentrystatus
-> unit
314 and leavetextentrystatus
= | Cancel
| Confirm
315 and helpitem
= string * int * action
318 | Action
of (uioh
-> uioh
)
321 let isbirdseye = function Birdseye _
-> true | _
-> false;;
322 let istextentry = function Textentry _
-> true | _
-> false;;
326 | Loading
of (page
* gen
)
328 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
330 | Outlining
of outline list
333 let nouioh : uioh
= object (self
)
336 method special _
= self
337 method button _ _ _ _
= self
338 method motion _ _
= self
339 method pmotion _ _
= self
340 method infochanged _
= ()
341 method scrollpw
= (0, nan
, nan
)
342 method scrollph
= (0, nan
, nan
)
346 { mutable csock
: Unix.file_descr
347 ; mutable ssock
: Unix.file_descr
348 ; mutable errfd
: Unix.file_descr
option
349 ; mutable stderr
: Unix.file_descr
350 ; mutable errmsgs
: Buffer.t
351 ; mutable newerrmsgs
: bool
355 ; mutable scrollw
: int
356 ; mutable hscrollh
: int
357 ; mutable anchor
: anchor
359 ; mutable layout
: page list
360 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
361 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
362 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
363 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
364 ; mutable pagecount
: int
365 ; mutable currently
: currently
366 ; mutable mstate
: mstate
367 ; mutable searchpattern
: string
368 ; mutable rects
: (pageno
* recttype
* rect
) list
369 ; mutable rects1
: (pageno
* recttype
* rect
) list
370 ; mutable text
: string
371 ; mutable fullscreen
: (width
* height
) option
372 ; mutable mode
: mode
373 ; mutable uioh
: uioh
374 ; mutable outlines
: outline array
375 ; mutable bookmarks
: outline list
376 ; mutable path
: string
377 ; mutable password
: string
378 ; mutable invalidated
: int
379 ; mutable memused
: memsize
381 ; mutable throttle
: (page list
* int * float) option
382 ; mutable autoscroll
: int option
383 ; mutable ghyll
: int option -> unit
384 ; mutable help
: helpitem array
385 ; mutable docinfo
: (int * string) list
386 ; mutable deadline
: float
387 ; mutable texid
: GlTex.texture_id
option
389 ; mutable prevzoom
: float
390 ; mutable progress
: float
393 { pat
: string circbuf
394 ; pag
: string circbuf
395 ; nav
: anchor circbuf
396 ; sel
: string circbuf
417 ; presentation
= false
422 ; proportional
= true
423 ; trimmargins
= false
424 ; trimfuzz
= (0,0,0,0)
425 ; memlimit
= 32 lsl 20
430 ; bgcolor
= (0.5, 0.5, 0.5)
432 ; scrollbarinpm
= true
435 ; mustoresize
= 128 lsl 20
441 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
442 | Psun
-> "xdg-open \"%s\""
443 | Posx
-> "open \"%s\""
444 | Pwindows
| Pcygwin
| Pmingw
-> "start %s"
445 | Punknown
-> "echo %s")
449 | Pfreebsd
| Pdragonflybsd
| Popenbsd
| Pnetbsd
452 | Pwindows
| Pcygwin
| Pmingw
-> "wsel"
457 ; redirectstderr
= false
464 let conf = { defconf with angle
= defconf.angle
};;
467 { mutable fontsize
: int
468 ; mutable wwidth
: float
469 ; mutable maxrows
: int
481 fstate.fontsize
<- n
;
482 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
483 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
487 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
488 let len = String.length s
in
489 if colonpos >= 0 && colonpos + 3 < len
491 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
494 try String.rindex_from s
colonpos ' '
498 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
501 | "http" | "ftp" | "mailto" ->
503 try String.index_from s
colonpos ' '
504 with Not_found
-> len
506 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
516 then (try Sys.getenv
"COMSPEC" with Not_found
-> "cmd"), "/c"
520 let args = [|shell; farg
; s
|] in
521 ignore
(Unix.create_process
shell args Unix.stdin
Unix.stdout
Unix.stderr
)
525 if String.length
conf.urilauncher
= 0
526 then print_endline uri
528 let url = geturl uri
in
529 if String.length
url = 0
530 then print_endline uri
532 let re = Str.regexp
"%s" in
533 let command = Str.global_replace
re url conf.urilauncher
in
537 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
543 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
544 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
548 let strings = version () :: "" :: Help.keys
in
551 let url = geturl s
in
552 if String.length
url > 0
553 then (s
, 0, Action
(fun u
-> gotouri url; u
))
554 else (s
, 0, Noaction
)
564 ; stderr
= Unix.stderr
565 ; errmsgs
= Buffer.create
0
572 ; anchor
= emptyanchor
575 ; tilelru
= Queue.create
()
576 ; pagemap
= Hashtbl.create
10
577 ; tilemap
= Hashtbl.create
10
594 { nav
= cbnew 10 (0, 0.0)
617 Printf.kprintf prerr_endline fmt
619 Printf.kprintf ignore fmt
622 let redirectstderr () =
623 if conf.redirectstderr
625 let rfd, wfd
= Unix.pipe
() in
626 state.stderr
<- Unix.dup
Unix.stderr
;
627 state.errfd
<- Some
rfd;
628 Unix.dup2 wfd
Unix.stderr
;
630 state.newerrmsgs
<- false;
631 begin match state.errfd
with
634 Unix.dup2
state.stderr
Unix.stderr
;
638 prerr_string
(Buffer.contents
state.errmsgs
);
640 Buffer.clear
state.errmsgs
;
646 let postRedisplay who
=
648 then prerr_endline
("redisplay for " ^ who
);
649 Glut.postRedisplay ();
654 let b = Buffer.create
(String.length s
+ 1) in
655 Buffer.add_string
b s
;
660 let colorspace_of_string s
=
661 match String.lowercase s
with
665 | _
-> failwith
"invalid colorspace"
668 let int_of_colorspace = function
674 let colorspace_of_int = function
678 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
681 let colorspace_to_string = function
687 let intentry_with_suffix text key
=
688 let c = Char.unsafe_chr key
in
689 match Char.lowercase
c with
691 let text = addchar text c in
695 let text = addchar text c in
699 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
703 let columns_to_string (n
, a
, b) =
705 then Printf.sprintf
"%d" n
706 else Printf.sprintf
"%d,%d,%d" n a
b;
709 let columns_of_string s
=
711 (int_of_string s
, 0, 0)
713 Scanf.sscanf s
"%u,%u,%u" (fun n a
b -> (n
, a
, b));
717 let len = String.length s
in
719 let b = Buffer.create
n in
720 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
721 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
722 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
723 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
724 Buffer.add_string
b s
;
725 let s'
= Buffer.contents
b in
726 let n'
= Unix.write fd
s'
0 n in
727 if n'
!= n then failwith
"write failed";
732 let n = Unix.read fd
s 0 4 in
733 if n != 4 then failwith
"incomplete read(len)";
735 lor (Char.code
s.[0] lsl 24)
736 lor (Char.code
s.[1] lsl 16)
737 lor (Char.code
s.[2] lsl 8)
738 lor (Char.code
s.[3] lsl 0)
740 let s = String.create
len in
746 then failwith
"EWOULDBLOCK encountered 10 times"
750 with Unix.Unix_error
(Unix.EWOULDBLOCK
, _
, _
) ->
751 let _, _, _ = Unix.select
[fd
] [] [] 0.01 in
757 if n != len then failwith
"incomplete read(data)";
762 let b = Buffer.create
10 in
763 Buffer.add_string
b s;
764 let rec combine = function
767 Buffer.add_char
b ' '
;
770 | `
b b -> if b then "1" else "0"
772 | `i i
-> string_of_int i
773 | `f f
-> string_of_float f
774 | `I f
-> string_of_int
(truncate f
)
776 Buffer.add_string
b s;
783 let cmd = Buffer.contents
(makecmd s l
) in
784 writecmd state.csock
cmd;
790 let d = conf.winh
- h
in
797 let rec f pn ph pi fh l
=
799 | (n, _, h
, _) :: rest
->
800 let ips = calcips h
in
805 if isbirdseye state.mode
&& pn
= 0
810 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
815 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
819 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
822 let fh = f 0 0 0 0 state.pdims
in
827 match conf.columns
with
828 | None
-> calcheight ()
830 if Array.length
b > 0
832 let (_, _, y
, (_, _, h
, _)) = b.(Array.length
b - 1) in
837 let getpageyh pageno
=
838 let rec f pn ph pi y l
=
840 | (n, _, h
, _) :: rest
->
841 let ips = calcips h
in
844 let h = if n = pageno
then h else ph
in
845 if conf.presentation
&& n = pageno
847 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
849 y
+ (pageno
- pn
) * (ph
+ pi
), h
851 let y = y + (if conf.presentation
then pi
else 0) in
852 let y = y + (n - pn
) * (ph
+ pi
) in
856 y + (pageno
- pn
) * (ph
+ pi
), ph
858 f 0 0 0 0 state.pdims
861 let getpageyh pageno
=
862 match conf.columns
with
863 | None
-> getpageyh pageno
865 let (_, _, y, (_, _, h, _)) = b.(pageno
) in
869 let getpagedim pageno
=
872 | (n, _, _, _) as pdim
:: rest
->
874 then (if n = pageno
then pdim
else ppdim
)
879 f (-1, -1, -1, -1) state.pdims
882 let getpagey pageno
= fst
(getpageyh pageno
);;
885 let sh = sh - state.hscrollh
in
886 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~accu
=
887 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
889 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
890 let ips = calcips h in
892 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
896 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
898 prev
, pdims
, pdimno
, 0
900 let dy = dy + yinc in
901 let py = py + yinc in
902 if pageno
= state.pagecount
|| dy >= sh
907 if py + h <= vy - yinc
909 let py = py + h + ips in
910 let dy = max
0 (py - y) in
919 let pagey = vy - py in
920 let pagevh = h - pagey in
921 let pagevh = min
(sh - dy) pagevh in
922 let off = if yinc > 0 then py - vy else 0 in
923 let py = py + h + ips in
926 if state.w
< conf.winw
- state.scrollw
927 then (conf.winw
- state.scrollw
- state.w
) / 2
930 let dispx = xoff + state.x
in
936 let lw = w
- pagex in
937 min
lw (conf.winw
- state.scrollw
)
945 ; pagey = pagey + off
947 ; pagevh = pagevh - off
949 ; pagedispy
= dy + off
952 let accu = e :: accu in
961 if state.invalidated
= 0
979 let layoutN ((columns
, coverA
, coverB
), b) y sh =
980 let sh = sh - state.hscrollh
in
981 let rec fold accu n =
982 if n = Array.length
b
985 let pdimno, dx
, vy, (_, w
, h, xoff) = b.(n) in
988 || n = state.pagecount
- coverB
989 || (n - coverA
) mod columns
= columns
- 1)
995 let pagey = max
0 (y - vy) in
996 let pagedispy = if pagey > 0 then 0 else vy - y in
997 let pagedispx, pagex, pagevw =
999 if n = coverA
- 1 || n = state.pagecount
- coverB
1000 then state.x
+ (conf.winw
- state.scrollw
- w
) / 2
1001 else dx
+ xoff + state.x
1004 then 0, -pdx, w
+ pdx
1005 else pdx, 0, min
(conf.winw
- state.scrollw
) w
1007 let pagevh = min
(h - pagey) (sh - pagedispy) in
1008 if pagedispx < conf.winw
- state.scrollw
&& pagevw > 0 && pagevh > 0
1012 ; pagedimno
= pdimno
1019 ; pagedispx = pagedispx
1020 ; pagedispy = pagedispy
1031 if state.invalidated
= 0
1032 then List.rev
(fold [] 0)
1037 match conf.columns
with
1038 | None
-> layout1 y sh
1039 | Some
c -> layoutN c y sh
1043 let y = state.y + incr
in
1045 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1049 let getopaque pageno
=
1050 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
1051 with Not_found
-> None
1054 let putopaque pageno opaque
=
1055 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
1059 let tilex = l
.pagex mod conf.tilew
in
1060 let tiley = l
.pagey mod conf.tileh
in
1062 let col = l
.pagex / conf.tilew
in
1063 let row = l
.pagey / conf.tileh
in
1066 let a = l
.pagew
- l
.pagex in
1067 let b = conf.winw
- state.scrollw
in
1069 and vh
= l
.pagevh in
1071 let rec rowloop row y0 dispy
h =
1075 let dh = conf.tileh
- y0
in
1076 let dh = min
h dh in
1077 let rec colloop col x0
dispx w
=
1081 let dw = conf.tilew
- x0
in
1082 let dw = min w
dw in
1084 f col row dispx dispy x0 y0
dw dh;
1085 colloop (col+1) 0 (dispx+dw) (w
-dw)
1088 colloop col tilex l
.pagedispx vw;
1089 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1093 then rowloop row tiley l
.pagedispy vh
;
1096 let gettileopaque l
col row =
1098 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1100 try Some
(Hashtbl.find
state.tilemap
key)
1101 with Not_found
-> None
1104 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1105 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1106 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1109 let drawtiles l color
=
1111 let f col row x
y tilex tiley w
h =
1112 match gettileopaque l
col row with
1113 | Some
(opaque
, _, t
) ->
1114 let params = x
, y, w
, h, tilex, tiley in
1118 GlFunc.blend_func `zero `one_minus_src_color
;
1120 drawtile
params opaque
;
1122 then Gl.disable `blend
;
1125 let s = Printf.sprintf
1129 let w = measurestr
fstate.fontsize
s in
1130 GlMisc.push_attrib
[`current
];
1131 GlDraw.color
(0.0, 0.0, 0.0);
1133 (float (x
-2), float (y-2))
1134 (float (x
+2) +. w, float (y + fstate.fontsize
+ 2));
1135 GlDraw.color
(1.0, 1.0, 1.0);
1136 drawstring fstate.fontsize x
(y + fstate.fontsize
- 1) s;
1137 GlMisc.pop_attrib
();
1142 let lw = conf.winw
- state.scrollw
- x
in
1145 let lh = conf.winh
- y in
1148 Gl.enable `texture_2d
;
1149 begin match state.texid
with
1151 GlTex.bind_texture `texture_2d id
;
1154 and x1
= float (x
+w)
1155 and y1
= float (y+h) in
1157 let tw = float w /. 64.0
1158 and th
= float h /. 64.0 in
1159 let tx0 = float tilex /. 64.0
1160 and ty0
= float tiley /. 64.0 in
1162 and ty1
= ty0
+. th
in
1163 GlDraw.begins `quads
;
1164 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0
);
1165 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1
);
1166 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1
, y1
);
1167 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1
, y0
);
1170 Gl.disable `texture_2d
;
1172 GlDraw.color
(1.0, 1.0, 1.0);
1175 (float (x
+w), float (y+h));
1177 if w > 128 && h > fstate.fontsize
+ 10
1179 GlDraw.color
(0.0, 0.0, 0.0);
1182 then (col*conf.tilew
, row*conf.tileh
)
1185 drawstring2 fstate.fontsize x
y "Loading %d [%d,%d]" l
.pageno
c r
;
1192 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1194 let tilevisible1 l x
y =
1196 and ax1
= l
.pagex + l
.pagevw
1198 and ay1
= l
.pagey + l
.pagevh in
1202 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1203 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1205 let rx0 = max
ax0 bx0
1206 and ry0
= max ay0 by0
1207 and rx1
= min ax1
bx1
1208 and ry1
= min ay1 by1
in
1210 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1211 nonemptyintersection
1214 let tilevisible layout n x
y =
1215 let rec findpageinlayout = function
1216 | l
:: _ when l
.pageno
= n -> tilevisible1 l x
y
1217 | _ :: rest
-> findpageinlayout rest
1220 findpageinlayout layout
1223 let tileready l x
y =
1224 tilevisible1 l x
y &&
1225 gettileopaque l
(x
/conf.tilew
) (y/conf.tileh
) != None
1228 let tilepage n p
layout =
1229 let rec loop = function
1233 let f col row _ _ _ _ _ _ =
1234 if state.currently
= Idle
1236 match gettileopaque l
col row with
1239 let x = col*conf.tilew
1240 and y = row*conf.tileh
in
1242 let w = l
.pagew
- x in
1246 let h = l
.pageh
- y in
1258 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1259 conf.tilew
, conf.tileh
1268 if state.invalidated
= 0 then loop layout;
1271 let preloadlayout visiblepages
=
1272 let presentation = conf.presentation in
1273 let interpagespace = conf.interpagespace in
1274 let maxy = state.maxy in
1275 conf.presentation <- false;
1276 conf.interpagespace <- 0;
1277 state.maxy <- calcheight ();
1279 match visiblepages
with
1281 | l
:: _ -> getpagey l
.pageno
+ l
.pagey
1283 let y = if y < conf.winh
then 0 else y - conf.winh
in
1284 let h = state.y - y + conf.winh
*3 in
1285 let pages = layout y h in
1286 conf.presentation <- presentation;
1287 conf.interpagespace <- interpagespace;
1293 let rec loop pages =
1294 if state.currently
!= Idle
1299 begin match getopaque l
.pageno
with
1301 wcmd "page" [`i l
.pageno
; `i l
.pagedimno
];
1302 state.currently
<- Loading
(l
, state.gen
);
1304 tilepage l
.pageno opaque
pages;
1309 if state.invalidated
= 0 then loop pages
1314 if conf.preload && state.currently
= Idle
1315 then load (preloadlayout pages);
1318 let layoutready layout =
1319 let rec fold all ls
=
1320 all
&& match ls
with
1322 let seen = ref false in
1323 let allvisible = ref true in
1324 let foo col row _ _ _ _ _ _ =
1326 allvisible := !allvisible &&
1327 begin match gettileopaque l
col row with
1333 fold (!seen && !allvisible) rest
1336 let alltilesvisible = fold true layout in
1341 let y = bound y 0 state.maxy in
1342 let y, layout, proceed
=
1343 match conf.maxwait
with
1344 | Some time
when state.ghyll
== noghyll ->
1345 begin match state.throttle
with
1347 let layout = layout y conf.winh
in
1348 let ready = layoutready layout in
1352 state.throttle
<- Some
(layout, y, now ());
1354 else G.postRedisplay "gotoy showall (None)";
1356 | Some
(_, _, started
) ->
1357 let dt = now () -. started
in
1360 state.throttle
<- None
;
1361 let layout = layout y conf.winh
in
1363 G.postRedisplay "maxwait";
1370 let layout = layout y conf.winh
in
1371 if true || layoutready layout
1372 then G.postRedisplay "gotoy ready";
1378 state.layout <- layout;
1379 begin match state.mode
with
1380 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1381 if not
(pagevisible layout pageno
)
1383 match state.layout with
1386 state.mode
<- Birdseye
(
1387 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1394 state.ghyll
<- noghyll;
1397 let conttiling pageno opaque
=
1398 tilepage pageno opaque
1399 (if conf.preload then preloadlayout state.layout else state.layout)
1402 let gotoy_and_clear_text y =
1404 if not
conf.verbose
then state.text <- "";
1408 match state.layout with
1410 | l
:: _ -> (l
.pageno
, float l
.pagey /. float l
.pageh
)
1413 let getanchory (n, top
) =
1414 let y, h = getpageyh n in
1415 y + (truncate
(top
*. float h));
1418 let gotoanchor anchor
=
1419 gotoy (getanchory anchor
);
1423 cbput state.hists
.nav
(getanchor ());
1427 let anchor = cbgetc state.hists
.nav dir
in
1432 let rec scroll f n a b =
1433 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1435 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1437 then s (float f /. float a)
1440 then 1.0 -. s ((float (f-b) /. float (n-b)))
1447 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1448 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1450 let ins = float a *. iv1
1451 and outs
= float (n-b) *. iv1 in
1453 ins +. outs
+. float ones
1455 let rec set (_N
, _A
, _B
) y sy
=
1456 let sum = summa
1.0 _N _A _B
in
1457 let dy = float (y - sy
) in
1461 then state.ghyll
<- noghyll
1464 let s = scroll n _N _A _B
in
1465 let y1 = y1 +. ((s *. dy) /. sum) in
1466 gotoy_and_clear_text (truncate
y1);
1467 state.ghyll
<- gf (n+1) y1;
1471 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1473 gf 0 (float state.y)
1476 match conf.ghyllscroll
with
1478 gotoy_and_clear_text y
1480 if state.ghyll
== noghyll
1481 then set nab
y state.y
1482 else state.ghyll
(Some
y)
1485 let gotopage n top
=
1486 let y, h = getpageyh n in
1487 let y = y + (truncate
(top
*. float h)) in
1491 let gotopage1 n top
=
1492 let y = getpagey n in
1502 state.invalidated
<- state.invalidated
+ 1;
1505 let writeopen path password
=
1506 writecmd state.csock
("open " ^ path ^
"\000" ^ password ^
"\000");
1509 let opendoc path password
=
1512 state.password
<- password
;
1513 state.gen
<- state.gen
+ 1;
1514 state.docinfo
<- [];
1516 setaalevel
conf.aalevel
;
1517 writeopen path password
;
1518 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1519 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1523 let c = c *. conf.colorscale
in
1527 let scalecolor2 (r
, g
, b) =
1528 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1532 let docolumns = function
1534 | Some
((columns
, coverA
, coverB
), _) ->
1535 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1536 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1537 if pageno
= state.pagecount
1540 let pdimno, ((_, w, h, xoff) as pdim
), pdims
=
1542 | ((pageno'
, _, _, _) as pdim
) :: rest
when pageno'
= pageno
->
1543 pdimno+1, pdim
, rest
1548 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1550 (conf.winw
- state.scrollw
- w) / 2,
1551 y + rowh
+ conf.interpagespace, h
1554 if (pageno
- coverA
) mod columns
= 0
1555 then 0, y + rowh
+ conf.interpagespace, h
1556 else x, y, max rowh
h
1559 let rec fixrow m
= if m
= pageno
then () else
1560 let (pdimno, x, y, ((_, _, h, _) as pdim
)) = a.(m
) in
1563 let y = y + (rowh
- h) / 2 in
1564 a.(m
) <- (pdimno, x, y, pdim
);
1568 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1569 then fixrow (pageno
- columns
);
1570 a.(pageno
) <- (pdimno, x, y, pdim
);
1571 let x = x + w + xoff*2 + conf.interpagespace in
1572 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1574 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1575 conf.columns
<- Some
((columns
, coverA
, coverB
), a);
1577 docolumns conf.columns
;
1578 state.maxy <- calcheight ();
1580 if state.w <= conf.winw
- state.scrollw
1584 match state.mode
with
1585 | Birdseye
(_, _, pageno
, _, _) ->
1586 let y, h = getpageyh pageno
in
1587 let top = (conf.winh
- h) / 2 in
1588 gotoy (max
0 (y - top))
1589 | _ -> gotoanchor state.anchor
1593 let firsttime = ref true in
1595 GlDraw.viewport
0 0 w h;
1596 if state.invalidated
= 0 && not
!firsttime
1597 then state.anchor <- getanchor ();
1601 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
1605 setfontsize fstate.fontsize
;
1606 GlMat.mode `modelview
;
1607 GlMat.load_identity
();
1609 GlMat.mode `projection
;
1610 GlMat.load_identity
();
1611 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
1612 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
1613 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
1616 match conf.columns
with
1618 | Some
((c, _, _), _) -> (w - (c-1)*conf.interpagespace) / c
1621 wcmd "geometry" [`i
w; `i
h];
1625 let len = String.length
state.text in
1628 match state.mode
with
1629 | View
-> state.hscrollh
1634 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
1635 (x+.w, float (conf.winh
- hscrollh))
1638 let w = float (conf.winw
- state.scrollw
- 1) in
1639 if state.progress
>= 0.0 && state.progress
< 1.0
1641 GlDraw.color
(0.3, 0.3, 0.3);
1642 let w1 = w *. state.progress
in
1644 GlDraw.color
(0.0, 0.0, 0.0);
1648 GlDraw.color
(0.0, 0.0, 0.0);
1652 GlDraw.color
(1.0, 1.0, 1.0);
1653 drawstring fstate.fontsize
1654 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
1657 match state.mode
with
1658 | Textentry
((prefix
, text, _, _, _), _) ->
1662 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
1664 Printf.sprintf
"%s%s_" prefix
text
1673 if not
(istextentry state.mode
)
1675 let s1 = "(press 'e' to review error messasges)" in
1676 if String.length
s > 0 then s ^
" " ^
s1 else s1
1681 if String.length
s > 0
1686 state.text <- Printf.sprintf
"%c%s" c s;
1687 G.postRedisplay "showtext";
1691 let len = Queue.length
state.tilelru
in
1693 if state.memused
<= conf.memlimit
1698 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
1699 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
1700 let (_, pw
, ph
, _) = getpagedim n in
1703 && colorspace
= conf.colorspace
1704 && angle
= conf.angle
1709 match state.throttle
with
1712 then preloadlayout state.layout
1714 | Some
(layout, _, _) ->
1717 let x = col*conf.tilew
1718 and y = row*conf.tileh
in
1719 tilevisible layout n x y
1721 then Queue.push lruitem
state.tilelru
1723 wcmd "freetile" [`
s p
];
1724 state.memused
<- state.memused
- s;
1725 state.uioh#infochanged Memused
;
1726 Hashtbl.remove
state.tilemap k
;
1735 Queue.iter
(fun (k
, p
, s) ->
1736 wcmd "freetile" [`
s p
];
1737 state.memused
<- state.memused
- s;
1738 state.uioh#infochanged Memused
;
1739 Hashtbl.remove
state.tilemap k
;
1741 Queue.clear
state.tilelru
;
1745 let logcurrently = function
1746 | Idle
-> dolog "Idle"
1747 | Loading
(l
, gen
) ->
1748 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
1749 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
1751 "Tiling %d[%d,%d] page=%s cs=%s angle"
1752 l
.pageno
col row pageopaque
1753 (colorspace_to_string colorspace
)
1755 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1756 angle gen
conf.angle
state.gen
1758 conf.tilew
conf.tileh
1765 (* dolog "%S" cmds; *)
1768 try String.index cmds ' '
1769 with Not_found
-> -1
1774 let l = String.length cmds
in
1775 let op = String.sub cmds
0 spacepos in
1777 if l - spacepos < 2 then ""
1778 else String.sub cmds
(spacepos+1) (l-spacepos-1)
1783 state.uioh#infochanged Pdim
;
1787 state.rects
<- state.rects1
;
1788 G.postRedisplay "clearrects";
1792 try Scanf.sscanf
args "%u" (fun n -> n)
1794 dolog "error processing 'continue' %S: %s"
1795 cmds
(Printexc.to_string exn
);
1798 state.pagecount
<- n;
1799 state.invalidated
<- state.invalidated
- 1;
1800 begin match state.currently
with
1802 state.currently
<- Idle
;
1803 state.outlines
<- Array.of_list
(List.rev
l)
1806 if state.invalidated
= 0
1808 if conf.maxwait
= None
1809 then G.postRedisplay "continue";
1812 Glut.setWindowTitle
args
1819 then showtext ' '
args
1822 let progress, text =
1824 Scanf.sscanf
args "%f %n"
1826 f, String.sub
args pos
(String.length
args - pos
))
1828 dolog "error processing 'progress' %S: %s"
1829 cmds
(Printexc.to_string exn
);
1833 state.progress <- progress;
1834 G.postRedisplay "progress"
1837 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1839 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1840 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1841 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1843 dolog "error processing 'firstmatch' %S: %s"
1844 cmds
(Printexc.to_string exn
);
1847 let y = (getpagey pageno) + truncate y0
in
1850 state.rects1
<- [pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)]
1853 let pageno, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
=
1855 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
1856 (fun p
c x0 y0 x1
y1 x2 y2 x3 y3
->
1857 (p
, c, x0, y0
, x1
, y1, x2
, y2
, x3
, y3
))
1859 dolog "error processing 'match' %S: %s"
1860 cmds
(Printexc.to_string exn
);
1864 (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) :: state.rects1
1869 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
1871 dolog "error processing 'page' %S: %s"
1872 cmds
(Printexc.to_string exn
);
1875 begin match state.currently
with
1876 | Loading
(l, gen
) ->
1877 vlog "page %d took %f sec" l.pageno t
;
1878 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
1879 begin match state.throttle
with
1881 let preloadedpages =
1883 then preloadlayout state.layout
1888 Set.Make
(struct type t
= int let compare = (-) end) in
1890 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
1891 IntSet.empty
preloadedpages
1894 Hashtbl.fold (fun ((pageno, _) as key) opaque
accu ->
1895 if not
(IntSet.mem
pageno set)
1897 wcmd "freepage" [`
s opaque
];
1903 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
1906 state.currently
<- Idle
;
1909 tilepage l.pageno pageopaque state.layout;
1911 load preloadedpages;
1912 if pagevisible state.layout l.pageno
1913 && layoutready state.layout
1914 then G.postRedisplay "page";
1917 | Some
(layout, _, _) ->
1918 state.currently
<- Idle
;
1919 tilepage l.pageno pageopaque layout;
1924 dolog "Inconsistent loading state";
1925 logcurrently state.currently
;
1930 let (x, y, opaque
, size
, t
) =
1932 Scanf.sscanf
args "%u %u %s %u %f"
1933 (fun x y p size t
-> (x, y, p
, size
, t
))
1935 dolog "error processing 'tile' %S: %s"
1936 cmds
(Printexc.to_string exn
);
1939 begin match state.currently
with
1940 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
1941 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
1943 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
1945 wcmd "freetile" [`
s opaque
];
1946 state.currently
<- Idle
;
1950 puttileopaque l col row gen cs angle opaque size t
;
1951 state.memused
<- state.memused
+ size
;
1952 state.uioh#infochanged Memused
;
1954 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
1955 opaque
, size
) state.tilelru
;
1958 match state.throttle
with
1959 | None
-> state.layout
1960 | Some
(layout, _, _) -> layout
1963 state.currently
<- Idle
;
1965 && conf.colorspace
= cs
1966 && conf.angle
= angle
1967 && tilevisible layout l.pageno x y
1968 then conttiling l.pageno pageopaque;
1970 begin match state.throttle
with
1972 preload state.layout;
1974 && conf.colorspace
= cs
1975 && conf.angle
= angle
1976 && tilevisible state.layout l.pageno x y
1977 then G.postRedisplay "tile nothrottle";
1979 | Some
(layout, y, _) ->
1980 let ready = layoutready layout in
1984 state.layout <- layout;
1985 state.throttle
<- None
;
1986 G.postRedisplay "throttle";
1993 dolog "Inconsistent tiling state";
1994 logcurrently state.currently
;
2001 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2003 dolog "error processing 'pdim' %S: %s"
2004 cmds
(Printexc.to_string exn
);
2007 state.uioh#infochanged Pdim
;
2008 state.pdims
<- pdim :: state.pdims
2011 let (l, n, t
, h, pos
) =
2013 Scanf.sscanf
args "%u %u %d %u %n"
2014 (fun l n t
h pos
-> l, n, t
, h, pos
)
2016 dolog "error processing 'o' %S: %s"
2017 cmds
(Printexc.to_string exn
);
2020 let s = String.sub
args pos
(String.length
args - pos
) in
2021 let outline = (s, l, (n, float t
/. float h)) in
2022 begin match state.currently
with
2023 | Outlining outlines
->
2024 state.currently
<- Outlining
(outline :: outlines
)
2026 state.currently
<- Outlining
[outline]
2028 dolog "invalid outlining state";
2029 logcurrently currently
2033 state.docinfo
<- (1, args) :: state.docinfo
2036 state.uioh#infochanged Docinfo
;
2037 state.docinfo
<- List.rev
state.docinfo
2040 dolog "unknown cmd `%S'" cmds
2044 if state.deadline
== nan
then state.deadline
<- now ();
2046 match state.errfd
with
2047 | None
-> [state.csock
]
2048 | Some fd
-> [state.csock
; fd
]
2050 let rec loop delay
=
2052 if state.ghyll
== noghyll
2058 then max
0.0 (deadline -. now ())
2062 try Unix.select
r [] [] timeout
2063 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [] ,[]
2068 begin match state.autoscroll
with
2069 | Some step
when step
!= 0 ->
2070 let y = state.y + step
in
2074 else if y >= state.maxy then 0 else y
2077 if state.mode
= View
2078 then state.text <- "";
2079 state.deadline <- state.deadline +. 0.005;
2082 state.deadline <- state.deadline +. delay
;
2086 let rec checkfds c = function
2088 | fd
:: rest
when fd
= state.csock
->
2089 let cmd = readcmd state.csock
in
2093 let s = String.create
80 in
2094 let n = Unix.read fd
s 0 80 in
2095 if conf.redirectstderr
2097 Buffer.add_substring
state.errmsgs
s 0 n;
2098 state.newerrmsgs
<- true;
2099 Glut.postRedisplay ();
2102 prerr_string
(String.sub
s 0 n);
2115 let action = function
2116 | HCprev
-> cbget cb ~
-1
2117 | HCnext
-> cbget cb
1
2118 | HCfirst
-> cbget cb ~
-(cb
.rc)
2119 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2120 and cancel
() = cb
.rc <- rc
2124 let search pattern forward
=
2125 if String.length pattern
> 0
2128 match state.layout with
2131 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2134 let b = makecmd "search"
2135 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
2137 Buffer.add_char
b '
,'
;
2138 Buffer.add_string
b pattern
;
2139 Buffer.add_char
b '
\000'
;
2142 writecmd state.csock
cmd;
2145 let intentry text key =
2146 let c = Char.unsafe_chr
key in
2149 let text = addchar text c in
2153 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2157 let textentry text key =
2158 let c = Char.unsafe_chr
key in
2160 | _ when key >= 32 && key < 127 ->
2161 let text = addchar text c in
2165 dolog "unhandled key %d char `%c'" key (Char.unsafe_chr
key);
2169 let reqlayout angle proportional
=
2170 match state.throttle
with
2172 if state.invalidated
= 0 then state.anchor <- getanchor ();
2173 conf.angle
<- angle
mod 360;
2174 conf.proportional
<- proportional
;
2176 wcmd "reqlayout" [`i
conf.angle
; `
b proportional
];
2180 let settrim trimmargins trimfuzz
=
2181 if state.invalidated
= 0 then state.anchor <- getanchor ();
2182 conf.trimmargins
<- trimmargins
;
2183 conf.trimfuzz
<- trimfuzz
;
2184 let x0, y0
, x1
, y1 = trimfuzz
in
2187 `
b conf.trimmargins
;
2193 Hashtbl.iter
(fun _ opaque
->
2194 wcmd "freepage" [`
s opaque
];
2196 Hashtbl.clear
state.pagemap
;
2200 match state.throttle
with
2202 let zoom = max
0.01 zoom in
2203 if zoom <> conf.zoom
2205 state.prevzoom
<- conf.zoom;
2208 then (state.x <- 0; 0.0)
2209 else float state.x /. float state.w
2212 reshape conf.winw
conf.winh
;
2215 let x = relx *. float state.w in
2216 state.x <- truncate
x;
2218 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2221 | Some
(layout, y, started
) ->
2223 match conf.maxwait
with
2227 let dt = now () -. started
in
2235 let setcolumns columns coverA coverB
=
2238 conf.columns
<- None
;
2243 conf.columns
<- Some
((columns
, coverA
, coverB
), [||]);
2246 reshape conf.winw
conf.winh
;
2249 let enterbirdseye () =
2250 let zoom = float conf.thumbw
/. float conf.winw
in
2251 let birdseyepageno =
2252 let cy = conf.winh
/ 2 in
2256 let rec fold best
= function
2259 let d = cy - (l.pagedispy + l.pagevh/2)
2260 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2261 if abs
d < abs dbest
2268 state.mode
<- Birdseye
(
2269 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2272 conf.presentation <- false;
2273 conf.interpagespace <- 10;
2274 conf.hlinks
<- false;
2276 state.mstate
<- Mnone
;
2277 conf.maxwait
<- None
;
2279 match conf.beyecolumns
with
2282 Some
((c, 0, 0), [||])
2285 Glut.setCursor
Glut.CURSOR_INHERIT
;
2288 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2293 reshape conf.winw
conf.winh
;
2296 let leavebirdseye (c, leftx
, pageno, _, anchor) goback
=
2298 conf.zoom <- c.zoom;
2299 conf.presentation <- c.presentation;
2300 conf.interpagespace <- c.interpagespace;
2301 conf.maxwait
<- c.maxwait
;
2302 conf.hlinks
<- c.hlinks
;
2303 conf.beyecolumns
<- (
2304 match conf.columns
with
2305 | Some
((c, _, _), _) -> Some
c
2309 match c.columns
with
2310 | Some
(c, _) -> Some
(c, [||])
2316 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2319 reshape conf.winw
conf.winh
;
2320 state.anchor <- if goback
then anchor else (pageno, 0.0);
2323 let togglebirdseye () =
2324 match state.mode
with
2325 | Birdseye vals
-> leavebirdseye vals
true
2326 | View
-> enterbirdseye ()
2330 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2331 let pageno = max
0 (pageno - incr
) in
2332 let rec loop = function
2333 | [] -> gotopage1 pageno 0
2334 | l :: _ when l.pageno = pageno ->
2335 if l.pagedispy >= 0 && l.pagey = 0
2336 then G.postRedisplay "upbirdseye"
2337 else gotopage1 pageno 0
2338 | _ :: rest
-> loop rest
2341 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2344 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2345 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2346 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2347 let rec loop = function
2349 let y, h = getpageyh pageno in
2350 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2352 | l :: _ when l.pageno = pageno ->
2353 if l.pagevh != l.pageh
2354 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2355 else G.postRedisplay "downbirdseye"
2356 | _ :: rest
-> loop rest
2361 let optentry mode
_ key =
2362 let btos b = if b then "on" else "off" in
2363 let c = Char.unsafe_chr
key in
2367 try conf.scrollstep
<- int_of_string
s with exc
->
2368 state.text <- Printf.sprintf
"bad integer `%s': %s"
2369 s (Printexc.to_string exc
)
2371 TEswitch
("scroll step: ", "", None
, intentry, ondone)
2376 conf.autoscrollstep
<- int_of_string
s;
2377 if state.autoscroll
<> None
2378 then state.autoscroll
<- Some
conf.autoscrollstep
2380 state.text <- Printf.sprintf
"bad integer `%s': %s"
2381 s (Printexc.to_string exc
)
2383 TEswitch
("auto scroll step: ", "", None
, intentry, ondone)
2388 let n, a, b = columns_of_string s in
2391 state.text <- Printf.sprintf
"bad columns `%s': %s"
2392 s (Printexc.to_string exc
)
2394 TEswitch
("columns: ", "", None
, textentry, ondone)
2399 let zoom = float (int_of_string
s) /. 100.0 in
2402 state.text <- Printf.sprintf
"bad integer `%s': %s"
2403 s (Printexc.to_string exc
)
2405 TEswitch
("zoom: ", "", None
, intentry, ondone)
2410 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2412 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2413 begin match mode
with
2415 leavebirdseye beye
false;
2420 state.text <- Printf.sprintf
"bad integer `%s': %s"
2421 s (Printexc.to_string exc
)
2423 TEswitch
("thumbnail width: ", "", None
, intentry, ondone)
2428 Some
(int_of_string
s)
2430 state.text <- Printf.sprintf
"bad integer `%s': %s"
2431 s (Printexc.to_string exc
);
2434 | Some angle
-> reqlayout angle
conf.proportional
2437 TEswitch
("rotation: ", "", None
, intentry, ondone)
2440 conf.icase
<- not
conf.icase
;
2441 TEdone
("case insensitive search " ^
(btos conf.icase
))
2444 conf.preload <- not
conf.preload;
2446 TEdone
("preload " ^
(btos conf.preload))
2449 conf.verbose
<- not
conf.verbose
;
2450 TEdone
("verbose " ^
(btos conf.verbose
))
2453 conf.debug
<- not
conf.debug
;
2454 TEdone
("debug " ^
(btos conf.debug
))
2457 conf.maxhfit
<- not
conf.maxhfit
;
2459 state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
2460 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2463 conf.crophack
<- not
conf.crophack
;
2464 TEdone
("crophack " ^
btos conf.crophack
)
2468 match conf.maxwait
with
2470 conf.maxwait
<- Some infinity
;
2471 "always wait for page to complete"
2473 conf.maxwait
<- None
;
2474 "show placeholder if page is not ready"
2479 conf.underinfo
<- not
conf.underinfo
;
2480 TEdone
("underinfo " ^
btos conf.underinfo
)
2483 conf.savebmarks
<- not
conf.savebmarks
;
2484 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2490 match state.layout with
2495 conf.interpagespace <- int_of_string
s;
2496 state.maxy <- calcheight ();
2497 let y = getpagey pageno in
2500 state.text <- Printf.sprintf
"bad integer `%s': %s"
2501 s (Printexc.to_string exc
)
2503 TEswitch
("vertical margin: ", "", None
, intentry, ondone)
2506 reqlayout conf.angle
(not
conf.proportional
);
2507 TEdone
("proportional display " ^
btos conf.proportional
)
2510 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2511 TEdone
("trim margins " ^
btos conf.trimmargins
)
2514 conf.invert
<- not
conf.invert
;
2515 TEdone
("invert colors " ^
btos conf.invert
)
2519 cbput state.hists
.sel
s;
2522 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2526 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2530 class type lvsource
= object
2531 method getitemcount
: int
2532 method getitem
: int -> (string * int)
2533 method hasaction
: int -> bool
2542 method getactive
: int
2543 method getfirst
: int
2544 method getqsearch
: string
2545 method setqsearch
: string -> unit
2549 class virtual lvsourcebase
= object
2550 val mutable m_active
= 0
2551 val mutable m_first
= 0
2552 val mutable m_qsearch
= ""
2553 val mutable m_pan
= 0
2554 method getactive
= m_active
2555 method getfirst
= m_first
2556 method getqsearch
= m_qsearch
2557 method getpan
= m_pan
2558 method setqsearch
s = m_qsearch
<- s
2561 let textentryspecial key = function
2562 | ((c, _, (Some
(action, _) as onhist), onkey
, ondone), mode
) ->
2565 | Glut.KEY_UP
-> action HCprev
2566 | Glut.KEY_DOWN
-> action HCnext
2567 | Glut.KEY_HOME
-> action HCfirst
2568 | Glut.KEY_END
-> action HClast
2571 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
2572 G.postRedisplay "special textentry";
2576 let textentrykeyboard key ((c, text, opthist
, onkey
, ondone), onleave
) =
2578 state.mode
<- Textentry
(te
, onleave
);
2581 G.postRedisplay "textentrykeyboard enttext";
2583 match Char.unsafe_chr
key with
2584 | '
\008'
-> (* backspace *)
2585 let len = String.length
text in
2589 G.postRedisplay "textentrykeyboard after cancel";
2592 let s = String.sub
text 0 (len - 1) in
2593 enttext (c, s, opthist
, onkey
, ondone)
2599 G.postRedisplay "textentrykeyboard after confirm"
2601 | '
\007'
(* ctrl-g *)
2602 | '
\027'
-> (* escape *)
2603 if String.length
text = 0
2605 begin match opthist
with
2607 | Some
(_, onhistcancel
) -> onhistcancel
()
2611 G.postRedisplay "textentrykeyboard after cancel2"
2614 enttext (c, "", opthist
, onkey
, ondone)
2617 | '
\127'
-> () (* delete *)
2620 begin match onkey
text key with
2624 G.postRedisplay "textentrykeyboard after confirm2";
2627 enttext (c, text, opthist
, onkey
, ondone);
2631 G.postRedisplay "textentrykeyboard after cancel3"
2634 state.mode
<- Textentry
(te
, onleave
);
2635 G.postRedisplay "textentrykeyboard switch";
2639 let firstof first active
=
2640 if first
> active
|| abs
(first
- active
) > fstate.maxrows
- 1
2641 then max
0 (active
- (fstate.maxrows
/2))
2645 let calcfirst first active
=
2648 let rows = active
- first
in
2649 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
2653 let scrollph y maxy =
2654 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2655 let sh = float conf.winh
/. sh in
2656 let sh = max
sh (float conf.scrollh
) in
2661 else float y /. float maxy
2663 let position = (float conf.winh
-. sh) *. percent in
2666 if position +. sh > float conf.winh
2667 then float conf.winh
-. sh
2673 let coe s = (s :> uioh
);;
2675 class listview ~
(source
:lvsource
) ~trusted
=
2677 val m_pan
= source#getpan
2678 val m_first
= source#getfirst
2679 val m_active
= source#getactive
2680 val m_qsearch
= source#getqsearch
2681 val m_prev_uioh
= state.uioh
2683 method private elemunder
y =
2684 let n = y / (fstate.fontsize
+1) in
2685 if m_first
+ n < source#getitemcount
2687 if source#hasaction
(m_first
+ n)
2688 then Some
(m_first
+ n)
2695 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2696 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
2697 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2698 GlDraw.color
(1., 1., 1.);
2699 Gl.enable `texture_2d
;
2700 let fs = fstate.fontsize
in
2702 let ww = fstate.wwidth
in
2703 let tabw = 30.0*.ww in
2704 let itemcount = source#getitemcount
in
2706 if (row - m_first
) * nfs > conf.winh
2709 if row >= 0 && row < itemcount
2711 let (s, level
) = source#getitem
row in
2712 let y = (row - m_first
) * nfs in
2713 let x = 5.0 +. float (level
+ m_pan
) *. ww in
2716 Gl.disable `texture_2d
;
2717 GlDraw.polygon_mode `both `line
;
2718 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
2719 GlDraw.rect (1., float (y + 1))
2720 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
2721 GlDraw.polygon_mode `both `fill
;
2722 GlDraw.color
(1., 1., 1.);
2723 Gl.enable `texture_2d
;
2726 let drawtabularstring s =
2727 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
2730 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
2733 let len = String.length
s - tabpos - 1 in
2734 let s1 = String.sub
s 0 tabpos
2735 and s2
= String.sub
s (tabpos + 1) len in
2736 let nx = drawstr x s1 in
2738 let x = x +. (max
tabw sw) in
2745 let _ = drawtabularstring s in
2752 Gl.disable `texture_2d
;
2754 method updownlevel incr
=
2755 let len = source#getitemcount
in
2757 if m_active
>= 0 && m_active
< len
2758 then snd
(source#getitem m_active
)
2762 if i
= len then i
-1 else if i
= -1 then 0 else
2763 let _, l = source#getitem i
in
2764 if l != curlevel then i
else flow (i
+incr
)
2766 let active = flow m_active
in
2767 let first = calcfirst m_first
active in
2768 G.postRedisplay "special outline updownlevel";
2769 {< m_active
= active; m_first
= first >}
2771 method private key1
key =
2772 let set active first qsearch
=
2773 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
2775 let search active pattern incr
=
2778 if n >= 0 && n < source#getitemcount
2780 let s, _ = source#getitem
n in
2782 (try ignore
(Str.search_forward
re s 0); true
2783 with Not_found
-> false)
2785 else loop (n + incr
)
2792 let re = Str.regexp_case_fold pattern
in
2799 | 18 | 19 -> (* ctrl-r/ctlr-s *)
2800 let incr = if key = 18 then -1 else 1 in
2802 match search (m_active
+ incr) m_qsearch
incr with
2804 state.text <- m_qsearch ^
" [not found]";
2807 state.text <- m_qsearch
;
2808 active, firstof m_first
active
2810 G.postRedisplay "listview ctrl-r/s";
2811 set active first m_qsearch
;
2813 | 8 -> (* backspace *)
2814 let len = String.length m_qsearch
in
2821 G.postRedisplay "listview empty qsearch";
2822 set m_active m_first
"";
2825 let qsearch = String.sub m_qsearch
0 (len - 1) in
2827 match search m_active
qsearch ~
-1 with
2829 state.text <- qsearch ^
" [not found]";
2832 state.text <- qsearch;
2833 active, firstof m_first
active
2835 G.postRedisplay "listview backspace qsearch";
2836 set active first qsearch
2839 | _ when key >= 32 && key < 127 ->
2840 let pattern = addchar m_qsearch
(Char.chr
key) in
2842 match search m_active
pattern 1 with
2844 state.text <- pattern ^
" [not found]";
2847 state.text <- pattern;
2848 active, firstof m_first
active
2850 G.postRedisplay "listview qsearch add";
2851 set active first pattern;
2853 | 27 -> (* escape *)
2855 if String.length m_qsearch
= 0
2857 G.postRedisplay "list view escape";
2860 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
2862 | None
-> m_prev_uioh
2867 G.postRedisplay "list view kill qsearch";
2868 source#setqsearch
"";
2869 coe {< m_qsearch
= "" >}
2874 let self = {< m_qsearch
= "" >} in
2875 source#setqsearch
"";
2877 G.postRedisplay "listview enter";
2878 if m_active
>= 0 && m_active
< source#getitemcount
2880 source#exit
(coe self) false m_active m_first m_pan
"";
2883 source#exit
(coe self) true m_active m_first m_pan
"";
2886 begin match opt with
2887 | None
-> m_prev_uioh
2891 | 127 -> (* delete *)
2894 | _ -> dolog "unknown key %d" key; coe self
2896 method private special1
key =
2897 let itemcount = source#getitemcount
in
2898 let find start
incr =
2900 if i
= -1 || i
= itemcount
2903 if source#hasaction i
2905 else find (i
+ incr)
2910 let set active first =
2911 let first = bound first 0 (itemcount - fstate.maxrows
) in
2913 coe {< m_active
= active; m_first
= first >}
2916 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
2918 let incr1 = if incr > 0 then 1 else -1 in
2919 if isvisible m_first m_active
2922 let next = m_active
+ incr in
2924 if next < 0 || next >= itemcount
2926 else find next incr1
2928 if next = -1 || abs
(m_active
- next) > fstate.maxrows
2934 let first = m_first
+ incr in
2935 let first = bound first 0 (itemcount - 1) in
2937 let next = m_active
+ incr in
2938 let next = bound next 0 (itemcount - 1) in
2941 let active = if next = -1 then m_active
else next in
2944 let first = min
next m_first
in
2946 if abs
(next - first) > fstate.maxrows
2952 let first = m_first
+ incr in
2953 let first = bound first 0 (itemcount - 1) in
2955 let next = m_active
+ incr in
2956 let next = bound next 0 (itemcount - 1) in
2957 let next = find next incr1 in
2959 if next = -1 || abs
(m_active
- first) > fstate.maxrows
2961 let active = if m_active
= -1 then next else m_active
in
2966 if isvisible first active
2972 G.postRedisplay "listview navigate";
2975 begin match key with
2976 | Glut.KEY_UP
-> navigate ~
-1
2977 | Glut.KEY_DOWN
-> navigate 1
2978 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
2979 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
2983 G.postRedisplay "listview right";
2984 coe {< m_pan
= m_pan
- 1 >}
2988 G.postRedisplay "listview left";
2989 coe {< m_pan
= m_pan
+ 1 >}
2992 let active = find 0 1 in
2993 G.postRedisplay "listview home";
2997 let first = max
0 (itemcount - fstate.maxrows
) in
2998 let active = find (itemcount - 1) ~
-1 in
2999 G.postRedisplay "listview end";
3006 match state.mode
with
3007 | Textentry te
-> textentrykeyboard key te
; coe self
3008 | _ -> self#key1
key
3010 method special
key =
3011 match state.mode
with
3012 | Textentry te
-> textentryspecial key te
; coe self
3013 | _ -> self#special1
key
3015 method button button bstate
x y =
3018 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollbw
->
3019 G.postRedisplay "listview scroll";
3020 if bstate
= Glut.DOWN
3022 let _, position, sh = self#
scrollph in
3023 if y > truncate
position && y < truncate
(position +. sh)
3025 state.mstate
<- Mscrolly
;
3029 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3030 let first = truncate
(s *. float source#getitemcount
) in
3031 let first = min source#getitemcount
first in
3032 Some
(coe {< m_first
= first; m_active
= first >})
3034 state.mstate
<- Mnone
;
3037 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
3038 begin match self#elemunder
y with
3040 G.postRedisplay "listview click";
3042 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3046 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
3047 let len = source#getitemcount
in
3049 if n = 4 && m_first
+ fstate.maxrows
>= len
3053 let first = m_first
+ (if n == 3 then -1 else 1) in
3054 bound first 0 (len - 1)
3056 G.postRedisplay "listview wheel";
3057 Some
(coe {< m_first
= first >})
3062 | None
-> m_prev_uioh
3066 match state.mstate
with
3068 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3069 let first = truncate
(s *. float source#getitemcount
) in
3070 let first = min source#getitemcount
first in
3071 G.postRedisplay "listview motion";
3072 coe {< m_first
= first; m_active
= first >}
3075 method pmotion
x y =
3076 if x < conf.winw
- conf.scrollbw
3079 match self#elemunder
y with
3080 | None
-> Glut.setCursor
Glut.CURSOR_INHERIT
; m_active
3081 | Some
n -> Glut.setCursor
Glut.CURSOR_INFO
; n
3085 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3090 Glut.setCursor
Glut.CURSOR_INHERIT
;
3094 method infochanged
_ = ()
3096 method scrollpw
= (0, 0.0, 0.0)
3098 let nfs = fstate.fontsize
+ 1 in
3099 let y = m_first
* nfs in
3100 let itemcount = source#getitemcount
in
3101 let maxi = max
0 (itemcount - fstate.maxrows
) in
3102 let maxy = maxi * nfs in
3103 let p, h = scrollph y maxy in
3107 class outlinelistview ~source
=
3109 inherit listview ~source
:(source
:> lvsource
) ~trusted
:false as super
3113 | 14 -> (* ctrl-n *)
3114 source#narrow m_qsearch
;
3115 G.postRedisplay "outline ctrl-n";
3116 coe {< m_first
= 0; m_active
= 0 >}
3118 | 21 -> (* ctrl-u *)
3120 G.postRedisplay "outline ctrl-u";
3122 coe {< m_first
= 0; m_active
= 0 >}
3124 | 12 -> (* ctrl-l *)
3125 let first = m_active
- (fstate.maxrows
/ 2) in
3126 G.postRedisplay "outline ctrl-l";
3127 coe {< m_first
= first >}
3129 | 127 -> (* delete *)
3130 source#remove m_active
;
3131 G.postRedisplay "outline delete";
3132 let active = max
0 (m_active
-1) in
3133 coe {< m_first
= firstof m_first
active;
3134 m_active
= active >}
3136 | key -> super#
key key
3138 method special
key =
3139 let calcfirst first active =
3142 let rows = active - first in
3143 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3147 let active = m_active
+ incr in
3148 let active = bound active 0 (source#getitemcount
- 1) in
3149 let first = calcfirst m_first
active in
3150 G.postRedisplay "special outline navigate";
3151 coe {< m_active
= active; m_first
= first >}
3154 | Glut.KEY_UP
-> navigate ~
-1
3155 | Glut.KEY_DOWN
-> navigate 1
3156 | Glut.KEY_PAGE_UP
-> navigate ~
-(fstate.maxrows
)
3157 | Glut.KEY_PAGE_DOWN
-> navigate fstate.maxrows
3161 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3163 G.postRedisplay "special outline right";
3164 {< m_pan
= m_pan
+ 1 >}
3166 else self#updownlevel
1
3172 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
3174 G.postRedisplay "special outline left";
3175 {< m_pan
= m_pan
- 1 >}
3177 else self#updownlevel ~
-1
3182 G.postRedisplay "special outline home";
3183 coe {< m_first
= 0; m_active
= 0 >}
3186 let active = source#getitemcount
- 1 in
3187 let first = max
0 (active - fstate.maxrows
) in
3188 G.postRedisplay "special outline end";
3189 coe {< m_active
= active; m_first
= first >}
3191 | _ -> super#special
key
3194 let outlinesource usebookmarks
=
3197 inherit lvsourcebase
3198 val mutable m_items
= empty
3199 val mutable m_orig_items
= empty
3200 val mutable m_prev_items
= empty
3201 val mutable m_narrow_pattern
= ""
3202 val mutable m_hadremovals
= false
3204 method getitemcount
=
3205 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3208 if n == Array.length m_items
&& m_hadremovals
3210 ("[Confirm removal]", 0)
3212 let s, n, _ = m_items
.(n) in
3215 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3216 ignore
(uioh
, first, qsearch);
3217 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3219 if String.length m_narrow_pattern
= 0
3225 if not
confrimremoval
3227 let _, _, anchor = m_items
.(active) in
3232 state.bookmarks
<- Array.to_list m_items
;
3233 m_orig_items
<- m_items
;
3236 else m_items
<- items;
3240 method hasaction
_ = true
3243 if Array.length m_items
!= Array.length m_orig_items
3244 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3247 method narrow
pattern =
3248 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3252 let rec loop accu n =
3255 m_narrow_pattern
<- pattern;
3256 m_items
<- Array.of_list
accu
3259 let (s, _, _) as o = m_items
.(n) in
3261 if (try ignore
(Str.search_forward
re s 0); true
3262 with Not_found
-> false)
3268 loop [] (Array.length m_items
- 1)
3273 then Array.of_list
state.bookmarks
3276 m_items
<- m_orig_items
3281 if m
>= 0 && m
< Array.length m_items
3283 m_hadremovals
<- true;
3284 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3285 let n = if n >= m
then n+1 else n in
3290 method reset
anchor items =
3291 m_hadremovals
<- false;
3292 if m_orig_items
== empty || m_prev_items
!= items
3294 m_orig_items
<- items;
3295 if String.length m_narrow_pattern
= 0
3296 then m_items
<- items;
3298 m_prev_items
<- items;
3299 let rely = getanchory anchor in
3301 let rec loop n best bestd
=
3302 if n = Array.length m_items
3305 let (_, _, anchor) = m_items
.(n) in
3306 let orely = getanchory anchor in
3307 let d = abs
(orely - rely) in
3310 else loop (n+1) best bestd
3315 m_first
<- firstof m_first
active
3319 let enterselector usebookmarks
=
3320 let source = outlinesource usebookmarks
in
3324 then Array.of_list
state.bookmarks
3327 if Array.length
outlines = 0
3329 showtext ' ' errmsg
;
3332 state.text <- source#greetmsg
;
3333 Glut.setCursor
Glut.CURSOR_INHERIT
;
3334 let anchor = getanchor () in
3335 source#reset
anchor outlines;
3336 state.uioh
<- coe (new outlinelistview ~
source);
3337 G.postRedisplay "enter selector";
3341 let enteroutlinemode =
3342 let f = enterselector false in
3343 fun ()-> f "Document has no outline";
3346 let enterbookmarkmode =
3347 let f = enterselector true in
3348 fun () -> f "Document has no bookmarks (yet)";
3351 let color_of_string s =
3352 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3353 (float r /. 256.0, float g
/. 256.0, float b /. 256.0)
3357 let color_to_string (r, g
, b) =
3358 let r = truncate
(r *. 256.0)
3359 and g
= truncate
(g
*. 256.0)
3360 and b = truncate
(b *. 256.0) in
3361 Printf.sprintf
"%d/%d/%d" r g
b
3364 let irect_of_string s =
3365 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1
y1 -> (x0,y0
,x1
,y1))
3368 let irect_to_string (x0,y0
,x1
,y1) =
3369 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1
y1
3372 let makecheckers () =
3373 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3375 converted by Issac Trotts. July 25, 2002 *)
3376 let image_height = 64
3377 and image_width
= 64 in
3381 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3383 for i
= 0 to image_width
- 1 do
3384 for j
= 0 to image_height - 1 do
3385 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3386 (if (i
land 8 ) lxor (j
land 8) = 0
3387 then [|255;255;255|] else [|200;200;200|])
3392 let image = make_image () in
3393 let id = GlTex.gen_texture
() in
3394 GlTex.bind_texture `texture_2d
id;
3395 GlPix.store
(`unpack_alignment
1);
3396 GlTex.image2d
image;
3397 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3400 `mag_filter `nearest
;
3401 `min_filter `nearest
];
3405 let setcheckers enabled
=
3406 match state.texid
with
3408 if enabled
then state.texid
<- Some
(makecheckers ())
3413 GlTex.delete_texture texid
;
3414 state.texid
<- None
;
3418 let int_of_string_with_suffix s =
3419 let l = String.length
s in
3423 let suffix = Char.lowercase
s.[l-1] in
3425 | 'k'
-> String.sub
s 0 (l-1), 10
3426 | 'm'
-> String.sub
s 0 (l-1), 20
3427 | 'g'
-> String.sub
s 0 (l-1), 30
3431 let n = int_of_string
s1 in
3432 let m = n lsl shift
in
3434 then raise
(Failure
"value too large")
3438 let string_with_suffix_of_int n =
3446 if n land ((1 lsl 20) - 1) = 0
3449 if n land ((1 lsl 10) - 1) = 0
3456 let h = n mod 1000 in
3459 then string_of_int
h ^
s
3461 let s = Printf.sprintf
"_%03d%s" h s in
3468 let defghyllscroll = (40, 8, 32);;
3469 let ghyllscroll_of_string s =
3470 let (n, a, b) as nab
=
3473 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3475 if n <= a || n <= b || a >= b
3476 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3480 let ghyllscroll_to_string ((n, a, b) as nab
) =
3481 if nab
= defghyllscroll
3483 else Printf.sprintf
"%d,%d,%d" n a b;
3486 let describe_location () =
3488 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3490 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3491 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3495 else (100. *. (float state.y /. float maxy))
3499 Printf.sprintf
"page %d of %d [%.2f%%]"
3500 (fn+1) state.pagecount
percent
3503 "pages %d-%d of %d [%.2f%%]"
3504 (fn+1) (ln
+1) state.pagecount
percent
3508 let btos b = if b then "\xe2\x88\x9a" else "" in
3509 let showextended = ref false in
3510 let leave mode
= function
3511 | Confirm
-> state.mode
<- mode
3512 | Cancel
-> state.mode
<- mode
in
3515 val mutable m_first_time
= true
3516 val mutable m_l
= []
3517 val mutable m_a
= [||]
3518 val mutable m_prev_uioh
= nouioh
3519 val mutable m_prev_mode
= View
3521 inherit lvsourcebase
3523 method reset prev_mode prev_uioh
=
3524 m_a
<- Array.of_list
(List.rev m_l
);
3526 m_prev_mode
<- prev_mode
;
3527 m_prev_uioh
<- prev_uioh
;
3531 if n >= Array.length m_a
3535 | _, _, _, Action
_ -> m_active
<- n
3539 m_first_time
<- false;
3542 method int name get
set =
3544 (name
, `
int get
, 1, Action
(
3547 try set (int_of_string
s)
3549 state.text <- Printf.sprintf
"bad integer `%s': %s"
3550 s (Printexc.to_string exn
)
3553 let te = name ^
": ", "", None
, intentry, ondone in
3554 state.mode
<- Textentry
(te, leave m_prev_mode
);
3558 method int_with_suffix name get
set =
3560 (name
, `intws get
, 1, Action
(
3563 try set (int_of_string_with_suffix s)
3565 state.text <- Printf.sprintf
"bad integer `%s': %s"
3566 s (Printexc.to_string exn
)
3570 name ^
": ", "", None
, intentry_with_suffix, ondone
3572 state.mode
<- Textentry
(te, leave m_prev_mode
);
3576 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3578 (name
, `
bool (btos, get
), offset
, Action
(
3585 method color name get
set =
3587 (name
, `color get
, 1, Action
(
3589 let invalid = (nan
, nan
, nan
) in
3592 try color_of_string s
3594 state.text <- Printf.sprintf
"bad color `%s': %s"
3595 s (Printexc.to_string exn
);
3601 let te = name ^
": ", "", None
, textentry, ondone in
3602 state.text <- color_to_string (get
());
3603 state.mode
<- Textentry
(te, leave m_prev_mode
);
3607 method string name get
set =
3609 (name
, `
string get
, 1, Action
(
3611 let ondone s = set s in
3612 let te = name ^
": ", "", None
, textentry, ondone in
3613 state.mode
<- Textentry
(te, leave m_prev_mode
);
3617 method colorspace name get
set =
3619 (name
, `
string get
, 1, Action
(
3622 let vals = [| "rgb"; "bgr"; "gray" |] in
3624 inherit lvsourcebase
3627 m_active
<- int_of_colorspace conf.colorspace
;
3630 method getitemcount
= Array.length
vals
3631 method getitem
n = (vals.(n), 0)
3632 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3633 ignore
(uioh
, first, pan
, qsearch);
3634 if not cancel
then set active;
3636 method hasaction
_ = true
3640 coe (new listview ~
source ~trusted
:true)
3643 method caption
s offset
=
3644 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
3646 method caption2
s f offset
=
3647 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
3649 method getitemcount
= Array.length m_a
3652 let tostr = function
3653 | `
int f -> string_of_int
(f ())
3654 | `intws
f -> string_with_suffix_of_int (f ())
3656 | `color
f -> color_to_string (f ())
3657 | `
bool (btos, f) -> btos (f ())
3660 let name, t
, offset
, _ = m_a
.(n) in
3661 ((let s = tostr t
in
3662 if String.length
s > 0
3663 then Printf.sprintf
"%s\t%s" name s
3667 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3671 m_qsearch
<- qsearch;
3673 match m_a
.(active) with
3674 | _, _, _, Action
f -> f uioh
3686 method hasaction
n =
3688 | _, _, _, Action
_ -> true
3692 let rec fillsrc prevmode prevuioh
=
3693 let sep () = src#caption
"" 0 in
3694 let colorp name get
set =
3696 (fun () -> color_to_string (get
()))
3699 let c = color_of_string v in
3702 state.text <- Printf.sprintf
"bad color `%s': %s"
3703 v (Printexc.to_string exn
);
3706 let oldmode = state.mode
in
3707 let birdseye = isbirdseye state.mode
in
3709 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
3711 src#
bool "presentation mode"
3712 (fun () -> conf.presentation)
3714 conf.presentation <- v;
3715 state.anchor <- getanchor ();
3718 src#
bool "ignore case in searches"
3719 (fun () -> conf.icase
)
3720 (fun v -> conf.icase
<- v);
3723 (fun () -> conf.preload)
3724 (fun v -> conf.preload <- v);
3726 src#
bool "highlight links"
3727 (fun () -> conf.hlinks
)
3728 (fun v -> conf.hlinks
<- v);
3730 src#
bool "under info"
3731 (fun () -> conf.underinfo
)
3732 (fun v -> conf.underinfo
<- v);
3734 src#
bool "persistent bookmarks"
3735 (fun () -> conf.savebmarks
)
3736 (fun v -> conf.savebmarks
<- v);
3738 src#
bool "proportional display"
3739 (fun () -> conf.proportional
)
3740 (fun v -> reqlayout conf.angle
v);
3742 src#
bool "trim margins"
3743 (fun () -> conf.trimmargins
)
3744 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
3746 src#
bool "persistent location"
3747 (fun () -> conf.jumpback
)
3748 (fun v -> conf.jumpback
<- v);
3751 src#
int "inter-page space"
3752 (fun () -> conf.interpagespace)
3754 conf.interpagespace <- n;
3756 match state.layout with
3761 state.maxy <- calcheight ();
3762 let y = getpagey pageno in
3767 (fun () -> conf.pagebias
)
3768 (fun v -> conf.pagebias
<- v);
3770 src#
int "scroll step"
3771 (fun () -> conf.scrollstep
)
3772 (fun n -> conf.scrollstep
<- n);
3774 src#
int "auto scroll step"
3776 match state.autoscroll
with
3778 | _ -> conf.autoscrollstep
)
3780 if state.autoscroll
<> None
3781 then state.autoscroll
<- Some
n;
3782 conf.autoscrollstep
<- n);
3785 (fun () -> truncate
(conf.zoom *. 100.))
3786 (fun v -> setzoom ((float v) /. 100.));
3789 (fun () -> conf.angle
)
3790 (fun v -> reqlayout v conf.proportional
);
3792 src#
int "scroll bar width"
3793 (fun () -> state.scrollw
)
3797 reshape conf.winw
conf.winh
;
3800 src#
int "scroll handle height"
3801 (fun () -> conf.scrollh
)
3802 (fun v -> conf.scrollh
<- v;);
3804 src#
int "thumbnail width"
3805 (fun () -> conf.thumbw
)
3807 conf.thumbw
<- min
4096 v;
3810 leavebirdseye beye
false;
3815 src#
string "columns"
3817 match conf.columns
with
3819 | Some
(multicol
, _) -> columns_to_string multicol
)
3821 let n, a, b = columns_of_string v in
3825 src#caption
"Presentation mode" 0;
3826 src#
bool "scrollbar visible"
3827 (fun () -> conf.scrollbarinpm
)
3829 if v != conf.scrollbarinpm
3831 conf.scrollbarinpm
<- v;
3832 if conf.presentation
3834 state.scrollw
<- if v then conf.scrollbw
else 0;
3835 reshape conf.winw
conf.winh
;
3841 src#caption
"Pixmap cache" 0;
3842 src#int_with_suffix
"size (advisory)"
3843 (fun () -> conf.memlimit
)
3844 (fun v -> conf.memlimit
<- v);
3847 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
3848 (string_with_suffix_of_int state.memused
)
3849 (Hashtbl.length
state.tilemap
)) 1;
3852 src#caption
"Layout" 0;
3853 src#caption2
"Dimension"
3855 Printf.sprintf
"%dx%d (virtual %dx%d)"
3861 src#caption2
"Position" (fun () ->
3862 Printf.sprintf
"%dx%d" state.x state.y
3865 src#caption2
"Visible" (fun () -> describe_location ()) 1
3869 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
3870 "Save these parameters as global defaults at exit"
3871 (fun () -> conf.bedefault
)
3872 (fun v -> conf.bedefault
<- v)
3876 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
3877 src#
bool ~offset
:0 ~
btos "Extended parameters"
3878 (fun () -> !showextended)
3879 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
3883 (fun () -> conf.checkers
)
3884 (fun v -> conf.checkers
<- v; setcheckers v);
3886 (fun () -> conf.verbose
)
3887 (fun v -> conf.verbose
<- v);
3888 src#
bool "invert colors"
3889 (fun () -> conf.invert
)
3890 (fun v -> conf.invert
<- v);
3892 (fun () -> conf.maxhfit
)
3893 (fun v -> conf.maxhfit
<- v);
3894 src#
bool "redirect stderr"
3895 (fun () -> conf.redirectstderr)
3896 (fun v -> conf.redirectstderr <- v; redirectstderr ());
3897 src#
string "uri launcher"
3898 (fun () -> conf.urilauncher
)
3899 (fun v -> conf.urilauncher
<- v);
3900 src#
string "tile size"
3901 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
3904 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
3905 conf.tileh
<- max
64 w;
3906 conf.tilew
<- max
64 h;
3909 state.text <- Printf.sprintf
"bad tile size `%s': %s"
3910 v (Printexc.to_string exn
));
3911 src#
int "texture count"
3912 (fun () -> conf.texcount
)
3915 then conf.texcount
<- v
3916 else showtext '
!'
" Failed to set texture count please retry later"
3918 src#
int "slice height"
3919 (fun () -> conf.sliceheight
)
3921 conf.sliceheight
<- v;
3922 wcmd "sliceh" [`i
conf.sliceheight
];
3924 src#
int "anti-aliasing level"
3925 (fun () -> conf.aalevel
)
3927 conf.aalevel
<- bound v 0 8;
3928 state.anchor <- getanchor ();
3929 opendoc state.path
state.password
;
3931 src#
int "ui font size"
3932 (fun () -> fstate.fontsize
)
3933 (fun v -> setfontsize (bound v 5 100));
3934 colorp "background color"
3935 (fun () -> conf.bgcolor
)
3936 (fun v -> conf.bgcolor
<- v);
3937 src#
bool "crop hack"
3938 (fun () -> conf.crophack
)
3939 (fun v -> conf.crophack
<- v);
3940 src#
string "trim fuzz"
3941 (fun () -> irect_to_string conf.trimfuzz
)
3944 conf.trimfuzz
<- irect_of_string v;
3946 then settrim true conf.trimfuzz
;
3948 state.text <- Printf.sprintf
"bad irect `%s': %s"
3949 v (Printexc.to_string exn
)
3951 src#
string "throttle"
3953 match conf.maxwait
with
3954 | None
-> "show place holder if page is not ready"
3957 then "wait for page to fully render"
3959 "wait " ^ string_of_float
time
3960 ^
" seconds before showing placeholder"
3964 let f = float_of_string
v in
3966 then conf.maxwait
<- None
3967 else conf.maxwait
<- Some
f
3969 state.text <- Printf.sprintf
"bad time `%s': %s"
3970 v (Printexc.to_string exn
)
3972 src#
string "ghyll scroll"
3974 match conf.ghyllscroll
with
3976 | Some nab
-> ghyllscroll_to_string nab
3981 if String.length
v = 0
3983 else Some
(ghyllscroll_of_string v)
3985 conf.ghyllscroll
<- gs
3987 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
3988 v (Printexc.to_string exn
)
3990 src#
string "selection command"
3991 (fun () -> conf.selcmd
)
3992 (fun v -> conf.selcmd
<- v);
3993 src#colorspace
"color space"
3994 (fun () -> colorspace_to_string conf.colorspace
)
3996 conf.colorspace
<- colorspace_of_int v;
4003 src#caption
"Document" 0;
4004 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4005 src#caption2
"Pages"
4006 (fun () -> string_of_int
state.pagecount
) 1;
4007 src#caption2
"Dimensions"
4008 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4012 src#caption
"Trimmed margins" 0;
4013 src#caption2
"Dimensions"
4014 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4017 src#reset prevmode prevuioh
;
4021 let prevmode = state.mode
4022 and prevuioh
= state.uioh in
4023 fillsrc prevmode prevuioh
;
4024 let source = (src :> lvsource
) in
4025 state.uioh <- coe (object (self)
4026 inherit listview ~
source ~trusted
:true as super
4027 val mutable m_prevmemused
= 0
4028 method infochanged
= function
4030 if m_prevmemused
!= state.memused
4032 m_prevmemused
<- state.memused
;
4033 G.postRedisplay "memusedchanged";
4035 | Pdim
-> G.postRedisplay "pdimchanged"
4036 | Docinfo
-> fillsrc prevmode prevuioh
4038 method special
key =
4039 if Glut.getModifiers
() land Glut.active_ctrl
= 0
4042 | Glut.KEY_LEFT
-> coe (self#updownlevel ~
-1)
4043 | Glut.KEY_RIGHT
-> coe (self#updownlevel
1)
4044 | _ -> super#special
key
4045 else super#special
key
4047 G.postRedisplay "info";
4053 inherit lvsourcebase
4054 method getitemcount
= Array.length
state.help
4056 let s, n, _ = state.help
.(n) in
4059 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4063 m_qsearch
<- qsearch;
4064 match state.help
.(active) with
4065 | _, _, Action
f -> Some
(f uioh)
4075 method hasaction
n =
4076 match state.help
.(n) with
4077 | _, _, Action
_ -> true
4084 state.uioh <- coe (new listview ~
source ~trusted
:true);
4085 G.postRedisplay "help";
4090 let re = Str.regexp
"[\r\n]" in
4092 inherit lvsourcebase
4093 val mutable m_items
= [||]
4095 method getitemcount
= 1 + Array.length m_items
4100 else m_items
.(n-1), 0
4102 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4107 then Buffer.clear
state.errmsgs
;
4108 m_qsearch
<- qsearch;
4115 method hasaction
n =
4119 state.newerrmsgs
<- false;
4120 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4121 m_items
<- Array.of_list
l
4129 let source = (msgsource :> lvsource
) in
4130 state.uioh <- coe (object
4131 inherit listview ~
source ~trusted
:false as super
4134 then msgsource#reset
;
4137 G.postRedisplay "msgs";
4140 let quickbookmark ?title
() =
4141 match state.layout with
4147 let sec = Unix.gettimeofday
() in
4148 let tm = Unix.localtime
sec in
4149 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4153 (tm.Unix.tm_year
+ 1900)
4156 | Some
title -> title
4159 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4164 state.fullscreen
<- None
;
4165 Glut.reshapeWindow
w h;
4168 let viewkeyboard key =
4170 let mode = state.mode in
4171 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4174 G.postRedisplay "view:enttext"
4176 let c = Char.chr
key in
4178 | '
\027'
| 'q'
-> (* escape *)
4179 begin match state.mstate
with
4181 state.mstate
<- Mnone
;
4182 Glut.setCursor
Glut.CURSOR_INHERIT
;
4183 G.postRedisplay "kill zoom rect";
4188 | '
\008'
-> (* backspace *)
4189 let y = getnav ~
-1 in
4190 gotoy_and_clear_text y
4198 G.postRedisplay "dehighlight";
4201 let ondone isforw
s =
4202 cbput state.hists
.pat
s;
4203 state.searchpattern
<- s;
4206 let s = String.create
1 in
4208 enttext (s, "", Some
(onhist state.hists
.pat
),
4209 textentry, ondone (c ='
/'
))
4211 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4212 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4213 setzoom (conf.zoom +. incr)
4218 try int_of_string
s with exc
->
4219 state.text <- Printf.sprintf
"bad integer `%s': %s"
4220 s (Printexc.to_string exc
);
4226 state.text <- "page bias is now " ^ string_of_int
n;
4229 enttext ("page bias: ", "", None
, intentry, ondone)
4231 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4232 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4233 setzoom (max
0.01 (conf.zoom -. decr))
4236 let ondone msg
= state.text <- msg
in
4238 "option [acfhilpstvxACPRSZTIS]: ", "", None
,
4239 optentry state.mode, ondone
4242 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4245 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4246 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4250 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
4256 try int_of_string
s with exc
->
4257 state.text <- Printf.sprintf
"bad integer `%s': %s"
4258 s (Printexc.to_string exc
);
4264 cbput state.hists
.pag
(string_of_int
n);
4265 gotopage1 (n + conf.pagebias
- 1) 0;
4268 let pageentry text key =
4269 match Char.unsafe_chr
key with
4270 | 'g'
-> TEdone
text
4271 | _ -> intentry text key
4273 let text = "x" in text.[0] <- c;
4274 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone)
4277 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4278 reshape conf.winw
conf.winh
;
4281 conf.hlinks
<- not
conf.hlinks
;
4282 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4283 G.postRedisplay "toggle highlightlinks";
4286 begin match state.autoscroll
with
4288 conf.autoscrollstep
<- step
;
4289 state.autoscroll
<- None
4291 if conf.autoscrollstep
= 0
4292 then state.autoscroll
<- Some
1
4293 else state.autoscroll
<- Some
conf.autoscrollstep
4297 conf.presentation <- not
conf.presentation;
4298 if conf.presentation
4300 if not
conf.scrollbarinpm
4301 then state.scrollw
<- 0;
4304 state.scrollw
<- conf.scrollbw
;
4306 showtext ' '
("presentation mode " ^
4307 if conf.presentation then "on" else "off");
4308 state.anchor <- getanchor ();
4312 begin match state.fullscreen
with
4314 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4317 state.fullscreen
<- None
;
4322 gotoy_and_clear_text 0
4325 gotopage1 (state.pagecount
- 1) 0
4328 search state.searchpattern
true
4331 search state.searchpattern
false
4334 begin match state.layout with
4337 gotoy_and_clear_text (getpagey l.pageno)
4341 begin match List.rev
state.layout with
4344 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4345 gotoy_and_clear_text (getpagey pageno)
4348 | '
\127'
-> (* del *)
4349 begin match state.layout with
4352 let pageno = max
0 (l.pageno-1) in
4353 gotoy_and_clear_text (getpagey pageno)
4357 showtext ' '
(describe_location ());
4360 begin match state.layout with
4363 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4368 enterbookmarkmode ()
4376 | '
e'
when conf.redirectstderr ->
4381 match state.layout with
4384 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4388 enttext ("bookmark: ", "", None
, textentry, ondone)
4392 showtext ' '
"Quick bookmark added";
4395 begin match state.layout with
4397 let rect = getpdimrect
l.pagedimno
in
4401 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4402 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4404 (truncate
(rect.(1) -. rect.(0)),
4405 truncate
(rect.(3) -. rect.(0)))
4407 let w = truncate
((float w)*.conf.zoom)
4408 and h = truncate
((float h)*.conf.zoom) in
4411 state.anchor <- getanchor ();
4412 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4414 G.postRedisplay "z";
4419 | '
\000'
-> (* ctrl-2 *)
4420 let maxw = getmaxw
() in
4422 then setzoom (maxw /. float conf.winw
)
4425 reqlayout (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
4429 bound (conf.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 0.0 1.0
4431 G.postRedisplay "brightness";
4434 begin match state.mode with
4435 | Birdseye beye
-> upbirdseye 1 beye
4436 | _ -> gotoy (clamp (-conf.scrollstep
))
4440 begin match state.mode with
4441 | Birdseye beye
-> downbirdseye 1 beye
4442 | _ -> gotoy (clamp conf.scrollstep
)
4446 state.anchor <- getanchor ();
4447 opendoc state.path
state.password
4449 | '
v'
when not
conf.debug
->
4450 List.iter
debugl state.layout;
4452 | '
v'
when conf.debug
->
4455 match getopaque l.pageno with
4458 let x0, y0
, x1
, y1 = pagebbox opaque
in
4459 let a,b = float x0, float y0
in
4460 let c,d = float x1
, float y0
in
4461 let e,f = float x1
, float y1 in
4462 let h,j
= float x0, float y1 in
4463 let rect = (a,b,c,d,e,f,h,j
) in
4465 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
4467 G.postRedisplay "v";
4470 vlog "huh? %d %c" key (Char.chr
key);
4473 let birdseyekeyboard key ((_, _, pageno, _, _) as beye
) =
4475 | 27 -> (* escape *)
4476 leavebirdseye beye
true
4478 | 12 -> (* ctrl-l *)
4479 let y, h = getpageyh pageno in
4480 let top = (conf.winh
- h) / 2 in
4481 gotoy (max
0 (y - top))
4484 leavebirdseye beye
false
4490 let keyboard ~
key ~
x ~
y =
4493 if key = 7 && not
(istextentry state.mode) (* ctrl-g *)
4494 then wcmd "interrupt" []
4495 else state.uioh <- state.uioh#
key key
4498 let birdseyespecial key ((oconf
, leftx
, _, hooverpageno
, anchor) as beye
) =
4500 match conf.columns
with
4502 | Some
((c, _, _), _) -> c
4505 | Glut.KEY_UP
-> upbirdseye incr beye
4506 | Glut.KEY_DOWN
-> downbirdseye incr beye
4507 | Glut.KEY_LEFT
-> upbirdseye 1 beye
4508 | Glut.KEY_RIGHT
-> downbirdseye 1 beye
4510 | Glut.KEY_PAGE_UP
->
4511 begin match state.layout with
4515 state.mode <- Birdseye
(
4516 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4518 gotopage1 l.pageno 0;
4521 let layout = layout (state.y-conf.winh
) conf.winh
in
4523 | [] -> gotoy (clamp (-conf.winh
))
4525 state.mode <- Birdseye
(
4526 oconf
, leftx
, l.pageno, hooverpageno
, anchor
4528 gotopage1 l.pageno 0
4531 | [] -> gotoy (clamp (-conf.winh
))
4534 | Glut.KEY_PAGE_DOWN
->
4535 begin match List.rev
state.layout with
4537 let layout = layout (state.y + conf.winh
) conf.winh
in
4538 begin match layout with
4540 let incr = l.pageh
- l.pagevh in
4545 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
4547 G.postRedisplay "birdseye pagedown";
4549 else gotoy (clamp (incr + conf.interpagespace*2));
4553 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
4554 gotopage1 l.pageno 0;
4557 | [] -> gotoy (clamp conf.winh
)
4561 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
4565 let pageno = state.pagecount
- 1 in
4566 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
4567 if not
(pagevisible state.layout pageno)
4570 match List.rev
state.pdims
with
4572 | (_, _, h, _) :: _ -> h
4574 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
4575 else G.postRedisplay "birdseye end";
4579 let setautoscrollspeed step goingdown
=
4580 let incr = max
1 ((abs step
) / 2) in
4581 let incr = if goingdown
then incr else -incr in
4582 let astep = step
+ incr in
4583 state.autoscroll
<- Some
astep;
4586 let special ~
key ~
x ~
y =
4589 state.uioh <- state.uioh#
special key
4594 match state.mode with
4595 | Textentry
_ -> scalecolor 0.4
4596 | View
-> scalecolor 1.0
4597 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
4598 if l.pageno = hooverpageno
4601 if l.pageno = pageno
4607 begin match getopaque l.pageno with
4609 if tileready l l.pagex l.pagey
4611 let x = l.pagedispx - l.pagex
4612 and y = l.pagedispy - l.pagey in
4613 postprocess opaque
conf.hlinks
x y;
4619 let scrollindicator () =
4620 let sbw, ph
, sh = state.uioh#
scrollph in
4621 let sbh, pw
, sw = state.uioh#scrollpw
in
4623 GlDraw.color (0.64, 0.64, 0.64);
4625 (float (conf.winw
- sbw), 0.)
4626 (float conf.winw
, float conf.winh
)
4629 (0., float (conf.winh
- sbh))
4630 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
4632 GlDraw.color (0.0, 0.0, 0.0);
4635 (float (conf.winw
- sbw), ph
)
4636 (float conf.winw
, ph
+. sh)
4639 (pw
, float (conf.winh
- sbh))
4640 (pw
+. sw, float conf.winh
)
4644 let pagetranslatepoint l x y =
4645 let dy = y - l.pagedispy in
4646 let y = dy + l.pagey in
4647 let dx = x - l.pagedispx in
4648 let x = dx + l.pagex in
4653 match state.mstate
with
4654 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
4657 | Msel
((x0, y0
), (x1
, y1)) ->
4658 let rec loop = function
4660 if ((y0
>= l.pagedispy && y0
<= (l.pagedispy + l.pagevh))
4661 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
4662 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
4663 || ((x1
>= l.pagedispx && x1
<= (l.pagedispx + l.pagevw))))
4665 match getopaque l.pageno with
4667 let dx, dy = pagetranslatepoint l 0 0 in
4672 GlMat.mode `modelview
;
4674 GlMat.translate ~
x:(float ~
-dx) ~
y:(float ~
-dy) ();
4675 seltext opaque
(x0, y0
, x1
, y1);
4686 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
4687 GlDraw.polygon_mode `both `fill
;
4688 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4690 (fun (pageno, c, (x0, y0
, x1
, y1, x2
, y2
, x3
, y3
)) ->
4692 if l.pageno = pageno
4694 let dx = float (l.pagedispx - l.pagex) in
4695 let dy = float (l.pagedispy - l.pagey) in
4696 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
4697 GlDraw.begins `quads
;
4699 GlDraw.vertex2
(x0+.dx, y0
+.dy);
4700 GlDraw.vertex2
(x1
+.dx, y1+.dy);
4701 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
4702 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
4713 GlClear.color (scalecolor2 conf.bgcolor
);
4714 GlClear.clear
[`
color];
4715 List.iter
drawpage state.layout;
4720 begin match state.mstate
with
4721 | Mzoomrect
((x0, y0
), (x1
, y1)) ->
4723 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
4724 GlDraw.polygon_mode `both `fill
;
4725 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
4726 GlDraw.rect (float x0, float y0
)
4727 (float x1
, float y1);
4732 Glut.swapBuffers
();
4736 let rec f = function
4738 begin match getopaque l.pageno with
4740 let x0 = l.pagedispx in
4741 let x1 = x0 + l.pagevw in
4742 let y0 = l.pagedispy in
4743 let y1 = y0 + l.pagevh in
4744 if y >= y0 && y <= y1 && x >= x0 && x <= x1
4746 let px, py = pagetranslatepoint l x y in
4747 match whatsunder opaque
px py with
4759 let zoomrect x y x1 y1 =
4762 and y0 = min
y y1 in
4763 gotoy (state.y + y0);
4764 state.anchor <- getanchor ();
4765 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
4767 if state.w < conf.winw
- state.scrollw
4768 then (conf.winw
- state.scrollw
- state.w) / 2
4771 state.x <- (state.x + margin) - x0;
4773 Glut.setCursor
Glut.CURSOR_INHERIT
;
4774 state.mstate
<- Mnone
;
4778 let winw = conf.winw - state.scrollw
- 1 in
4779 let s = float x /. float winw in
4780 let destx = truncate
(float (state.w + winw) *. s) in
4781 state.x <- winw - destx;
4782 gotoy_and_clear_text state.y;
4783 state.mstate
<- Mscrollx
;
4787 let s = float y /. float conf.winh
in
4788 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
4789 gotoy_and_clear_text desty;
4790 state.mstate
<- Mscrolly
;
4793 let viewmouse button bstate
x y =
4795 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
4796 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
4798 match state.mstate
with
4799 | Mzoom
(oldn
, i
) ->
4807 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
4809 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
4811 let zoom = conf.zoom -. incr in
4813 state.mstate
<- Mzoom
(n, 0);
4815 state.mstate
<- Mzoom
(n, i
+1);
4817 else state.mstate
<- Mzoom
(n, 0)
4819 | _ -> state.mstate
<- Mzoom
(n, 0)
4822 match state.autoscroll
with
4823 | Some step
-> setautoscrollspeed step
(n=4)
4827 then -conf.scrollstep
4828 else conf.scrollstep
4830 let incr = incr * 2 in
4831 let y = clamp incr in
4832 gotoy_and_clear_text y
4835 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
4836 if bstate
= Glut.DOWN
4838 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4839 state.mstate
<- Mpan
(x, y)
4842 state.mstate
<- Mnone
4844 | Glut.RIGHT_BUTTON
->
4845 if bstate
= Glut.DOWN
4847 Glut.setCursor
Glut.CURSOR_CYCLE
;
4849 state.mstate
<- Mzoomrect
(p, p)
4852 match state.mstate
with
4853 | Mzoomrect
((x0, y0), _) ->
4854 if abs
(x-x0) > 10 && abs
(y - y0) > 10
4855 then zoomrect x0 y0 x y
4857 state.mstate
<- Mnone
;
4858 Glut.setCursor
Glut.CURSOR_INHERIT
;
4859 G.postRedisplay "kill accidental zoom rect";
4862 Glut.setCursor
Glut.CURSOR_INHERIT
;
4863 state.mstate
<- Mnone
4866 | Glut.LEFT_BUTTON
when x > conf.winw - state.scrollw
->
4867 if bstate
= Glut.DOWN
4869 let _, position, sh = state.uioh#
scrollph in
4870 if y > truncate
position && y < truncate
(position +. sh)
4871 then state.mstate
<- Mscrolly
4874 state.mstate
<- Mnone
4876 | Glut.LEFT_BUTTON
when y > conf.winh
- state.hscrollh ->
4877 if bstate
= Glut.DOWN
4879 let _, position, sw = state.uioh#scrollpw
in
4880 if x > truncate
position && x < truncate
(position +. sw)
4881 then state.mstate
<- Mscrollx
4884 state.mstate
<- Mnone
4886 | Glut.LEFT_BUTTON
->
4887 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
4888 begin match dest with
4889 | Ulinkgoto
(pageno, top) ->
4893 gotopage1 pageno top;
4899 | Uremote
_ | Uunexpected
_ | Ulaunch
_ | Unamed
_ -> ()
4901 | Unone
when bstate
= Glut.DOWN
->
4902 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
4903 state.mstate
<- Mpan
(x, y);
4905 | Unone
| Utext
_ ->
4906 if bstate
= Glut.DOWN
4908 if conf.angle
mod 360 = 0
4910 state.mstate
<- Msel
((x, y), (x, y));
4911 G.postRedisplay "mouse select";
4915 match state.mstate
with
4918 | Mzoom
_ | Mscrollx
| Mscrolly
->
4919 state.mstate
<- Mnone
4921 | Mzoomrect
((x0, y0), _) ->
4925 Glut.setCursor
Glut.CURSOR_INHERIT
;
4926 state.mstate
<- Mnone
4928 | Msel
((_, y0), (_, y1)) ->
4929 let rec loop = function
4932 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
4933 || ((y1 >= l.pagedispy
4934 && y1 <= (l.pagedispy + l.pagevh)))
4936 match getopaque l.pageno with
4938 copysel
conf.selcmd opaque
;
4939 G.postRedisplay "copysel"
4944 Glut.setCursor
Glut.CURSOR_INHERIT
;
4945 state.mstate
<- Mnone
;
4952 let birdseyemouse button bstate
x y
4953 (conf, leftx
, _, hooverpageno
, anchor) =
4955 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
4956 let rec loop = function
4959 if y > l.pagedispy && y < l.pagedispy + l.pagevh
4960 && x > l.pagedispx && x < l.pagedispx + l.pagevw
4962 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
4967 | Glut.OTHER_BUTTON
_ -> viewmouse button bstate
x y
4971 let mouse bstate button
x y =
4972 state.uioh <- state.uioh#button button bstate
x y;
4975 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
4978 state.uioh <- state.uioh#
motion x y
4982 state.uioh <- state.uioh#
pmotion x y;
4989 begin match state.mode with
4990 | Textentry
textentry -> textentrykeyboard key textentry
4991 | Birdseye
birdseye -> birdseyekeyboard key birdseye
4992 | View
-> viewkeyboard key
4996 method special key =
4997 begin match state.mode with
4998 | View
| (Birdseye
_) when key = Glut.KEY_F9
->
5002 birdseyespecial key vals
5004 | View
when key = Glut.KEY_F1
->
5008 begin match state.autoscroll
with
5009 | Some step
when key = Glut.KEY_DOWN
|| key = Glut.KEY_UP
->
5010 setautoscrollspeed step
(key = Glut.KEY_DOWN
)
5015 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
5017 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5019 if Glut.getModifiers
() land Glut.active_shift
!= 0
5020 then (setzoom state.prevzoom
; state.y)
5021 else clamp (-conf.winh
/2)
5022 else clamp (-conf.scrollstep
)
5024 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5026 if Glut.getModifiers
() land Glut.active_shift
!= 0
5027 then (setzoom state.prevzoom
; state.y)
5028 else clamp (conf.winh
/2)
5029 else clamp (conf.scrollstep
)
5030 | Glut.KEY_PAGE_UP
->
5031 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5033 match state.layout with
5035 | l :: _ -> state.y - l.pagey
5038 | Glut.KEY_PAGE_DOWN
->
5039 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5041 match List.rev
state.layout with
5043 | l :: _ -> getpagey l.pageno
5051 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
5053 | (Glut.KEY_RIGHT
| Glut.KEY_LEFT
) when
5054 Glut.getModifiers
() land Glut.active_alt
!= 0 ->
5055 getnav (if key = Glut.KEY_LEFT
then 1 else -1)
5057 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
5059 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5060 then (conf.winw / 2)
5063 state.x <- state.x - dx;
5065 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
5067 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
5068 then (conf.winw / 2)
5071 state.x <- state.x + dx;
5076 if abs
(state.y - y) > conf.scrollstep
*2
5078 else gotoy_and_clear_text y
5081 | Textentry
te -> textentryspecial key te
5085 method button button bstate
x y =
5086 begin match state.mode with
5087 | View
-> viewmouse button bstate
x y
5088 | Birdseye beye
-> birdseyemouse button bstate
x y beye
5094 begin match state.mode with
5096 | View
| Birdseye
_ ->
5097 match state.mstate
with
5098 | Mzoom
_ | Mnone
-> ()
5103 state.mstate
<- Mpan
(x, y);
5104 if conf.zoom > 1.0 then state.x <- state.x + dx;
5106 gotoy_and_clear_text y
5109 state.mstate
<- Msel
(a, (x, y));
5110 G.postRedisplay "motion select";
5113 let y = min
conf.winh
(max
0 y) in
5117 let x = min
conf.winw (max
0 x) in
5120 | Mzoomrect
(p0
, _) ->
5121 state.mstate
<- Mzoomrect
(p0
, (x, y));
5122 G.postRedisplay "motion zoomrect";
5126 method pmotion x y =
5127 begin match state.mode with
5128 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5129 let rec loop = function
5131 if hooverpageno
!= -1
5133 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5134 G.postRedisplay "pmotion birdseye no hoover";
5137 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5138 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5140 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5141 G.postRedisplay "pmotion birdseye hoover";
5150 match state.mstate
with
5152 begin match getunder x y with
5153 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
5155 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
5156 Glut.setCursor
Glut.CURSOR_INFO
5157 | Ulinkgoto
(page
, _) ->
5159 then showtext '
p'
("age: " ^ string_of_int
(page
+1));
5160 Glut.setCursor
Glut.CURSOR_INFO
5162 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
5163 Glut.setCursor
Glut.CURSOR_TEXT
5165 if conf.underinfo
then showtext 'u'
("nexpected: " ^
s);
5166 Glut.setCursor
Glut.CURSOR_INHERIT
5168 if conf.underinfo
then showtext '
l'
("launch: " ^
s);
5169 Glut.setCursor
Glut.CURSOR_INHERIT
5171 if conf.underinfo
then showtext '
n'
("named: " ^
s);
5172 Glut.setCursor
Glut.CURSOR_INHERIT
5174 if conf.underinfo
then showtext '
r'
("emote: " ^
s);
5175 Glut.setCursor
Glut.CURSOR_INHERIT
5178 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5183 method infochanged
_ = ()
5186 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5187 let p, h = scrollph state.y maxy in
5191 let winw = conf.winw - state.scrollw
- 1 in
5192 let fwinw = float winw in
5194 let sw = fwinw /. float state.w in
5195 let sw = fwinw *. sw in
5196 max
sw (float conf.scrollh
)
5199 let f = state.w+winw in
5200 let r = float (winw-state.x) /. float f in
5201 let p = fwinw *. r in
5205 if position +. sw > fwinw
5206 then fwinw -. position
5209 state.hscrollh, position, sw
5216 let fontpath = ref "";;
5217 let wmclasshack = ref false;;
5220 let l = String.length
s in
5221 let b = Buffer.create
l in
5229 | Pwindows
| Pmingw
-> Sys.getenv
"HOMEPATH"
5230 | _ -> Sys.getenv
"HOME"
5233 ("Can not determine home directory location: " ^
5234 Printexc.to_string exn
);
5238 let config_of c attrs
=
5242 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5243 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5244 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5245 | "preload" -> { c with preload = bool_of_string
v }
5246 | "page-bias" -> { c with pagebias
= int_of_string
v }
5247 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5248 | "auto-scroll-step" ->
5249 { c with autoscrollstep
= max
0 (int_of_string
v) }
5250 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5251 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5254 match String.lowercase
v with
5255 | "true" -> Some infinity
5257 | f -> Some
(float_of_string
f)
5259 { c with maxwait
= mw}
5260 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5261 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5262 | "vertical-margin" ->
5263 { c with interpagespace = max
0 (int_of_string
v) }
5265 let zoom = float_of_string
v /. 100. in
5266 let zoom = max
zoom 0.0 in
5267 { c with zoom = zoom }
5268 | "presentation" -> { c with presentation = bool_of_string
v }
5269 | "rotation-angle" -> { c with angle
= int_of_string
v }
5270 | "width" -> { c with winw = max
20 (int_of_string
v) }
5271 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5272 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5273 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5274 | "pixmap-cache-size" ->
5275 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5276 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5277 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5278 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5279 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5280 | "background-color" -> { c with bgcolor
= color_of_string v }
5281 | "scrollbar-in-presentation" ->
5282 { c with scrollbarinpm
= bool_of_string
v }
5283 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5284 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5285 | "mupdf-store-size" ->
5286 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5287 | "checkers" -> { c with checkers
= bool_of_string
v }
5288 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5289 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5290 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5291 | "wmclass-hack" -> wmclasshack := bool_of_string
v; c
5292 | "uri-launcher" -> { c with urilauncher
= unent v }
5293 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5294 | "invert-colors" -> { c with invert
= bool_of_string
v }
5295 | "brightness" -> { c with colorscale
= float_of_string
v }
5296 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5298 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5300 let nab = columns_of_string v in
5301 { c with columns
= Some
(nab, [||]) }
5302 | "birds-eye-columns" ->
5303 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5304 | "selection-command" -> { c with selcmd
= unent v }
5307 prerr_endline
("Error processing attribute (`" ^
5308 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5311 let rec fold c = function
5314 let c = apply c k
v in
5320 let fromstring f pos
n v d =
5323 dolog "Error processing attribute (%S=%S) at %d\n%s"
5324 n v pos
(Printexc.to_string exn
)
5329 let bookmark_of attrs
=
5330 let rec fold title page
rely = function
5331 | ("title", v) :: rest
-> fold v page
rely rest
5332 | ("page", v) :: rest
-> fold title v rely rest
5333 | ("rely", v) :: rest
-> fold title page
v rest
5334 | _ :: rest
-> fold title page
rely rest
5335 | [] -> title, page
, rely
5337 fold "invalid" "0" "0" attrs
5341 let rec fold path page
rely pan
= function
5342 | ("path", v) :: rest
-> fold v page
rely pan rest
5343 | ("page", v) :: rest
-> fold path
v rely pan rest
5344 | ("rely", v) :: rest
-> fold path page
v pan rest
5345 | ("pan", v) :: rest
-> fold path page
rely v rest
5346 | _ :: rest
-> fold path page
rely pan rest
5347 | [] -> path
, page
, rely, pan
5349 fold "" "0" "0" "0" attrs
5352 let setconf dst
src =
5353 dst
.scrollbw
<- src.scrollbw
;
5354 dst
.scrollh
<- src.scrollh
;
5355 dst
.icase
<- src.icase
;
5356 dst
.preload <- src.preload;
5357 dst
.pagebias
<- src.pagebias
;
5358 dst
.verbose
<- src.verbose
;
5359 dst
.scrollstep
<- src.scrollstep
;
5360 dst
.maxhfit
<- src.maxhfit
;
5361 dst
.crophack
<- src.crophack
;
5362 dst
.autoscrollstep
<- src.autoscrollstep
;
5363 dst
.maxwait
<- src.maxwait
;
5364 dst
.hlinks
<- src.hlinks
;
5365 dst
.underinfo
<- src.underinfo
;
5366 dst
.interpagespace <- src.interpagespace;
5367 dst
.zoom <- src.zoom;
5368 dst
.presentation <- src.presentation;
5369 dst
.angle
<- src.angle
;
5370 dst
.winw <- src.winw;
5371 dst
.winh
<- src.winh
;
5372 dst
.savebmarks
<- src.savebmarks
;
5373 dst
.memlimit
<- src.memlimit
;
5374 dst
.proportional
<- src.proportional
;
5375 dst
.texcount
<- src.texcount
;
5376 dst
.sliceheight
<- src.sliceheight
;
5377 dst
.thumbw
<- src.thumbw
;
5378 dst
.jumpback
<- src.jumpback
;
5379 dst
.bgcolor
<- src.bgcolor
;
5380 dst
.scrollbarinpm
<- src.scrollbarinpm
;
5381 dst
.tilew
<- src.tilew
;
5382 dst
.tileh
<- src.tileh
;
5383 dst
.mustoresize
<- src.mustoresize
;
5384 dst
.checkers
<- src.checkers
;
5385 dst
.aalevel
<- src.aalevel
;
5386 dst
.trimmargins
<- src.trimmargins
;
5387 dst
.trimfuzz
<- src.trimfuzz
;
5388 dst
.urilauncher
<- src.urilauncher
;
5389 dst
.colorspace
<- src.colorspace
;
5390 dst
.invert
<- src.invert
;
5391 dst
.colorscale
<- src.colorscale
;
5392 dst
.redirectstderr <- src.redirectstderr;
5393 dst
.ghyllscroll
<- src.ghyllscroll
;
5394 dst
.columns
<- src.columns
;
5395 dst
.beyecolumns
<- src.beyecolumns
;
5396 dst
.selcmd
<- src.selcmd
;
5400 let h = Hashtbl.create
10 in
5401 let dc = { defconf with angle
= defconf.angle
} in
5402 let rec toplevel v t spos
_ =
5404 | Vdata
| Vcdata
| Vend
-> v
5405 | Vopen
("llppconfig", _, closed
) ->
5408 else { v with f = llppconfig
}
5410 error
"unexpected subelement at top level" s spos
5411 | Vclose
_ -> error
"unexpected close at top level" s spos
5413 and llppconfig
v t spos
_ =
5415 | Vdata
| Vcdata
-> v
5416 | Vend
-> error
"unexpected end of input in llppconfig" s spos
5417 | Vopen
("defaults", attrs
, closed
) ->
5418 let c = config_of dc attrs
in
5422 else { v with f = skip
"defaults" (fun () -> v) }
5424 | Vopen
("ui-font", attrs
, closed
) ->
5425 let rec getsize size
= function
5427 | ("size", v) :: rest
->
5429 fromstring int_of_string spos
"size" v fstate.fontsize
in
5431 | l -> getsize size l
5433 fstate.fontsize
<- getsize fstate.fontsize attrs
;
5436 else { v with f = uifont
(Buffer.create
10) }
5438 | Vopen
("doc", attrs
, closed
) ->
5439 let pathent, spage
, srely
, span
= doc_of attrs
in
5440 let path = unent pathent
5441 and pageno = fromstring int_of_string spos
"page" spage
0
5442 and rely = fromstring float_of_string spos
"rely" srely
0.0
5443 and pan
= fromstring int_of_string spos
"pan" span
0 in
5444 let c = config_of dc attrs
in
5445 let anchor = (pageno, rely) in
5447 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
5448 else { v with f = doc
path pan
anchor c [] }
5451 error
"unexpected subelement in llppconfig" s spos
5453 | Vclose
"llppconfig" -> { v with f = toplevel }
5454 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
5456 and uifont
b v t spos
epos =
5459 Buffer.add_substring
b s spos
(epos - spos
);
5461 | Vopen
(_, _, _) ->
5462 error
"unexpected subelement in ui-font" s spos
5463 | Vclose
"ui-font" ->
5464 if String.length
!fontpath = 0
5465 then fontpath := Buffer.contents
b;
5466 { v with f = llppconfig
}
5467 | Vclose
_ -> error
"unexpected close in ui-font" s spos
5468 | Vend
-> error
"unexpected end of input in ui-font" s spos
5470 and doc
path pan
anchor c bookmarks
v t spos
_ =
5472 | Vdata
| Vcdata
-> v
5473 | Vend
-> error
"unexpected end of input in doc" s spos
5474 | Vopen
("bookmarks", _, closed
) ->
5477 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
5479 | Vopen
(_, _, _) ->
5480 error
"unexpected subelement in doc" s spos
5483 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
5484 { v with f = llppconfig
}
5486 | Vclose
_ -> error
"unexpected close in doc" s spos
5488 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
5490 | Vdata
| Vcdata
-> v
5491 | Vend
-> error
"unexpected end of input in bookmarks" s spos
5492 | Vopen
("item", attrs
, closed
) ->
5493 let titleent, spage
, srely
= bookmark_of attrs
in
5494 let page = fromstring int_of_string spos
"page" spage
0
5495 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
5496 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
5498 then { v with f = pbookmarks
path pan
anchor c bookmarks }
5501 { v with f = skip
"item" f }
5504 error
"unexpected subelement in bookmarks" s spos
5506 | Vclose
"bookmarks" ->
5507 { v with f = doc
path pan
anchor c bookmarks }
5509 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
5511 and skip tag
f v t spos
_ =
5513 | Vdata
| Vcdata
-> v
5515 error
("unexpected end of input in skipped " ^ tag
) s spos
5516 | Vopen
(tag'
, _, closed
) ->
5520 let f'
() = { v with f = skip tag
f } in
5521 { v with f = skip tag'
f'
}
5525 else error
("unexpected close in skipped " ^ tag
) s spos
5528 parse
{ f = toplevel; accu = () } s;
5534 let len = in_channel_length ic
in
5535 let s = String.create
len in
5536 really_input ic
s 0 len;
5539 | Parse_error
(msg
, s, pos
) ->
5540 let subs = subs s pos
in
5541 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
5542 failwith
("parse error: " ^
s)
5545 failwith
("config load error: " ^
Printexc.to_string exn
)
5551 let dir = Filename.concat
home ".config" in
5552 if Sys.is_directory
dir then dir else home
5555 Filename.concat
dir "llpp.conf"
5558 let confpath = ref defconfpath;;
5561 if Sys.file_exists
!confpath
5564 (try Some
(open_in_bin
!confpath)
5567 ("Error opening configuation file `" ^
!confpath ^
"': " ^
5568 Printexc.to_string exn
);
5577 ("Error loading configuation from `" ^
!confpath ^
"': " ^
5578 Printexc.to_string exn
);
5584 f (Hashtbl.create
0, defconf)
5589 let pc, pb
, px, pa
=
5591 Hashtbl.find h (Filename.basename
state.path)
5592 with Not_found
-> dc, [], 0, (0, 0.0)
5596 state.bookmarks <- pb
;
5598 state.scrollw
<- conf.scrollbw
;
5600 then state.anchor <- pa
;
5601 cbput state.hists
.nav pa
;
5606 let add_attrs bb always
dc c =
5609 then Printf.bprintf bb
"\n %s='%b'" s a
5612 then Printf.bprintf bb
"\n %s='%d'" s a
5615 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
5618 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
5621 then Printf.bprintf bb
"\n %s='%f'" s a
5625 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
5629 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
5633 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
5637 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
5643 | Some
(_N
, _A
, _B
) ->
5644 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
5654 else string_of_float
f
5656 Printf.bprintf bb
"\n %s='%s'" s v
5661 | Some
((n, a, b), _) when n > 1 ->
5662 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
5668 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
5673 then dc.winw, dc.winh
5675 match state.fullscreen
with
5677 | None
-> c.winw, c.winh
5679 let zoom, presentation, interpagespace, maxwait
=
5681 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
5683 match state.mode with
5684 | Birdseye
(bc
, _, _, _, _) ->
5685 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
5686 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
5688 oi
"width" w dc.winw;
5689 oi
"height" h dc.winh
;
5690 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
5691 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
5692 ob "case-insensitive-search" c.icase
dc.icase
;
5693 ob "preload" c.preload dc.preload;
5694 oi
"page-bias" c.pagebias
dc.pagebias
;
5695 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
5696 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
5697 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
5698 ob "crop-hack" c.crophack
dc.crophack
;
5699 oW
"throttle" maxwait
dc.maxwait
;
5700 ob "highlight-links" c.hlinks
dc.hlinks
;
5701 ob "under-cursor-info" c.underinfo
dc.underinfo
;
5702 oi
"vertical-margin" interpagespace dc.interpagespace;
5703 oz
"zoom" zoom dc.zoom;
5704 ob "presentation" presentation dc.presentation;
5705 oi
"rotation-angle" c.angle
dc.angle
;
5706 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
5707 ob "proportional-display" c.proportional
dc.proportional
;
5708 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
5709 oi
"tex-count" c.texcount
dc.texcount
;
5710 oi
"slice-height" c.sliceheight
dc.sliceheight
;
5711 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
5712 ob "persistent-location" c.jumpback
dc.jumpback
;
5713 oc
"background-color" c.bgcolor
dc.bgcolor
;
5714 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
5715 oi
"tile-width" c.tilew
dc.tilew
;
5716 oi
"tile-height" c.tileh
dc.tileh
;
5717 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
5718 ob "checkers" c.checkers
dc.checkers
;
5719 oi
"aalevel" c.aalevel
dc.aalevel
;
5720 ob "trim-margins" c.trimmargins
dc.trimmargins
;
5721 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
5722 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
5723 oC
"color-space" c.colorspace
dc.colorspace
;
5724 ob "invert-colors" c.invert
dc.invert
;
5725 oF
"brightness" c.colorscale
dc.colorscale
;
5726 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
5727 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
5728 oco
"columns" c.columns
dc.columns
;
5729 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
5731 then ob "wmclass-hack" !wmclasshack false;
5732 os
"selection-command" c.selcmd
dc.selcmd
;
5736 let uifontsize = fstate.fontsize
in
5737 let bb = Buffer.create
32768 in
5739 let dc = if conf.bedefault
then conf else dc in
5740 Buffer.add_string
bb "<llppconfig>\n";
5742 if String.length
!fontpath > 0
5744 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
5750 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
5753 Buffer.add_string
bb "<defaults ";
5754 add_attrs bb true dc dc;
5755 Buffer.add_string
bb "/>\n";
5757 let adddoc path pan
anchor c bookmarks =
5758 if bookmarks == [] && c = dc && anchor = emptyanchor
5761 Printf.bprintf
bb "<doc path='%s'"
5762 (enent
path 0 (String.length
path));
5764 if anchor <> emptyanchor
5766 let n, y = anchor in
5767 Printf.bprintf
bb " page='%d'" n;
5770 Printf.bprintf
bb " rely='%f'" y
5775 then Printf.bprintf
bb " pan='%d'" pan
;
5777 add_attrs bb false dc c;
5779 begin match bookmarks with
5780 | [] -> Buffer.add_string
bb "/>\n"
5782 Buffer.add_string
bb ">\n<bookmarks>\n";
5783 List.iter
(fun (title, _level
, (page, rely)) ->
5785 "<item title='%s' page='%d'"
5786 (enent
title 0 (String.length
title))
5791 Printf.bprintf
bb " rely='%f'" rely
5793 Buffer.add_string
bb "/>\n";
5795 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
5801 match state.mode with
5802 | Birdseye
(c, pan, _, _, _) ->
5804 match conf.columns
with
5805 | Some
((c, _, _), _) -> Some
c
5808 match c.columns
with
5809 | Some
(c, _) -> Some
(c, [||])
5812 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
5813 | _ -> state.x, conf
5815 let basename = Filename.basename state.path in
5816 adddoc basename pan (getanchor ())
5819 match state.autoscroll
with
5821 | None
-> conf.autoscrollstep
}
5822 (if conf.savebmarks
then state.bookmarks else []);
5824 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
5826 then adddoc path x y c bookmarks
5828 Buffer.add_string
bb "</llppconfig>";
5831 if Buffer.length
bb > 0
5834 let tmp = !confpath ^
".tmp" in
5835 let oc = open_out_bin
tmp in
5836 Buffer.output_buffer
oc bb;
5838 Unix.rename
tmp !confpath;
5841 ("error while saving configuration: " ^
Printexc.to_string exn
)
5848 [("-p", Arg.String
(fun s -> state.password
<- s) ,
5849 "<password> Set password");
5851 ("-f", Arg.String
(fun s -> Config.fontpath := s),
5852 "<path> Set path to the user interface font");
5854 ("-c", Arg.String
(fun s -> Config.confpath := s),
5855 "<path> Set path to the configuration file");
5857 ("-v", Arg.Unit
(fun () ->
5859 "%s\nconfiguration path: %s\n"
5863 exit
0), " Print version and exit");
5866 (fun s -> state.path <- s)
5867 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
5869 if String.length
state.path = 0
5870 then (prerr_endline
"file name missing"; exit
1);
5874 let _ = Glut.init
Sys.argv
in
5875 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
5876 let () = Glut.initWindowSize
conf.winw conf.winh
in
5877 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
5879 if not
(Glut.extensionSupported
"GL_ARB_texture_rectangle"
5880 || Glut.extensionSupported
"GL_EXT_texture_rectangle")
5881 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
5886 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
5888 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
5889 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5890 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
5891 Unix.bind
sock addr;
5893 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
5894 Unix.connect
csock addr;
5895 let ssock, _ = Unix.accept
sock in
5898 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
5899 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
5906 let () = Glut.displayFunc
display in
5907 let () = Glut.reshapeFunc
reshape in
5908 let () = Glut.keyboardFunc
keyboard in
5909 let () = Glut.specialFunc
special in
5910 let () = Glut.idleFunc
(Some
idle) in
5911 let () = Glut.mouseFunc
mouse in
5912 let () = Glut.motionFunc
motion in
5913 let () = Glut.passiveMotionFunc
pmotion in
5915 setcheckers conf.checkers
;
5917 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
5918 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
5919 !Config.wmclasshack, !Config.fontpath
5921 state.csock <- csock;
5922 state.ssock <- ssock;
5923 state.text <- "Opening " ^
state.path;
5924 setaalevel
conf.aalevel
;
5925 writeopen state.path state.password
;
5927 setfontsize fstate.fontsize
;
5935 | Glut.BadEnum
"key in special_of_int" ->
5936 showtext '
!'
" LablGlut bug: special key not recognized";
5943 | exn
when conf.redirectstderr ->
5945 Printf.sprintf
"exception %s\n%s"
5946 (Printexc.to_string exn
)
5947 (Printexc.get_backtrace
())
5950 Unix.single_write
state.stderr
s 0 (String.length
s);