From 58ffc3f0cb6149f821912a382c62f235b22ebdee Mon Sep 17 00:00:00 2001 From: Mike Lowis Date: Mon, 26 Sep 2016 11:20:15 -0400 Subject: [PATCH] Added edit.h as dep for all .o files and fixed some missing includes --- Makefile | 2 ++ buf.c | 4 ---- edit.h | 13 +++++++++++-- xedit.c | 56 ++++++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 53 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index bc11ad5..cc38fda 100644 --- 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 0213e2a..8981efd 100644 --- a/buf.c +++ b/buf.c @@ -1,8 +1,4 @@ #include -#include -#include -#include - #include "edit.h" void buf_load(Buf* buf, char* path) diff --git a/edit.h b/edit.h index 1faf6f9..cf54a80 100644 --- a/edit.h +++ b/edit.h @@ -1,3 +1,9 @@ +#include +#include +#include +#include +#include + /* 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 f32ef6c..e092175 100644 --- a/xedit.c +++ b/xedit.c @@ -1,7 +1,6 @@ +#define _GNU_SOURCE +#include #include -#include -#include - #include #include #include @@ -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, >rclr, 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; } -- 2.54.0