]> git.mdlowis.com Git - projs/tide.git/commitdiff
Added edit.h as dep for all .o files and fixed some missing includes
authorMike Lowis <mike.lowis@gentex.com>
Mon, 26 Sep 2016 15:20:15 +0000 (11:20 -0400)
committerMike Lowis <mike.lowis@gentex.com>
Mon, 26 Sep 2016 15:20:15 +0000 (11:20 -0400)
Makefile
buf.c
edit.h
xedit.c

index bc11ad5171a5275b434fae5ff9c7884763365bff..cc38fdae45089d2727a0c6aefe136401a812e15f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -19,4 +19,6 @@ unittests: $(TESTOBJS)
 clean:
        $(RM) edit unittests $(OBJS) $(TESTOBJS)
 
+$(OBJS): edit.h
+
 .PHONY: all test
diff --git a/buf.c b/buf.c
index 0213e2a1225e022a3dd136e3ee880721c84bbc35..8981efd22da55fa9ef333392cfa695d05b8f63f9 100644 (file)
--- a/buf.c
+++ b/buf.c
@@ -1,8 +1,4 @@
 #include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
 #include "edit.h"
 
 void buf_load(Buf* buf, char* path)
diff --git a/edit.h b/edit.h
index 1faf6f9fe6ed6d54ec967464f6792a7e3dc939cf..cf54a80e94f5ca15e2cd82dfb2e8d1eaddcfb6bc 100644 (file)
--- a/edit.h
+++ b/edit.h
@@ -1,3 +1,9 @@
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
 /* Definitons
  *****************************************************************************/
 enum ColorId {
@@ -60,7 +66,7 @@ enum {
 
 static enum { DARK = 0, LIGHT = 1 } ColorBase = DARK;
 
-static Color Palette[][2] = {
+static const Color Palette[][2] = {
 /*   Color Name   =   Dark      Light    */
     [CLR_BASE03]  = { 0x002b36, 0xfdf6e3 },
     [CLR_BASE02]  = { 0x073642, 0xeee8d5 },
@@ -80,5 +86,8 @@ static Color Palette[][2] = {
     [CLR_GREEN]   = { 0x859900, 0x859900 },
 };
 
+#ifdef __MACH__
 #define FONTNAME "Monaco:pixelsize=15:antialias=true:autohint=true"
-
+#else
+#define FONTNAME "Liberation Mono:pixelsize=14:antialias=true:autohint=true"
+#endif
diff --git a/xedit.c b/xedit.c
index f32ef6cad875092a543d0910cfd6b29e98673856..e092175dc4b996726d32a29043f2180cca6a5bf1 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -1,7 +1,6 @@
+#define _GNU_SOURCE
+#include <time.h>
 #include <signal.h>
-#include <stdio.h>
-#include <stdbool.h>
-
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xft/Xft.h>
@@ -37,6 +36,12 @@ void die(char* m) {
     exit(1);
 }
 
+static uint64_t time_ms(void) {
+    struct timespec ts;
+    timespec_get(&ts, TIME_UTC);
+    return (ts.tv_sec * 1000000000L + ts.tv_nsec) / 1000000L;
+}
+
 static int init(void) {
     signal(SIGPIPE, SIG_IGN); // Ignore the SIGPIPE signal
     /* open the X display and get basic attributes */
@@ -125,10 +130,14 @@ static void handle_key(XEvent* e) {
 
         case XK_Down:
             CursorPos = buf_byline(&Buffer, CursorPos, 1);
+            if (buf_bol(&Buffer, CursorPos) > EndRow)
+                EndRow++, StartRow = buf_byline(&Buffer, StartRow, 1);
             break;
 
         case XK_Up:
             CursorPos = buf_byline(&Buffer, CursorPos, -1);
+            if (CursorPos < StartRow)
+                EndRow--, StartRow = buf_byline(&Buffer, StartRow, -1);
             break;
 
         //default:
@@ -204,6 +213,14 @@ static XftColor xftcolor(enum ColorId cid) {
 }
 
 static void redraw(void) {
+    static uint64_t last_draw = 0;
+    uint64_t current = time_ms();
+    //if (current - last_draw < 200)
+    //    return;
+    last_draw = current;
+
+    puts("redraw");
+    uint64_t t1start = time_ms(), t1end;
     int fheight = X.font->height;
     int fwidth  = X.font->max_advance_width;
     /* Allocate the colors */
@@ -215,12 +232,8 @@ static void redraw(void) {
     XftDrawRect(X.xft, &bkgclr, 0, 0, X.width, X.height);
     /* draw the status background */
     XftDrawRect(X.xft, &gtrclr, 0, 0, X.width, fheight);
-    /* Scroll the view until the cursor is visible */
-    if (buf_bol(&Buffer, CursorPos) > EndRow)
-        EndRow++, StartRow = buf_byline(&Buffer, StartRow, 1);
-    else if (CursorPos < StartRow)
-        EndRow--, StartRow = buf_byline(&Buffer, StartRow, -1);
     /* Draw document text */
+    uint64_t t2start = time_ms(), t2end;
     int x = 0, y = 2;
     for (LastDrawnPos = StartRow; LastDrawnPos < buf_end(&Buffer); LastDrawnPos++) {
         if (x * fwidth >= X.width)
@@ -244,9 +257,13 @@ static void redraw(void) {
         x++;
     }
     EndRow = buf_bol(&Buffer, LastDrawnPos-2);
+    t2end = time_ms();
+    printf("text time: %lu\n", t2end - t2start);
     /* flush the pixels to the screen */
     XCopyArea(X.display, X.pixmap, X.window, X.gc, 0, 0, X.width, X.height, 0, 0);
     XFlush(X.display);
+    t1end = time_ms();
+    printf("redraw time: %lu\n", t1end - t1start);
 }
 
 int main(int argc, char** argv) {
@@ -255,15 +272,22 @@ int main(int argc, char** argv) {
     if (argc > 1)
         buf_load(&Buffer, argv[1]);
     XEvent e;
-    while (true) {
-        XPeekEvent(X.display,&e);
-        while (XPending(X.display)) {
-            XNextEvent(X.display, &e);
-            if (!XFilterEvent(&e, None))
-                handle_event(&e);
+
+        while(XNextEvent(X.display, &e) >= 0) {
+            handle_event(&e);
+            if (!XPending(X.display)) {
+                redraw();
+            }
         }
-        redraw();
-    }
+    //while (true) {
+        //XPeekEvent(X.display,&e);
+        //while (XPending(X.display)) {
+        //    XNextEvent(X.display, &e);
+        //    if (!XFilterEvent(&e, None))
+        //        handle_event(&e);
+        //}
+        //redraw();
+    //}
     deinit();
     return 0;
 }