From: Michael D. Lowis Date: Fri, 19 Jan 2018 03:32:52 +0000 (-0500) Subject: started implementing click handling X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=2bf13f640e2b308996a86b3b1a111bbe6849112f;p=archive%2Ftide-ocaml.git started implementing click handling --- diff --git a/Makefile b/Makefile index 60af2a7..8582501 100644 --- 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 bd5eae8..3dcbcd0 100644 --- 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"*) diff --git a/lib/cfg.ml b/lib/cfg.ml index a107b57..501f17c 100644 --- a/lib/cfg.ml +++ b/lib/cfg.ml @@ -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 diff --git a/lib/draw.ml b/lib/draw.ml index 2c4996c..be62bdc 100644 --- a/lib/draw.ml +++ b/lib/draw.ml @@ -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 diff --git a/lib/draw.mli b/lib/draw.mli index f97126a..ab4166e 100644 --- a/lib/draw.mli +++ b/lib/draw.mli @@ -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 (* diff --git a/lib/view.ml b/lib/view.ml index f9e20df..25e8521 100644 --- a/lib/view.ml +++ b/lib/view.ml @@ -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 } diff --git a/lib/x11.ml b/lib/x11.ml index 49465fd..fe9c0d0 100644 --- a/lib/x11.ml +++ b/lib/x11.ml @@ -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 } diff --git a/lib/x11_prims.c b/lib/x11_prims.c index 7fd4686..086d894 100644 --- a/lib/x11_prims.c +++ b/lib/x11_prims.c @@ -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)); }