]> git.mdlowis.com Git - projs/tide.git/commitdiff
refactored io and telemetry apis and fixed a bug in event handling
authorMichael D. Lowis <mike.lowis@gentex.com>
Thu, 31 Oct 2019 02:20:10 +0000 (22:20 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Thu, 31 Oct 2019 02:20:10 +0000 (22:20 -0400)
inc/edit.h
inc/io.h [new file with mode: 0644]
inc/x11.h
src/fetch.c
src/lib/argv0.c [new file with mode: 0644]
src/lib/gapbuf.c
src/lib/job.c
src/lib/telem.c
src/lib/writefd.c [new file with mode: 0644]
src/lib/x11.c
src/tide.c

index a8b35bc7f384a20dda53b936d58bb5cd37c500a0..41d1447fea743ec73651a86351b13ee1f2fbe0c1 100644 (file)
@@ -1,7 +1,3 @@
-/* Debug Telemetry
- *****************************************************************************/
-void telem_send(char* fmt, ...);
-
 /* Buffer management functions
  *****************************************************************************/
 /* undo/redo list item */
diff --git a/inc/io.h b/inc/io.h
new file mode 100644 (file)
index 0000000..82875e1
--- /dev/null
+++ b/inc/io.h
@@ -0,0 +1,5 @@
+/*
+    Helper functions for reading and writing file descriptors as well as outputting telemetry data.
+*/
+void telem_send(char* fmt, ...);
+long writefd(int fd, char* data, long towrite);
index 35276462d04278f228d2ad4d7ae79d02616402e3..d32fb268c820f6ecd0610f7bd621b580b0a9c22c 100644 (file)
--- a/inc/x11.h
+++ b/inc/x11.h
@@ -134,7 +134,7 @@ void x11_resize(XConf* x, XEvent* e);
 
 void x11_mkwin(XConf* x, int width, int height, int evmask);
 void x11_mkdialog(XConf* x, int width, int height, int evmask);
-void x11_process_events(XConf* x);
+bool x11_process_events(XConf* x);
 void x11_event_loop(XConf* x, void (*redraw)(XConf* x));
 int x11_getptr(XConf* x, int* ptrx, int* ptry);
 uint32_t x11_getkey(XConf* x, XEvent* e);
index f1b77c995765909d771fad9269b0a4c1e507641b..15676aaed979cb0a849b2f641248ec52ae52c6d6 100644 (file)
@@ -1,4 +1,5 @@
 #include <stdc.h>
+#include <io.h>
 #include <regex.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
diff --git a/src/lib/argv0.c b/src/lib/argv0.c
new file mode 100644 (file)
index 0000000..9adafa9
--- /dev/null
@@ -0,0 +1 @@
+char* ARGV0 = NULL;
\ No newline at end of file
index 95ac264a39aacd961086278af53c3407770e2b13..d1d046bfb8e7cec62d75c366f50b00ac60f7cb05 100644 (file)
@@ -2,6 +2,7 @@
 #include <dbc.h>
 #include <utf.h>
 #include <edit.h>
+#include <io.h>
 #include <ctype.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -89,18 +90,6 @@ void gapbuf_init(GapBuf* buf)
     buf->gapend    = buf->bufend;
 }
 
-static long writefd(int fd, char* data, long towrite)
-{
-    require(fd >= 0);
-    long nwrite = 0;
-    while (towrite && ((nwrite = write(fd, data, towrite)) > 0))
-    {
-        data += nwrite;
-        towrite -= nwrite;
-    }
-    return nwrite;
-}
-
 long gapbuf_save(GapBuf* buf, char* path)
 {
     require(buf != NULL);
@@ -138,6 +127,7 @@ void gapbuf_load(GapBuf* buf, char* path)
         buf->bufend   = buf->bufstart + buf->bufsize;
         buf->gapstart = buf->bufstart;
         buf->gapend   = buf->bufend;
+
         /* Read the file into the buffer */
         while (sb.st_size && (nread = read(fd, buf->gapstart, sb.st_size)) > 0)
             buf->gapstart += nread, sb.st_size -= nread;
index a2094d263751779e2fbe83c7e2fec372a73b5fbe..1ec1f6445e5fe2eb66243b2773418e5c4680ef20 100644 (file)
@@ -2,6 +2,7 @@
 #include <utf.h>
 #include <edit.h>
 #include <win.h>
+#include <io.h>
 #include <unistd.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
index b58c94a5c81e5b0952f9ec580c98d34a493f5567..bfb96dcfed2f4b584104441600e259fb3687c9c7 100644 (file)
@@ -2,21 +2,11 @@
 #include <time.h>
 #include <sys/types.h>
 #include <pwd.h>
+#include <io.h>
 
 static int TelemFd = -1;
 static char TelemBuf[16384];
 
-static long writefd(int fd, char* data, long towrite)
-{
-    long nwrite = 0;
-    while (towrite && ((nwrite = write(fd, data, towrite)) > 0))
-    {
-        data += nwrite;
-        towrite -= nwrite;
-    }
-    return nwrite;
-}
-
 static int open_telem(char* path)
 {
     static unsigned long prev = 0;
diff --git a/src/lib/writefd.c b/src/lib/writefd.c
new file mode 100644 (file)
index 0000000..3ee2947
--- /dev/null
@@ -0,0 +1,12 @@
+#include <io.h>
+
+long writefd(int fd, char* data, long towrite)
+{
+    long nwrite = 0;
+    while (towrite && ((nwrite = write(fd, data, towrite)) > 0))
+    {
+        data += nwrite;
+        towrite -= nwrite;
+    }
+    return nwrite;
+}
index 9599e1fa4f5e7ce8de133d1b88601b250346f31e..74fe61d5658485ccf496ac26d941f594e9d2d0ca 100644 (file)
@@ -1,5 +1,6 @@
 #include <x11.h>
 #include <utf.h>
+#include <io.h>
 #include <locale.h>
 #include <signal.h>
 #include <sys/types.h>
@@ -93,8 +94,9 @@ static void update_state(XConf* x, XEvent* e)
     }
 }
 
-void x11_process_events(XConf* x)
+bool x11_process_events(XConf* x)
 {
+    bool has_event = false;
     int nevents;
     /* reap zombie background processes */
     for (int status; waitpid(-1, &status, WNOHANG) > 0;);
@@ -104,14 +106,21 @@ void x11_process_events(XConf* x)
         XGetMotionEvents(x->display, x->self, CurrentTime, CurrentTime, &nevents);
         for (XEvent e; XPending(x->display);)
         {
+            has_event = true;
             XNextEvent(x->display, &e);
             update_state(x, &e);
             if (!XFilterEvent(&e, None) && x->eventfns[e.type])
             {
+                telem_send("EV_HANDLE(type: %d)\n", e.type);
                 (x->eventfns[e.type])(x, &e);
             }
+            else
+            {
+                telem_send("EV_IGNORE(type: %d)\n", e.type);
+            }
         }
     }
+    return has_event;
 }
 
 void x11_event_loop(XConf* x, void (*redraw)(XConf* x))
index 69dc86830c224387de0e82ed55513c05ed091202..96816d0ab5a3f237b06a7ab2382a82c09cd5ce27 100644 (file)
@@ -4,6 +4,7 @@
 #include <edit.h>
 #include <win.h>
 #include <x11.h>
+#include <io.h>
 #include <draw.h>
 #include <locale.h>
 #include <sys/wait.h>
@@ -280,7 +281,10 @@ static void xupdate(Job* job)
 {
     /* redraw if we have changes or if we have input from a job */
     x11_process_events(&X);
-    if (!job) xredraw(&X);
+    if (x11_process_events(&X) || !job)
+    {
+        xredraw(&X);
+    }
 }
 
 void win_init(void)