summaryrefslogtreecommitdiff
path: root/patch/acme-moveto-undo/moveto.c
diff options
context:
space:
mode:
Diffstat (limited to 'patch/acme-moveto-undo/moveto.c')
-rw-r--r--patch/acme-moveto-undo/moveto.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/patch/acme-moveto-undo/moveto.c b/patch/acme-moveto-undo/moveto.c
new file mode 100644
index 0000000..dae0a6b
--- /dev/null
+++ b/patch/acme-moveto-undo/moveto.c
@@ -0,0 +1,37 @@
+#include <u.h>
+#include <libc.h>
+#include <draw.h>
+#include <thread.h>
+#include <cursor.h>
+#include <mouse.h>
+#include <keyboard.h>
+#include <frame.h>
+#include <fcall.h>
+#include <plumb.h>
+#include "dat.h"
+
+static Point newmouse;
+static Point oldmouse;
+
+/* call moveto, but record old and new mouse positions */
+void
+recmoveto(Mousectl *mc, Point pt){
+ static vlong prevtime = 0;
+ vlong curtime = nsec();
+ if(curtime-prevtime>500000000){ /* 500ms */
+ newmouse = pt;
+ oldmouse = mouse->xy;
+ }
+ prevtime = curtime;
+ moveto(mc, pt);
+}
+
+void
+undomoveto(Mousectl *mc){
+ Point tmp;
+ moveto(mc, oldmouse);
+ tmp = newmouse;
+ newmouse = oldmouse;
+ oldmouse = tmp;
+}
+