+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
/* Definitons
*****************************************************************************/
enum ColorId {
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 },
[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
+#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>
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 */
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:
}
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 */
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)
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) {
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;
}