]> git.mdlowis.com Git - projs/tide.git/commitdiff
started reworking event loop
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 26 Mar 2018 03:22:25 +0000 (23:22 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 26 Mar 2018 03:22:25 +0000 (23:22 -0400)
inc/edit.h
lib/job.c
lib/x11.c
tide.c

index 08cfa11e0f4b10a768dd3cadf394747549f48505..01f1e62c7852ccce1dd363eb033e32c3f839c625 100644 (file)
@@ -211,6 +211,7 @@ struct Job {
 };
 
 bool job_poll(int fd, int ms);
+void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data);
 void job_create(char** cmd, jobfn_t readfn, jobfn_t writefn, void* data);
 void job_start(char** cmd, char* data, size_t ndata, View* dest);
 
index bc6451d5fb2dc01a648b5f29f30323169b77f414..d6601747c9e91934d22064c9838414b354da0bf3 100644 (file)
--- a/lib/job.c
+++ b/lib/job.c
@@ -48,18 +48,20 @@ bool job_poll(int fd, int ms) {
     return (ret > 0);
 }
 
+void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) {
+    Job *job = calloc(1, sizeof(job));
+    job->fd = fd;
+    job->readfn = readfn;
+    job->writefn = writefn;
+    job->data = data;
+    job->next = JobList;
+    JobList = job;
+}
+
 void job_create(char** cmd, jobfn_t readfn, jobfn_t writefn, void* data) {
     int fd = -1, pid = -1;
-    if (job_execute(cmd, &fd, &pid) > 0) {
-        Job *job = calloc(1, sizeof(job));
-        job->fd = fd;
-        job->pid = pid;
-        job->readfn = readfn;
-        job->writefn = writefn;
-        job->data = data;
-        job->next = JobList;
-        JobList = job;
-    }
+    if (job_execute(cmd, &fd, &pid) > 0)
+        job_spawn(fd, readfn, writefn, data);
 }
 
 void job_start(char** cmd, char* data, size_t ndata, View* dest) {
index eac2b88357ca97a9a9d20de6a5180dcc3c20a5df..6ce53ad79bd496f83df37141968ddc8b34a67937 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -401,7 +401,27 @@ void win_save(char* path) {
     buf_save(&(view->buffer));
 }
 
+static void xupdate(Job* job) {
+    bool pending = job_poll(ConnectionNumber(X.display), Timeout);
+    int nevents = XEventsQueued(X.display, QueuedAfterFlush);
+    if (pending || nevents) {
+        for (XEvent e; XPending(X.display);) {
+            XNextEvent(X.display, &e);
+            if (!XFilterEvent(&e, None) && EventHandlers[e.type])
+                (EventHandlers[e.type])(&e);
+        }
+           onredraw(X.width, X.height);
+           XCopyArea(X.display, X.pixmap, X.self, X.gc, 0, 0, X.width, X.height, 0, 0);
+    }
+       XFlush(X.display);
+}
+
 void win_loop(void) {
+#if 0
+    XMapWindow(X.display, X.self);
+    job_spawn(ConnectionNumber(X.display), xupdate, 0, 0);
+    while (1) job_poll(-1, Timeout);
+#else
     XMapWindow(X.display, X.self);
     while (Running) {
         bool pending = job_poll(ConnectionNumber(X.display), Timeout);
@@ -426,8 +446,11 @@ void win_loop(void) {
         job_start((char*[]){ "xcpd", NULL }, text, len, NULL);
         while (job_poll(-1, 100));
     }
+#endif
 }
 
+
+
 void win_settext(WinRegion id, char* text) {
     View* view = win_view(id);
     view->buffer.gapstart = view->buffer.bufstart;
@@ -545,6 +568,16 @@ static void onredraw(int width, int height) {
             Row* row = view_getrow(view, y);
             draw_glyphs(Regions[i].x, Regions[i].y + ((y+1) * fheight), row->cols, row->rlen, row->len);
         }
+
+        /* place the cursor on screen */
+        if (Regions[i].csrx != SIZE_MAX && Regions[i].csry != SIZE_MAX) {
+            x11_draw_rect(
+                Regions[i].clrcsr.fg,
+                Regions[i].x + (Regions[i].csrx * fwidth),
+                Regions[i].y + (Regions[i].csry * fheight),
+                1, fheight);
+        }
+
     }
 
     /* draw the scroll region */
@@ -556,14 +589,6 @@ static void onredraw(int width, int height) {
     x11_draw_rect(clr_scroll.bg, 0, Regions[SCROLL].y - 2, Regions[SCROLL].width, thumbreg);
     x11_draw_rect(clr_scroll.fg, 0, thumboff, Regions[SCROLL].width, thumbsz);
 
-    /* place the cursor on screen */
-    if (Regions[Focused].csrx != SIZE_MAX && Regions[Focused].csry != SIZE_MAX) {
-        x11_draw_rect(
-            Regions[Focused].clrcsr.fg,
-            Regions[Focused].x + (Regions[Focused].csrx * fwidth),
-            Regions[Focused].y + (Regions[Focused].csry * fheight),
-            1, fheight);
-    }
 }
 
 static void oninput(int mods, Rune key) {
diff --git a/tide.c b/tide.c
index c7cf3008aa58135048b99bc80adb791eeef8b421..97006d583bd6c0255ea3df6482c6e1465490976f 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -634,6 +634,7 @@ void onlayout(void) {
 
 void onshutdown(void) {
     quit();
+    exit(0);
 }
 
 static void oninput(Rune rune) {
@@ -689,6 +690,7 @@ void edit_relative(char* path) {
     free(origdir);
 }
 
+
 #ifndef TEST
 int main(int argc, char** argv) {
     /* setup the shell */