From 8da1fc6057f0ba77d04429c81913e850864ee80b Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Wed, 6 Sep 2017 21:07:53 -0400 Subject: [PATCH] fixed segfault in handling of TShutdown --- Makefile | 2 +- edit.ml | 2 +- lib/x11_prims.c | 21 +++++++++------------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 6f84b66..22c6baa 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ LIBS = -L/usr/X11R6/lib -lX11 -lXft ifeq ($(NATIVE), 1) OC = ocamlopt - OCFLAGS = + OCFLAGS = -g MKLIB = ocamlmklib MKLIBFLAGS = -custom OBJEXT = cmx diff --git a/edit.ml b/edit.ml index 938adf7..369fbc6 100644 --- a/edit.ml +++ b/edit.ml @@ -23,7 +23,7 @@ let onevent = function | 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 + | MouseMove e -> onmousemove e.mods e.x e.y | Paste e -> print_endline "paste" | Command e -> print_endline "command" | PipeClosed e -> print_endline "pipeclosed" diff --git a/lib/x11_prims.c b/lib/x11_prims.c index 1d454c2..62f440b 100644 --- a/lib/x11_prims.c +++ b/lib/x11_prims.c @@ -9,8 +9,12 @@ #include #include -/* The order of this enum should match the type specified in x11.ml */ +/* The order of this enum should match the type specified in x11.ml. The + variants are divided into two groups, those with args and those without. + Each group's tags increment, starting at 0, in the order the appear in the + type definition */ enum { + TShutdown = 0, TFocus = 0, TKeyPress, TMouseClick, @@ -21,8 +25,7 @@ enum { TPipeClosed, TPipeWriteReady, TPipeReadReady, - TUpdate, - TShutdown + TUpdate }; enum Keys { @@ -182,18 +185,12 @@ CAMLprim value x11_event_loop(value ms, value cbfn) { if (XFilterEvent(&e, None)) continue; if (!EventHandlers[e.type]) continue; event = EventHandlers[e.type](&e); - if (event != Val_unit) { - puts("B event"); - printf("event: %#x\n", event); + if (event != Val_unit) 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); } } @@ -336,7 +333,7 @@ static value ev_mouse(XEvent* e) { int mods = e->xbutton.state, btn = e->xbutton.button, x = e->xbutton.x, y = e->xbutton.y; if (e->type == MotionNotify) - return mkrecord(TMouseDrag, 3, Val_int(mods), Val_int(x), Val_int(y)); + return mkrecord(TMouseMove, 3, Val_int(mods), Val_int(x), Val_int(y)); else if (e->type == ButtonPress) return mkrecord(TMouseClick, 4, Val_int(mods), Val_int(btn), Val_int(x), Val_int(y)); else @@ -368,7 +365,7 @@ static value ev_propnotify(XEvent* e) { 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, 1, 0); + return mkrecord(TShutdown, 0); return Val_unit; } -- 2.52.0