]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
added region tracking logic
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 20 Feb 2018 03:30:51 +0000 (22:30 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 20 Feb 2018 03:30:51 +0000 (22:30 -0500)
edit.ml
lib/internals.h
lib/x11.ml
lib/x11_prims.c

diff --git a/edit.ml b/edit.ml
index 4854514c5da5615c73cfc52cca7c166e0d180e53..6ab045a830ff28f4117036a8471eeb100ba56c34 100644 (file)
--- 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
index 0786453663fd2d5ce9808bc918c94de4e5da2dfd..2ee593016202d1f6ff730b9c8fa627c86e9d50dc 100644 (file)
@@ -20,6 +20,7 @@
    type definition */
 enum {
     TFocus = 0,
+    TSetRegion,
     TKeyPress,
     TMouseClick,
     TMouseRelease,
index fe9c0d06499ff9d913f5580282b0cdfa9860d636..a735710399649659d88ea12ac9fa5629a6e17d22 100644 (file)
@@ -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 }
index 086d894f0a939f16932a85ce0440d08efe3a6789..2f6b8f6dfebf11f593aea58accbb26e05dd46e8a 100644 (file)
@@ -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]) {