]> git.mdlowis.com Git - archive/tide-ocaml.git/commitdiff
onshutdown wasnt a fucntion before but is now. ocaml can be super confusing
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 7 Sep 2017 01:58:18 +0000 (21:58 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 7 Sep 2017 01:58:18 +0000 (21:58 -0400)
edit.ml
lib/x11_prims.c

diff --git a/edit.ml b/edit.ml
index 369fbc6ec46f68b5b90161b69f00c2ddc4622f61..e128c7d78c4acbcb16a6a99bd7b95f41f4ac311c 100644 (file)
--- a/edit.ml
+++ b/edit.ml
@@ -15,7 +15,7 @@ let onmousemove mods x y =
 let onupdate width height =
   print_endline "onupdate"
 
-let onshutdown =
+let onshutdown () =
   print_endline "onshutdown"
 
 let onevent = function
@@ -30,28 +30,13 @@ let onevent = function
   | PipeWriteReady e -> print_endline "pipewriteready"
   | PipeReadReady e  -> print_endline "pipereadready"
   | Update e         -> onupdate e.width e.height
-  | Shutdown         -> print_endline "shutdown"
+  | Shutdown         -> onshutdown ()
 
 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
-  | 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 62f440bb91c991e2a2df55cd620bbe5c7b965210..188f7e6b6aea81779a7975dc473e728dc3154dcd 100644 (file)
@@ -14,7 +14,6 @@
    Each group's tags increment, starting at 0, in the order the appear in the
    type definition */
 enum {
-    TShutdown = 0,
     TFocus = 0,
     TKeyPress,
     TMouseClick,
@@ -25,7 +24,9 @@ enum {
     TPipeClosed,
     TPipeWriteReady,
     TPipeReadReady,
-    TUpdate
+    TUpdate,
+    TShutdown = 0,
+    TNone = -1
 };
 
 enum Keys {
@@ -170,22 +171,25 @@ CAMLprim value x11_event_loop(value ms, value cbfn) {
         XEvent e; XPeekEvent(X.display, &e);
         bool pending = false; //pollfds(Int_val(ms), cbfn);
         int nevents  = XEventsQueued(X.display, QueuedAfterFlush);
+
+        /* Update the mouse posistion and simulate a mosuemove event for it */
+        //Window xw; int _, x, y; unsigned int mods;
+        //XQueryPointer(X.display, X.self, &xw, &xw, &_, &_, &x, &y, &mods);
+        //caml_callback(cbfn, mkrecord(TMouseMove, 3, mods, x, y));
+
         if (pending || nevents) {
             /* pare down irrelevant mouse drag events to just the latest */
-            XTimeCoord* coords = XGetMotionEvents(X.display, X.self, CurrentTime, CurrentTime, &nevents);
+            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_int(TNone))
                     caml_callback(cbfn, event);
             }
 
@@ -341,11 +345,11 @@ static value ev_mouse(XEvent* e) {
 }
 
 static value ev_selclear(XEvent* e) {
-    return Val_unit;
+    return Val_int(TNone);
 }
 
 static value ev_selnotify(XEvent* e) {
-    value event = Val_unit;
+    value event = Val_int(TNone);
     if (e->xselection.property == None) {
         char* propdata = readprop(X.self, e->xselection.selection);
         event = mkrecord(TPaste, 1, caml_copy_string(propdata));
@@ -355,22 +359,22 @@ static value ev_selnotify(XEvent* e) {
 }
 
 static value ev_selrequest(XEvent* e) {
-    return Val_unit;
+    return Val_int(TNone);
 }
 
 static value ev_propnotify(XEvent* e) {
-    return Val_unit;
+    return Val_int(TNone);
 }
 
 static value ev_clientmsg(XEvent* e) {
     Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
     if (e->xclient.data.l[0] == wmDeleteMessage)
         return mkrecord(TShutdown, 0);
-    return Val_unit;
+    return Val_int(TNone);
 }
 
 static value ev_configure(XEvent* e) {
-    value event = Val_unit;
+    value event = Val_int(TNone);
     if (e->xconfigure.width != X.width || e->xconfigure.height != X.height) {
         X.width  = e->xconfigure.width;
         X.height = e->xconfigure.height;