From: Michael D. Lowis Date: Tue, 20 Feb 2018 03:30:51 +0000 (-0500) Subject: added region tracking logic X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=3fbc4ee9286245066baf202fa70a52acc95c2250;p=archive%2Ftide-ocaml.git added region tracking logic --- diff --git a/edit.ml b/edit.ml index 4854514..6ab045a 100644 --- a/edit.ml +++ b/edit.ml @@ -1,7 +1,9 @@ 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 ******************************************************************************) @@ -15,8 +17,8 @@ let scroll_dn view = 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*) @@ -36,7 +38,7 @@ let onselect mods x y nclicks = 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 | _ -> () @@ -44,12 +46,12 @@ let onselect mods x y nclicks = 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 ******************************************************************************) @@ -57,26 +59,37 @@ let onfocus focused = 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; @@ -89,6 +102,7 @@ let onshutdown () = 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 diff --git a/lib/internals.h b/lib/internals.h index 0786453..2ee5930 100644 --- a/lib/internals.h +++ b/lib/internals.h @@ -20,6 +20,7 @@ type definition */ enum { TFocus = 0, + TSetRegion, TKeyPress, TMouseClick, TMouseRelease, diff --git a/lib/x11.ml b/lib/x11.ml index fe9c0d0..a735710 100644 --- a/lib/x11.ml +++ b/lib/x11.ml @@ -6,6 +6,7 @@ type xftfont (* opaque type for xft font structure *) (* X event definitions *) type xevent = | Focus of bool + | SetRegion of { x: int; y: int } | KeyPress of { mods: int; rune: int } | MouseClick of { mods: int; btn: int; x: int; y: int; nclicks: int } | MouseRelease of { mods: int; btn: int; x: int; y: int } diff --git a/lib/x11_prims.c b/lib/x11_prims.c index 086d894..2f6b8f6 100644 --- a/lib/x11_prims.c +++ b/lib/x11_prims.c @@ -139,6 +139,11 @@ uint64_t getmillis(void) { 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 ); @@ -146,6 +151,11 @@ CAMLprim value x11_event_loop(value ms, value cbfn) { 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]) {