]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
rework event handling to call dedicated functions for each event
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 6 Sep 2017 20:31:42 +0000 (16:31 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 6 Sep 2017 20:31:42 +0000 (16:31 -0400)
edit.ml
lib/x11.ml
lib/x11_prims.c

diff --git a/edit.ml b/edit.ml
index 96f703acc5a0a9d05b5ee65233a7bca35a3d5a5a..938adf7383933036af32759ff6caab41722e0cbd 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -1,15 +1,42 @@
 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 onfocus focused =
+  print_endline "onfocus"
+
+let onkeypress mods rune =
+  print_endline "onkeypress"
+
+let onmousebtn mods btn x y pressed =
+  print_endline "onmousebtn"
+
+let onmousemove mods x y =
+  print_endline "onmousemove"
+
+let onupdate width height =
+  print_endline "onupdate"
+
+let onshutdown =
+  print_endline "onshutdown"
+
+let onevent = 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
+  | MouseMove 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         -> print_endline "shutdown"
 
 let () =
   let win = make_window 640 480 in
   show_window win true;
+  event_loop 50 onevent
+(*
   event_loop 50 (function
   | Focus state      -> onfocus state
   | KeyPress e       -> onkeypress e.mods e.rune
@@ -24,7 +51,7 @@ let () =
   | Update e         -> onupdate e.width e.height
   | Shutdown         -> onshutdown
   )
-
+*)
 (*
   let server = Tide.start_server () in
   let nargs = Array.length Sys.argv in
index 817d78c9756acd18f86477aac7500ffb231d651c..0d4b19dab8e92619e1c88113d921c60af5c16db9 100644 (file)
@@ -5,7 +5,7 @@ type xevent =
   | 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 }
+  | MouseMove of { mods: int; x: int; y: int }
   | Paste of { text: string }
   | Command of { commands: string array }
   | PipeClosed of { fd: int }
index 7f0affd5c274bf9c8097d2121805734ca24c866b..1d454c2f5a17e8e20535a3ece7e56b992142dfa6 100644 (file)
@@ -15,7 +15,7 @@ enum {
     TKeyPress,
     TMouseClick,
     TMouseRelease,
-    TMouseDrag,
+    TMouseMove,
     TPaste,
     TCommand,
     TPipeClosed,
@@ -172,18 +172,28 @@ CAMLprim value x11_event_loop(value ms, value cbfn) {
             XTimeCoord* coords = XGetMotionEvents(X.display, X.self, CurrentTime, CurrentTime, &nevents);
             if (coords) XFree(coords);
 
+            /* Update the mouse posistion and simulate a mosuemove event for it */
+            // XQueryPointer
+            //caml_callback(cbfn, mkrecord(TMouseMove, 3, mods, x, y));
+
             /* now take the events, convert them, and call the callback */
             for (XEvent e; XPending(X.display);) {
                 XNextEvent(X.display, &e);
                 if (XFilterEvent(&e, None)) continue;
                 if (!EventHandlers[e.type]) continue;
                 event = EventHandlers[e.type](&e);
-                if (event != Val_unit)
+                if (event != Val_unit) {
+                puts("B event");
+                printf("event: %#x\n", event);
                     caml_callback(cbfn, event);
+                puts("A event");
+                }
             }
 
             if (X.running) {
+                puts("B event");
                 caml_callback(cbfn, mkrecord(TUpdate, 2, X.width, X.height));
+                puts("A event");
                 XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
             }
         }
@@ -356,11 +366,10 @@ static value ev_propnotify(XEvent* e) {
 }
 
 static value ev_clientmsg(XEvent* e) {
-    value event = Val_unit;
     Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
     if (e->xclient.data.l[0] == wmDeleteMessage)
-        event = mkrecord(TShutdown, 0);
-    return event;
+        return mkrecord(TShutdown, 1, 0);
+    return Val_unit;
 }
 
 static value ev_configure(XEvent* e) {