]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
added code to destructure events and call subfunctions for each
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 6 Sep 2017 02:10:42 +0000 (22:10 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 6 Sep 2017 02:10:42 +0000 (22:10 -0400)
edit.ml
lib/x11.ml
lib/x11_prims.c

diff --git a/edit.ml b/edit.ml
index 244938f488452c7fafb72fe51b3c9252682f3065..96f703acc5a0a9d05b5ee65233a7bca35a3d5a5a 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -1,22 +1,30 @@
 open X11
+
+let onfocus focused = ()
+let onkeypress mods rune = ()
+let onmousebtn mods btn x y pressed = ()
+let onmousedrag mods x y = ()
+let onupdate width height = ()
+let onshutdown = ()
+
 let () =
-  let win = X11.make_window 640 480 in
-  X11.show_window win true;
-  X11.event_loop 50 (function
-  | Focus _          -> print_endline "focus"
-  | KeyPress _       -> print_endline "keypress"
-  | MouseClick _     -> print_endline "mouseclick"
-  | MouseRelease _   -> print_endline "mouserelease"
-  | MouseDrag _      -> print_endline "mousedrag"
-  | Paste _          -> print_endline "paste"
-  | Resize _         -> print_endline "resize"
-  | Command _        -> print_endline "command"
-  | PipeClosed _     -> print_endline "pipeclosed"
-  | PipeWriteReady _ -> print_endline "pipewriteready"
-  | PipeReadReady _  -> print_endline "pipereadready"
-  | Update           -> print_endline "update"
-  | Shutdown         -> print_endline "shutdown"
+  let win = make_window 640 480 in
+  show_window win true;
+  event_loop 50 (function
+  | 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
+  | MouseDrag e      -> onmousedrag e.mods e.x e.y
+  | Paste e          -> print_endline "paste"
+  | Command e        -> print_endline "command"
+  | PipeClosed e     -> print_endline "pipeclosed"
+  | PipeWriteReady e -> print_endline "pipewriteready"
+  | PipeReadReady e  -> print_endline "pipereadready"
+  | Update e         -> onupdate e.width e.height
+  | Shutdown         -> onshutdown
   )
+
 (*
   let server = Tide.start_server () in
   let nargs = Array.length Sys.argv in
index 7753f98152bbbf5d270524be24d0ff037b653201..817d78c9756acd18f86477aac7500ffb231d651c 100644 (file)
@@ -1,13 +1,12 @@
 type xatom
 type xwin
 type xevent =
-  | Focus of { focused: bool }
+  | Focus of bool
   | KeyPress of { mods: int; rune: int }
   | MouseClick of { mods: int; btn: int; x: int; y: int }
   | MouseRelease of { mods: int; btn: int; x: int; y: int }
   | MouseDrag of { mods: int; x: int; y: int }
   | Paste of { text: string }
-  (*| Resize of { height: int; width: int }*)
   | Command of { commands: string array }
   | PipeClosed of { fd: int }
   | PipeWriteReady of { fd: int }
index afab8e71cdea49eacefd51e922a51093a52e5892..7f0affd5c274bf9c8097d2121805734ca24c866b 100644 (file)
@@ -162,6 +162,7 @@ CAMLprim value x11_show_window(value win, value state) {
 
 CAMLprim value x11_event_loop(value ms, value cbfn) {
     CAMLparam2(ms, cbfn);
+    CAMLlocal1( event );
     while (X.running) {
         XEvent e; XPeekEvent(X.display, &e);
         bool pending = false; //pollfds(Int_val(ms), cbfn);
@@ -176,11 +177,9 @@ CAMLprim value x11_event_loop(value ms, value cbfn) {
                 XNextEvent(X.display, &e);
                 if (XFilterEvent(&e, None)) continue;
                 if (!EventHandlers[e.type]) continue;
-                value event = EventHandlers[e.type](&e);
+                event = EventHandlers[e.type](&e);
                 if (event != Val_unit)
                     caml_callback(cbfn, event);
-                else
-                    puts("ignored");
             }
 
             if (X.running) {