open X11
-let edit_view = ref (View.empty 640 480)
let tags_view = ref (View.empty 640 480)
+let edit_view = ref (View.empty 640 480)
+let divider = ref 0
+let focus_view = ref edit_view
(* Mouse Actions
******************************************************************************)
view := View.scroll_dn !view
done
-let select_at view x y =
- view := View.select_at !view x y
+let select_at ?extend:(ext=false) view x y =
+ view := View.select_at ~extend:ext !view x y
let select_ctx_at view x y = ()
(*view := View.select_ctx_at !view x y*)
Printf.printf "select (%d,%d) %d" x y nclicks;
print_endline "";
match nclicks with
- | 1 -> select_at edit_view x y
+ | 1 -> select_at !focus_view x y
| 2 -> select_ctx_at edit_view x y
| 3 -> select_line_at edit_view x y
| _ -> ()
let onexec mods x y nclicks =
Printf.printf "exec (%d,%d) %d" x y nclicks;
print_endline "";
- exec_at edit_view x y
+ exec_at !focus_view x y
let onfetch mods x y nclicks =
Printf.printf "fetch (%d,%d) %d" x y nclicks;
print_endline "";
- fetch_at edit_view x y
+ fetch_at !focus_view x y
(* Event functions
******************************************************************************)
Printf.printf "focused %b" focused;
print_endline ""
-let onkeypress mods rune = ()
+let onsetregion x y =
+ Printf.printf "setregion %d %d %b" x y (y <= !divider);
+ print_endline "";
+ if y <= !divider then
+ focus_view := tags_view
+ else
+ focus_view := edit_view
+
+let onkeypress mods rune =
+ Printf.printf "keypress %d %d" mods rune;
+ print_endline ""
let onmousebtn mods btn x y pressed nclicks =
if pressed then match btn with
| 1 -> onselect mods x y nclicks
| 2 -> onexec mods x y nclicks
| 3 -> onfetch mods x y nclicks
- | 4 -> scroll_up edit_view
- | 5 -> scroll_dn edit_view
+ | 4 -> scroll_up !focus_view
+ | 5 -> scroll_dn !focus_view
| _ -> ()
let onmousemove mods x y =
Printf.printf "select (%d,%d)" x y;
print_endline "";
- edit_view := View.select_at ~extend:true !edit_view x y
+ select_at ~extend:true !focus_view x y
let onupdate width height =
let csr = Draw.Cursor.make (width, height) 0 0 in
tags_view := View.draw !tags_view csr;
Draw.hrule csr.width csr;
+ divider := csr.y;
let scrollcsr = (Draw.Cursor.clone csr) in
Draw.Cursor.move_x csr 15;
edit_view := View.draw !edit_view csr;
let onevent evnt =
try match evnt with
| Focus state -> onfocus state
+ | SetRegion e -> onsetregion e.x e.y
| KeyPress e -> onkeypress e.mods e.rune
| MouseClick e -> onmousebtn e.mods e.btn e.x e.y true e.nclicks
| MouseRelease e -> onmousebtn e.mods e.btn e.x e.y false 1
return ms;
}
+static void get_pointer(int* ptrx, int* ptry) {
+ Window xw; int x; unsigned int ux;
+ XQueryPointer(X.display, X.self, &xw, &xw, &x, &x, ptrx, ptry, &ux);
+}
+
CAMLprim value x11_event_loop(value ms, value cbfn) {
CAMLparam2(ms, cbfn);
CAMLlocal1( event );
while (X.running) {
XPeekEvent(X.display, &e);
uint64_t t = getmillis();
+
+ int x = 0, y = 0;
+ get_pointer(&x,&y);
+ caml_callback(cbfn, mkvariant(TSetRegion, 2, Val_int(x), Val_int(y)));
+
while (XPending(X.display)) {
XNextEvent(X.display, &e);
if (!XFilterEvent(&e, None) && EventHandlers[e.type]) {