From 09d8cff4a64d9c2a95e00fd87d5053f6f4e76133 Mon Sep 17 00:00:00 2001 From: malc Date: Mon, 27 Feb 2012 18:39:34 +0400 Subject: [PATCH] Do the right thing and in the proper order --- main.ml | 9 ++++++--- wsi.ml | 45 +++++++++++++++++++++++++++++++-------------- wsi.mli | 2 +- 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/main.ml b/main.ml index bee110f..70547ca 100644 --- a/main.ml +++ b/main.ml @@ -6312,7 +6312,7 @@ let () = Config.load (); let globalkeyhash = findkeyhash conf "global" in - state.wsfd <- Wsi.init (object + let wsfd, winw, winh = Wsi.init (object method expose = if nogeomcmds state.geomcmds then display () @@ -6348,7 +6348,9 @@ let () = method enter x y = state.mpos <- (x, y); pmotion x y method leave = state.mpos <- (-1, -1) method quit = raise Quit - end) conf.winw conf.winh; + end) conf.winw conf.winh in + + state.wsfd <- wsfd; if not ( List.exists GlMisc.check_extension @@ -6380,7 +6382,8 @@ let () = opendoc state.path state.password; state.uioh <- uioh; setfontsize fstate.fontsize; - doreshape conf.winw conf.winh; + reshape winw winh; + display (); let rec loop deadline = let r = diff --git a/wsi.ml b/wsi.ml index c8847ce..c36ee24 100644 --- a/wsi.ml +++ b/wsi.ml @@ -58,7 +58,6 @@ type state = ; mutable w : int ; mutable h : int ; mutable fs : bool - ; mutable parent : int } ;; @@ -79,7 +78,6 @@ let state = ; h = -1 ; fs = false ; stringatom = 31 - ; parent = -1 } ;; @@ -212,6 +210,12 @@ let createwindowreq wid parent x y w h bw mask = s; ;; +let getgeometryreq wid = + let s = "\014u\002\000dddd" in + w32 s 4 wid; + s; +;; + let mapreq wid = let s = "\008u\002\000wwww" in w32 s 4 wid; @@ -398,9 +402,6 @@ let rec readresp sock = | 18 -> vlog "unmap"; | 19 -> (* map *) - if state.parent = -1 && state.w > 0 && state.h > 0 - then state.t#reshape state.w state.h; - state.t#display; vlog "map"; | 12 -> (* exposure *) @@ -428,15 +429,12 @@ let rec readresp sock = vlog "atom %#x" atom | 21 -> (* reparent *) - state.parent <- r32 resp 24; - state.w <- -1; - state.h <- -1; vlog "reparent" | 22 -> (* configure *) - vlog "configure"; let w = r16 resp 20 and h = r16 resp 22 in + vlog "configure %d %d %d %d" state.w state.h w h; if w != state.w || h != state.h then ( state.w <- w; @@ -578,13 +576,9 @@ let setup sock screennum w h = (* + 0x01000000 *) (* OwnerGrabButton *) in let wid = state.idbase in - state.w <- w; - state.h <- h; let s = createwindowreq wid root 0 0 w h 0 mask in sendstr s sock; - glx wid; - let s = mapreq wid in sendstr s sock; @@ -658,6 +652,29 @@ let setup sock screennum w h = ); ); ); + let s = getgeometryreq wid in + let completed = ref false in + sendwithrep sock s (fun resp -> + glx wid; + + let w = r16 resp 16 + and h = r16 resp 18 in + state.w <- w; + state.h <- h; + completed := true; + ); + let now = Unix.gettimeofday in + let deadline = now () +. 2.0 in + let rec readtillcompletion () = + let r, _, _ = Unix.select [sock] [] [] (deadline -. now ()) in + match r with + | [] -> readtillcompletion () + | _ -> + readresp sock; + if not !completed + then readtillcompletion () + in + readtillcompletion (); | c -> error "unknown conection setup response %d" (Char.code c) @@ -777,7 +794,7 @@ let init t w h = state.sock <- fd; setup fd screennum w h; state.t <- t; - fd; + fd, state.w, state.h; ;; let settitle s = diff --git a/wsi.mli b/wsi.mli index 7dff951..48e4e83 100644 --- a/wsi.mli +++ b/wsi.mli @@ -23,7 +23,7 @@ val setcursor : cursor -> unit;; val settitle : string -> unit;; val swapb : unit -> unit;; val readresp : Unix.file_descr -> unit;; -val init : t -> int -> int -> Unix.file_descr;; +val init : t -> int -> int -> Unix.file_descr * int * int;; val fullscreen : unit -> unit;; val reshape : int -> int -> unit;; val withalt : int -> bool;; -- 2.11.4.GIT