6 | Ulinkgoto
of (int * int)
8 | Uunexpected
of string
11 | Uremote
of (string * int)
12 and facename
= string;;
14 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
15 let now = Unix.gettimeofday
;;
17 type params
= (angle
* proportional
* trimparams
18 * texcount
* sliceheight
* memsize
19 * colorspace
* fontpath
)
28 and proportional
= bool
29 and trimmargins
= bool
30 and interpagespace
= int
38 and irect
= (int * int * int * int)
39 and trimparams
= (trimmargins
* irect
)
40 and colorspace
= | Rgb
| Bgr
| Gray
49 | LDfirstvisible
of (int * int * int)
64 | KMmulti
of key list
* key list
66 and keyhash
= (key
, keymap
) Hashtbl.t
69 | KSinto
of (key list
* key list
)
72 type platform
= | Punknown
| Plinux
| Posx
| Psun
| Pfreebsd
73 | Pdragonflybsd
| Popenbsd
| Pnetbsd
| Pcygwin
;;
75 type pipe
= (Unix.file_descr
* Unix.file_descr
);;
77 external init
: pipe
-> params
-> unit = "ml_init";;
78 external seltext
: string -> (int * int * int * int) -> unit = "ml_seltext";;
79 external copysel
: Unix.file_descr
-> opaque
-> unit = "ml_copysel";;
80 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
81 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
82 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
83 external drawstr
: int -> int -> int -> string -> float = "ml_draw_string";;
84 external measurestr
: int -> string -> float = "ml_measure_string";;
85 external getmaxw
: unit -> float = "ml_getmaxw";;
86 external postprocess
:
87 opaque
-> int -> int -> int -> (int * string * int) -> int = "ml_postprocess";;
88 external pagebbox
: opaque
-> (int * int * int * int) = "ml_getpagebox";;
89 external platform
: unit -> platform
= "ml_platform";;
90 external setaalevel
: int -> unit = "ml_setaalevel";;
91 external realloctexts
: int -> bool = "ml_realloctexts";;
92 external cloexec
: Unix.file_descr
-> unit = "ml_cloexec";;
93 external findlink
: opaque
-> linkdir
-> link
= "ml_findlink";;
94 external getlink
: opaque
-> int -> under
= "ml_getlink";;
95 external getlinkrect
: opaque
-> int -> irect
= "ml_getlinkrect";;
96 external getlinkcount
: opaque
-> int = "ml_getlinkcount";;
97 external findpwl
: int -> int -> pagewithlinks
= "ml_find_page_with_links"
98 external popen
: string -> (Unix.file_descr
* int) list
-> unit = "ml_popen";;
100 let platform_to_string = function
101 | Punknown
-> "unknown"
105 | Pfreebsd
-> "FreeBSD"
106 | Pdragonflybsd
-> "DragonflyBSD"
107 | Popenbsd
-> "OpenBSD"
108 | Pnetbsd
-> "NetBSD"
109 | Pcygwin
-> "Cygwin"
112 let platform = platform ();;
115 if platform = Pcygwin
117 let sh = "/bin/sh" in
118 let args = [|sh; "-c"; cmd
|] in
119 let rec std si so se
= function
121 | (fd
, 0) :: rest
-> std fd so se rest
122 | (fd
, -1) :: rest
->
123 Unix.set_close_on_exec fd
;
126 failwith
("unexpected fdn in cygwin popen " ^ string_of_int n
)
128 let si, so
, se
= std Unix.stdin
Unix.stdout
Unix.stderr fda
in
129 ignore
(Unix.create_process
sh args si so se
)
138 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
141 external drawtile
: tileparams
-> opaque
-> unit = "ml_drawtile";;
143 type mpos
= int * int
145 | Msel
of (mpos
* mpos
)
147 | Mscrolly
| Mscrollx
148 | Mzoom
of (int * int)
149 | Mzoomrect
of (mpos
* mpos
)
153 type textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
154 and onkey
= string -> int -> te
155 and ondone
= string -> unit
156 and histcancel
= unit -> unit
157 and onhist
= ((histcmd
-> string) * histcancel
)
158 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
159 and cancelonempty
= bool
164 | TEswitch
of textentry
175 let bound v minv maxv
=
176 max minv
(min maxv v
);
180 { store
= Array.create n v
187 let drawstring size x y s
=
189 Gl.enable `texture_2d
;
190 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
191 ignore
(drawstr size x y s
);
193 Gl.disable `texture_2d
;
196 let drawstring1 size x y s
=
200 let drawstring2 size x y fmt
=
201 Printf.kprintf
(drawstring size
(x
+1) (y
+size
+1)) fmt
204 let cbcap b
= Array.length b
.store
;;
209 b
.wc
<- (b
.wc
+ 1) mod cap;
211 b
.len
<- min
(b
.len
+ 1) cap;
214 let cbempty b
= b
.len
= 0;;
216 let cbgetg b circular dir
=
220 let rc = b
.rc + dir
in
232 else max
0 (min
rc (b
.len
-1))
238 let cbget b
= cbgetg b
false;;
239 let cbgetc b
= cbgetg b
true;;
257 dolog "l %d dim=%d {" l
.pageno l
.pagedimno
;
258 dolog " WxH %dx%d" l
.pagew l
.pageh
;
259 dolog " vWxH %dx%d" l
.pagevw l
.pagevh
;
260 dolog " pagex,y %d,%d" l
.pagex l
.pagey
;
261 dolog " dispx,y %d,%d" l
.pagedispx l
.pagedispy
;
262 dolog " column %d" l
.pagecol
;
266 let debugrect (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
) =
268 dolog " x0,y0=(% f, % f)" x0 y0
;
269 dolog " x1,y1=(% f, % f)" x1 y1
;
270 dolog " x2,y2=(% f, % f)" x2 y2
;
271 dolog " x3,y3=(% f, % f)" x3 y3
;
275 type multicolumns
= multicol
* pagegeom
276 and splitcolumns
= columncount
* pagegeom
277 and pagegeom
= ((pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
)
278 and multicol
= columncount
* covercount
* covercount
280 and columncount
= int
281 and covercount
= int;;
284 { mutable scrollbw
: int
285 ; mutable scrollh
: int
286 ; mutable icase
: bool
287 ; mutable preload
: bool
288 ; mutable pagebias
: int
289 ; mutable verbose
: bool
290 ; mutable debug
: bool
291 ; mutable scrollstep
: int
292 ; mutable maxhfit
: bool
293 ; mutable crophack
: bool
294 ; mutable autoscrollstep
: int
295 ; mutable maxwait
: float option
296 ; mutable hlinks
: bool
297 ; mutable underinfo
: bool
298 ; mutable interpagespace
: interpagespace
299 ; mutable zoom
: float
300 ; mutable presentation
: bool
301 ; mutable angle
: angle
304 ; mutable savebmarks
: bool
305 ; mutable proportional
: proportional
306 ; mutable trimmargins
: trimmargins
307 ; mutable trimfuzz
: irect
308 ; mutable memlimit
: memsize
309 ; mutable texcount
: texcount
310 ; mutable sliceheight
: sliceheight
311 ; mutable thumbw
: width
312 ; mutable jumpback
: bool
313 ; mutable bgcolor
: float * float * float
314 ; mutable bedefault
: bool
315 ; mutable scrollbarinpm
: bool
316 ; mutable tilew
: int
317 ; mutable tileh
: int
318 ; mutable mustoresize
: memsize
319 ; mutable checkers
: bool
320 ; mutable aalevel
: int
321 ; mutable urilauncher
: string
322 ; mutable pathlauncher
: string
323 ; mutable colorspace
: colorspace
324 ; mutable invert
: bool
325 ; mutable colorscale
: float
326 ; mutable redirectstderr
: bool
327 ; mutable ghyllscroll
: (int * int * int) option
328 ; mutable columns
: columns
329 ; mutable beyecolumns
: columncount
option
330 ; mutable selcmd
: string
331 ; mutable updatecurs
: bool
332 ; mutable keyhashes
: (string * keyhash
) list
333 ; mutable hfsize
: int
334 ; mutable fullsplit
: bool
338 | Cmulti
of multicolumns
339 | Csplit
of splitcolumns
342 type anchor
= pageno
* top
;;
344 type outline
= string * int * anchor
;;
346 type rect
= float * float * float * float * float * float * float * float;;
348 type tile
= opaque
* pixmapsize
* elapsed
349 and elapsed
= float;;
350 type pagemapkey
= pageno
* gen
;;
351 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
355 let emptyanchor = (0, 0.0);;
357 type infochange
= | Memused
| Docinfo
| Pdim
;;
359 class type uioh
= object
360 method display
: unit
361 method key
: int -> int -> uioh
362 method button
: int -> bool -> int -> int -> int -> uioh
363 method motion
: int -> int -> uioh
364 method pmotion
: int -> int -> uioh
365 method infochanged
: infochange
-> unit
366 method scrollpw
: (int * float * float)
367 method scrollph
: (int * float * float)
368 method modehash
: keyhash
372 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
373 | Textentry
of (textentry
* onleave
)
375 | LinkNav
of linktarget
376 and onleave
= leavetextentrystatus
-> unit
377 and leavetextentrystatus
= | Cancel
| Confirm
378 and helpitem
= string * int * action
381 | Action
of (uioh
-> uioh
)
383 | Ltexact
of (pageno
* int)
387 let isbirdseye = function Birdseye _
-> true | _
-> false;;
388 let istextentry = function Textentry _
-> true | _
-> false;;
392 | Loading
of (page
* gen
)
394 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
396 | Outlining
of outline list
399 let emptykeyhash = Hashtbl.create
0;;
400 let nouioh : uioh
= object (self
)
402 method key _ _
= self
403 method button _ _ _ _ _
= self
404 method motion _ _
= self
405 method pmotion _ _
= self
406 method infochanged _
= ()
407 method scrollpw
= (0, nan
, nan
)
408 method scrollph
= (0, nan
, nan
)
409 method modehash
= emptykeyhash
413 { mutable sr
: Unix.file_descr
414 ; mutable sw
: Unix.file_descr
415 ; mutable wsfd
: Unix.file_descr
416 ; mutable errfd
: Unix.file_descr
option
417 ; mutable stderr
: Unix.file_descr
418 ; mutable errmsgs
: Buffer.t
419 ; mutable newerrmsgs
: bool
423 ; mutable scrollw
: int
424 ; mutable hscrollh
: int
425 ; mutable anchor
: anchor
426 ; mutable ranchors
: (string * string * anchor
) list
428 ; mutable layout
: page list
429 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
430 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
431 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
432 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
433 ; mutable pagecount
: int
434 ; mutable currently
: currently
435 ; mutable mstate
: mstate
436 ; mutable searchpattern
: string
437 ; mutable rects
: (pageno
* recttype
* rect
) list
438 ; mutable rects1
: (pageno
* recttype
* rect
) list
439 ; mutable text
: string
440 ; mutable fullscreen
: (width
* height
) option
441 ; mutable mode
: mode
442 ; mutable uioh
: uioh
443 ; mutable outlines
: outline array
444 ; mutable bookmarks
: outline list
445 ; mutable path
: string
446 ; mutable password
: string
447 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
448 ; mutable memused
: memsize
450 ; mutable throttle
: (page list
* int * float) option
451 ; mutable autoscroll
: int option
452 ; mutable ghyll
: (int option -> unit)
453 ; mutable help
: helpitem array
454 ; mutable docinfo
: (int * string) list
455 ; mutable texid
: GlTex.texture_id
option
457 ; mutable prevzoom
: float
458 ; mutable progress
: float
459 ; mutable redisplay
: bool
460 ; mutable mpos
: mpos
461 ; mutable keystate
: keystate
462 ; mutable glinks
: bool
465 { pat
: string circbuf
466 ; pag
: string circbuf
467 ; nav
: anchor circbuf
468 ; sel
: string circbuf
489 ; presentation
= false
494 ; proportional
= true
495 ; trimmargins
= false
496 ; trimfuzz
= (0,0,0,0)
497 ; memlimit
= 32 lsl 20
502 ; bgcolor
= (0.5, 0.5, 0.5)
504 ; scrollbarinpm
= true
507 ; mustoresize
= 256 lsl 20
512 | Plinux
| Pfreebsd
| Pdragonflybsd
513 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
514 | Posx
-> "open \"%s\""
515 | Pcygwin
-> "cygstart \"%s\""
516 | Punknown
-> "echo %s")
517 ; pathlauncher
= "lp \"%s\""
520 | Plinux
| Pfreebsd
| Pdragonflybsd
521 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
528 ; redirectstderr
= false
536 let mk n
= (n
, Hashtbl.create
1) in
550 let findkeyhash c name
=
551 try List.assoc name c
.keyhashes
552 with Not_found
-> failwith
("invalid mode name `" ^ name ^
"'")
555 let conf = { defconf with angle
= defconf.angle
};;
558 { mutable fontsize
: int
559 ; mutable wwidth
: float
560 ; mutable maxrows
: int
572 fstate.fontsize
<- n
;
573 fstate.wwidth
<- measurestr
fstate.fontsize
"w";
574 fstate.maxrows
<- (conf.winh
- fstate.fontsize
- 1) / (fstate.fontsize
+ 1);
578 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
579 let len = String.length s
in
580 if colonpos >= 0 && colonpos + 3 < len
582 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
585 try String.rindex_from s
colonpos ' '
589 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
592 | "http" | "ftp" | "mailto" ->
594 try String.index_from s
colonpos ' '
595 with Not_found
-> len
597 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
605 if String.length
conf.urilauncher
= 0
606 then print_endline uri
608 let url = geturl uri
in
609 if String.length
url = 0
610 then print_endline uri
612 let re = Str.regexp
"%s" in
613 let command = Str.global_replace
re url conf.urilauncher
in
617 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
623 Printf.sprintf
"llpp version %s (%s/%dbit, ocaml %s)" Help.version
624 (platform_to_string platform) Sys.word_size
Sys.ocaml_version
628 let strings = version () :: "" :: Help.keys
in
631 let url = geturl s
in
632 if String.length
url > 0
633 then (s
, 0, Action
(fun u
-> gotouri url; u
))
634 else (s
, 0, Noaction
)
639 let firstgeomcmds = "", [];;
646 ; stderr
= Unix.stderr
647 ; errmsgs
= Buffer.create
0
654 ; anchor
= emptyanchor
658 ; tilelru
= Queue.create
()
659 ; pagemap
= Hashtbl.create
10
660 ; tilemap
= Hashtbl.create
10
675 ; geomcmds
= firstgeomcmds
677 { nav
= cbnew 10 (0, 0.0)
703 Printf.kprintf prerr_endline fmt
705 Printf.kprintf ignore fmt
709 if String.length
conf.pathlauncher
= 0
710 then print_endline
state.path
712 let re = Str.regexp
"%s" in
713 let command = Str.global_replace
re state.path
conf.pathlauncher
in
717 "failed to execute `%s': %s\n" command (Printexc.to_string exn
);
723 type 'a t
= | Res
of 'a
| Exn
of exn
;;
726 try Res
(Unix.pipe ())
732 with exn
-> f
(Printexc.to_string exn
)
736 try Res
(Unix.dup fd
)
741 try Res
(Unix.dup2 fd1 fd2
)
746 let redirectstderr () =
747 let clofail what errmsg
= dolog "failed to close %s: %s" what errmsg
in
748 if conf.redirectstderr
750 match Ne.pipe () with
752 dolog "failed to create stderr redirection pipes: %s"
753 (Printexc.to_string exn
)
756 begin match Ne.dup Unix.stderr
with
758 dolog "failed to dup stderr: %s" (Printexc.to_string exn
);
759 Ne.clo r
(clofail "pipe/r");
760 Ne.clo w
(clofail "pipe/w");
762 | Ne.Res dupstderr
->
763 begin match Ne.dup2 w
Unix.stderr
with
765 dolog "failed to dup2 to stderr: %s"
766 (Printexc.to_string exn
);
767 Ne.clo dupstderr
(clofail "stderr duplicate");
768 Ne.clo r
(clofail "redir pipe/r");
769 Ne.clo w
(clofail "redir pipe/w");
772 state.stderr
<- dupstderr
;
773 state.errfd
<- Some r
;
777 state.newerrmsgs
<- false;
778 begin match state.errfd
with
780 begin match Ne.dup2 state.stderr
Unix.stderr
with
782 dolog "failed to dup2 original stderr: %s"
783 (Printexc.to_string exn
)
785 Ne.clo fd
(clofail "dup of stderr");
786 Unix.dup2 state.stderr
Unix.stderr
;
791 prerr_string
(Buffer.contents
state.errmsgs
);
793 Buffer.clear
state.errmsgs
;
799 let postRedisplay who
=
801 then prerr_endline
("redisplay for " ^ who
);
802 state.redisplay
<- true;
806 let getopaque pageno
=
807 try Some
(Hashtbl.find
state.pagemap
(pageno
, state.gen
))
808 with Not_found
-> None
811 let putopaque pageno opaque
=
812 Hashtbl.replace
state.pagemap
(pageno
, state.gen
) opaque
815 let pagetranslatepoint l x y
=
816 let dy = y
- l
.pagedispy
in
817 let y = dy + l
.pagey
in
818 let dx = x
- l
.pagedispx
in
819 let x = dx + l
.pagex
in
826 begin match getopaque l
.pageno
with
828 let x0 = l
.pagedispx
in
829 let x1 = x0 + l
.pagevw
in
830 let y0 = l
.pagedispy
in
831 let y1 = y0 + l
.pagevh
in
832 if y >= y0 && y <= y1 && x >= x0 && x <= x1
834 let px, py
= pagetranslatepoint l
x y in
835 match whatsunder opaque
px py
with
848 state.text
<- Printf.sprintf
"%c%s" c s
;
849 G.postRedisplay "showtext";
852 let undertext = function
855 | Ulinkgoto
(pageno
, _
) -> Printf.sprintf
"%s: page %d" state.path
(pageno
+1)
856 | Utext s
-> "font: " ^ s
857 | Uunexpected s
-> "unexpected: " ^ s
858 | Ulaunch s
-> "launch: " ^ s
859 | Unamed s
-> "named: " ^ s
860 | Uremote
(filename
, pageno
) ->
861 Printf.sprintf
"%s: page %d" filename
(pageno
+1)
864 let updateunder x y =
865 match getunder x y with
866 | Unone
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
868 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
869 Wsi.setcursor
Wsi.CURSOR_INFO
870 | Ulinkgoto
(pageno
, _
) ->
872 then showtext 'p'
("age: " ^ string_of_int
(pageno
+1));
873 Wsi.setcursor
Wsi.CURSOR_INFO
875 if conf.underinfo
then showtext '
f'
("ont: " ^ s
);
876 Wsi.setcursor
Wsi.CURSOR_TEXT
878 if conf.underinfo
then showtext 'u'
("nexpected: " ^ s
);
879 Wsi.setcursor
Wsi.CURSOR_INHERIT
881 if conf.underinfo
then showtext 'l'
("aunch: " ^ s
);
882 Wsi.setcursor
Wsi.CURSOR_INHERIT
884 if conf.underinfo
then showtext 'n'
("amed: " ^ s
);
885 Wsi.setcursor
Wsi.CURSOR_INHERIT
886 | Uremote
(filename
, pageno
) ->
887 if conf.underinfo
then showtext 'r'
888 (Printf.sprintf
"emote: %s (%d)" filename
(pageno
+1));
889 Wsi.setcursor
Wsi.CURSOR_INFO
892 let showlinktype under
=
898 let s = undertext under
in
903 let b = Buffer.create
(String.length
s + 1) in
904 Buffer.add_string
b s;
909 let colorspace_of_string s =
910 match String.lowercase
s with
914 | _
-> failwith
"invalid colorspace"
917 let int_of_colorspace = function
923 let colorspace_of_int = function
927 | n
-> failwith
("invalid colorspace index " ^ string_of_int n
)
930 let colorspace_to_string = function
936 let intentry_with_suffix text key
=
938 if key
>= 32 && key
< 127
942 match Char.lowercase
c with
944 let text = addchar text c in
948 let text = addchar text c in
952 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
956 let multicolumns_to_string (n
, a
, b) =
958 then Printf.sprintf
"%d" n
959 else Printf.sprintf
"%d,%d,%d" n a
b;
962 let multicolumns_of_string s =
964 (int_of_string
s, 0, 0)
966 Scanf.sscanf
s "%u,%u,%u" (fun n a
b -> (n
, a
, b));
971 let n = Unix.read fd
s 0 4 in
972 if n != 4 then failwith
"incomplete read(len)";
974 lor (Char.code
s.[0] lsl 24)
975 lor (Char.code
s.[1] lsl 16)
976 lor (Char.code
s.[2] lsl 8)
977 lor (Char.code
s.[3] lsl 0)
979 let s = String.create
len in
980 let n = Unix.read fd
s 0 len in
981 if n != len then failwith
"incomplete read(data)";
985 let btod b = if b then 1 else 0;;
988 let b = Buffer.create
16 in
989 Buffer.add_string
b "llll";
992 let s = Buffer.contents
b in
993 let n = String.length
s in
995 (* dolog "wcmd %S" (String.sub s 4 len); *)
996 s.[0] <- Char.chr
((len lsr 24) land 0xff);
997 s.[1] <- Char.chr
((len lsr 16) land 0xff);
998 s.[2] <- Char.chr
((len lsr 8) land 0xff);
999 s.[3] <- Char.chr
(len land 0xff);
1000 let n'
= Unix.write
state.sw
s 0 n in
1001 if n'
!= n then failwith
"write failed";
1006 if conf.presentation
1008 let d = conf.winh
- h
in
1015 let rec f pn ph pi fh l
=
1017 | (n, _
, h
, _
) :: rest
->
1018 let ips = calcips h
in
1020 if conf.presentation
1023 if isbirdseye state.mode
&& pn
= 0
1028 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
1033 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
1037 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
1040 let fh = f 0 0 0 0 state.pdims
in
1045 match conf.columns
with
1046 | Csingle
-> calcheight ()
1047 | Cmulti
((c, _
, _
), b) ->
1048 let rec loop y h
n =
1052 if n = Array.length
b
1055 let (_
, _
, y'
, (_
, _
, h'
, _
)) = b.(n) in
1061 loop max_int
0 (((Array.length
b - 1) / c) * c)
1063 if Array.length
b > 0
1065 let (_
, _
, y, (_
, _
, h
, _
)) = b.(Array.length
b - 1) in
1070 let getpageyh pageno
=
1071 let rec f pn ph pi
y l
=
1073 | (n, _
, h
, _
) :: rest
->
1074 let ips = calcips h
in
1077 let h = if n = pageno
then h else ph
in
1078 if conf.presentation
&& n = pageno
1080 y + (pageno
- pn
) * (ph
+ pi
) + pi
, h
1082 y + (pageno
- pn
) * (ph
+ pi
), h
1084 let y = y + (if conf.presentation
then pi
else 0) in
1085 let y = y + (n - pn
) * (ph
+ pi
) in
1089 y + (pageno
- pn
) * (ph
+ pi
), ph
1091 f 0 0 0 0 state.pdims
1094 let getpageyh pageno
=
1095 match conf.columns
with
1096 | Csingle
-> getpageyh pageno
1098 let (_
, _
, y, (_
, _
, h, _
)) = b.(pageno
) in
1102 let (_
, _
, y, (_
, _
, h, _
)) = b.(n) in
1106 let getpagedim pageno
=
1109 | (n, _
, _
, _
) as pdim
:: rest
->
1111 then (if n = pageno
then pdim
else ppdim
)
1116 f (-1, -1, -1, -1) state.pdims
1119 let getpagey pageno
= fst
(getpageyh pageno
);;
1121 let nogeomcmds cmds
=
1123 | s, [] -> String.length
s = 0
1128 let sh = sh - state.hscrollh
in
1129 let rec f ~pageno ~pdimno ~prev ~py ~
dy ~pdims ~accu
=
1130 let ((w
, h, ips, xoff
) as curr
), rest
, pdimno
, yinc
=
1132 | (pageno'
, w
, h, xoff
) :: rest
when pageno'
= pageno
->
1133 let ips = calcips h in
1135 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
1139 (w
, h, ips, xoff
), rest
, pdimno
+ 1, yinc
1141 prev
, pdims
, pdimno
, 0
1143 let dy = dy + yinc in
1144 let py = py + yinc in
1145 if pageno
= state.pagecount
|| dy >= sh
1150 if py + h <= vy - yinc
1152 let py = py + h + ips in
1153 let dy = max
0 (py - y) in
1154 f ~pageno
:(pageno
+1)
1162 let pagey = vy - py in
1163 let pagevh = h - pagey in
1164 let pagevh = min
(sh - dy) pagevh in
1165 let off = if yinc > 0 then py - vy else 0 in
1166 let py = py + h + ips in
1169 if state.w
< conf.winw
- state.scrollw
1170 then (conf.winw
- state.scrollw
- state.w
) / 2
1173 let dispx = xoff + state.x in
1179 let lw = w
- pagex in
1180 min
lw (conf.winw
- state.scrollw
)
1184 ; pagedimno
= pdimno
1188 ; pagey = pagey + off
1190 ; pagevh = pagevh - off
1192 ; pagedispy
= dy + off
1196 let accu = e :: accu in
1197 f ~pageno
:(pageno
+1)
1218 let layoutN ((columns
, coverA
, coverB
), b) y sh =
1219 let sh = sh - state.hscrollh
in
1220 let rec fold accu n =
1221 if n = Array.length
b
1224 let pdimno, dx, vy, (_
, w
, h, xoff) = b.(n) in
1227 || n = state.pagecount
- coverB
1228 || (n - coverA
) mod columns
= columns
- 1)
1234 let pagey = max
0 (y - vy) in
1235 let pagedispy = if pagey > 0 then 0 else vy - y in
1236 let pagedispx, pagex =
1238 if n = coverA
- 1 || n = state.pagecount
- coverB
1239 then state.x + (conf.winw
- state.scrollw
- w
) / 2
1240 else dx + xoff + state.x
1247 let vw = conf.winw
- state.scrollw
- pagedispx in
1248 let pw = w
- pagex in
1251 let pagevh = min
(h - pagey) (sh - pagedispy) in
1252 if pagevw > 0 && pagevh > 0
1256 ; pagedimno
= pdimno
1263 ; pagedispx = pagedispx
1264 ; pagedispy = pagedispy
1276 List.rev
(fold [] 0)
1279 let layoutS (columns
, b) y sh =
1280 let sh = sh - state.hscrollh
in
1281 let rec fold accu n =
1282 if n = Array.length
b
1285 let pdimno, px, vy, (_
, pagew
, pageh
, xoff) = b.(n) in
1292 let x = xoff + state.x in
1293 let pagey = max
0 (y - vy) in
1294 let pagedispy = if pagey > 0 then 0 else vy - y in
1295 let pagedispx, pagex =
1309 let pagecolw = pagew
/columns
in
1311 if not
conf.fullsplit
&& pagecolw < conf.winw
1312 then pagedispx + ((conf.winw
- state.scrollw
- pagecolw) / 2)
1316 let vw = conf.winw
- pagedispx - state.scrollw
in
1317 let pw = pagew
- pagex in
1323 else min
pagevw pagecolw
1325 let pagevh = min
(pageh
- pagey) (sh - pagedispy) in
1326 if pagevw > 0 && pagevh > 0
1329 { pageno
= n/columns
1330 ; pagedimno
= pdimno
1337 ; pagedispx = pagedispx
1338 ; pagedispy = pagedispy
1339 ; pagecol
= n mod columns
1350 List.rev
(fold [] 0)
1354 if nogeomcmds state.geomcmds
1356 match conf.columns
with
1357 | Csingle
-> layout1 y sh
1358 | Cmulti
c -> layoutN c y sh
1359 | Csplit
s -> layoutS s y sh
1364 let y = state.y + incr
in
1366 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
1371 let tilex = l
.pagex mod conf.tilew
in
1372 let tiley = l
.pagey mod conf.tileh
in
1374 let col = l
.pagex / conf.tilew
in
1375 let row = l
.pagey / conf.tileh
in
1377 let rec rowloop row y0 dispy
h =
1381 let dh = conf.tileh
- y0 in
1382 let dh = min
h dh in
1383 let rec colloop col x0 dispx w
=
1387 let dw = conf.tilew
- x0 in
1388 let dw = min w
dw in
1390 f col row dispx dispy
x0 y0 dw dh;
1391 colloop (col+1) 0 (dispx+dw) (w
-dw)
1394 colloop col tilex l
.pagedispx l
.pagevw;
1395 rowloop (row+1) 0 (dispy
+dh) (h-dh)
1398 if l
.pagevw > 0 && l
.pagevh > 0
1399 then rowloop row tiley l
.pagedispy l
.pagevh;
1402 let gettileopaque l
col row =
1404 l
.pageno
, state.gen
, conf.colorspace
, conf.angle
, l
.pagew
, l
.pageh
, col, row
1406 try Some
(Hashtbl.find
state.tilemap
key)
1407 with Not_found
-> None
1410 let puttileopaque l
col row gen colorspace angle opaque size elapsed
=
1411 let key = l
.pageno
, gen
, colorspace
, angle
, l
.pagew
, l
.pageh
, col, row in
1412 Hashtbl.add
state.tilemap
key (opaque
, size
, elapsed
)
1415 let drawtiles l color
=
1417 let f col row x y tilex tiley w
h =
1418 match gettileopaque l
col row with
1419 | Some
(opaque
, _
, t
) ->
1420 let params = x, y, w
, h, tilex, tiley in
1424 GlFunc.blend_func `zero `one_minus_src_color
;
1426 drawtile
params opaque
;
1428 then Gl.disable `blend
;
1431 let s = Printf.sprintf
1435 let w = measurestr
fstate.fontsize
s in
1436 GlMisc.push_attrib
[`current
];
1437 GlDraw.color
(0.0, 0.0, 0.0);
1439 (float (x-2), float (y-2))
1440 (float (x+2) +. w, float (y + fstate.fontsize
+ 2));
1441 GlDraw.color
(1.0, 1.0, 1.0);
1442 drawstring fstate.fontsize
x (y + fstate.fontsize
- 1) s;
1443 GlMisc.pop_attrib
();
1448 let lw = conf.winw
- state.scrollw
- x in
1451 let lh = conf.winh
- y in
1454 Gl.enable `texture_2d
;
1455 begin match state.texid
with
1457 GlTex.bind_texture `texture_2d id
;
1460 and x1 = float (x+w)
1461 and y1 = float (y+h) in
1463 let tw = float w /. 64.0
1464 and th
= float h /. 64.0 in
1465 let tx0 = float tilex /. 64.0
1466 and ty0
= float tiley /. 64.0 in
1468 and ty1
= ty0
+. th
in
1469 GlDraw.begins `quads
;
1470 GlTex.coord2
(tx0, ty0
); GlDraw.vertex2
(x0, y0);
1471 GlTex.coord2
(tx0, ty1
); GlDraw.vertex2
(x0, y1);
1472 GlTex.coord2
(tx1, ty1
); GlDraw.vertex2
(x1, y1);
1473 GlTex.coord2
(tx1, ty0
); GlDraw.vertex2
(x1, y0);
1476 Gl.disable `texture_2d
;
1478 GlDraw.color
(1.0, 1.0, 1.0);
1481 (float (x+w), float (y+h));
1483 if w > 128 && h > fstate.fontsize
+ 10
1485 GlDraw.color
(0.0, 0.0, 0.0);
1488 then (col*conf.tilew
, row*conf.tileh
)
1491 drawstring2 fstate.fontsize
x y "Loading %d [%d,%d]" l
.pageno
c r
;
1498 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
1500 let tilevisible1 l
x y =
1502 and ax1
= l
.pagex + l
.pagevw
1504 and ay1
= l
.pagey + l
.pagevh in
1508 let bx1 = min
(bx0 + conf.tilew
) l
.pagew
1509 and by1
= min
(by0
+ conf.tileh
) l
.pageh
in
1511 let rx0 = max
ax0 bx0
1512 and ry0
= max ay0 by0
1513 and rx1
= min ax1
bx1
1514 and ry1
= min ay1 by1
in
1516 let nonemptyintersection = rx1
> rx0 && ry1
> ry0
in
1517 nonemptyintersection
1520 let tilevisible layout n x y =
1521 let rec findpageinlayout m
= function
1522 | l
:: rest
when l
.pageno
= n ->
1523 tilevisible1 l
x y || (
1524 match conf.columns
with
1525 | Csplit
(c, _
) when c > m
-> findpageinlayout (m
+1) rest
1528 | _
:: rest
-> findpageinlayout 0 rest
1531 findpageinlayout 0 layout;
1534 let tileready l
x y =
1535 tilevisible1 l
x y &&
1536 gettileopaque l
(x/conf.tilew
) (y/conf.tileh
) != None
1539 let tilepage n p
layout =
1540 let rec loop = function
1544 let f col row _ _ _ _ _ _
=
1545 if state.currently
= Idle
1547 match gettileopaque l
col row with
1550 let x = col*conf.tilew
1551 and y = row*conf.tileh
in
1553 let w = l
.pagew
- x in
1557 let h = l
.pageh
- y in
1560 wcmd "tile %s %d %d %d %d" p
x y w h;
1563 l
, p
, conf.colorspace
, conf.angle
, state.gen
, col, row,
1564 conf.tilew
, conf.tileh
1573 if nogeomcmds state.geomcmds
1577 let preloadlayout visiblepages
=
1578 let presentation = conf.presentation in
1579 let interpagespace = conf.interpagespace in
1580 let maxy = state.maxy in
1581 conf.presentation <- false;
1582 conf.interpagespace <- 0;
1583 state.maxy <- calcheight ();
1585 match visiblepages
with
1586 | [] -> if state.y >= maxy then maxy else 0
1587 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
1589 let y = if y < conf.winh
then 0 else y - conf.winh
in
1590 let h = state.y - y + conf.winh
*3 in
1591 let pages = layout y h in
1592 conf.presentation <- presentation;
1593 conf.interpagespace <- interpagespace;
1599 let rec loop pages =
1600 if state.currently
!= Idle
1605 begin match getopaque l
.pageno
with
1607 wcmd "page %d %d" l
.pageno l
.pagedimno
;
1608 state.currently
<- Loading
(l
, state.gen
);
1610 tilepage l
.pageno opaque
pages;
1615 if nogeomcmds state.geomcmds
1621 if conf.preload && state.currently
= Idle
1622 then load (preloadlayout pages);
1625 let layoutready layout =
1626 let rec fold all ls
=
1627 all
&& match ls
with
1629 let seen = ref false in
1630 let allvisible = ref true in
1631 let foo col row _ _ _ _ _ _
=
1633 allvisible := !allvisible &&
1634 begin match gettileopaque l
col row with
1640 fold (!seen && !allvisible) rest
1643 let alltilesvisible = fold true layout in
1648 let y = bound y 0 state.maxy in
1649 let y, layout, proceed
=
1650 match conf.maxwait
with
1651 | Some time
when state.ghyll
== noghyll ->
1652 begin match state.throttle
with
1654 let layout = layout y conf.winh
in
1655 let ready = layoutready layout in
1659 state.throttle
<- Some
(layout, y, now ());
1661 else G.postRedisplay "gotoy showall (None)";
1663 | Some
(_
, _
, started
) ->
1664 let dt = now () -. started
in
1667 state.throttle
<- None
;
1668 let layout = layout y conf.winh
in
1670 G.postRedisplay "maxwait";
1677 let layout = layout y conf.winh
in
1678 if true || layoutready layout
1679 then G.postRedisplay "gotoy ready";
1685 state.layout <- layout;
1686 begin match state.mode
with
1687 | LinkNav
(Ltexact
(pageno
, linkno
)) ->
1688 let rec loop = function
1690 state.mode
<- LinkNav
(Ltgendir
0)
1691 | l
:: _
when l
.pageno
= pageno
->
1692 begin match getopaque pageno
with
1694 state.mode
<- LinkNav
(Ltgendir
0)
1696 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
1697 if not
(x0 >= l
.pagex && x1 <= l
.pagex + l
.pagevw
1698 && y0 >= l
.pagey && y1 <= l
.pagey + l
.pagevh)
1699 then state.mode
<- LinkNav
(Ltgendir
0)
1701 | _
:: rest
-> loop rest
1706 begin match state.mode
with
1707 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
1708 if not
(pagevisible layout pageno
)
1710 match state.layout with
1713 state.mode
<- Birdseye
(
1714 conf, leftx
, l
.pageno
, hooverpageno
, anchor
1717 | LinkNav
(Ltgendir dir
as lt
) ->
1719 let rec loop = function
1722 match getopaque l
.pageno
with
1728 then LDfirstvisible
(l
.pagex, l
.pagey, dir
)
1730 if dir
> 0 then LDfirst
else LDlast
1736 | Lnotfound
-> loop rest
1738 showlinktype (getlink opaque
n);
1739 Ltexact
(l
.pageno
, n)
1743 state.mode
<- LinkNav
linknav
1748 state.ghyll
<- noghyll;
1751 let mx, my
= state.mpos
in
1756 let conttiling pageno opaque
=
1757 tilepage pageno opaque
1758 (if conf.preload then preloadlayout state.layout else state.layout)
1761 let gotoy_and_clear_text y =
1762 if not
conf.verbose
then state.text <- "";
1767 match state.layout with
1770 let coloff = l
.pagecol
* l
.pageh
in
1771 (l
.pageno
, (float l
.pagey +. float coloff) /. float l
.pageh
)
1774 let getanchory (n, top
) =
1775 let y, h = getpageyh n in
1776 y + (truncate
(top
*. float h));
1779 let gotoanchor anchor
=
1780 gotoy (getanchory anchor
);
1784 cbput state.hists
.nav
(getanchor ());
1788 let anchor = cbgetc state.hists
.nav dir
in
1793 let rec scroll f n a
b =
1794 (* http://devmaster.net/forums/topic/9796-ease-in-ease-out-algorithm/ *)
1796 let s x = 3.0*.x**2.0 -. 2.0*.x**3.0 in
1798 then s (float f /. float a
)
1801 then 1.0 -. s ((float (f-b) /. float (n-b)))
1808 http://integrals.wolfram.com/index.jsp?expr=3x%5E2-2x%5E3&random=false *)
1809 let iv x = -.((-.2.0 +. x)*.x**3.0)/.2.0 in
1811 let ins = float a
*. iv1
1812 and outs
= float (n-b) *. iv1 in
1814 ins +. outs
+. float ones
1816 let rec set (_N
, _A
, _B
) y sy
=
1817 let sum = summa
1.0 _N _A _B
in
1818 let dy = float (y - sy
) in
1822 then state.ghyll
<- noghyll
1825 let s = scroll n _N _A _B
in
1826 let y1 = y1 +. ((s *. dy) /. sum) in
1827 gotoy_and_clear_text (truncate
y1);
1828 state.ghyll
<- gf (n+1) y1;
1832 | Some
y'
-> set (_N
/2, 0, 0) y'
state.y
1834 gf 0 (float state.y)
1837 match conf.ghyllscroll
with
1839 gotoy_and_clear_text y
1841 if state.ghyll
== noghyll
1842 then set nab
y state.y
1843 else state.ghyll
(Some
y)
1846 let gotopage n top
=
1847 let y, h = getpageyh n in
1848 let y = y + (truncate
(top
*. float h)) in
1852 let gotopage1 n top
=
1853 let y = getpagey n in
1858 let invalidate s f =
1863 match state.geomcmds
with
1864 | ps
, [] when String.length ps
= 0 ->
1866 state.geomcmds
<- s, [];
1869 state.geomcmds
<- ps
, [s, f];
1871 | ps
, (s'
, _
) :: rest
when s'
= s ->
1872 state.geomcmds
<- ps
, ((s, f) :: rest
);
1875 state.geomcmds
<- ps
, ((s, f) :: cmds
);
1878 let opendoc path password
=
1880 state.password
<- password
;
1881 state.gen
<- state.gen
+ 1;
1882 state.docinfo
<- [];
1884 setaalevel
conf.aalevel
;
1885 Wsi.settitle
("llpp " ^
Filename.basename path
);
1886 wcmd "open %s\000%s\000" path password
;
1887 invalidate "reqlayout"
1889 wcmd "reqlayout %d %d" conf.angle
(btod conf.proportional
));
1893 let c = c *. conf.colorscale
in
1897 let scalecolor2 (r
, g
, b) =
1898 (r
*. conf.colorscale
, g
*. conf.colorscale
, b *. conf.colorscale
);
1901 let docolumns = function
1904 | Cmulti
((columns
, coverA
, coverB
), _
) ->
1905 let a = Array.make
state.pagecount
(-1, -1, -1, (-1, -1, -1, -1)) in
1906 let rec loop pageno
pdimno pdim
x y rowh pdims
=
1907 let rec fixrow m
= if m
= pageno
then () else
1908 let (pdimno, x, y, ((_
, _
, h, _
) as pdim
)) = a.(m
) in
1911 let y = y + (rowh
- h) / 2 in
1912 a.(m
) <- (pdimno, x, y, pdim
);
1916 if pageno
= state.pagecount
1917 then fixrow (((pageno
- 1) / columns
) * columns
)
1919 let pdimno, ((_
, w, h, xoff) as pdim
), pdims
=
1921 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1922 pdimno+1, pdim
, rest
1927 if pageno
= coverA
- 1 || pageno
= state.pagecount
- coverB
1929 (conf.winw
- state.scrollw
- w) / 2,
1930 y + rowh
+ conf.interpagespace, h
1933 if (pageno
- coverA
) mod columns
= 0
1934 then 0, y + rowh
+ conf.interpagespace, h
1935 else x, y, max rowh
h
1938 if pageno
> 1 && (pageno
- coverA
) mod columns
= 0
1939 then fixrow (pageno
- columns
);
1940 a.(pageno
) <- (pdimno, x, y, pdim
);
1941 let x = x + w + xoff*2 + conf.interpagespace in
1942 loop (pageno
+1) pdimno pdim
x y rowh' pdims
1944 loop 0 ~
-1 (-1,-1,-1,-1) 0 0 0 state.pdims
;
1945 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), a);
1948 let a = Array.make
(state.pagecount
*c) (-1, -1, -1, (-1, -1, -1, -1)) in
1949 let rec loop pageno
pdimno pdim
y pdims
=
1950 if pageno
= state.pagecount
1953 let pdimno, ((_
, w, h, _
) as pdim
), pdims
=
1955 | ((pageno'
, _
, _
, _
) as pdim
) :: rest
when pageno'
= pageno
->
1956 pdimno+1, pdim
, rest
1961 let rec loop1 n x y =
1962 if n = c then y else (
1963 a.(pageno
*c + n) <- (pdimno, x, y, pdim
);
1964 loop1 (n+1) (x+cw) (y + h + conf.interpagespace)
1967 let y = loop1 0 0 y in
1968 loop (pageno
+1) pdimno pdim
y pdims
1970 loop 0 ~
-1 (-1,-1,-1,-1) 0 state.pdims
;
1971 conf.columns
<- Csplit
(c, a);
1975 docolumns conf.columns
;
1976 state.maxy <- calcheight ();
1978 if state.w <= conf.winw
- state.scrollw
1982 match state.mode
with
1983 | Birdseye
(_
, _
, pageno
, _
, _
) ->
1984 let y, h = getpageyh pageno
in
1985 let top = (conf.winh
- h) / 2 in
1986 gotoy (max
0 (y - top))
1987 | _
-> gotoanchor state.anchor
1991 GlDraw.viewport
0 0 w h;
1992 let firsttime = state.geomcmds
== firstgeomcmds in
1993 if not
firsttime && nogeomcmds state.geomcmds
1994 then state.anchor <- getanchor ();
1997 let w = truncate
(float w *. conf.zoom
) - state.scrollw
in
2000 setfontsize fstate.fontsize
;
2001 GlMat.mode `modelview
;
2002 GlMat.load_identity
();
2004 GlMat.mode `projection
;
2005 GlMat.load_identity
();
2006 GlMat.rotate ~
x:1.0 ~angle
:180.0 ();
2007 GlMat.translate ~
x:~
-.1.0 ~
y:~
-.1.0 ();
2008 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
2013 else float state.x /. float state.w
2015 invalidate "geometry"
2019 then state.x <- truncate
(relx *. float w);
2021 match conf.columns
with
2023 | Cmulti
((c, _
, _
), _
) -> (w - (c-1)*conf.interpagespace) / c
2024 | Csplit
(c, _
) -> w * c
2026 wcmd "geometry %d %d" w h);
2030 let len = String.length
state.text in
2033 match state.mode
with
2036 let h, _
, _
= state.uioh#scrollpw
in
2042 (x, float (conf.winh
- (fstate.fontsize
+ 4) - hscrollh))
2043 (x+.w, float (conf.winh
- hscrollh))
2046 let w = float (conf.winw
- state.scrollw
- 1) in
2047 if state.progress
>= 0.0 && state.progress
< 1.0
2049 GlDraw.color
(0.3, 0.3, 0.3);
2050 let w1 = w *. state.progress
in
2052 GlDraw.color
(0.0, 0.0, 0.0);
2056 GlDraw.color
(0.0, 0.0, 0.0);
2060 GlDraw.color
(1.0, 1.0, 1.0);
2061 drawstring fstate.fontsize
2062 (if len > 0 then 8 else 2) (conf.winh
- hscrollh - 5) s;
2065 match state.mode
with
2066 | Textentry
((prefix
, text, _
, _
, _
, _
), _
) ->
2070 Printf.sprintf
"%s%s_ [%s]" prefix
text state.text
2072 Printf.sprintf
"%s%s_" prefix
text
2081 if not
(istextentry state.mode
)
2083 let s1 = "(press 'e' to review error messasges)" in
2084 if String.length
s > 0 then s ^
" " ^
s1 else s1
2089 if String.length
s > 0
2094 let len = Queue.length
state.tilelru
in
2096 if state.memused
<= conf.memlimit
2101 let (k
, p
, s) as lruitem
= Queue.pop
state.tilelru
in
2102 let n, gen
, colorspace
, angle
, pagew
, pageh
, col, row = k
in
2103 let (_
, pw, ph
, _
) = getpagedim n in
2106 && colorspace
= conf.colorspace
2107 && angle
= conf.angle
2112 match state.throttle
with
2115 then preloadlayout state.layout
2117 | Some
(layout, _
, _
) ->
2120 let x = col*conf.tilew
2121 and y = row*conf.tileh
in
2122 tilevisible layout n x y
2124 then Queue.push lruitem
state.tilelru
2126 wcmd "freetile %s" p
;
2127 state.memused
<- state.memused
- s;
2128 state.uioh#infochanged Memused
;
2129 Hashtbl.remove
state.tilemap k
;
2138 Queue.iter
(fun (k
, p
, s) ->
2139 wcmd "freetile %s" p
;
2140 state.memused
<- state.memused
- s;
2141 state.uioh#infochanged Memused
;
2142 Hashtbl.remove
state.tilemap k
;
2144 Queue.clear
state.tilelru
;
2148 let logcurrently = function
2149 | Idle
-> dolog "Idle"
2150 | Loading
(l
, gen
) ->
2151 dolog "Loading %d gen=%d curgen=%d" l
.pageno gen
state.gen
2152 | Tiling
(l
, pageopaque
, colorspace
, angle
, gen
, col, row, tilew
, tileh
) ->
2154 "Tiling %d[%d,%d] page=%s cs=%s angle"
2155 l
.pageno
col row pageopaque
2156 (colorspace_to_string colorspace
)
2158 dolog "gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2159 angle gen
conf.angle
state.gen
2161 conf.tilew
conf.tileh
2168 (* dolog "%S" cmds; *)
2171 try String.index cmds ' '
2172 with Not_found
-> -1
2177 let l = String.length cmds
in
2178 let op = String.sub cmds
0 spacepos in
2180 if l - spacepos < 2 then ""
2181 else String.sub cmds
(spacepos+1) (l-spacepos-1)
2186 state.uioh#infochanged Pdim
;
2190 state.rects
<- state.rects1
;
2191 G.postRedisplay "clearrects";
2195 try Scanf.sscanf
args "%u" (fun n -> n)
2197 dolog "error processing 'continue' %S: %s"
2198 cmds
(Printexc.to_string exn
);
2201 state.pagecount
<- n;
2202 begin match state.currently
with
2204 state.currently
<- Idle
;
2205 state.outlines
<- Array.of_list
(List.rev
l)
2209 let cur, cmds
= state.geomcmds
in
2210 if String.length
cur = 0
2211 then failwith
"umpossible";
2213 begin match List.rev cmds
with
2215 state.geomcmds
<- "", [];
2219 state.geomcmds
<- s, List.rev rest
;
2221 if conf.maxwait
= None
2222 then G.postRedisplay "continue";
2232 then showtext ' '
args
2235 let progress, text =
2237 Scanf.sscanf
args "%f %n"
2239 f, String.sub
args pos
(String.length
args - pos
))
2241 dolog "error processing 'progress' %S: %s"
2242 cmds
(Printexc.to_string exn
);
2246 state.progress <- progress;
2247 G.postRedisplay "progress"
2250 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2252 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2253 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2254 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2256 dolog "error processing 'firstmatch' %S: %s"
2257 cmds
(Printexc.to_string exn
);
2260 let y = (getpagey pageno) + truncate
y0 in
2263 state.rects1
<- [pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)]
2266 let pageno, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
=
2268 Scanf.sscanf
args "%u %d %f %f %f %f %f %f %f %f"
2269 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
2270 (p
, c, x0, y0, x1, y1, x2
, y2
, x3
, y3
))
2272 dolog "error processing 'match' %S: %s"
2273 cmds
(Printexc.to_string exn
);
2277 (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) :: state.rects1
2282 Scanf.sscanf
args "%s %f" (fun p t
-> p
, t
)
2284 dolog "error processing 'page' %S: %s"
2285 cmds
(Printexc.to_string exn
);
2288 begin match state.currently
with
2289 | Loading
(l, gen
) ->
2290 vlog "page %d took %f sec" l.pageno t
;
2291 Hashtbl.replace
state.pagemap
(l.pageno, gen
) pageopaque;
2292 begin match state.throttle
with
2294 let preloadedpages =
2296 then preloadlayout state.layout
2301 Set.Make
(struct type t
= int let compare = (-) end) in
2303 List.fold_left
(fun s l -> IntSet.add
l.pageno s)
2304 IntSet.empty
preloadedpages
2307 Hashtbl.fold (fun ((pageno, _
) as key) opaque
accu ->
2308 if not
(IntSet.mem
pageno set)
2310 wcmd "freepage %s" opaque
;
2316 List.iter
(Hashtbl.remove
state.pagemap
) evictedpages;
2319 state.currently
<- Idle
;
2322 tilepage l.pageno pageopaque state.layout;
2324 load preloadedpages;
2325 if pagevisible state.layout l.pageno
2326 && layoutready state.layout
2327 then G.postRedisplay "page";
2330 | Some
(layout, _
, _
) ->
2331 state.currently
<- Idle
;
2332 tilepage l.pageno pageopaque layout;
2337 dolog "Inconsistent loading state";
2338 logcurrently state.currently
;
2343 let (x, y, opaque
, size
, t
) =
2345 Scanf.sscanf
args "%u %u %s %u %f"
2346 (fun x y p size t
-> (x, y, p
, size
, t
))
2348 dolog "error processing 'tile' %S: %s"
2349 cmds
(Printexc.to_string exn
);
2352 begin match state.currently
with
2353 | Tiling
(l, pageopaque, cs
, angle
, gen
, col, row, tilew
, tileh
) ->
2354 vlog "tile %d [%d,%d] took %f sec" l.pageno col row t
;
2356 if tilew
!= conf.tilew
|| tileh
!= conf.tileh
2358 wcmd "freetile %s" opaque
;
2359 state.currently
<- Idle
;
2363 puttileopaque l col row gen cs angle opaque size t
;
2364 state.memused
<- state.memused
+ size
;
2365 state.uioh#infochanged Memused
;
2367 Queue.push
((l.pageno, gen
, cs
, angle
, l.pagew
, l.pageh
, col, row),
2368 opaque
, size
) state.tilelru
;
2371 match state.throttle
with
2372 | None
-> state.layout
2373 | Some
(layout, _
, _
) -> layout
2376 state.currently
<- Idle
;
2378 && conf.colorspace
= cs
2379 && conf.angle
= angle
2380 && tilevisible layout l.pageno x y
2381 then conttiling l.pageno pageopaque;
2383 begin match state.throttle
with
2385 preload state.layout;
2387 && conf.colorspace
= cs
2388 && conf.angle
= angle
2389 && tilevisible state.layout l.pageno x y
2390 then G.postRedisplay "tile nothrottle";
2392 | Some
(layout, y, _
) ->
2393 let ready = layoutready layout in
2397 state.layout <- layout;
2398 state.throttle
<- None
;
2399 G.postRedisplay "throttle";
2406 dolog "Inconsistent tiling state";
2407 logcurrently state.currently
;
2414 Scanf.sscanf
args "%u %u %u %u" (fun n w h x -> n, w, h, x)
2416 dolog "error processing 'pdim' %S: %s"
2417 cmds
(Printexc.to_string exn
);
2420 state.uioh#infochanged Pdim
;
2421 state.pdims
<- pdim :: state.pdims
2424 let (l, n, t
, h, pos
) =
2426 Scanf.sscanf
args "%u %u %d %u %n"
2427 (fun l n t
h pos
-> l, n, t
, h, pos
)
2429 dolog "error processing 'o' %S: %s"
2430 cmds
(Printexc.to_string exn
);
2433 let s = String.sub
args pos
(String.length
args - pos
) in
2434 let outline = (s, l, (n, float t
/. float h)) in
2435 begin match state.currently
with
2436 | Outlining outlines
->
2437 state.currently
<- Outlining
(outline :: outlines
)
2439 state.currently
<- Outlining
[outline]
2441 dolog "invalid outlining state";
2442 logcurrently currently
2446 state.docinfo
<- (1, args) :: state.docinfo
2449 state.uioh#infochanged Docinfo
;
2450 state.docinfo
<- List.rev
state.docinfo
2453 dolog "unknown cmd `%S'" cmds
2458 let action = function
2459 | HCprev
-> cbget cb ~
-1
2460 | HCnext
-> cbget cb
1
2461 | HCfirst
-> cbget cb ~
-(cb
.rc)
2462 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
2463 and cancel
() = cb
.rc <- rc
2467 let search pattern forward
=
2468 if String.length pattern
> 0
2471 match state.layout with
2474 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
2476 wcmd "search %d %d %d %d,%s\000"
2477 (btod conf.icase
) pn py (btod forward
) pattern
;
2480 let intentry text key =
2482 if key >= 32 && key < 127
2488 let text = addchar text c in
2492 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2496 let linknentry text key =
2498 if key >= 32 && key < 127
2504 let text = addchar text c in
2508 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key c;
2513 if String.length
s > 0
2516 let l = String.length
s in
2517 let rec loop pos
n = if pos
= l then n else
2518 let m = Char.code
s.[pos
] - (if pos
= 0 && l > 1 then 96 else 97) in
2519 loop (pos
+1) (n*26 + m)
2522 let rec loop n = function
2525 match getopaque l.pageno with
2526 | None
-> loop n rest
2528 let m = getlinkcount opaque
in
2531 let under = getlink opaque
n in
2534 else loop (n-m) rest
2536 loop n state.layout;
2540 let textentry text key =
2541 if key land 0xff00 = 0xff00
2543 else TEcont
(text ^
Wsi.toutf8
key)
2546 let reqlayout angle proportional
=
2547 match state.throttle
with
2549 if nogeomcmds state.geomcmds
2550 then state.anchor <- getanchor ();
2551 conf.angle
<- angle
mod 360;
2554 match state.mode
with
2555 | LinkNav _
-> state.mode
<- View
2558 conf.proportional
<- proportional
;
2559 invalidate "reqlayout"
2560 (fun () -> wcmd "reqlayout %d %d" conf.angle
(btod proportional
));
2564 let settrim trimmargins trimfuzz
=
2565 if nogeomcmds state.geomcmds
2566 then state.anchor <- getanchor ();
2567 conf.trimmargins
<- trimmargins
;
2568 conf.trimfuzz
<- trimfuzz
;
2569 let x0, y0, x1, y1 = trimfuzz
in
2570 invalidate "settrim"
2572 wcmd "settrim %d %d %d %d %d" (btod conf.trimmargins
) x0 y0 x1 y1);
2573 Hashtbl.iter
(fun _ opaque
->
2574 wcmd "freepage %s" opaque
;
2576 Hashtbl.clear
state.pagemap
;
2580 match state.throttle
with
2582 let zoom = max
0.01 zoom in
2583 if zoom <> conf.zoom
2585 state.prevzoom
<- conf.zoom;
2587 reshape conf.winw
conf.winh
;
2588 state.text <- Printf.sprintf
"zoom is now %-5.1f" (zoom *. 100.0);
2591 | Some
(layout, y, started
) ->
2593 match conf.maxwait
with
2597 let dt = now () -. started
in
2605 let setcolumns mode columns coverA coverB
=
2609 then showtext '
!'
"split mode doesn't work in bird's eye"
2611 conf.columns
<- Csplit
(-columns
, [||]);
2619 conf.columns
<- Csingle
;
2624 conf.columns
<- Cmulti
((columns
, coverA
, coverB
), [||]);
2628 reshape conf.winw
conf.winh
;
2631 let enterbirdseye () =
2632 let zoom = float conf.thumbw
/. float conf.winw
in
2633 let birdseyepageno =
2634 let cy = conf.winh
/ 2 in
2638 let rec fold best
= function
2641 let d = cy - (l.pagedispy + l.pagevh/2)
2642 and dbest
= cy - (best
.pagedispy + best
.pagevh/2) in
2643 if abs
d < abs dbest
2650 state.mode
<- Birdseye
(
2651 { conf with zoom = conf.zoom }, state.x, birdseyepageno, -1, getanchor ()
2654 conf.presentation <- false;
2655 conf.interpagespace <- 10;
2656 conf.hlinks
<- false;
2658 state.mstate
<- Mnone
;
2659 conf.maxwait
<- None
;
2661 match conf.beyecolumns
with
2664 Cmulti
((c, 0, 0), [||])
2667 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
2670 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
2675 reshape conf.winw
conf.winh
;
2678 let leavebirdseye (c, leftx
, pageno, _
, anchor) goback
=
2680 conf.zoom <- c.zoom;
2681 conf.presentation <- c.presentation;
2682 conf.interpagespace <- c.interpagespace;
2683 conf.maxwait
<- c.maxwait
;
2684 conf.hlinks
<- c.hlinks
;
2685 conf.beyecolumns
<- (
2686 match conf.columns
with
2687 | Cmulti
((c, _
, _
), _
) -> Some
c
2689 | Csplit _
-> failwith
"leaving bird's eye split mode"
2692 match c.columns
with
2693 | Cmulti
(c, _
) -> Cmulti
(c, [||])
2694 | Csingle
-> Csingle
2695 | Csplit
(c, _
) -> Csplit
(c, [||])
2700 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
2703 reshape conf.winw
conf.winh
;
2704 state.anchor <- if goback
then anchor else (pageno, 0.0);
2707 let togglebirdseye () =
2708 match state.mode
with
2709 | Birdseye vals
-> leavebirdseye vals
true
2710 | View
-> enterbirdseye ()
2714 let upbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2715 let pageno = max
0 (pageno - incr
) in
2716 let rec loop = function
2717 | [] -> gotopage1 pageno 0
2718 | l :: _
when l.pageno = pageno ->
2719 if l.pagedispy >= 0 && l.pagey = 0
2720 then G.postRedisplay "upbirdseye"
2721 else gotopage1 pageno 0
2722 | _
:: rest
-> loop rest
2725 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
2728 let downbirdseye incr
(conf, leftx
, pageno, hooverpageno
, anchor) =
2729 let pageno = min
(state.pagecount
- 1) (pageno + incr
) in
2730 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
2731 let rec loop = function
2733 let y, h = getpageyh pageno in
2734 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
2736 | l :: _
when l.pageno = pageno ->
2737 if l.pagevh != l.pageh
2738 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
2739 else G.postRedisplay "downbirdseye"
2740 | _
:: rest
-> loop rest
2745 let optentry mode _
key =
2746 let btos b = if b then "on" else "off" in
2747 if key >= 32 && key < 127
2749 let c = Char.chr
key in
2753 try conf.scrollstep
<- int_of_string
s with exc
->
2754 state.text <- Printf.sprintf
"bad integer `%s': %s"
2755 s (Printexc.to_string exc
)
2757 TEswitch
("scroll step: ", "", None
, intentry, ondone, true)
2762 conf.autoscrollstep
<- int_of_string
s;
2763 if state.autoscroll
<> None
2764 then state.autoscroll
<- Some
conf.autoscrollstep
2766 state.text <- Printf.sprintf
"bad integer `%s': %s"
2767 s (Printexc.to_string exc
)
2769 TEswitch
("auto scroll step: ", "", None
, intentry, ondone, true)
2772 let mode = state.mode in
2775 let n, a, b = multicolumns_of_string s in
2776 setcolumns mode n a b;
2778 state.text <- Printf.sprintf
"bad columns `%s': %s"
2779 s (Printexc.to_string exc
)
2781 TEswitch
("columns: ", "", None
, textentry, ondone, true)
2786 let zoom = float (int_of_string
s) /. 100.0 in
2789 state.text <- Printf.sprintf
"bad integer `%s': %s"
2790 s (Printexc.to_string exc
)
2792 TEswitch
("zoom: ", "", None
, intentry, ondone, true)
2797 conf.thumbw
<- bound (int_of_string
s) 2 4096;
2799 Printf.sprintf
"thumbnail width is set to %d" conf.thumbw
;
2800 begin match mode with
2802 leavebirdseye beye
false;
2807 state.text <- Printf.sprintf
"bad integer `%s': %s"
2808 s (Printexc.to_string exc
)
2810 TEswitch
("thumbnail width: ", "", None
, intentry, ondone, true)
2815 Some
(int_of_string
s)
2817 state.text <- Printf.sprintf
"bad integer `%s': %s"
2818 s (Printexc.to_string exc
);
2821 | Some angle
-> reqlayout angle
conf.proportional
2824 TEswitch
("rotation: ", "", None
, intentry, ondone, true)
2827 conf.icase
<- not
conf.icase
;
2828 TEdone
("case insensitive search " ^
(btos conf.icase
))
2831 conf.preload <- not
conf.preload;
2833 TEdone
("preload " ^
(btos conf.preload))
2836 conf.verbose
<- not
conf.verbose
;
2837 TEdone
("verbose " ^
(btos conf.verbose
))
2840 conf.debug
<- not
conf.debug
;
2841 TEdone
("debug " ^
(btos conf.debug
))
2844 conf.maxhfit
<- not
conf.maxhfit
;
2845 state.maxy <- calcheight ();
2846 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
2849 conf.crophack
<- not
conf.crophack
;
2850 TEdone
("crophack " ^
btos conf.crophack
)
2854 match conf.maxwait
with
2856 conf.maxwait
<- Some infinity
;
2857 "always wait for page to complete"
2859 conf.maxwait
<- None
;
2860 "show placeholder if page is not ready"
2865 conf.underinfo
<- not
conf.underinfo
;
2866 TEdone
("underinfo " ^
btos conf.underinfo
)
2869 conf.savebmarks
<- not
conf.savebmarks
;
2870 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
2876 match state.layout with
2881 conf.interpagespace <- int_of_string
s;
2882 docolumns conf.columns
;
2883 state.maxy <- calcheight ();
2884 let y = getpagey pageno in
2887 state.text <- Printf.sprintf
"bad integer `%s': %s"
2888 s (Printexc.to_string exc
)
2890 TEswitch
("vertical margin: ", "", None
, intentry, ondone, true)
2893 reqlayout conf.angle
(not
conf.proportional
);
2894 TEdone
("proportional display " ^
btos conf.proportional
)
2897 settrim (not
conf.trimmargins
) conf.trimfuzz
;
2898 TEdone
("trim margins " ^
btos conf.trimmargins
)
2901 conf.invert
<- not
conf.invert
;
2902 TEdone
("invert colors " ^
btos conf.invert
)
2906 cbput state.hists
.sel
s;
2909 TEswitch
("selection command: ", "", Some
(onhist state.hists
.sel
),
2910 textentry, ondone, true)
2913 conf.fullsplit
<- not
conf.fullsplit
;
2915 TEdone
("full split " ^
btos conf.fullsplit
)
2918 state.text <- Printf.sprintf
"bad option %d `%c'" key c;
2924 class type lvsource
= object
2925 method getitemcount
: int
2926 method getitem
: int -> (string * int)
2927 method hasaction
: int -> bool
2936 method getactive
: int
2937 method getfirst
: int
2938 method getqsearch
: string
2939 method setqsearch
: string -> unit
2943 class virtual lvsourcebase
= object
2944 val mutable m_active
= 0
2945 val mutable m_first
= 0
2946 val mutable m_qsearch
= ""
2947 val mutable m_pan
= 0
2948 method getactive
= m_active
2949 method getfirst
= m_first
2950 method getqsearch
= m_qsearch
2951 method getpan
= m_pan
2952 method setqsearch
s = m_qsearch
<- s
2955 let withoutlastutf8 s =
2956 let len = String.length
s in
2964 let b = Char.code
s.[pos
] in
2965 if b land 0b110000 = 0b11000000
2970 if Char.code
s.[len-1] land 0x80 = 0
2974 String.sub
s 0 first;
2977 let textentrykeyboard
2978 key _mask
((c, text, opthist
, onkey
, ondone, cancelonempty
), onleave
) =
2980 state.mode <- Textentry
(te
, onleave
);
2983 G.postRedisplay "textentrykeyboard enttext";
2985 let histaction cmd
=
2988 | Some
(action, _
) ->
2989 state.mode <- Textentry
(
2990 (c, action cmd
, opthist
, onkey
, ondone, cancelonempty
), onleave
2992 G.postRedisplay "textentry histaction"
2995 | 0xff08 -> (* backspace *)
2996 let s = withoutlastutf8 text in
2997 let len = String.length
s in
2998 if cancelonempty
&& len = 0
3001 G.postRedisplay "textentrykeyboard after cancel";
3004 enttext (c, s, opthist
, onkey
, ondone, cancelonempty
)
3010 G.postRedisplay "textentrykeyboard after confirm"
3012 | 0xff52 -> histaction HCprev
3013 | 0xff54 -> histaction HCnext
3014 | 0xff50 -> histaction HCfirst
3015 | 0xff57 -> histaction HClast
3017 | 0xff1b -> (* escape*)
3018 if String.length
text = 0
3020 begin match opthist
with
3022 | Some
(_
, onhistcancel
) -> onhistcancel
()
3026 G.postRedisplay "textentrykeyboard after cancel2"
3029 enttext (c, "", opthist
, onkey
, ondone, cancelonempty
)
3032 | 0xff9f | 0xffff -> () (* delete *)
3034 | _
when key != 0 && key land 0xff00 != 0xff00 ->
3035 begin match onkey
text key with
3039 G.postRedisplay "textentrykeyboard after confirm2";
3042 enttext (c, text, opthist
, onkey
, ondone, cancelonempty
);
3046 G.postRedisplay "textentrykeyboard after cancel3"
3049 state.mode <- Textentry
(te
, onleave
);
3050 G.postRedisplay "textentrykeyboard switch";
3054 vlog "unhandled key %s" (Wsi.keyname
key)
3057 let firstof first active
=
3058 if first > active
|| abs
(first - active
) > fstate.maxrows
- 1
3059 then max
0 (active
- (fstate.maxrows
/2))
3063 let calcfirst first active
=
3066 let rows = active
- first in
3067 if rows > fstate.maxrows
then active
- fstate.maxrows
else first
3071 let scrollph y maxy =
3072 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
3073 let sh = float conf.winh
/. sh in
3074 let sh = max
sh (float conf.scrollh
) in
3079 else float y /. float maxy
3081 let position = (float conf.winh
-. sh) *. percent in
3084 if position +. sh > float conf.winh
3085 then float conf.winh
-. sh
3091 let coe s = (s :> uioh
);;
3093 class listview ~
(source
:lvsource
) ~trusted ~modehash
=
3095 val m_pan
= source#getpan
3096 val m_first
= source#getfirst
3097 val m_active
= source#getactive
3098 val m_qsearch
= source#getqsearch
3099 val m_prev_uioh
= state.uioh
3101 method private elemunder
y =
3102 let n = y / (fstate.fontsize
+1) in
3103 if m_first
+ n < source#getitemcount
3105 if source#hasaction
(m_first
+ n)
3106 then Some
(m_first
+ n)
3113 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
3114 GlDraw.color
(0., 0., 0.) ~alpha
:0.85;
3115 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
3116 GlDraw.color
(1., 1., 1.);
3117 Gl.enable `texture_2d
;
3118 let fs = fstate.fontsize
in
3120 let ww = fstate.wwidth
in
3121 let tabw = 30.0*.ww in
3122 let itemcount = source#getitemcount
in
3124 if (row - m_first
) * nfs > conf.winh
3127 if row >= 0 && row < itemcount
3129 let (s, level
) = source#getitem
row in
3130 let y = (row - m_first
) * nfs in
3131 let x = 5.0 +. float (level
+ m_pan
) *. ww in
3134 Gl.disable `texture_2d
;
3135 GlDraw.polygon_mode `both `line
;
3136 GlDraw.color
(1., 1., 1.) ~alpha
:0.9;
3137 GlDraw.rect (1., float (y + 1))
3138 (float (conf.winw
- conf.scrollbw
- 1), float (y + fs + 3));
3139 GlDraw.polygon_mode `both `fill
;
3140 GlDraw.color
(1., 1., 1.);
3141 Gl.enable `texture_2d
;
3144 let drawtabularstring s =
3145 let drawstr x s = drawstring1 fs (truncate
x) (y+nfs) s in
3148 let tabpos = try String.index
s '
\t'
with Not_found
-> -1 in
3151 let len = String.length
s - tabpos - 1 in
3152 let s1 = String.sub
s 0 tabpos
3153 and s2
= String.sub
s (tabpos + 1) len in
3154 let nx = drawstr x s1 in
3156 let x = x +. (max
tabw sw) in
3163 let _ = drawtabularstring s in
3170 Gl.disable `texture_2d
;
3172 method updownlevel incr
=
3173 let len = source#getitemcount
in
3175 if m_active
>= 0 && m_active
< len
3176 then snd
(source#getitem m_active
)
3180 if i
= len then i
-1 else if i
= -1 then 0 else
3181 let _, l = source#getitem i
in
3182 if l != curlevel then i
else flow (i
+incr
)
3184 let active = flow m_active
in
3185 let first = calcfirst m_first
active in
3186 G.postRedisplay "outline updownlevel";
3187 {< m_active
= active; m_first
= first >}
3189 method private key1
key mask
=
3190 let set1 active first qsearch
=
3191 coe {< m_active
= active; m_first
= first; m_qsearch
= qsearch
>}
3193 let search active pattern incr
=
3196 if n >= 0 && n < source#getitemcount
3198 let s, _ = source#getitem
n in
3200 (try ignore
(Str.search_forward
re s 0); true
3201 with Not_found
-> false)
3203 else loop (n + incr
)
3210 let re = Str.regexp_case_fold pattern
in
3216 let itemcount = source#getitemcount
in
3217 let find start incr
=
3219 if i
= -1 || i
= itemcount
3222 if source#hasaction i
3224 else find (i
+ incr
)
3229 let set active first =
3230 let first = bound first 0 (itemcount - fstate.maxrows
) in
3232 coe {< m_active
= active; m_first
= first >}
3235 let isvisible first n = n >= first && n - first <= fstate.maxrows
in
3237 let incr1 = if incr
> 0 then 1 else -1 in
3238 if isvisible m_first m_active
3241 let next = m_active
+ incr
in
3243 if next < 0 || next >= itemcount
3245 else find next incr1
3247 if next = -1 || abs
(m_active
- next) > fstate.maxrows
3253 let first = m_first
+ incr
in
3254 let first = bound first 0 (itemcount - 1) in
3256 let next = m_active
+ incr
in
3257 let next = bound next 0 (itemcount - 1) in
3260 let active = if next = -1 then m_active
else next in
3263 let first = min
next m_first
in
3265 if abs
(next - first) > fstate.maxrows
3271 let first = m_first
+ incr
in
3272 let first = bound first 0 (itemcount - 1) in
3274 let next = m_active
+ incr
in
3275 let next = bound next 0 (itemcount - 1) in
3276 let next = find next incr1 in
3278 if next = -1 || abs
(m_active
- first) > fstate.maxrows
3280 let active = if m_active
= -1 then next else m_active
in
3285 if isvisible first active
3291 G.postRedisplay "listview navigate";
3295 | (0x72|0x73) when Wsi.withctrl mask
-> (* ctrl-r/ctlr-s *)
3296 let incr = if key = 0x72 then -1 else 1 in
3298 match search (m_active
+ incr) m_qsearch
incr with
3300 state.text <- m_qsearch ^
" [not found]";
3303 state.text <- m_qsearch
;
3304 active, firstof m_first
active
3306 G.postRedisplay "listview ctrl-r/s";
3307 set1 active first m_qsearch
;
3309 | 0xff08 -> (* backspace *)
3310 if String.length m_qsearch
= 0
3313 let qsearch = withoutlastutf8 m_qsearch
in
3314 let len = String.length
qsearch in
3318 G.postRedisplay "listview empty qsearch";
3319 set1 m_active m_first
"";
3323 match search m_active
qsearch ~
-1 with
3325 state.text <- qsearch ^
" [not found]";
3328 state.text <- qsearch;
3329 active, firstof m_first
active
3331 G.postRedisplay "listview backspace qsearch";
3332 set1 active first qsearch
3335 | key when (key != 0 && key land 0xff00 != 0xff00) ->
3336 let pattern = m_qsearch ^
Wsi.toutf8
key in
3338 match search m_active
pattern 1 with
3340 state.text <- pattern ^
" [not found]";
3343 state.text <- pattern;
3344 active, firstof m_first
active
3346 G.postRedisplay "listview qsearch add";
3347 set1 active first pattern;
3349 | 0xff1b -> (* escape *)
3351 if String.length m_qsearch
= 0
3353 G.postRedisplay "list view escape";
3356 source#exit
(coe self
) true m_active m_first m_pan m_qsearch
3358 | None
-> m_prev_uioh
3363 G.postRedisplay "list view kill qsearch";
3364 source#setqsearch
"";
3365 coe {< m_qsearch
= "" >}
3368 | 0xff0d -> (* return *)
3370 let self = {< m_qsearch
= "" >} in
3371 source#setqsearch
"";
3373 G.postRedisplay "listview enter";
3374 if m_active
>= 0 && m_active
< source#getitemcount
3376 source#exit
(coe self) false m_active m_first m_pan
"";
3379 source#exit
(coe self) true m_active m_first m_pan
"";
3382 begin match opt with
3383 | None
-> m_prev_uioh
3387 | 0xff9f | 0xffff -> (* delete *)
3390 | 0xff52 -> navigate ~
-1 (* up *)
3391 | 0xff54 -> navigate 1 (* down *)
3392 | 0xff55 -> navigate ~
-(fstate.maxrows
) (* prior *)
3393 | 0xff56 -> navigate fstate.maxrows
(* next *)
3395 | 0xff53 -> (* right *)
3397 G.postRedisplay "listview right";
3398 coe {< m_pan
= m_pan
- 1 >}
3400 | 0xff51 -> (* left *)
3402 G.postRedisplay "listview left";
3403 coe {< m_pan
= m_pan
+ 1 >}
3405 | 0xff50 -> (* home *)
3406 let active = find 0 1 in
3407 G.postRedisplay "listview home";
3410 | 0xff57 -> (* end *)
3411 let first = max
0 (itemcount - fstate.maxrows
) in
3412 let active = find (itemcount - 1) ~
-1 in
3413 G.postRedisplay "listview end";
3416 | key when (key = 0 || key land 0xff00 = 0xff00) ->
3420 dolog "listview unknown key %#x" key; coe self
3422 method key key mask
=
3423 match state.mode with
3424 | Textentry te
-> textentrykeyboard key mask te
; coe self
3425 | _ -> self#key1
key mask
3427 method button button down
x y _ =
3430 | 1 when x > conf.winw
- conf.scrollbw
->
3431 G.postRedisplay "listview scroll";
3434 let _, position, sh = self#
scrollph in
3435 if y > truncate
position && y < truncate
(position +. sh)
3437 state.mstate
<- Mscrolly
;
3441 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3442 let first = truncate
(s *. float source#getitemcount
) in
3443 let first = min source#getitemcount
first in
3444 Some
(coe {< m_first
= first; m_active
= first >})
3446 state.mstate
<- Mnone
;
3449 | 1 when not down
->
3450 begin match self#elemunder
y with
3452 G.postRedisplay "listview click";
3454 (coe {< m_active
= n >}) false n m_first m_pan m_qsearch
3458 | n when (n == 4 || n == 5) && not down
->
3459 let len = source#getitemcount
in
3461 if n = 5 && m_first
+ fstate.maxrows
>= len
3465 let first = m_first
+ (if n == 4 then -1 else 1) in
3466 bound first 0 (len - 1)
3468 G.postRedisplay "listview wheel";
3469 Some
(coe {< m_first
= first >})
3474 | None
-> m_prev_uioh
3478 match state.mstate
with
3480 let s = float (max
0 (y - conf.scrollh
)) /. float conf.winh
in
3481 let first = truncate
(s *. float source#getitemcount
) in
3482 let first = min source#getitemcount
first in
3483 G.postRedisplay "listview motion";
3484 coe {< m_first
= first; m_active
= first >}
3487 method pmotion
x y =
3488 if x < conf.winw
- conf.scrollbw
3491 match self#elemunder
y with
3492 | None
-> Wsi.setcursor
Wsi.CURSOR_INHERIT
; m_active
3493 | Some
n -> Wsi.setcursor
Wsi.CURSOR_INFO
; n
3497 then (G.postRedisplay "listview pmotion"; {< m_active
= n >})
3502 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3506 method infochanged
_ = ()
3508 method scrollpw
= (0, 0.0, 0.0)
3510 let nfs = fstate.fontsize
+ 1 in
3511 let y = m_first
* nfs in
3512 let itemcount = source#getitemcount
in
3513 let maxi = max
0 (itemcount - fstate.maxrows
) in
3514 let maxy = maxi * nfs in
3515 let p, h = scrollph y maxy in
3518 method modehash
= modehash
3521 class outlinelistview ~source
=
3524 ~source
:(source
:> lvsource
)
3526 ~modehash
:(findkeyhash conf "outline")
3529 method key key mask
=
3530 let calcfirst first active =
3533 let rows = active - first in
3534 if rows > fstate.maxrows
then active - fstate.maxrows
else first
3538 let active = m_active
+ incr in
3539 let active = bound active 0 (source#getitemcount
- 1) in
3540 let first = calcfirst m_first
active in
3541 G.postRedisplay "outline navigate";
3542 coe {< m_active
= active; m_first
= first >}
3544 let ctrl = Wsi.withctrl mask
in
3546 | 110 when ctrl -> (* ctrl-n *)
3547 source#narrow m_qsearch
;
3548 G.postRedisplay "outline ctrl-n";
3549 coe {< m_first
= 0; m_active
= 0 >}
3551 | 117 when ctrl -> (* ctrl-u *)
3553 G.postRedisplay "outline ctrl-u";
3555 coe {< m_first
= 0; m_active
= 0 >}
3557 | 108 when ctrl -> (* ctrl-l *)
3558 let first = m_active
- (fstate.maxrows
/ 2) in
3559 G.postRedisplay "outline ctrl-l";
3560 coe {< m_first
= first >}
3562 | 0xff9f | 0xffff -> (* delete *)
3563 source#remove m_active
;
3564 G.postRedisplay "outline delete";
3565 let active = max
0 (m_active
-1) in
3566 coe {< m_first
= firstof m_first
active;
3567 m_active
= active >}
3569 | 0xff52 -> navigate ~
-1 (* up *)
3570 | 0xff54 -> navigate 1 (* down *)
3571 | 0xff55 -> (* prior *)
3572 navigate ~
-(fstate.maxrows
)
3573 | 0xff56 -> (* next *)
3574 navigate fstate.maxrows
3576 | 0xff53 -> (* [ctrl-]right *)
3580 G.postRedisplay "outline ctrl right";
3581 {< m_pan
= m_pan
+ 1 >}
3583 else self#updownlevel
1
3587 | 0xff51 -> (* [ctrl-]left *)
3591 G.postRedisplay "outline ctrl left";
3592 {< m_pan
= m_pan
- 1 >}
3594 else self#updownlevel ~
-1
3598 | 0xff50 -> (* home *)
3599 G.postRedisplay "outline home";
3600 coe {< m_first
= 0; m_active
= 0 >}
3602 | 0xff57 -> (* end *)
3603 let active = source#getitemcount
- 1 in
3604 let first = max
0 (active - fstate.maxrows
) in
3605 G.postRedisplay "outline end";
3606 coe {< m_active
= active; m_first
= first >}
3608 | _ -> super#
key key mask
3611 let outlinesource usebookmarks
=
3614 inherit lvsourcebase
3615 val mutable m_items
= empty
3616 val mutable m_orig_items
= empty
3617 val mutable m_prev_items
= empty
3618 val mutable m_narrow_pattern
= ""
3619 val mutable m_hadremovals
= false
3621 method getitemcount
=
3622 Array.length m_items
+ (if m_hadremovals
then 1 else 0)
3625 if n == Array.length m_items
&& m_hadremovals
3627 ("[Confirm removal]", 0)
3629 let s, n, _ = m_items
.(n) in
3632 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
3633 ignore
(uioh
, first, qsearch);
3634 let confrimremoval = m_hadremovals
&& active = Array.length m_items
in
3636 if String.length m_narrow_pattern
= 0
3642 if not
confrimremoval
3644 let _, _, anchor = m_items
.(active) in
3649 state.bookmarks
<- Array.to_list m_items
;
3650 m_orig_items
<- m_items
;
3653 else m_items
<- items;
3657 method hasaction
_ = true
3660 if Array.length m_items
!= Array.length m_orig_items
3661 then "Narrowed to " ^ m_narrow_pattern ^
" (ctrl-u to restore)"
3664 method narrow
pattern =
3665 let reopt = try Some
(Str.regexp_case_fold
pattern) with _ -> None
in
3669 let rec loop accu n =
3672 m_narrow_pattern
<- pattern;
3673 m_items
<- Array.of_list
accu
3676 let (s, _, _) as o = m_items
.(n) in
3678 if (try ignore
(Str.search_forward
re s 0); true
3679 with Not_found
-> false)
3685 loop [] (Array.length m_items
- 1)
3690 then Array.of_list
state.bookmarks
3693 m_items
<- m_orig_items
3698 if m >= 0 && m < Array.length m_items
3700 m_hadremovals
<- true;
3701 m_items
<- Array.init
(Array.length m_items
- 1) (fun n ->
3702 let n = if n >= m then n+1 else n in
3707 method reset
anchor items =
3708 m_hadremovals
<- false;
3709 if m_orig_items
== empty || m_prev_items
!= items
3711 m_orig_items
<- items;
3712 if String.length m_narrow_pattern
= 0
3713 then m_items
<- items;
3715 m_prev_items
<- items;
3716 let rely = getanchory anchor in
3718 let rec loop n best bestd
=
3719 if n = Array.length m_items
3722 let (_, _, anchor) = m_items
.(n) in
3723 let orely = getanchory anchor in
3724 let d = abs
(orely - rely) in
3727 else loop (n+1) best bestd
3732 m_first
<- firstof m_first
active
3736 let enterselector usebookmarks
=
3737 let source = outlinesource usebookmarks
in
3741 then Array.of_list
state.bookmarks
3744 if Array.length
outlines = 0
3746 showtext ' ' errmsg
;
3749 state.text <- source#greetmsg
;
3750 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
3751 let anchor = getanchor () in
3752 source#reset
anchor outlines;
3753 state.uioh
<- coe (new outlinelistview ~
source);
3754 G.postRedisplay "enter selector";
3758 let enteroutlinemode =
3759 let f = enterselector false in
3760 fun ()-> f "Document has no outline";
3763 let enterbookmarkmode =
3764 let f = enterselector true in
3765 fun () -> f "Document has no bookmarks (yet)";
3768 let color_of_string s =
3769 Scanf.sscanf
s "%d/%d/%d" (fun r g
b ->
3770 (float r
/. 256.0, float g
/. 256.0, float b /. 256.0)
3774 let color_to_string (r
, g
, b) =
3775 let r = truncate
(r *. 256.0)
3776 and g
= truncate
(g
*. 256.0)
3777 and b = truncate
(b *. 256.0) in
3778 Printf.sprintf
"%d/%d/%d" r g
b
3781 let irect_of_string s =
3782 Scanf.sscanf
s "%d/%d/%d/%d" (fun x0 y0 x1 y1 -> (x0,y0,x1,y1))
3785 let irect_to_string (x0,y0,x1,y1) =
3786 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
3789 let makecheckers () =
3790 (* Appropriated from lablGL-1.04/LablGlut/examples/lablGL/checker.ml which had
3792 converted by Issac Trotts. July 25, 2002 *)
3793 let image_height = 64
3794 and image_width
= 64 in
3798 GlPix.create `ubyte ~format
:`rgb ~width
:image_width ~height
:image_height
3800 for i
= 0 to image_width
- 1 do
3801 for j
= 0 to image_height - 1 do
3802 Raw.sets
(GlPix.to_raw
image) ~pos
:(3*(i
*image_height+j
))
3803 (if (i
land 8 ) lxor (j
land 8) = 0
3804 then [|255;255;255|] else [|200;200;200|])
3809 let image = make_image () in
3810 let id = GlTex.gen_texture
() in
3811 GlTex.bind_texture `texture_2d
id;
3812 GlPix.store
(`unpack_alignment
1);
3813 GlTex.image2d
image;
3814 List.iter
(GlTex.parameter ~target
:`texture_2d
)
3817 `mag_filter `nearest
;
3818 `min_filter `nearest
];
3822 let setcheckers enabled
=
3823 match state.texid
with
3825 if enabled
then state.texid
<- Some
(makecheckers ())
3830 GlTex.delete_texture texid
;
3831 state.texid
<- None
;
3835 let int_of_string_with_suffix s =
3836 let l = String.length
s in
3840 let suffix = Char.lowercase
s.[l-1] in
3842 | 'k'
-> String.sub
s 0 (l-1), 10
3843 | '
m'
-> String.sub
s 0 (l-1), 20
3844 | 'g'
-> String.sub
s 0 (l-1), 30
3848 let n = int_of_string
s1 in
3849 let m = n lsl shift
in
3851 then raise
(Failure
"value too large")
3855 let string_with_suffix_of_int n =
3863 if n land ((1 lsl 20) - 1) = 0
3866 if n land ((1 lsl 10) - 1) = 0
3873 let h = n mod 1000 in
3876 then string_of_int
h ^
s
3878 let s = Printf.sprintf
"_%03d%s" h s in
3885 let defghyllscroll = (40, 8, 32);;
3886 let ghyllscroll_of_string s =
3887 let (n, a, b) as nab
=
3890 else Scanf.sscanf
s "%u,%u,%u" (fun n a b -> n, a, b)
3892 if n <= a || n <= b || a >= b
3893 then failwith
"invalid ghyll N,A,B (N <= A, A < B, N <= B)";
3897 let ghyllscroll_to_string ((n, a, b) as nab
) =
3898 if nab
= defghyllscroll
3900 else Printf.sprintf
"%d,%d,%d" n a b;
3903 let describe_location () =
3905 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
3907 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
3908 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
3912 else (100. *. (float state.y /. float maxy))
3916 Printf.sprintf
"page %d of %d [%.2f%%]"
3917 (fn+1) state.pagecount
percent
3920 "pages %d-%d of %d [%.2f%%]"
3921 (fn+1) (ln
+1) state.pagecount
percent
3925 let btos b = if b then "\xe2\x88\x9a" else "" in
3926 let showextended = ref false in
3927 let leave mode = function
3928 | Confirm
-> state.mode <- mode
3929 | Cancel
-> state.mode <- mode in
3932 val mutable m_first_time
= true
3933 val mutable m_l
= []
3934 val mutable m_a
= [||]
3935 val mutable m_prev_uioh
= nouioh
3936 val mutable m_prev_mode
= View
3938 inherit lvsourcebase
3940 method reset prev_mode prev_uioh
=
3941 m_a
<- Array.of_list
(List.rev m_l
);
3943 m_prev_mode
<- prev_mode
;
3944 m_prev_uioh
<- prev_uioh
;
3948 if n >= Array.length m_a
3952 | _, _, _, Action
_ -> m_active
<- n
3956 m_first_time
<- false;
3959 method int name get
set =
3961 (name
, `
int get
, 1, Action
(
3964 try set (int_of_string
s)
3966 state.text <- Printf.sprintf
"bad integer `%s': %s"
3967 s (Printexc.to_string exn
)
3970 let te = name ^
": ", "", None
, intentry, ondone, true in
3971 state.mode <- Textentry
(te, leave m_prev_mode
);
3975 method int_with_suffix name get
set =
3977 (name
, `intws get
, 1, Action
(
3980 try set (int_of_string_with_suffix s)
3982 state.text <- Printf.sprintf
"bad integer `%s': %s"
3983 s (Printexc.to_string exn
)
3987 name ^
": ", "", None
, intentry_with_suffix, ondone, true
3989 state.mode <- Textentry
(te, leave m_prev_mode
);
3993 method bool ?
(offset
=1) ?
(btos=btos) name get
set =
3995 (name
, `
bool (btos, get
), offset
, Action
(
4002 method color name get
set =
4004 (name
, `color get
, 1, Action
(
4006 let invalid = (nan
, nan
, nan
) in
4009 try color_of_string s
4011 state.text <- Printf.sprintf
"bad color `%s': %s"
4012 s (Printexc.to_string exn
);
4018 let te = name ^
": ", "", None
, textentry, ondone, true in
4019 state.text <- color_to_string (get
());
4020 state.mode <- Textentry
(te, leave m_prev_mode
);
4024 method string name get
set =
4026 (name
, `
string get
, 1, Action
(
4028 let ondone s = set s in
4029 let te = name ^
": ", "", None
, textentry, ondone, true in
4030 state.mode <- Textentry
(te, leave m_prev_mode
);
4034 method colorspace name get
set =
4036 (name
, `
string get
, 1, Action
(
4039 let vals = [| "rgb"; "bgr"; "gray" |] in
4041 inherit lvsourcebase
4044 m_active
<- int_of_colorspace conf.colorspace
;
4047 method getitemcount
= Array.length
vals
4048 method getitem
n = (vals.(n), 0)
4049 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4050 ignore
(uioh
, first, pan
, qsearch);
4051 if not cancel
then set active;
4053 method hasaction
_ = true
4057 let modehash = findkeyhash conf "info" in
4058 coe (new listview ~
source ~trusted
:true ~
modehash)
4061 method caption
s offset
=
4062 m_l
<- (s, `
empty, offset
, Noaction
) :: m_l
4064 method caption2
s f offset
=
4065 m_l
<- (s, `
string f, offset
, Noaction
) :: m_l
4067 method getitemcount
= Array.length m_a
4070 let tostr = function
4071 | `
int f -> string_of_int
(f ())
4072 | `intws
f -> string_with_suffix_of_int (f ())
4074 | `color
f -> color_to_string (f ())
4075 | `
bool (btos, f) -> btos (f ())
4078 let name, t
, offset
, _ = m_a
.(n) in
4079 ((let s = tostr t
in
4080 if String.length
s > 0
4081 then Printf.sprintf
"%s\t%s" name s
4085 method exit ~uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4089 m_qsearch
<- qsearch;
4091 match m_a
.(active) with
4092 | _, _, _, Action
f -> f uioh
4104 method hasaction
n =
4106 | _, _, _, Action
_ -> true
4110 let rec fillsrc prevmode prevuioh
=
4111 let sep () = src#caption
"" 0 in
4112 let colorp name get
set =
4114 (fun () -> color_to_string (get
()))
4117 let c = color_of_string v in
4120 state.text <- Printf.sprintf
"bad color `%s': %s"
4121 v (Printexc.to_string exn
);
4124 let oldmode = state.mode in
4125 let birdseye = isbirdseye state.mode in
4127 src#caption
(if birdseye then "Setup (Bird's eye)" else "Setup") 0;
4129 src#
bool "presentation mode"
4130 (fun () -> conf.presentation)
4132 conf.presentation <- v;
4133 state.anchor <- getanchor ();
4136 src#
bool "ignore case in searches"
4137 (fun () -> conf.icase
)
4138 (fun v -> conf.icase
<- v);
4141 (fun () -> conf.preload)
4142 (fun v -> conf.preload <- v);
4144 src#
bool "highlight links"
4145 (fun () -> conf.hlinks
)
4146 (fun v -> conf.hlinks
<- v);
4148 src#
bool "under info"
4149 (fun () -> conf.underinfo
)
4150 (fun v -> conf.underinfo
<- v);
4152 src#
bool "persistent bookmarks"
4153 (fun () -> conf.savebmarks
)
4154 (fun v -> conf.savebmarks
<- v);
4156 src#
bool "proportional display"
4157 (fun () -> conf.proportional
)
4158 (fun v -> reqlayout conf.angle
v);
4160 src#
bool "trim margins"
4161 (fun () -> conf.trimmargins
)
4162 (fun v -> settrim v conf.trimfuzz
; fillsrc prevmode prevuioh
);
4164 src#
bool "persistent location"
4165 (fun () -> conf.jumpback
)
4166 (fun v -> conf.jumpback
<- v);
4169 src#
int "inter-page space"
4170 (fun () -> conf.interpagespace)
4172 conf.interpagespace <- n;
4173 docolumns conf.columns
;
4175 match state.layout with
4180 state.maxy <- calcheight ();
4181 let y = getpagey pageno in
4186 (fun () -> conf.pagebias
)
4187 (fun v -> conf.pagebias
<- v);
4189 src#
int "scroll step"
4190 (fun () -> conf.scrollstep
)
4191 (fun n -> conf.scrollstep
<- n);
4193 src#
int "auto scroll step"
4195 match state.autoscroll
with
4197 | _ -> conf.autoscrollstep
)
4199 if state.autoscroll
<> None
4200 then state.autoscroll
<- Some
n;
4201 conf.autoscrollstep
<- n);
4204 (fun () -> truncate
(conf.zoom *. 100.))
4205 (fun v -> setzoom ((float v) /. 100.));
4208 (fun () -> conf.angle
)
4209 (fun v -> reqlayout v conf.proportional
);
4211 src#
int "scroll bar width"
4212 (fun () -> state.scrollw
)
4216 reshape conf.winw
conf.winh
;
4219 src#
int "scroll handle height"
4220 (fun () -> conf.scrollh
)
4221 (fun v -> conf.scrollh
<- v;);
4223 src#
int "thumbnail width"
4224 (fun () -> conf.thumbw
)
4226 conf.thumbw
<- min
4096 v;
4229 leavebirdseye beye
false;
4234 let mode = state.mode in
4235 src#
string "columns"
4237 match conf.columns
with
4239 | Cmulti
(multi
, _) -> multicolumns_to_string multi
4240 | Csplit
(count
, _) -> "-" ^ string_of_int count
4243 let n, a, b = multicolumns_of_string v in
4244 setcolumns mode n a b);
4247 src#caption
"Presentation mode" 0;
4248 src#
bool "scrollbar visible"
4249 (fun () -> conf.scrollbarinpm
)
4251 if v != conf.scrollbarinpm
4253 conf.scrollbarinpm
<- v;
4254 if conf.presentation
4256 state.scrollw
<- if v then conf.scrollbw
else 0;
4257 reshape conf.winw
conf.winh
;
4263 src#caption
"Pixmap cache" 0;
4264 src#int_with_suffix
"size (advisory)"
4265 (fun () -> conf.memlimit
)
4266 (fun v -> conf.memlimit
<- v);
4269 (fun () -> Printf.sprintf
"%s bytes, %d tiles"
4270 (string_with_suffix_of_int state.memused
)
4271 (Hashtbl.length
state.tilemap
)) 1;
4274 src#caption
"Layout" 0;
4275 src#caption2
"Dimension"
4277 Printf.sprintf
"%dx%d (virtual %dx%d)"
4283 src#caption2
"Position" (fun () ->
4284 Printf.sprintf
"%dx%d" state.x state.y
4287 src#caption2
"Visible" (fun () -> describe_location ()) 1
4291 src#
bool ~offset
:0 ~
btos:(fun v -> if v then "(on)" else "(off)")
4292 "Save these parameters as global defaults at exit"
4293 (fun () -> conf.bedefault
)
4294 (fun v -> conf.bedefault
<- v)
4298 let btos b = if b then "\xc2\xab" else "\xc2\xbb" in
4299 src#
bool ~offset
:0 ~
btos "Extended parameters"
4300 (fun () -> !showextended)
4301 (fun v -> showextended := v; fillsrc prevmode prevuioh
);
4305 (fun () -> conf.checkers
)
4306 (fun v -> conf.checkers
<- v; setcheckers v);
4307 src#
bool "update cursor"
4308 (fun () -> conf.updatecurs
)
4309 (fun v -> conf.updatecurs
<- v);
4311 (fun () -> conf.verbose
)
4312 (fun v -> conf.verbose
<- v);
4313 src#
bool "full split"
4314 (fun () -> conf.fullsplit
)
4315 (fun v -> conf.fullsplit
<- v; gotoy state.y);
4316 src#
bool "invert colors"
4317 (fun () -> conf.invert
)
4318 (fun v -> conf.invert
<- v);
4320 (fun () -> conf.maxhfit
)
4321 (fun v -> conf.maxhfit
<- v);
4322 src#
bool "redirect stderr"
4323 (fun () -> conf.redirectstderr)
4324 (fun v -> conf.redirectstderr <- v; redirectstderr ());
4325 src#
string "uri launcher"
4326 (fun () -> conf.urilauncher
)
4327 (fun v -> conf.urilauncher
<- v);
4328 src#
string "path launcher"
4329 (fun () -> conf.pathlauncher
)
4330 (fun v -> conf.pathlauncher
<- v);
4331 src#
string "tile size"
4332 (fun () -> Printf.sprintf
"%dx%d" conf.tilew
conf.tileh
)
4335 let w, h = Scanf.sscanf
v "%dx%d" (fun w h -> w, h) in
4336 conf.tilew
<- max
64 w;
4337 conf.tileh
<- max
64 h;
4340 state.text <- Printf.sprintf
"bad tile size `%s': %s"
4341 v (Printexc.to_string exn
));
4342 src#
int "texture count"
4343 (fun () -> conf.texcount
)
4346 then conf.texcount
<- v
4347 else showtext '
!'
" Failed to set texture count please retry later"
4349 src#
int "slice height"
4350 (fun () -> conf.sliceheight
)
4352 conf.sliceheight
<- v;
4353 wcmd "sliceh %d" conf.sliceheight
;
4355 src#
int "anti-aliasing level"
4356 (fun () -> conf.aalevel
)
4358 conf.aalevel
<- bound v 0 8;
4359 state.anchor <- getanchor ();
4360 opendoc state.path
state.password
;
4362 src#
int "ui font size"
4363 (fun () -> fstate.fontsize
)
4364 (fun v -> setfontsize (bound v 5 100));
4365 src#
int "hint font size"
4366 (fun () -> conf.hfsize
)
4367 (fun v -> conf.hfsize
<- bound v 5 100);
4368 colorp "background color"
4369 (fun () -> conf.bgcolor
)
4370 (fun v -> conf.bgcolor
<- v);
4371 src#
bool "crop hack"
4372 (fun () -> conf.crophack
)
4373 (fun v -> conf.crophack
<- v);
4374 src#
string "trim fuzz"
4375 (fun () -> irect_to_string conf.trimfuzz
)
4378 conf.trimfuzz
<- irect_of_string v;
4380 then settrim true conf.trimfuzz
;
4382 state.text <- Printf.sprintf
"bad irect `%s': %s"
4383 v (Printexc.to_string exn
)
4385 src#
string "throttle"
4387 match conf.maxwait
with
4388 | None
-> "show place holder if page is not ready"
4391 then "wait for page to fully render"
4393 "wait " ^ string_of_float
time
4394 ^
" seconds before showing placeholder"
4398 let f = float_of_string
v in
4400 then conf.maxwait
<- None
4401 else conf.maxwait
<- Some
f
4403 state.text <- Printf.sprintf
"bad time `%s': %s"
4404 v (Printexc.to_string exn
)
4406 src#
string "ghyll scroll"
4408 match conf.ghyllscroll
with
4410 | Some nab
-> ghyllscroll_to_string nab
4415 if String.length
v = 0
4417 else Some
(ghyllscroll_of_string v)
4419 conf.ghyllscroll
<- gs
4421 state.text <- Printf.sprintf
"bad ghyll `%s': %s"
4422 v (Printexc.to_string exn
)
4424 src#
string "selection command"
4425 (fun () -> conf.selcmd
)
4426 (fun v -> conf.selcmd
<- v);
4427 src#colorspace
"color space"
4428 (fun () -> colorspace_to_string conf.colorspace
)
4430 conf.colorspace
<- colorspace_of_int v;
4437 src#caption
"Document" 0;
4438 List.iter
(fun (_, s) -> src#caption
s 1) state.docinfo
;
4439 src#caption2
"Pages"
4440 (fun () -> string_of_int
state.pagecount
) 1;
4441 src#caption2
"Dimensions"
4442 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4446 src#caption
"Trimmed margins" 0;
4447 src#caption2
"Dimensions"
4448 (fun () -> string_of_int
(List.length
state.pdims
)) 1;
4451 src#reset prevmode prevuioh
;
4455 let prevmode = state.mode
4456 and prevuioh
= state.uioh in
4457 fillsrc prevmode prevuioh
;
4458 let source = (src :> lvsource
) in
4459 let modehash = findkeyhash conf "info" in
4460 state.uioh <- coe (object (self)
4461 inherit listview ~
source ~trusted
:true ~
modehash as super
4462 val mutable m_prevmemused
= 0
4463 method infochanged
= function
4465 if m_prevmemused
!= state.memused
4467 m_prevmemused
<- state.memused
;
4468 G.postRedisplay "memusedchanged";
4470 | Pdim
-> G.postRedisplay "pdimchanged"
4471 | Docinfo
-> fillsrc prevmode prevuioh
4473 method key key mask
=
4474 if not
(Wsi.withctrl mask
)
4477 | 0xff51 -> coe (self#updownlevel ~
-1)
4478 | 0xff53 -> coe (self#updownlevel
1)
4479 | _ -> super#
key key mask
4480 else super#
key key mask
4482 G.postRedisplay "info";
4488 inherit lvsourcebase
4489 method getitemcount
= Array.length
state.help
4491 let s, n, _ = state.help
.(n) in
4494 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4498 m_qsearch
<- qsearch;
4499 match state.help
.(active) with
4500 | _, _, Action
f -> Some
(f uioh)
4510 method hasaction
n =
4511 match state.help
.(n) with
4512 | _, _, Action
_ -> true
4519 let modehash = findkeyhash conf "help" in
4520 state.uioh <- coe (new listview ~
source ~trusted
:true ~
modehash);
4521 G.postRedisplay "help";
4526 let re = Str.regexp
"[\r\n]" in
4528 inherit lvsourcebase
4529 val mutable m_items
= [||]
4531 method getitemcount
= 1 + Array.length m_items
4536 else m_items
.(n-1), 0
4538 method exit ~
uioh ~cancel ~
active ~
first ~pan ~
qsearch =
4543 then Buffer.clear
state.errmsgs
;
4544 m_qsearch
<- qsearch;
4551 method hasaction
n =
4555 state.newerrmsgs
<- false;
4556 let l = Str.split
re (Buffer.contents
state.errmsgs
) in
4557 m_items
<- Array.of_list
l
4565 let source = (msgsource :> lvsource
) in
4566 let modehash = findkeyhash conf "listview" in
4567 state.uioh <- coe (object
4568 inherit listview ~
source ~trusted
:false ~
modehash as super
4571 then msgsource#reset
;
4574 G.postRedisplay "msgs";
4577 let quickbookmark ?title
() =
4578 match state.layout with
4584 let sec = Unix.gettimeofday
() in
4585 let tm = Unix.localtime
sec in
4586 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
4590 (tm.Unix.tm_year
+ 1900)
4593 | Some
title -> title
4596 (title, 0, (l.pageno, float l.pagey /. float l.pageh
))
4601 state.fullscreen
<- None
;
4605 let setautoscrollspeed step goingdown
=
4606 let incr = max
1 ((abs step
) / 2) in
4607 let incr = if goingdown
then incr else -incr in
4608 let astep = step
+ incr in
4609 state.autoscroll
<- Some
astep;
4612 let gotounder = function
4613 | Ulinkgoto
(pageno, top) ->
4617 gotopage1 pageno top;
4623 | Uremote
(filename
, pageno) ->
4625 if Sys.file_exists filename
4628 let dir = Filename.dirname
state.path in
4629 let path = Filename.concat
dir filename
in
4630 if Sys.file_exists
path
4634 if String.length
path > 0
4636 let anchor = getanchor () in
4637 let ranchor = state.path, state.password
, anchor in
4638 state.anchor <- (pageno, 0.0);
4639 state.ranchors
<- ranchor :: state.ranchors
;
4642 else showtext '
!'
("Could not find " ^ filename
)
4644 | Uunexpected
_ | Ulaunch
_ | Unamed
_ | Utext
_ | Unone
-> ()
4648 match conf.columns
with
4650 | _ -> conf.zoom > 1.0
4653 let viewkeyboard key mask
=
4655 let mode = state.mode in
4656 state.mode <- Textentry
(te, fun _ -> state.mode <- mode);
4659 G.postRedisplay "view:enttext"
4661 let ctrl = Wsi.withctrl mask
in
4666 | 0xff63 -> (* insert *)
4667 if conf.angle
mod 360 = 0
4669 state.mode <- LinkNav
(Ltgendir
0);
4672 else showtext '
!'
"Keyboard link naviagtion does not work under rotation"
4674 | 0xff1b | 113 -> (* escape / q *)
4675 begin match state.mstate
with
4677 state.mstate
<- Mnone
;
4678 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
4679 G.postRedisplay "kill zoom rect";
4681 match state.ranchors
with
4683 | (path, password
, anchor) :: rest
->
4684 state.ranchors
<- rest
;
4685 state.anchor <- anchor;
4686 opendoc path password
4689 | 0xff08 -> (* backspace *)
4690 let y = getnav ~
-1 in
4691 gotoy_and_clear_text y
4699 G.postRedisplay "dehighlight";
4701 | 47 | 63 -> (* / ? *)
4702 let ondone isforw
s =
4703 cbput state.hists
.pat
s;
4704 state.searchpattern
<- s;
4707 let s = String.create
1 in
4708 s.[0] <- Char.chr
key;
4709 enttext (s, "", Some
(onhist state.hists
.pat
),
4710 textentry, ondone (key = 47), true)
4712 | 43 | 0xffab when ctrl -> (* ctrl-+ *)
4713 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
4714 setzoom (conf.zoom +. incr)
4716 | 43 | 0xffab -> (* + *)
4719 try int_of_string
s with exc
->
4720 state.text <- Printf.sprintf
"bad integer `%s': %s"
4721 s (Printexc.to_string exc
);
4727 state.text <- "page bias is now " ^ string_of_int
n;
4730 enttext ("page bias: ", "", None
, intentry, ondone, true)
4732 | 45 | 0xffad when ctrl -> (* ctrl-- *)
4733 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
4734 setzoom (max
0.01 (conf.zoom -. decr))
4736 | 45 | 0xffad -> (* - *)
4737 let ondone msg
= state.text <- msg
in
4739 "option [acfhilpstvxACFPRSZTIS]: ", "", None
,
4740 optentry state.mode, ondone, true
4743 | 48 when ctrl -> (* ctrl-0 *)
4746 | 49 when ctrl -> (* 1 *)
4747 let zoom = zoomforh
conf.winw
conf.winh
state.scrollw
in
4751 | 0xffc6 -> (* f9 *)
4754 | 57 when ctrl -> (* ctrl-9 *)
4757 | (48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57)
4758 when not
ctrl -> (* 0..9 *)
4761 try int_of_string
s with exc
->
4762 state.text <- Printf.sprintf
"bad integer `%s': %s"
4763 s (Printexc.to_string exc
);
4769 cbput state.hists
.pag
(string_of_int
n);
4770 gotopage1 (n + conf.pagebias
- 1) 0;
4773 let pageentry text key =
4774 match Char.unsafe_chr
key with
4775 | 'g'
-> TEdone
text
4776 | _ -> intentry text key
4778 let text = "x" in text.[0] <- Char.chr
key;
4779 enttext (":", text, Some
(onhist state.hists
.pag
), pageentry, ondone, true)
4782 state.scrollw
<- if state.scrollw
> 0 then 0 else conf.scrollbw
;
4783 reshape conf.winw
conf.winh
;
4786 conf.hlinks
<- not
conf.hlinks
;
4787 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
4788 G.postRedisplay "toggle highlightlinks";
4791 state.glinks
<- true;
4792 let mode = state.mode in
4793 state.mode <- Textentry
(
4794 (":", "", None
, linknentry, linkndone (fun under ->
4799 state.glinks
<- false;
4803 G.postRedisplay "view:linkent(F)"
4806 state.glinks
<- true;
4807 let mode = state.mode in
4808 state.mode <- Textentry
(
4809 (":", "", None
, linknentry, linkndone (fun under ->
4810 match Ne.pipe () with
4812 showtext '
!'
(Printf.sprintf
"pipe failed: %s"
4813 (Printexc.to_string exn
));
4816 try popen conf.selcmd
[r, 0; w, -1]; true
4819 (Printf.sprintf
"failed to execute %s: %s"
4820 conf.selcmd
(Printexc.to_string exn
));
4824 Ne.clo fd
(fun msg
->
4825 showtext '
!'
(Printf.sprintf
"failed to close %s: %s" cap msg
)
4828 let s = undertext under in
4832 let l = String.length
s in
4833 let n = Unix.write
w s 0 l in
4838 "failed to write %d characters to sel pipe, wrote %d"
4843 (Printf.sprintf
"failed to write to sel pipe: %s"
4844 (Printexc.to_string exn
)
4853 state.glinks
<- false;
4857 G.postRedisplay "view:linkent"
4860 begin match state.autoscroll
with
4862 conf.autoscrollstep
<- step
;
4863 state.autoscroll
<- None
4865 if conf.autoscrollstep
= 0
4866 then state.autoscroll
<- Some
1
4867 else state.autoscroll
<- Some
conf.autoscrollstep
4870 | 112 when ctrl -> (* ctrl-p *)
4874 conf.presentation <- not
conf.presentation;
4875 if conf.presentation
4877 if not
conf.scrollbarinpm
4878 then state.scrollw
<- 0;
4881 state.scrollw
<- conf.scrollbw
;
4883 showtext ' '
("presentation mode " ^
4884 if conf.presentation then "on" else "off");
4885 state.anchor <- getanchor ();
4889 begin match state.fullscreen
with
4891 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
4894 state.fullscreen
<- None
;
4899 gotoy_and_clear_text 0
4902 gotopage1 (state.pagecount
- 1) 0
4904 | 112 | 78 -> (* p|N *)
4905 search state.searchpattern
false
4907 | 110 | 0xffc0 -> (* n|F3 *)
4908 search state.searchpattern
true
4911 begin match state.layout with
4914 gotoy_and_clear_text (getpagey l.pageno)
4918 begin match List.rev
state.layout with
4921 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
4922 gotoy_and_clear_text (getpagey pageno)
4925 | 0xff9f | 0xffff -> (* delete *)
4926 begin match state.layout with
4929 let pageno = max
0 (l.pageno-1) in
4930 gotoy_and_clear_text (getpagey pageno)
4934 showtext ' '
(describe_location ());
4937 begin match state.layout with
4940 doreshape (l.pagew
+ state.scrollw
) l.pageh
;
4945 enterbookmarkmode ()
4947 | 104 | 0xffbe -> (* h|F1 *)
4953 | 101 when conf.redirectstderr -> (* e *)
4958 match state.layout with
4961 (s, 0, (l.pageno, float l.pagey /. float l.pageh
))
4965 enttext ("bookmark: ", "", None
, textentry, ondone, true)
4969 showtext ' '
"Quick bookmark added";
4972 begin match state.layout with
4974 let rect = getpdimrect
l.pagedimno
in
4978 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
4979 truncate
(1.2 *. (rect.(3) -. rect.(0))))
4981 (truncate
(rect.(1) -. rect.(0)),
4982 truncate
(rect.(3) -. rect.(0)))
4984 let w = truncate
((float w)*.conf.zoom)
4985 and h = truncate
((float h)*.conf.zoom) in
4988 state.anchor <- getanchor ();
4989 doreshape (w + state.scrollw
) (h + conf.interpagespace)
4991 G.postRedisplay "z";
4996 | 50 when ctrl -> (* ctrl-2 *)
4997 let maxw = getmaxw
() in
4999 then setzoom (maxw /. float conf.winw
)
5001 | 60 | 62 -> (* < > *)
5002 reqlayout (conf.angle
+ (if key = 62 then 30 else -30)) conf.proportional
5004 | 91 | 93 -> (* [ ] *)
5006 bound (conf.colorscale
+. (if key = 93 then 0.1 else -0.1)) 0.0 1.0
5008 G.postRedisplay "brightness";
5010 | 0xff54 | 0xff52 when ctrl && Wsi.withshift mask
->
5011 setzoom state.prevzoom
5013 | 107 | 0xff52 -> (* k up *)
5014 begin match state.autoscroll
with
5016 begin match state.mode with
5017 | Birdseye beye
-> upbirdseye 1 beye
5020 then gotoy_and_clear_text (clamp ~
-(conf.winh
/2))
5021 else gotoy_and_clear_text (clamp (-conf.scrollstep
))
5024 setautoscrollspeed n false
5027 | 106 | 0xff54 -> (* j down *)
5028 begin match state.autoscroll
with
5030 begin match state.mode with
5031 | Birdseye beye
-> downbirdseye 1 beye
5034 then gotoy_and_clear_text (clamp (conf.winh
/2))
5035 else gotoy_and_clear_text (clamp conf.scrollstep
)
5038 setautoscrollspeed n true
5041 | 0xff51 | 0xff53 when not
(Wsi.withalt mask
) -> (* left / right *)
5049 let dx = if key = 0xff51 then dx else -dx in
5050 state.x <- state.x + dx;
5051 gotoy_and_clear_text state.y
5054 G.postRedisplay "lef/right"
5057 | 0xff55 -> (* prior *)
5061 match state.layout with
5063 | l :: _ -> state.y - l.pagey
5069 | 0xff56 -> (* next *)
5073 match List.rev
state.layout with
5075 | l :: _ -> getpagey l.pageno
5081 | 0xff50 -> gotoghyll 0
5082 | 0xff57 -> gotoghyll (clamp state.maxy)
5083 | 0xff53 when Wsi.withalt mask
->
5084 gotoghyll (getnav ~
-1)
5085 | 0xff51 when Wsi.withalt mask
->
5086 gotoghyll (getnav 1)
5089 state.anchor <- getanchor ();
5090 opendoc state.path state.password
5092 | 118 when conf.debug
-> (* v *)
5095 match getopaque l.pageno with
5098 let x0, y0, x1, y1 = pagebbox opaque
in
5099 let a,b = float x0, float y0 in
5100 let c,d = float x1, float y0 in
5101 let e,f = float x1, float y1 in
5102 let h,j
= float x0, float y1 in
5103 let rect = (a,b,c,d,e,f,h,j
) in
5105 state.rects
<- (l.pageno, l.pageno mod 3, rect) :: state.rects
;
5107 G.postRedisplay "v";
5110 vlog "huh? %s" (Wsi.keyname
key)
5113 let linknavkeyboard key mask
linknav =
5114 let getpage pageno =
5115 let rec loop = function
5117 | l :: _ when l.pageno = pageno -> Some
l
5118 | _ :: rest
-> loop rest
5119 in loop state.layout
5121 let doexact (pageno, n) =
5122 match getopaque pageno, getpage pageno with
5123 | Some opaque
, Some
l ->
5126 let under = getlink opaque
n in
5127 G.postRedisplay "link gotounder";
5133 | 0xff50 -> (* home *)
5134 Some
(findlink opaque LDfirst
), -1
5136 | 0xff57 -> (* end *)
5137 Some
(findlink opaque LDlast
), 1
5139 | 0xff51 -> (* left *)
5140 Some
(findlink opaque
(LDleft
n)), -1
5142 | 0xff53 -> (* right *)
5143 Some
(findlink opaque
(LDright
n)), 1
5145 | 0xff52 -> (* up *)
5146 Some
(findlink opaque
(LDup
n)), -1
5148 | 0xff54 -> (* down *)
5149 Some
(findlink opaque
(LDdown
n)), 1
5154 begin match findpwl
l.pageno dir with
5158 state.mode <- LinkNav
(Ltgendir
dir);
5159 let y, h = getpageyh pageno in
5162 then y + h - conf.winh
5167 begin match getopaque pageno, getpage pageno with
5168 | Some opaque
, Some
_ ->
5170 let ld = if dir > 0 then LDfirst
else LDlast
in
5173 begin match link with
5175 showlinktype (getlink opaque
m);
5176 state.mode <- LinkNav
(Ltexact
(pageno, m));
5177 G.postRedisplay "linknav jpage";
5184 begin match opt with
5185 | Some Lnotfound
-> pwl l dir;
5186 | Some
(Lfound
m) ->
5190 let _, y0, _, y1 = getlinkrect opaque
m in
5192 then gotopage1 l.pageno y0
5194 let d = fstate.fontsize
+ 1 in
5195 if y1 - l.pagey > l.pagevh - d
5196 then gotopage1 l.pageno (y1 - conf.winh
- state.hscrollh + d)
5197 else G.postRedisplay "linknav";
5199 showlinktype (getlink opaque
m);
5200 state.mode <- LinkNav
(Ltexact
(l.pageno, m));
5203 | None
-> viewkeyboard key mask
5205 | _ -> viewkeyboard key mask
5210 G.postRedisplay "leave linknav"
5214 | Ltgendir
_ -> viewkeyboard key mask
5215 | Ltexact exact
-> doexact exact
5218 let keyboard key mask
=
5219 if (key = 103 && Wsi.withctrl mask
) && not
(istextentry state.mode)
5220 then wcmd "interrupt"
5221 else state.uioh <- state.uioh#
key key mask
5224 let birdseyekeyboard key mask
5225 ((oconf
, leftx
, pageno, hooverpageno
, anchor) as beye
) =
5227 match conf.columns
with
5229 | Cmulti
((c, _, _), _) -> c
5230 | Csplit
_ -> failwith
"bird's eye split mode"
5233 | 108 when Wsi.withctrl mask
-> (* ctrl-l *)
5234 let y, h = getpageyh pageno in
5235 let top = (conf.winh
- h) / 2 in
5236 gotoy (max
0 (y - top))
5237 | 0xff0d -> leavebirdseye beye
false
5238 | 0xff1b -> leavebirdseye beye
true (* escape *)
5239 | 0xff52 -> upbirdseye incr beye
(* prior *)
5240 | 0xff54 -> downbirdseye incr beye
(* next *)
5241 | 0xff51 -> upbirdseye 1 beye
(* up *)
5242 | 0xff53 -> downbirdseye 1 beye
(* down *)
5245 begin match state.layout with
5249 state.mode <- Birdseye
(
5250 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5252 gotopage1 l.pageno 0;
5255 let layout = layout (state.y-conf.winh
) conf.winh
in
5257 | [] -> gotoy (clamp (-conf.winh
))
5259 state.mode <- Birdseye
(
5260 oconf
, leftx
, l.pageno, hooverpageno
, anchor
5262 gotopage1 l.pageno 0
5265 | [] -> gotoy (clamp (-conf.winh
))
5269 begin match List.rev
state.layout with
5271 let layout = layout (state.y + conf.winh
) conf.winh
in
5272 begin match layout with
5274 let incr = l.pageh
- l.pagevh in
5279 oconf
, leftx
, state.pagecount
- 1, hooverpageno
, anchor
5281 G.postRedisplay "birdseye pagedown";
5283 else gotoy (clamp (incr + conf.interpagespace*2));
5287 Birdseye
(oconf
, leftx
, l.pageno, hooverpageno
, anchor);
5288 gotopage1 l.pageno 0;
5291 | [] -> gotoy (clamp conf.winh
)
5295 state.mode <- Birdseye
(oconf
, leftx
, 0, hooverpageno
, anchor);
5299 let pageno = state.pagecount
- 1 in
5300 state.mode <- Birdseye
(oconf
, leftx
, pageno, hooverpageno
, anchor);
5301 if not
(pagevisible state.layout pageno)
5304 match List.rev
state.pdims
with
5306 | (_, _, h, _) :: _ -> h
5308 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
5309 else G.postRedisplay "birdseye end";
5310 | _ -> viewkeyboard key mask
5313 let drawpage l linkindexbase
=
5315 match state.mode with
5316 | Textentry
_ -> scalecolor 0.4
5318 | View
-> scalecolor 1.0
5319 | Birdseye
(_, _, pageno, hooverpageno
, _) ->
5320 if l.pageno = hooverpageno
5323 if l.pageno = pageno
5329 begin match getopaque l.pageno with
5331 if tileready l l.pagex l.pagey
5333 let x = l.pagedispx - l.pagex
5334 and y = l.pagedispy - l.pagey in
5335 let hlmask = (if conf.hlinks
then 1 else 0)
5336 + (if state.glinks
&& not
(isbirdseye state.mode) then 2 else 0)
5339 match state.mode with
5340 | Textentry
((_, s, _, _, _, _), _) when state.glinks
-> s
5343 postprocess opaque
hlmask x y (linkindexbase
, s, conf.hfsize
);
5350 let scrollindicator () =
5351 let sbw, ph
, sh = state.uioh#
scrollph in
5352 let sbh, pw, sw = state.uioh#scrollpw
in
5354 GlDraw.color (0.64, 0.64, 0.64);
5356 (float (conf.winw
- sbw), 0.)
5357 (float conf.winw
, float conf.winh
)
5360 (0., float (conf.winh
- sbh))
5361 (float (conf.winw
- state.scrollw
- 1), float conf.winh
)
5363 GlDraw.color (0.0, 0.0, 0.0);
5366 (float (conf.winw
- sbw), ph
)
5367 (float conf.winw
, ph
+. sh)
5370 (pw, float (conf.winh
- sbh))
5371 (pw +. sw, float conf.winh
)
5376 match state.mstate
with
5377 | Mnone
| Mscrolly
| Mscrollx
| Mpan
_ | Mzoom
_ | Mzoomrect
_ ->
5380 | Msel
((x0, y0), (x1, y1)) ->
5381 let rec loop = function
5383 if ((y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5384 || ((y1 >= l.pagedispy && y1 <= (l.pagedispy + l.pagevh))))
5385 && ((x0 >= l.pagedispx && x0 <= (l.pagedispx + l.pagevw))
5386 || ((x1 >= l.pagedispx && x1 <= (l.pagedispx + l.pagevw))))
5388 match getopaque l.pageno with
5390 let x0, y0 = pagetranslatepoint l x0 y0 in
5391 let x1, y1 = pagetranslatepoint l x1 y1 in
5392 seltext opaque
(x0, y0, x1, y1);
5400 let showrects rects
=
5402 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
5403 GlDraw.polygon_mode `both `fill
;
5404 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5406 (fun (pageno, c, (x0, y0, x1, y1, x2
, y2
, x3
, y3
)) ->
5408 if l.pageno = pageno
5410 let dx = float (l.pagedispx - l.pagex) in
5411 let dy = float (l.pagedispy - l.pagey) in
5412 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
5413 GlDraw.begins `quads
;
5415 GlDraw.vertex2
(x0+.dx, y0+.dy);
5416 GlDraw.vertex2
(x1+.dx, y1+.dy);
5417 GlDraw.vertex2
(x2
+.dx, y2
+.dy);
5418 GlDraw.vertex2
(x3
+.dx, y3
+.dy);
5429 GlClear.color (scalecolor2 conf.bgcolor
);
5430 GlClear.clear
[`
color];
5431 let rec loop linkindexbase
= function
5433 let linkindexbase = linkindexbase + drawpage l linkindexbase in
5434 loop linkindexbase rest
5437 loop 0 state.layout;
5439 match state.mode with
5440 | LinkNav
(Ltexact
(pageno, linkno
)) ->
5441 begin match getopaque pageno with
5443 let x0, y0, x1, y1 = getlinkrect opaque linkno
in
5450 | None
-> state.rects
5457 begin match state.mstate
with
5458 | Mzoomrect
((x0, y0), (x1, y1)) ->
5460 GlDraw.color (0.3, 0.3, 0.3) ~alpha
:0.5;
5461 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
5462 GlDraw.rect (float x0, float y0)
5463 (float x1, float y1);
5472 let zoomrect x y x1 y1 =
5475 and y0 = min
y y1 in
5476 gotoy (state.y + y0);
5477 state.anchor <- getanchor ();
5478 let zoom = (float conf.winw
*. conf.zoom) /. float (x1 - x0) in
5480 if state.w < conf.winw
- state.scrollw
5481 then (conf.winw
- state.scrollw
- state.w) / 2
5484 state.x <- (state.x + margin) - x0;
5486 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5487 state.mstate
<- Mnone
;
5491 let winw = conf.winw - state.scrollw
- 1 in
5492 let s = float x /. float winw in
5493 let destx = truncate
(float (state.w + winw) *. s) in
5494 state.x <- winw - destx;
5495 gotoy_and_clear_text state.y;
5496 state.mstate
<- Mscrollx
;
5500 let s = float y /. float conf.winh
in
5501 let desty = truncate
(float (state.maxy - conf.winh
) *. s) in
5502 gotoy_and_clear_text desty;
5503 state.mstate
<- Mscrolly
;
5506 let viewmouse button down
x y mask
=
5508 | n when (n == 4 || n == 5) && not down
->
5509 if Wsi.withctrl mask
5511 match state.mstate
with
5512 | Mzoom
(oldn
, i
) ->
5520 if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01
5522 if conf.zoom -. 0.1 < 0.1 then -0.01 else -0.1
5524 let zoom = conf.zoom -. incr in
5526 state.mstate
<- Mzoom
(n, 0);
5528 state.mstate
<- Mzoom
(n, i
+1);
5530 else state.mstate
<- Mzoom
(n, 0)
5532 | _ -> state.mstate
<- Mzoom
(n, 0)
5535 match state.autoscroll
with
5536 | Some step
-> setautoscrollspeed step
(n=4)
5540 then -conf.scrollstep
5541 else conf.scrollstep
5543 let incr = incr * 2 in
5544 let y = clamp incr in
5545 gotoy_and_clear_text y
5548 | 1 when Wsi.withctrl mask
->
5551 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5552 state.mstate
<- Mpan
(x, y)
5555 state.mstate
<- Mnone
5560 Wsi.setcursor
Wsi.CURSOR_CYCLE
;
5562 state.mstate
<- Mzoomrect
(p, p)
5565 match state.mstate
with
5566 | Mzoomrect
((x0, y0), _) ->
5567 if abs
(x-x0) > 10 && abs
(y - y0) > 10
5568 then zoomrect x0 y0 x y
5570 state.mstate
<- Mnone
;
5571 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5572 G.postRedisplay "kill accidental zoom rect";
5575 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5576 state.mstate
<- Mnone
5579 | 1 when x > conf.winw - state.scrollw
->
5582 let _, position, sh = state.uioh#
scrollph in
5583 if y > truncate
position && y < truncate
(position +. sh)
5584 then state.mstate
<- Mscrolly
5587 state.mstate
<- Mnone
5589 | 1 when y > conf.winh
- state.hscrollh ->
5592 let _, position, sw = state.uioh#scrollpw
in
5593 if x > truncate
position && x < truncate
(position +. sw)
5594 then state.mstate
<- Mscrollx
5597 state.mstate
<- Mnone
5600 let dest = if down
then getunder x y else Unone
in
5601 begin match dest with
5605 | Uunexpected
_ | Ulaunch
_ | Unamed
_ ->
5608 | Unone
when down
->
5609 Wsi.setcursor
Wsi.CURSOR_CROSSHAIR
;
5610 state.mstate
<- Mpan
(x, y);
5612 | Unone
| Utext
_ ->
5615 if conf.angle
mod 360 = 0
5617 state.mstate
<- Msel
((x, y), (x, y));
5618 G.postRedisplay "mouse select";
5622 match state.mstate
with
5625 | Mzoom
_ | Mscrollx
| Mscrolly
->
5626 state.mstate
<- Mnone
5628 | Mzoomrect
((x0, y0), _) ->
5632 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5633 state.mstate
<- Mnone
5635 | Msel
((_, y0), (_, y1)) ->
5636 let rec loop = function
5639 if (y0 >= l.pagedispy && y0 <= (l.pagedispy + l.pagevh))
5640 || ((y1 >= l.pagedispy
5641 && y1 <= (l.pagedispy + l.pagevh)))
5643 match getopaque l.pageno with
5646 match Ne.pipe () with
5650 "can not create sel pipe: %s"
5651 (Printexc.to_string exn
));
5653 let doclose what fd
=
5654 Ne.clo fd
(fun msg
->
5655 dolog "%s close failed: %s" what msg
)
5658 popen conf.selcmd
[r, 0; w, -1];
5661 G.postRedisplay "copysel";
5663 dolog "can not exectute %S: %s"
5664 conf.selcmd
(Printexc.to_string exn
);
5672 Wsi.setcursor
Wsi.CURSOR_INHERIT
;
5673 state.mstate
<- Mnone
;
5680 let birdseyemouse button down
x y mask
5681 (conf, leftx
, _, hooverpageno
, anchor) =
5684 let rec loop = function
5687 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5688 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5690 leavebirdseye (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
5696 | _ -> viewmouse button down
x y mask
5699 let mouse button down
x y mask
=
5700 state.uioh <- state.uioh#button button down
x y mask
;
5704 state.uioh <- state.uioh#
motion x y
5708 state.uioh <- state.uioh#
pmotion x y;
5714 method key key mask
=
5715 begin match state.mode with
5716 | Textentry
textentry -> textentrykeyboard key mask
textentry
5717 | Birdseye
birdseye -> birdseyekeyboard key mask
birdseye
5718 | View
-> viewkeyboard key mask
5719 | LinkNav
linknav -> linknavkeyboard key mask
linknav
5723 method button button bstate
x y mask
=
5724 begin match state.mode with
5726 | View
-> viewmouse button bstate
x y mask
5727 | Birdseye beye
-> birdseyemouse button bstate
x y mask beye
5733 begin match state.mode with
5735 | View
| Birdseye
_ | LinkNav
_ ->
5736 match state.mstate
with
5737 | Mzoom
_ | Mnone
-> ()
5742 state.mstate
<- Mpan
(x, y);
5744 then state.x <- state.x + dx;
5746 gotoy_and_clear_text y
5749 state.mstate
<- Msel
(a, (x, y));
5750 G.postRedisplay "motion select";
5753 let y = min
conf.winh
(max
0 y) in
5757 let x = min
conf.winw (max
0 x) in
5760 | Mzoomrect
(p0
, _) ->
5761 state.mstate
<- Mzoomrect
(p0
, (x, y));
5762 G.postRedisplay "motion zoomrect";
5766 method pmotion x y =
5767 begin match state.mode with
5768 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
5769 let rec loop = function
5771 if hooverpageno
!= -1
5773 state.mode <- Birdseye
(conf, leftx
, pageno, -1, anchor);
5774 G.postRedisplay "pmotion birdseye no hoover";
5777 if y > l.pagedispy && y < l.pagedispy + l.pagevh
5778 && x > l.pagedispx && x < l.pagedispx + l.pagevw
5780 state.mode <- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
5781 G.postRedisplay "pmotion birdseye hoover";
5791 match state.mstate
with
5792 | Mnone
-> updateunder x y
5793 | Mpan
_ | Msel
_ | Mzoom
_ | Mscrolly
| Mscrollx
| Mzoomrect
_ ->
5798 method infochanged
_ = ()
5801 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
5802 let p, h = scrollph state.y maxy in
5806 let winw = conf.winw - state.scrollw
- 1 in
5807 let fwinw = float winw in
5809 let sw = fwinw /. float state.w in
5810 let sw = fwinw *. sw in
5811 max
sw (float conf.scrollh
)
5814 let f = state.w+winw in
5815 let r = float (winw-state.x) /. float f in
5816 let p = fwinw *. r in
5820 if position +. sw > fwinw
5821 then fwinw -. position
5824 state.hscrollh, position, sw
5828 match state.mode with
5829 | LinkNav
_ -> "links"
5830 | Textentry
_ -> "textentry"
5831 | Birdseye
_ -> "birdseye"
5834 findkeyhash conf modename
5841 let fontpath = ref "";;
5844 Map.Make
(struct type t
= (int * int) let compare = compare end);;
5847 let l = String.length
s in
5848 let b = Buffer.create
l in
5854 try Sys.getenv
"HOME"
5857 ("Can not determine home directory location: " ^
5858 Printexc.to_string exn
);
5862 let modifier_of_string = function
5863 | "alt" -> Wsi.altmask
5864 | "shift" -> Wsi.shiftmask
5865 | "ctrl" | "control" -> Wsi.ctrlmask
5866 | "meta" -> Wsi.metamask
5871 let r = Str.regexp
"-" in
5873 let elems = Str.full_split
r s in
5876 let m1 = modifier_of_string s in
5878 then (Wsi.namekey
s, m)
5881 | Str.Delim
s when n land 1 = 0 -> g s
5883 | Str.Delim
_ -> (k
, m)
5885 let rec loop n k
m = function
5888 let k, m = f n k m x in
5894 let keys_of_string =
5895 let r = Str.regexp
"[ \t]" in
5897 let elems = Str.split
r s in
5898 List.map
key_of_string elems
5901 let copykeyhashes c =
5902 List.map
(fun (k, v) -> k, Hashtbl.copy
v) c.keyhashes
;
5905 let config_of c attrs
=
5909 | "scroll-bar-width" -> { c with scrollbw
= max
0 (int_of_string
v) }
5910 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string
v) }
5911 | "case-insensitive-search" -> { c with icase
= bool_of_string
v }
5912 | "preload" -> { c with preload = bool_of_string
v }
5913 | "page-bias" -> { c with pagebias
= int_of_string
v }
5914 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string
v) }
5915 | "auto-scroll-step" ->
5916 { c with autoscrollstep
= max
0 (int_of_string
v) }
5917 | "max-height-fit" -> { c with maxhfit
= bool_of_string
v }
5918 | "crop-hack" -> { c with crophack
= bool_of_string
v }
5921 match String.lowercase
v with
5922 | "true" -> Some infinity
5924 | f -> Some
(float_of_string
f)
5926 { c with maxwait
= mw}
5927 | "highlight-links" -> { c with hlinks
= bool_of_string
v }
5928 | "under-cursor-info" -> { c with underinfo
= bool_of_string
v }
5929 | "vertical-margin" ->
5930 { c with interpagespace = max
0 (int_of_string
v) }
5932 let zoom = float_of_string
v /. 100. in
5933 let zoom = max
zoom 0.0 in
5934 { c with zoom = zoom }
5935 | "presentation" -> { c with presentation = bool_of_string
v }
5936 | "rotation-angle" -> { c with angle
= int_of_string
v }
5937 | "width" -> { c with winw = max
20 (int_of_string
v) }
5938 | "height" -> { c with winh
= max
20 (int_of_string
v) }
5939 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string
v }
5940 | "proportional-display" -> { c with proportional
= bool_of_string
v }
5941 | "pixmap-cache-size" ->
5942 { c with memlimit
= max
2 (int_of_string_with_suffix v) }
5943 | "tex-count" -> { c with texcount
= max
1 (int_of_string
v) }
5944 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string
v) }
5945 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string
v) }
5946 | "persistent-location" -> { c with jumpback
= bool_of_string
v }
5947 | "background-color" -> { c with bgcolor
= color_of_string v }
5948 | "scrollbar-in-presentation" ->
5949 { c with scrollbarinpm
= bool_of_string
v }
5950 | "tile-width" -> { c with tilew
= max
2 (int_of_string
v) }
5951 | "tile-height" -> { c with tileh
= max
2 (int_of_string
v) }
5952 | "mupdf-store-size" ->
5953 { c with mustoresize
= max
1024 (int_of_string_with_suffix v) }
5954 | "checkers" -> { c with checkers
= bool_of_string
v }
5955 | "aalevel" -> { c with aalevel
= max
0 (int_of_string
v) }
5956 | "trim-margins" -> { c with trimmargins
= bool_of_string
v }
5957 | "trim-fuzz" -> { c with trimfuzz
= irect_of_string v }
5958 | "uri-launcher" -> { c with urilauncher
= unent v }
5959 | "path-launcher" -> { c with pathlauncher
= unent v }
5960 | "color-space" -> { c with colorspace
= colorspace_of_string v }
5961 | "invert-colors" -> { c with invert
= bool_of_string
v }
5962 | "brightness" -> { c with colorscale
= float_of_string
v }
5963 | "redirectstderr" -> { c with redirectstderr = bool_of_string
v }
5965 { c with ghyllscroll
= Some
(ghyllscroll_of_string v) }
5967 let (n, _, _) as nab
= multicolumns_of_string v in
5969 then { c with columns
= Csplit
(-n, [||]) }
5970 else { c with columns
= Cmulti
(nab
, [||]) }
5971 | "birds-eye-columns" ->
5972 { c with beyecolumns
= Some
(max
(int_of_string
v) 2) }
5973 | "selection-command" -> { c with selcmd
= unent v }
5974 | "update-cursor" -> { c with updatecurs
= bool_of_string
v }
5975 | "hint-font-size" -> { c with hfsize
= bound (int_of_string
v) 5 100 }
5976 | "full-split" -> { c with fullsplit
= bool_of_string
v }
5979 prerr_endline
("Error processing attribute (`" ^
5980 k ^
"'=`" ^
v ^
"'): " ^
Printexc.to_string exn
);
5983 let rec fold c = function
5986 let c = apply c k v in
5989 fold { c with keyhashes
= copykeyhashes c } attrs
;
5992 let fromstring f pos
n v d =
5995 dolog "Error processing attribute (%S=%S) at %d\n%s"
5996 n v pos
(Printexc.to_string exn
)
6001 let bookmark_of attrs
=
6002 let rec fold title page
rely = function
6003 | ("title", v) :: rest
-> fold v page
rely rest
6004 | ("page", v) :: rest
-> fold title v rely rest
6005 | ("rely", v) :: rest
-> fold title page
v rest
6006 | _ :: rest
-> fold title page
rely rest
6007 | [] -> title, page
, rely
6009 fold "invalid" "0" "0" attrs
6013 let rec fold path page
rely pan
= function
6014 | ("path", v) :: rest
-> fold v page
rely pan rest
6015 | ("page", v) :: rest
-> fold path v rely pan rest
6016 | ("rely", v) :: rest
-> fold path page
v pan rest
6017 | ("pan", v) :: rest
-> fold path page
rely v rest
6018 | _ :: rest
-> fold path page
rely pan rest
6019 | [] -> path, page
, rely, pan
6021 fold "" "0" "0" "0" attrs
6025 let rec fold rs ls
= function
6026 | ("out", v) :: rest
-> fold v ls rest
6027 | ("in", v) :: rest
-> fold rs
v rest
6028 | _ :: rest
-> fold ls rs rest
6034 let setconf dst
src =
6035 dst
.scrollbw
<- src.scrollbw
;
6036 dst
.scrollh
<- src.scrollh
;
6037 dst
.icase
<- src.icase
;
6038 dst
.preload <- src.preload;
6039 dst
.pagebias
<- src.pagebias
;
6040 dst
.verbose
<- src.verbose
;
6041 dst
.scrollstep
<- src.scrollstep
;
6042 dst
.maxhfit
<- src.maxhfit
;
6043 dst
.crophack
<- src.crophack
;
6044 dst
.autoscrollstep
<- src.autoscrollstep
;
6045 dst
.maxwait
<- src.maxwait
;
6046 dst
.hlinks
<- src.hlinks
;
6047 dst
.underinfo
<- src.underinfo
;
6048 dst
.interpagespace <- src.interpagespace;
6049 dst
.zoom <- src.zoom;
6050 dst
.presentation <- src.presentation;
6051 dst
.angle
<- src.angle
;
6052 dst
.winw <- src.winw;
6053 dst
.winh
<- src.winh
;
6054 dst
.savebmarks
<- src.savebmarks
;
6055 dst
.memlimit
<- src.memlimit
;
6056 dst
.proportional
<- src.proportional
;
6057 dst
.texcount
<- src.texcount
;
6058 dst
.sliceheight
<- src.sliceheight
;
6059 dst
.thumbw
<- src.thumbw
;
6060 dst
.jumpback
<- src.jumpback
;
6061 dst
.bgcolor
<- src.bgcolor
;
6062 dst
.scrollbarinpm
<- src.scrollbarinpm
;
6063 dst
.tilew
<- src.tilew
;
6064 dst
.tileh
<- src.tileh
;
6065 dst
.mustoresize
<- src.mustoresize
;
6066 dst
.checkers
<- src.checkers
;
6067 dst
.aalevel
<- src.aalevel
;
6068 dst
.trimmargins
<- src.trimmargins
;
6069 dst
.trimfuzz
<- src.trimfuzz
;
6070 dst
.urilauncher
<- src.urilauncher
;
6071 dst
.colorspace
<- src.colorspace
;
6072 dst
.invert
<- src.invert
;
6073 dst
.colorscale
<- src.colorscale
;
6074 dst
.redirectstderr <- src.redirectstderr;
6075 dst
.ghyllscroll
<- src.ghyllscroll
;
6076 dst
.columns
<- src.columns
;
6077 dst
.beyecolumns
<- src.beyecolumns
;
6078 dst
.selcmd
<- src.selcmd
;
6079 dst
.updatecurs
<- src.updatecurs
;
6080 dst
.pathlauncher
<- src.pathlauncher
;
6081 dst
.keyhashes
<- copykeyhashes src;
6082 dst
.hfsize
<- src.hfsize
;
6083 dst
.fullsplit
<- src.fullsplit
;
6087 let h = Hashtbl.create
10 in
6088 let dc = { defconf with angle
= defconf.angle
} in
6089 let rec toplevel v t spos
_ =
6091 | Vdata
| Vcdata
| Vend
-> v
6092 | Vopen
("llppconfig", _, closed
) ->
6095 else { v with f = llppconfig
}
6097 error
"unexpected subelement at top level" s spos
6098 | Vclose
_ -> error
"unexpected close at top level" s spos
6100 and llppconfig
v t spos
_ =
6102 | Vdata
| Vcdata
-> v
6103 | Vend
-> error
"unexpected end of input in llppconfig" s spos
6104 | Vopen
("defaults", attrs
, closed
) ->
6105 let c = config_of dc attrs
in
6109 else { v with f = defaults
}
6111 | Vopen
("ui-font", attrs
, closed
) ->
6112 let rec getsize size
= function
6114 | ("size", v) :: rest
->
6116 fromstring int_of_string spos
"size" v fstate.fontsize
in
6118 | l -> getsize size l
6120 fstate.fontsize
<- getsize fstate.fontsize attrs
;
6123 else { v with f = uifont
(Buffer.create
10) }
6125 | Vopen
("doc", attrs
, closed
) ->
6126 let pathent, spage
, srely
, span
= doc_of attrs
in
6127 let path = unent pathent
6128 and pageno = fromstring int_of_string spos
"page" spage
0
6129 and rely = fromstring float_of_string spos
"rely" srely
0.0
6130 and pan
= fromstring int_of_string spos
"pan" span
0 in
6131 let c = config_of dc attrs
in
6132 let anchor = (pageno, rely) in
6134 then (Hashtbl.add
h path (c, [], pan
, anchor); v)
6135 else { v with f = doc
path pan
anchor c [] }
6138 error
"unexpected subelement in llppconfig" s spos
6140 | Vclose
"llppconfig" -> { v with f = toplevel }
6141 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
6143 and defaults
v t spos
_ =
6145 | Vdata
| Vcdata
-> v
6146 | Vend
-> error
"unexpected end of input in defaults" s spos
6147 | Vopen
("keymap", attrs
, closed
) ->
6149 try List.assoc
"mode" attrs
6150 with Not_found
-> "global" in
6155 let h = findkeyhash dc modename in
6156 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6159 { v with f = pkeymap
ret KeyMap.empty }
6161 | Vopen
(_, _, _) ->
6162 error
"unexpected subelement in defaults" s spos
6164 | Vclose
"defaults" ->
6165 { v with f = llppconfig
}
6167 | Vclose
_ -> error
"unexpected close in defaults" s spos
6169 and uifont
b v t spos
epos =
6172 Buffer.add_substring
b s spos
(epos - spos
);
6174 | Vopen
(_, _, _) ->
6175 error
"unexpected subelement in ui-font" s spos
6176 | Vclose
"ui-font" ->
6177 if String.length
!fontpath = 0
6178 then fontpath := Buffer.contents
b;
6179 { v with f = llppconfig
}
6180 | Vclose
_ -> error
"unexpected close in ui-font" s spos
6181 | Vend
-> error
"unexpected end of input in ui-font" s spos
6183 and doc
path pan
anchor c bookmarks
v t spos
_ =
6185 | Vdata
| Vcdata
-> v
6186 | Vend
-> error
"unexpected end of input in doc" s spos
6187 | Vopen
("bookmarks", _, closed
) ->
6190 else { v with f = pbookmarks
path pan
anchor c bookmarks
}
6192 | Vopen
("keymap", attrs
, closed
) ->
6194 try List.assoc
"mode" attrs
6195 with Not_found
-> "global"
6201 let h = findkeyhash c modename in
6202 KeyMap.iter
(Hashtbl.replace
h) keymap
;
6203 doc
path pan
anchor c bookmarks
6205 { v with f = pkeymap
ret KeyMap.empty }
6207 | Vopen
(_, _, _) ->
6208 error
"unexpected subelement in doc" s spos
6211 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
6212 { v with f = llppconfig
}
6214 | Vclose
_ -> error
"unexpected close in doc" s spos
6216 and pkeymap
ret keymap
v t spos
_ =
6218 | Vdata
| Vcdata
-> v
6219 | Vend
-> error
"unexpected end of input in keymap" s spos
6220 | Vopen
("map", attrs
, closed
) ->
6221 let r, l = map_of attrs
in
6222 let kss = fromstring keys_of_string spos
"in" r [] in
6223 let lss = fromstring keys_of_string spos
"out" l [] in
6227 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
6228 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
6231 then { v with f = pkeymap
ret keymap }
6234 { v with f = skip
"map" f }
6237 error
"unexpected subelement in keymap" s spos
6239 | Vclose
"keymap" ->
6240 { v with f = ret keymap }
6242 | Vclose
_ -> error
"unexpected close in keymap" s spos
6244 and pbookmarks
path pan
anchor c bookmarks
v t spos
_ =
6246 | Vdata
| Vcdata
-> v
6247 | Vend
-> error
"unexpected end of input in bookmarks" s spos
6248 | Vopen
("item", attrs
, closed
) ->
6249 let titleent, spage
, srely
= bookmark_of attrs
in
6250 let page = fromstring int_of_string spos
"page" spage
0
6251 and rely = fromstring float_of_string spos
"rely" srely
0.0 in
6252 let bookmarks = (unent titleent, 0, (page, rely)) :: bookmarks in
6254 then { v with f = pbookmarks
path pan
anchor c bookmarks }
6257 { v with f = skip
"item" f }
6260 error
"unexpected subelement in bookmarks" s spos
6262 | Vclose
"bookmarks" ->
6263 { v with f = doc
path pan
anchor c bookmarks }
6265 | Vclose
_ -> error
"unexpected close in bookmarks" s spos
6267 and skip tag
f v t spos
_ =
6269 | Vdata
| Vcdata
-> v
6271 error
("unexpected end of input in skipped " ^ tag
) s spos
6272 | Vopen
(tag'
, _, closed
) ->
6276 let f'
() = { v with f = skip tag
f } in
6277 { v with f = skip tag'
f'
}
6281 else error
("unexpected close in skipped " ^ tag
) s spos
6284 parse
{ f = toplevel; accu = () } s;
6290 let len = in_channel_length ic
in
6291 let s = String.create
len in
6292 really_input ic
s 0 len;
6295 | Parse_error
(msg
, s, pos
) ->
6296 let subs = subs s pos
in
6297 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
6298 failwith
("parse error: " ^
s)
6301 failwith
("config load error: " ^
Printexc.to_string exn
)
6307 let dir = Filename.concat
home ".config" in
6308 if Sys.is_directory
dir then dir else home
6311 Filename.concat
dir "llpp.conf"
6314 let confpath = ref defconfpath;;
6317 if Sys.file_exists
!confpath
6320 (try Some
(open_in_bin
!confpath)
6323 ("Error opening configuation file `" ^
!confpath ^
"': " ^
6324 Printexc.to_string exn
);
6333 ("Error loading configuation from `" ^
!confpath ^
"': " ^
6334 Printexc.to_string exn
);
6340 f (Hashtbl.create
0, defconf)
6345 let pc, pb
, px, pa
=
6347 Hashtbl.find h (Filename.basename
state.path)
6348 with Not_found
-> dc, [], 0, (0, 0.0)
6352 state.bookmarks <- pb
;
6354 state.scrollw
<- conf.scrollbw
;
6356 then state.anchor <- pa
;
6357 cbput state.hists
.nav pa
;
6362 let add_attrs bb always
dc c =
6365 then Printf.bprintf bb
"\n %s='%b'" s a
6368 then Printf.bprintf bb
"\n %s='%d'" s a
6371 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a)
6374 then Printf.bprintf bb
"\n %s='%d'" s (truncate
(a*.100.))
6377 then Printf.bprintf bb
"\n %s='%f'" s a
6381 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a)
6385 Printf.bprintf bb
"\n %s='%s'" s (colorspace_to_string a)
6389 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a)
6393 Printf.bprintf bb
"\n %s='%s'" s (enent
a 0 (String.length
a))
6399 | Some
(_N
, _A
, _B
) ->
6400 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
6410 else string_of_float
f
6412 Printf.bprintf bb
"\n %s='%s'" s v
6417 | Cmulti
((n, a, b), _) when n > 1 ->
6418 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a b
6419 | Csplit
(n, _) when n > 1 ->
6420 Printf.bprintf bb
"\n %s='%d'" s ~
-n
6426 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
6431 then dc.winw, dc.winh
6433 match state.fullscreen
with
6435 | None
-> c.winw, c.winh
6437 let zoom, presentation, interpagespace, maxwait
=
6439 then dc.zoom, dc.presentation, dc.interpagespace, dc.maxwait
6441 match state.mode with
6442 | Birdseye
(bc
, _, _, _, _) ->
6443 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.maxwait
6444 | _ -> c.zoom, c.presentation, c.interpagespace, c.maxwait
6446 oi
"width" w dc.winw;
6447 oi
"height" h dc.winh
;
6448 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
6449 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
6450 ob "case-insensitive-search" c.icase
dc.icase
;
6451 ob "preload" c.preload dc.preload;
6452 oi
"page-bias" c.pagebias
dc.pagebias
;
6453 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
6454 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
6455 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
6456 ob "crop-hack" c.crophack
dc.crophack
;
6457 oW
"throttle" maxwait
dc.maxwait
;
6458 ob "highlight-links" c.hlinks
dc.hlinks
;
6459 ob "under-cursor-info" c.underinfo
dc.underinfo
;
6460 oi
"vertical-margin" interpagespace dc.interpagespace;
6461 oz
"zoom" zoom dc.zoom;
6462 ob "presentation" presentation dc.presentation;
6463 oi
"rotation-angle" c.angle
dc.angle
;
6464 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
6465 ob "proportional-display" c.proportional
dc.proportional
;
6466 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
6467 oi
"tex-count" c.texcount
dc.texcount
;
6468 oi
"slice-height" c.sliceheight
dc.sliceheight
;
6469 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
6470 ob "persistent-location" c.jumpback
dc.jumpback
;
6471 oc
"background-color" c.bgcolor
dc.bgcolor
;
6472 ob "scrollbar-in-presentation" c.scrollbarinpm
dc.scrollbarinpm
;
6473 oi
"tile-width" c.tilew
dc.tilew
;
6474 oi
"tile-height" c.tileh
dc.tileh
;
6475 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
6476 ob "checkers" c.checkers
dc.checkers
;
6477 oi
"aalevel" c.aalevel
dc.aalevel
;
6478 ob "trim-margins" c.trimmargins
dc.trimmargins
;
6479 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
6480 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
6481 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
6482 oC
"color-space" c.colorspace
dc.colorspace
;
6483 ob "invert-colors" c.invert
dc.invert
;
6484 oF
"brightness" c.colorscale
dc.colorscale
;
6485 ob "redirectstderr" c.redirectstderr dc.redirectstderr;
6486 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
6487 oco
"columns" c.columns
dc.columns
;
6488 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
6489 os
"selection-command" c.selcmd
dc.selcmd
;
6490 ob "update-cursor" c.updatecurs
dc.updatecurs
;
6491 oi
"hint-font-size" c.hfsize
dc.hfsize
;
6492 ob "full-split" c.fullsplit
dc.fullsplit
;
6495 let keymapsbuf always
dc c =
6496 let bb = Buffer.create
16 in
6497 let rec loop = function
6499 | (modename, h) :: rest
->
6500 let dh = findkeyhash dc modename in
6501 if always
|| h <> dh
6503 if Hashtbl.length
h > 0
6505 if Buffer.length
bb > 0
6506 then Buffer.add_char
bb '
\n'
;
6507 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
6508 Hashtbl.iter
(fun i
o ->
6509 let isdifferent = always
||
6511 let dO = Hashtbl.find dh i
in
6513 with Not_found
-> true
6518 if Wsi.withctrl
m then Buffer.add_string
bb "ctrl-";
6519 if Wsi.withalt
m then Buffer.add_string
bb "alt-";
6520 if Wsi.withshift
m then Buffer.add_string
bb "shift-";
6521 if Wsi.withmeta
m then Buffer.add_string
bb "meta-";
6522 Buffer.add_string
bb (Wsi.keyname
k);
6525 let rec loop = function
6527 | km
:: [] -> addkm km
6528 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
6532 Buffer.add_string
bb "<map in='";
6536 Buffer.add_string
bb "' out='";
6538 Buffer.add_string
bb "'/>\n"
6541 Buffer.add_string
bb "' out='";
6543 Buffer.add_string
bb "'/>\n"
6545 | KMmulti
(ins, kms
) ->
6546 Buffer.add_char
bb ' '
;
6548 Buffer.add_string
bb "' out='";
6550 Buffer.add_string
bb "'/>\n"
6552 Buffer.add_string
bb "</keymap>";
6562 let uifontsize = fstate.fontsize
in
6563 let bb = Buffer.create
32768 in
6565 let dc = if conf.bedefault
then conf else dc in
6566 Buffer.add_string
bb "<llppconfig>\n";
6568 if String.length
!fontpath > 0
6570 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
6576 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
6579 Buffer.add_string
bb "<defaults ";
6580 add_attrs bb true dc dc;
6581 let kb = keymapsbuf true dc dc in
6582 if Buffer.length
kb > 0
6584 Buffer.add_string
bb ">\n";
6585 Buffer.add_buffer
bb kb;
6586 Buffer.add_string
bb "\n</defaults>\n";
6588 else Buffer.add_string
bb "/>\n";
6590 let adddoc path pan
anchor c bookmarks =
6591 if bookmarks == [] && c = dc && anchor = emptyanchor
6594 Printf.bprintf
bb "<doc path='%s'"
6595 (enent
path 0 (String.length
path));
6597 if anchor <> emptyanchor
6599 let n, y = anchor in
6600 Printf.bprintf
bb " page='%d'" n;
6603 Printf.bprintf
bb " rely='%f'" y
6608 then Printf.bprintf
bb " pan='%d'" pan
;
6610 add_attrs bb false dc c;
6611 let kb = keymapsbuf false dc c in
6613 begin match bookmarks with
6615 if Buffer.length
kb > 0
6617 Buffer.add_string
bb ">\n";
6618 Buffer.add_buffer
bb kb;
6619 Buffer.add_string
bb "\n</doc>\n";
6621 else Buffer.add_string
bb "/>\n"
6623 Buffer.add_string
bb ">\n<bookmarks>\n";
6624 List.iter
(fun (title, _level
, (page, rely)) ->
6626 "<item title='%s' page='%d'"
6627 (enent
title 0 (String.length
title))
6632 Printf.bprintf
bb " rely='%f'" rely
6634 Buffer.add_string
bb "/>\n";
6636 Buffer.add_string
bb "</bookmarks>";
6637 if Buffer.length
kb > 0
6639 Buffer.add_string
bb "\n";
6640 Buffer.add_buffer
bb kb;
6642 Buffer.add_string
bb "\n</doc>\n";
6648 match state.mode with
6649 | Birdseye
(c, pan, _, _, _) ->
6651 match conf.columns
with
6652 | Cmulti
((c, _, _), _) -> Some
c
6656 match c.columns
with
6657 | Cmulti
(c, _) -> Cmulti
(c, [||])
6658 | Csingle
-> Csingle
6659 | Csplit
_ -> failwith
"quit from bird's eye while split"
6661 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
6662 | _ -> state.x, conf
6664 let basename = Filename.basename state.path in
6665 adddoc basename pan (getanchor ())
6668 match state.autoscroll
with
6670 | None
-> conf.autoscrollstep
}
6671 (if conf.savebmarks
then state.bookmarks else []);
6673 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
6675 then adddoc path x y c bookmarks
6677 Buffer.add_string
bb "</llppconfig>";
6680 if Buffer.length
bb > 0
6683 let tmp = !confpath ^
".tmp" in
6684 let oc = open_out_bin
tmp in
6685 Buffer.output_buffer
oc bb;
6687 Unix.rename
tmp !confpath;
6690 ("error while saving configuration: " ^
Printexc.to_string exn
)
6697 [("-p", Arg.String
(fun s -> state.password
<- s) ,
6698 "<password> Set password");
6700 ("-f", Arg.String
(fun s -> Config.fontpath := s),
6701 "<path> Set path to the user interface font");
6703 ("-c", Arg.String
(fun s -> Config.confpath := s),
6704 "<path> Set path to the configuration file");
6706 ("-v", Arg.Unit
(fun () ->
6708 "%s\nconfiguration path: %s\n"
6712 exit
0), " Print version and exit");
6715 (fun s -> state.path <- s)
6716 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\nOptions:")
6718 if String.length
state.path = 0
6719 then (prerr_endline
"file name missing"; exit
1);
6723 let globalkeyhash = findkeyhash conf "global" in
6724 let wsfd, winw, winh
= Wsi.init
(object
6726 if nogeomcmds state.geomcmds
|| platform == Posx
6729 GlFunc.draw_buffer `front
;
6730 GlClear.color (scalecolor2 conf.bgcolor
);
6731 GlClear.clear
[`
color];
6732 GlFunc.draw_buffer `back
;
6734 method display = display ()
6735 method reshape w h = reshape w h
6736 method mouse b d x y m = mouse b d x y m
6737 method motion x y = state.mpos
<- (x, y); motion x y
6738 method pmotion x y = state.mpos
<- (x, y); pmotion x y
6740 let mascm = m land (
6741 Wsi.altmask
+ Wsi.shiftmask
+ Wsi.ctrlmask
+ Wsi.metamask
6743 match state.keystate
with
6745 let km = k, mascm in
6748 let modehash = state.uioh#
modehash in
6749 try Hashtbl.find modehash km
6751 try Hashtbl.find globalkeyhash km
6752 with Not_found
-> KMinsrt
(k, m)
6754 | KMinsrt
(k, m) -> keyboard k m
6755 | KMinsrl
l -> List.iter
(fun (k, m) -> keyboard k m) l
6756 | KMmulti
(l, r) -> state.keystate
<- KSinto
(l, r)
6758 | KSinto
((k'
, m'
) :: [], insrt
) when k'
=k && m'
land mascm = m'
->
6759 List.iter
(fun (k, m) -> keyboard k m) insrt
;
6760 state.keystate
<- KSnone
6761 | KSinto
((k'
, m'
) :: keys
, insrt
) when k'
=k && m'
land mascm = m'
->
6762 state.keystate
<- KSinto
(keys
, insrt
)
6764 state.keystate
<- KSnone
6766 method enter
x y = state.mpos
<- (x, y); pmotion x y
6767 method leave = state.mpos
<- (-1, -1)
6768 method quit
= raise Quit
6769 end) conf.winw conf.winh
(platform = Posx
) in
6774 List.exists
GlMisc.check_extension
6775 [ "GL_ARB_texture_rectangle"
6776 ; "GL_EXT_texture_recangle"
6777 ; "GL_NV_texture_rectangle" ]
6779 then (prerr_endline
"OpenGL does not suppport rectangular textures"; exit
1);
6782 match Ne.pipe () with
6784 Printf.eprintf
"pipe/crsw failed: %s" (Printexc.to_string exn
);
6788 match Ne.pipe () with
6790 Printf.eprintf
"pipe/srcw failed: %s" (Printexc.to_string exn
);
6800 setcheckers conf.checkers
;
6804 conf.angle
, conf.proportional
, (conf.trimmargins
, conf.trimfuzz
),
6805 conf.texcount
, conf.sliceheight
, conf.mustoresize
, conf.colorspace
,
6810 state.text <- "Opening " ^
state.path;
6812 opendoc state.path state.password
;
6815 let rec loop deadline
=
6817 match state.errfd
with
6818 | None
-> [state.sr
; state.wsfd]
6819 | Some fd
-> [state.sr
; state.wsfd; fd
]
6823 state.redisplay
<- false;
6830 if deadline
= infinity
6832 else max
0.0 (deadline
-. now)
6837 try Unix.select
r [] [] timeout
6838 with Unix.Unix_error
(Unix.EINTR
, _, _) -> [], [], []
6844 if state.ghyll
== noghyll
6846 match state.autoscroll
with
6847 | Some step
when step
!= 0 ->
6848 let y = state.y + step
in
6852 else if y >= state.maxy then 0 else y
6855 if state.mode = View
6856 then state.text <- "";
6859 else deadline
+. 0.01
6864 let rec checkfds = function
6866 | fd
:: rest
when fd
= state.sr
->
6867 let cmd = readcmd state.sr
in
6871 | fd
:: rest
when fd
= state.wsfd ->
6876 let s = String.create
80 in
6877 let n = Unix.read fd
s 0 80 in
6878 if conf.redirectstderr
6880 Buffer.add_substring
state.errmsgs
s 0 n;
6881 state.newerrmsgs
<- true;
6882 state.redisplay
<- true;
6885 prerr_string
(String.sub
s 0 n);
6893 if deadline
= infinity
6897 match state.autoscroll
with
6898 | Some step
when step
!= 0 -> deadline1
6899 | _ -> if state.ghyll
== noghyll then infinity
else deadline1