]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
started implementing click handling
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 19 Jan 2018 03:32:52 +0000 (22:32 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 19 Jan 2018 03:32:52 +0000 (22:32 -0500)
Makefile
edit.ml
lib/cfg.ml
lib/draw.ml
lib/draw.mli
lib/view.ml
lib/x11.ml
lib/x11_prims.c

index 60af2a75957fb5bf8501cd02d9154065c13bd141..85825014780b47d07ebad383feb7f055539714eb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -91,7 +91,8 @@ docs: tide.$(LIBEXT)
        ocamldoc -d docs -html -I lib $(LIBSRCS)
 
 # Dependency generation
-deps deps.mk: $(wildcard *.ml* lib/*.ml* tests/*.ml*)
+deps: deps.mk
+deps.mk: $(wildcard *.ml* lib/*.ml* tests/*.ml*)
        ocamldep -I . -I lib/ -I tests/ -all -one-line $^ > deps.mk
 -include deps.mk
 
diff --git a/edit.ml b/edit.ml
index bd5eae8359ac3799a1b0a0a5575d335ed6df83ae..3dcbcd0816a8359be7d24a54fc81809830779e60 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -13,22 +13,42 @@ let scroll_dn () =
     edit_view := View.scroll_dn !edit_view
   done
 
+(* Mouse Actions
+ ******************************************************************************)
+let onselect mods x y nclicks =
+  let sx,sy = !edit_view.pos and w,h = !edit_view.dim in
+  Printf.printf "lines: %d\n" ((h - sy) / Draw.font.height);
+  Printf.printf "select (%d,%d) %d" x y nclicks;
+  print_endline ""
+
+let onexec mods x y nclicks =
+  Printf.printf "exec (%d,%d) %d" x y nclicks;
+  print_endline ""
+
+let onfetch mods x y nclicks =
+  Printf.printf "fetch (%d,%d) %d" x y nclicks;
+  print_endline ""
+
 (* Event functions
  ******************************************************************************)
-let onfocus focused = ()
+let onfocus focused =
+  Printf.printf "focused %b" focused;
+  print_endline ""
 
 let onkeypress mods rune = ()
 
-let onmousebtn mods btn x y pressed =
+let onmousebtn mods btn x y pressed nclicks =
   if pressed then match btn with
-  | 1 -> ()
-  | 2 -> ()
-  | 3 -> ()
+  | 1 -> onselect mods x y nclicks
+  | 2 -> onexec mods x y nclicks
+  | 3 -> onfetch mods x y nclicks
   | 4 -> scroll_up ()
   | 5 -> scroll_dn ()
   | _ -> ()
 
-let onmousemove mods x y = ()
+let onmousemove mods x y =
+  Printf.printf "click (%d,%d)" x y;
+  print_endline ""
 
 let onupdate width height =
   let csr = Draw.Cursor.make (width, height) 0 0 in
@@ -46,8 +66,8 @@ let onevent evnt =
   try match evnt with
     | Focus state      -> onfocus state
     | KeyPress e       -> onkeypress e.mods e.rune
-    | MouseClick e     -> onmousebtn e.mods e.btn e.x e.y true
-    | MouseRelease e   -> onmousebtn e.mods e.btn e.x e.y false
+    | 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
     | MouseMove e      -> onmousemove e.mods e.x e.y
     | Paste e          -> () (*print_endline "paste"*)
     | Command e        -> () (*print_endline "command"*)
index a107b570e1894280a8322d3ff4250d2e7c7e3ccc..501f17c342db625910c1a935e9711042286e3ba0 100644 (file)
@@ -23,22 +23,25 @@ let clrvar name defval =
 (* tags region default contents *)
 let edit_tags = strvar "tide.ui.tags.edit"
     "Quit Save Undo Redo Cut Copy Paste | Find "
-let cmd_tags = strvar "tide.ui.font"
+let cmd_tags = strvar "tide.ui.tags.cmd"
     "Quit Undo Redo Cut Copy Paste | Send Find "
 
 (* font settings *)
-let font = strvar "tide.ui.tags.edit" "Verdana:size=11"
-let line_spacing = intvar "tide.ui.line_spacing" 1
+let font = strvar "tide.ui.font" "Verdana:size=11"
+(*let line_spacing = intvar "tide.ui.line_spacing" 1*)
 
 (* user interface related options *)
+(*
 let winwidth  = intvar "tide.ui.width" 640
 let winheight = intvar "tide.ui.height" 480
 let line_nums = boolvar "tide.ui.line_numbers" true
 let syntax_enabled = boolvar "tide.ui.syntax_enabled" true
 let ruler_column = intvar "tide.ui.rulercolumn" 80
 let event_timeout = intvar "tide.ui.timeout" 50
+*)
 
 (* input related options *)
+(*
 let copy_indent = boolvar "tide.input.copy_indent" true
 let trim_on_save = boolvar "tide.input.trim_on_save" true
 let expand_tabs = boolvar "tide.input.expand_tabs" true
@@ -46,6 +49,7 @@ let tab_width = intvar "tide.input.tab_width" 4
 let scroll_lines = intvar "tide.input.scroll_lines" 4
 let dbl_click_time = intvar "tide.input.click_time" 500
 let max_scan_dist = intvar "tide.input.max_scan_dist" 0
+*)
 
 module Color = struct
   (* color palette *)
@@ -69,6 +73,7 @@ module Color = struct
   |]
 
   (* UI color index definitions *)
+(*
   let scroll_nor = clrvar "tide.colors.scroll.normal"   (3, 0)
   let gutter_nor = clrvar "tide.colors.gutter.normal"   (1, 4)
   let gutter_sel = clrvar "tide.colors.gutter.selected" (2, 7)
@@ -81,6 +86,7 @@ module Color = struct
   let edit_csr = intvar "tide.colors.edit.cursor"       7
   let edit_rul = intvar "tide.colors.edit.ruler"        1
   let borders  = clrvar "tide.colors.borders"           (3, 3)
+*)
 
   (* syntax color definitions *)
   module Syntax = struct
@@ -89,17 +95,18 @@ module Color = struct
     let constant  = intvar "tide.colors.syntax.constant"  14
     let keyword   = intvar "tide.colors.syntax.keyword"   15
     let typedef   = intvar "tide.colors.syntax.typedef"   8
-
+    let preproc   = intvar "tide.colors.syntax.preproc"   9
+(*
     let number    = intvar "tide.colors.syntax.number"    14
     let boolean   = intvar "tide.colors.syntax.boolean"   14
     let float     = intvar "tide.colors.syntax.float"     14
     let string    = intvar "tide.colors.syntax.string"    14
     let char      = intvar "tide.colors.syntax.character" 14
-    let preproc   = intvar "tide.colors.syntax.preproc"   9
     let statement = intvar "tide.colors.syntax.statement" 10
     let procedure = intvar "tide.colors.syntax.function"  11
     let variable  = intvar "tide.colors.syntax.variable"  12
     let special   = intvar "tide.colors.syntax.special"   13
     let operator  = intvar "tide.colors.syntax.operator"  12
+*)
   end
 end
index 2c4996c86bb3530444aa5338eca71dc3f0b83efe..be62bdcc159719ce8a257e1405690b09cde35803 100644 (file)
@@ -26,6 +26,12 @@ module Cursor = struct
       startx = csr.startx; starty = csr.starty;
       x = csr.x; y = csr.y }
 
+  let pos csr =
+    (csr.x, csr.y)
+
+  let dim csr =
+    (csr.width, csr.height)
+
   let move_x csr n =
     csr.x <- csr.x + n
 
index f97126addf02ad0c72d46348f92c62631b764141..ab4166e9ba76382270e9cdf32b6da630d57565fe 100644 (file)
@@ -2,6 +2,8 @@ module Cursor : sig
   type t
   val make : (int * int) -> int -> int -> t
   val clone : t -> t
+  val pos : t -> (int * int)
+  val dim : t -> (int * int)
   val move_x : t -> int -> unit
   val max_width : t -> int
 (*
index f9e20df947cac1311e5940a9ca6ddbbaecccac7b..25e85216dbe5393c5b6b9c21bcaaf3936810b182 100644 (file)
@@ -2,13 +2,17 @@ type t = {
   num : int;
   buf : Buf.t;
   map : Scrollmap.t;
-  clr : Colormap.t
+  clr : Colormap.t;
+  pos : int * int;
+  dim : int * int
 }
 
 let from_buffer buf width height =
   { num = 0; buf = buf;
     map = Scrollmap.make buf width 0;
-    clr = Colormap.make (Buf.make_lexer buf) }
+    clr = Colormap.make (Buf.make_lexer buf);
+    pos = (0,0);
+    dim = (width, height) }
 
 let empty width height =
   from_buffer (Buf.empty) width height
@@ -24,8 +28,12 @@ let resize view width =
 
 let draw view csr =
   let view = (resize view (Draw.Cursor.max_width csr)) in
-  let num = Draw.buffer csr view.buf view.clr (Scrollmap.first view.map) in
-  { view with num = num }
+  let newcsr = (Draw.Cursor.clone csr) in
+  let num = Draw.buffer newcsr view.buf view.clr (Scrollmap.first view.map) in
+  { view with
+    num = num;
+    pos = Draw.Cursor.pos csr;
+    dim = Draw.Cursor.dim csr }
 
 let scroll_up view =
   { view with map = Scrollmap.scroll_up view.map view.buf }
index 49465fdbbe407f396f2d46c025b757abb22ab825..fe9c0d06499ff9d913f5580282b0cdfa9860d636 100644 (file)
@@ -7,7 +7,7 @@ type xftfont (* opaque type for xft font structure *)
 type xevent =
   | Focus of bool
   | KeyPress of { mods: int; rune: int }
-  | MouseClick of { mods: int; btn: int; x: int; y: int }
+  | MouseClick of { mods: int; btn: int; x: int; y: int; nclicks: int }
   | MouseRelease of { mods: int; btn: int; x: int; y: int }
   | MouseMove of { mods: int; x: int; y: int }
   | Paste of { text: string }
index 7fd46865a6b8dd5c88b8a53adc39e126e5d657ea..086d894f0a939f16932a85ce0440d08efe3a6789 100644 (file)
@@ -421,10 +421,10 @@ static void create_window(int height, int width) {
 }
 
 static value ev_focus(XEvent* e) {
-    bool focused = (e->type = FocusIn);
-    if (X.xic)
-        (focused ? XSetICFocus : XUnsetICFocus)(X.xic);
-    return mkvariant(TFocus, 1, Val_true);
+    bool focused = (e->type == FocusIn);
+    value focusval = (focused ? Val_true : Val_false);
+    if (X.xic) (focused ? XSetICFocus : XUnsetICFocus)(X.xic);
+    return mkvariant(TFocus, 1, focusval);
 }
 
 static value ev_keypress(XEvent* e) {
@@ -449,13 +449,23 @@ static value ev_keypress(XEvent* e) {
     return mkvariant(TKeyPress, 2, e->xkey.state, Val_int(special_keys(key)));
 }
 
+static int times_clicked(int btn, Time curr) {
+    static struct { Time time; int nclicks; } hist[5] = {0,0};
+    if (btn >= 5) return 1;
+    Time diff = curr - hist[btn].time;
+    hist[btn].time = curr;
+    if (diff < 250) return ++(hist[btn].nclicks);
+    else return (hist[btn].nclicks = 1);
+}
+
 static value ev_mouse(XEvent* e) {
+    Time time = e->xbutton.time;
     int mods = e->xbutton.state, btn = e->xbutton.button,
         x = e->xbutton.x, y = e->xbutton.y;
     if (e->type == MotionNotify)
         return mkvariant(TMouseMove, 3, Val_int(mods), Val_int(x), Val_int(y));
     else if (e->type == ButtonPress)
-        return mkvariant(TMouseClick, 4, Val_int(mods), Val_int(btn), Val_int(x), Val_int(y));
+        return mkvariant(TMouseClick, 5, Val_int(mods), Val_int(btn), Val_int(x), Val_int(y), Val_int(times_clicked(btn, time)));
     else
         return mkvariant(TMouseRelease, 4, Val_int(mods), Val_int(btn), Val_int(x), Val_int(y));
 }