open X11
let () =
- X11.make_window 640 480;
- X11.show_window true;
- X11.event_loop 50 (fun x ->
- match x with
+ let win = X11.make_window 640 480 in
+ X11.show_window win true;
+ X11.event_loop 50 (function
| Focus _ -> print_endline "focus"
| KeyPress _ -> print_endline "keypress"
| MouseClick _ -> print_endline "mouseclick"
| MouseRelease of { mods: int; btn: int; x: int; y: int }
| MouseDrag of { mods: int; x: int; y: int }
| Paste of { text: string }
- | Resize of { height: int; width: int }
+ (*| Resize of { height: int; width: int }*)
| Command of { commands: string array }
| PipeClosed of { fd: int }
| PipeWriteReady of { fd: int }
| PipeReadReady of { fd: int }
- | Update
+ | Update of { width: int; height: int }
| Shutdown
external connect : unit -> unit
external disconnect : unit -> unit
= "x11_disconnect"
-external make_window : int -> int -> unit
+external make_window : int -> int -> xwin
= "x11_make_window"
-external make_dialog : int -> int -> unit
+external make_dialog : int -> int -> xwin
= "x11_make_dialog"
-external show_window : bool -> unit
+external show_window : xwin -> bool -> unit
= "x11_show_window"
external event_loop : int -> (xevent -> unit) -> unit
= "x11_prop_get"
(* to be implemented
+
+void x11_draw_rect(int color, int x, int y, int width, int height)
+external draw_rect : int -> int -> int -> int -> int -> unit
+
external sel_set : xatom -> string -> unit
= "x11_sel_set"
external sel_fetch : xatom -> unit
TMouseRelease,
TMouseDrag,
TPaste,
- TResize,
TCommand,
TPipeClosed,
TPipeWriteReady,
CAMLreturn(Val_int(X.self));
}
-CAMLprim value x11_show_window(value state) {
- CAMLparam1(state);
+CAMLprim value x11_show_window(value win, value state) {
+ CAMLparam2(win,state);
if (Bool_val(state))
- XMapWindow(X.display, X.self);
+ XMapWindow(X.display, (Window)Int_val(win));
else
- XUnmapWindow(X.display, X.self);
+ XUnmapWindow(X.display, (Window)Int_val(win));
CAMLreturn(Val_unit);
}
}
if (X.running) {
- caml_callback(cbfn, mkrecord(TUpdate, 0));
+ caml_callback(cbfn, mkrecord(TUpdate, 2, X.width, X.height));
XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
}
}
X.height = e->xconfigure.height;
X.pixmap = XCreatePixmap(X.display, X.self, X.width, X.height, X.depth);
X.xft = XftDrawCreate(X.display, X.pixmap, X.visual, X.colormap);
- event = mkrecord(TResize, 2, X.height, X.width);
}
return event;
}