]> git.mdlowis.com Git - projs/tide.git/commitdiff
attempted to replace color palette access with new config options
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 21 Mar 2018 01:35:12 +0000 (21:35 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 21 Mar 2018 01:35:12 +0000 (21:35 -0400)
config.mk
inc/edit.h
inc/win.h
lib/buf.c
lib/colors.c
lib/config.c
lib/utf8.c
lib/view.c
lib/win.c
lib/x11.c
tide.c

index 928b2cc4697e3476505c69f3f1d0a7f6144eea0f..9a9d43d2eb5dac23f77608b0f8085bf445bc1f4d 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -15,7 +15,7 @@ INCS += -I/usr/include/freetype2
 
 # Compiler Setup
 CC = cc
-CFLAGS = --std=c99 -MMD $(INCS)
+CFLAGS = -g --std=c99 -MMD $(INCS)
 
 # Linker Setup
 LD = $(CC)
index e17ec0aa2590a48d66728b6a987b239cebc38e85..7519026d15786c7ddfbd0c74dfbb76b89a6e6f59 100644 (file)
@@ -232,26 +232,19 @@ int exec_spawn(char** cmd, int* in, int* out);
 
 /* Configuration Data
  *****************************************************************************/
-enum { /* Configuration Variables */
-    FontString = 0, EditTagString, CmdTagString, WinWidth, WinHeight,
-    LineSpacing, LineNumbers, RulerColumn, EventTimeout, CopyIndent, TrimOnSave,
-    ExpandTabs, TabWidth, ScrollLines, DblClickTime, MaxScanDist, SyntaxEnabled,
-    Color00, Color01, Color02, Color03, Color04, Color05, Color06, Color07,
-    Color08, Color09, Color10, Color11, Color12, Color13, Color14, Color15,
+typedef struct { int fg, bg; } CPair;
 
-    ClrScrollNor, ClrGutterNor, ClrGutterSel, ClrStatusNor, ClrTagsNor,
+extern char TagString[], FontString[];
+extern int Palette[16];
+extern int WinWidth, WinHeight, LineSpacing, RulerPos, Timeout, TabWidth, ScrollBy,
+    ClickTime, MaxScanDist, LineNums, Syntax, CopyIndent, TrimOnSave, ExpandTabs;
+extern CPair Colors[28];
+
+enum { /* Color Variables */
+    ClrScrollNor = 0, ClrGutterNor, ClrGutterSel, ClrStatusNor, ClrTagsNor,
     ClrTagsSel, ClrTagsCsr, ClrEditNor, ClrEditSel, ClrEditCsr, ClrEditRul,
     ClrBorders,
-
     SynNormal, SynComment, SynConstant, SynString, SynChar, SynNumber,
     SynBoolean, SynFloat, SynVariable, SynFunction, SynKeyword, SynOperator,
     SynPreProc, SynType, SynStatement, SynSpecial
 };
-
-void config_init(void* disp);
-void config_set_int(int key, int val);
-void config_set_bool(int key, bool val);
-void config_set_str(int key, char* val);
-int config_get_int(int key);
-bool config_get_bool(int key);
-char* config_get_str(int key);
index d1cef57cee835970cc2c16e0cf3e1ac6f58762fb..1194a5caca2873b35d7347e1d1fef4b37bc94fb6 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -24,7 +24,7 @@ typedef struct {
     size_t x, y;
     size_t height, width;
     size_t csrx, csry;
-    int clrnor, clrsel, clrcsr;
+    CPair clrnor, clrsel, clrcsr;
     bool warp_ptr;
     View view;
 } Region;
index e7717547498333ef4a37ea9c52890d602235a52b..eba84e6ed0086ac268dbe369d15117e871d2f35b 100644 (file)
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -30,8 +30,8 @@ void buf_init(Buf* buf, void (*errfn)(char*)) {
 
     /* reset the state to defaults */
     buf->modified    = false;
-    buf->expand_tabs = config_get_bool(ExpandTabs);
-    buf->copy_indent = config_get_bool(CopyIndent);
+    buf->expand_tabs = ExpandTabs;
+    buf->copy_indent = CopyIndent;
     buf->charset     = UTF_8;
     buf->crlf        = 0;
     buf->bufsize     = 8192;
@@ -144,7 +144,7 @@ size_t buf_insert(Buf* buf, bool fmt, size_t off, Rune rune) {
     bool is_eol = (rune == '\n' || rune == RUNE_CRLF);
     buf->modified = true;
     if (fmt && buf->expand_tabs && rune == '\t') {
-        size_t tabwidth = config_get_int(TabWidth);
+        size_t tabwidth = TabWidth;
         size_t n = (tabwidth - ((off - buf_bol(buf, off)) % tabwidth));
         log_insert(buf, &(buf->undo), off, off+n);
         for(; n > 0; n--) off += insert(buf, off, ' ');
index 572827004bf9828dfb68d40180b6801ba6d620e7..34acaca45c8c2bcef3437a5d2bb95265578ef84e 100644 (file)
@@ -15,7 +15,7 @@ static int read_byte(void);
 static int read_num(void);
 
 void colors_init(char* path) {
-    if (config_get_bool(SyntaxEnabled))
+    if (Syntax)
         exec_spawn((char*[]){ "tide-hl.rb", path, NULL }, &ChildIn, &ChildOut);
 }
 
@@ -25,7 +25,7 @@ SyntaxSpan* colors_scan(SyntaxSpan* spans, Buf* buf, size_t beg, size_t end) {
     /* if the engine died, clear all highlights and quit */
     if (ChildIn < 0 || !buf->path)
         return colors_rewind(spans, 0);
-
+#if 0
     /* commence the highlighting */
     if (beg < end) {
         write_chunk(buf, beg, end);
@@ -44,6 +44,7 @@ SyntaxSpan* colors_scan(SyntaxSpan* spans, Buf* buf, size_t beg, size_t end) {
         fflush(stdout);
         DataBeg = DataEnd = Buffer;
     }
+#endif
     return firstspan;
 }
 
index e22fe3553cb3a68420f32b1db8d33f7098ec4495..16bce14e2f47e8ad97a4acf0f0eaa57ee9ecd75d 100644 (file)
@@ -4,7 +4,6 @@
 #include <utf.h>
 #include <edit.h>
 
-#if 0
 enum { OFF = 0, ON = 1 };
 
 #ifdef __MACH__
@@ -15,21 +14,21 @@ enum { OFF = 0, ON = 1 };
     #define LNSPACE 1
 #endif
 
-char Tags[] = "Quit Save Undo Redo Cut Copy Paste | Find ";
-char Font[] = FONT;
+char TagString[] = "Quit Save Undo Redo Cut Copy Paste | Find ";
+char FontString[] = FONT;
 
 int /* Integer config options */
     WinWidth = 640,
     WinHeight = 480,
     LineSpacing = LNSPACE,
-    Ruler = 80,
+    RulerPos = 80,
     Timeout = 50,
     TabWidth = 4,
     ScrollBy = 4,
     ClickTime = 500,
     MaxScanDist = 0,
     LineNums = ON,
-    Syntax = ON,
+    Syntax = OFF,
     CopyIndent = ON,
     TrimOnSave = ON,
     ExpandTabs = ON;
@@ -53,206 +52,35 @@ int Palette[16] = {
     0xff859900
 };
 
-struct { int fg, bg; } Colors[] = {
+CPair Colors[28] = {
     /* UI Colors */
-    [ClrScrollNor] = { .bg = 0, .fg = 0 },
-    [ClrGutterNor] = { .bg = 0, .fg = 0 },
-    [ClrGutterSel] = { .bg = 0, .fg = 0 },
-    [ClrStatusNor] = { .bg = 0, .fg = 0 },
-    [ClrTagsNor]   = { .bg = 0, .fg = 0 },
-    [ClrTagsSel]   = { .bg = 0, .fg = 0 },
-    [ClrTagsCsr]   = { .bg = 0, .fg = 0 },
-    [ClrEditNor]   = { .bg = 0, .fg = 0 },
-    [ClrEditSel]   = { .bg = 0, .fg = 0 },
-    [ClrEditCsr]   = { .bg = 0, .fg = 0 },
-    [ClrEditRul]   = { .bg = 0, .fg = 0 },
-    [ClrBorders]   = { .bg = 0, .fg = 0 },
+    [ClrScrollNor] = { .bg = 3, .fg = 0 },
+    [ClrGutterNor] = { .bg = 1, .fg = 4 },
+    [ClrGutterSel] = { .bg = 2, .fg = 7 },
+    [ClrStatusNor] = { .bg = 0, .fg = 5 },
+    [ClrTagsNor]   = { .bg = 1, .fg = 5 },
+    [ClrTagsSel]   = { .bg = 2, .fg = 5 },
+    [ClrTagsCsr]   = { .bg = 0, .fg = 7 },
+    [ClrEditNor]   = { .bg = 0, .fg = 5 },
+    [ClrEditSel]   = { .bg = 2, .fg = 5 },
+    [ClrEditCsr]   = { .bg = 0, .fg = 7 },
+    [ClrEditRul]   = { .bg = 0, .fg = 1 },
+    [ClrBorders]   = { .bg = 3, .fg = 3 },
     /* Syntax Colors */
-    [SynNormal]    = { .bg = 0, .fg = 0 },
-    [SynComment]   = { .bg = 0, .fg = 0 },
-    [SynConstant]  = { .bg = 0, .fg = 0 },
-    [SynNumber]    = { .bg = 0, .fg = 0 },
-    [SynBoolean]   = { .bg = 0, .fg = 0 },
-    [SynFloat]     = { .bg = 0, .fg = 0 },
-    [SynString]    = { .bg = 0, .fg = 0 },
-    [SynChar]      = { .bg = 0, .fg = 0 },
-    [SynPreProc]   = { .bg = 0, .fg = 0 },
-    [SynType]      = { .bg = 0, .fg = 0 },
-    [SynKeyword]   = { .bg = 0, .fg = 0 },
-    [SynStatement] = { .bg = 0, .fg = 0 },
-    [SynFunction]  = { .bg = 0, .fg = 0 },
-    [SynVariable]  = { .bg = 0, .fg = 0 },
-    [SynSpecial]   = { .bg = 0, .fg = 0 },
-    [SynOperator]  = { .bg = 0, .fg = 0 },
+    [SynNormal]    = { .bg = 0, .fg =  },
+    [SynComment]   = { .bg = 0, .fg =  },
+    [SynConstant]  = { .bg = 0, .fg = 14 },
+    [SynNumber]    = { .bg = 0, .fg = 14 },
+    [SynBoolean]   = { .bg = 0, .fg = 14 },
+    [SynFloat]     = { .bg = 0, .fg = 14 },
+    [SynString]    = { .bg = 0, .fg = 14 },
+    [SynChar]      = { .bg = 0, .fg = 14 },
+    [SynPreProc]   = { .bg = 0, .fg =  },
+    [SynType]      = { .bg = 0, .fg =  },
+    [SynKeyword]   = { .bg = 0, .fg = 15 },
+    [SynStatement] = { .bg = 0, .fg = 10 },
+    [SynFunction]  = { .bg = 0, .fg = 11 },
+    [SynVariable]  = { .bg = 0, .fg = 12 },
+    [SynSpecial]   = { .bg = 0, .fg = 13 },
+    [SynOperator]  = { .bg = 0, .fg = 12 },
 };
-
-#endif
-
-XrmDatabase DB;
-struct {
-    char* name;
-    enum { STRING, INTEGER, BOOLEAN } type;
-    union {
-        bool opt;
-        int num;
-        char* str;
-    } value;
-} Options[] = {
-    [EditTagString] = { "tide.ui.tags.edit", STRING, {
-        .str = "Quit Save Undo Redo Cut Copy Paste | Find " } },
-    [CmdTagString] = { "tide.ui.tags.cmd", STRING, {
-        .str = "Quit Undo Redo Cut Copy Paste | Send Find " } },
-
-#ifdef __MACH__
-    [FontString] = { "tide.ui.font", STRING, {
-        .str = "Monaco:size=10:antialias=true:autohint=true" } },
-    [LineSpacing]  = { "tide.ui.line_spacing", INTEGER, { .num = 0    } },
-#else
-    [FontString] = { "tide.ui.font", STRING, {
-        .str = "Liberation Mono:pixelsize=14:antialias=true:autohint=true" } },
-    [LineSpacing]  = { "tide.ui.line_spacing", INTEGER, { .num = 1    } },
-#endif
-
-    /* user interface related options */
-    [WinWidth]      = { "tide.ui.width",          INTEGER, { .num = 640  } },
-    [WinHeight]     = { "tide.ui.height",         INTEGER, { .num = 480  } },
-    [LineNumbers]   = { "tide.ui.line_numbers",   BOOLEAN, { .opt = true } },
-    [SyntaxEnabled] = { "tide.ui.syntax_enabled", BOOLEAN, { .opt = true } },
-    [RulerColumn]   = { "tide.ui.ruler_column",   INTEGER, { .num = 80   } },
-    [EventTimeout]  = { "tide.ui.timeout",        INTEGER, { .num = 50   } },
-
-    /* input related options */
-    [CopyIndent]   = { "tide.input.copy_indent",   BOOLEAN, { .opt = true  } },
-    [TrimOnSave]   = { "tide.input.trim_on_save",  BOOLEAN, { .opt = true  } },
-    [ExpandTabs]   = { "tide.input.expand_tabs",   BOOLEAN, { .opt = true  } },
-    [TabWidth]     = { "tide.input.tab_width",     INTEGER, { .num = 4     } },
-    [ScrollLines]  = { "tide.input.scroll_lines",  INTEGER, { .num = 4     } },
-    [DblClickTime] = { "tide.input.click_time",    INTEGER, { .num = 500   } },
-    [MaxScanDist]  = { "tide.input.max_scan_dist", INTEGER, { .num = 0     } },
-
-    /* default color palette definition */
-    [Color00] = { "tide.palette.00", INTEGER, { .num = 0xff002b36 } },
-    [Color01] = { "tide.palette.01", INTEGER, { .num = 0xff073642 } },
-    [Color02] = { "tide.palette.02", INTEGER, { .num = 0xff40565d } },
-    [Color03] = { "tide.palette.03", INTEGER, { .num = 0xff657b83 } },
-    [Color04] = { "tide.palette.04", INTEGER, { .num = 0xff839496 } },
-    [Color05] = { "tide.palette.05", INTEGER, { .num = 0xff93a1a1 } },
-    [Color06] = { "tide.palette.06", INTEGER, { .num = 0xffeee8d5 } },
-    [Color07] = { "tide.palette.07", INTEGER, { .num = 0xfffdf6e3 } },
-    [Color08] = { "tide.palette.08", INTEGER, { .num = 0xffb58900 } }, // Yellow
-    [Color09] = { "tide.palette.09", INTEGER, { .num = 0xffcb4b16 } }, // Orange
-    [Color10] = { "tide.palette.10", INTEGER, { .num = 0xffdc322f } }, // Red
-    [Color11] = { "tide.palette.11", INTEGER, { .num = 0xffd33682 } }, // Magenta
-    [Color12] = { "tide.palette.12", INTEGER, { .num = 0xff6c71c4 } }, // Violet
-    [Color13] = { "tide.palette.13", INTEGER, { .num = 0xff268bd2 } }, // Blue
-    [Color14] = { "tide.palette.14", INTEGER, { .num = 0xff2aa198 } }, // Cyan
-    [Color15] = { "tide.palette.15", INTEGER, { .num = 0xff859900 } }, // Green
-
-    /* UI Colors */
-    [ClrScrollNor] = { "tide.colors.scroll.normal",   INTEGER, { .num = 0x0300 } },
-    [ClrGutterNor] = { "tide.colors.gutter.normal",   INTEGER, { .num = 0x0104 } },
-    [ClrGutterSel] = { "tide.colors.gutter.selected", INTEGER, { .num = 0x0207 } },
-    [ClrStatusNor] = { "tide.colors.status.normal",   INTEGER, { .num = 0x0005 } },
-    [ClrTagsNor]   = { "tide.colors.tags.normal",     INTEGER, { .num = 0x0105 } },
-    [ClrTagsSel]   = { "tide.colors.tags.selected",   INTEGER, { .num = 0x0205 } },
-    [ClrTagsCsr]   = { "tide.colors.tags.cursor",     INTEGER, { .num = 0x07   } },
-    [ClrEditNor]   = { "tide.colors.edit.normal",     INTEGER, { .num = 0x0005 } },
-    [ClrEditSel]   = { "tide.colors.edit.selected",   INTEGER, { .num = 0x0205 } },
-    [ClrEditCsr]   = { "tide.colors.edit.cursor",     INTEGER, { .num = 0x07   } },
-    [ClrEditRul]   = { "tide.colors.edit.ruler",      INTEGER, { .num = 0x01   } },
-    [ClrBorders]   = { "tide.colors.borders",         INTEGER, { .num = 0x0303 } },
-
-    /* Syntax Colors */
-    [SynNormal]    = { "tide.colors.syntax.normal",       INTEGER, { .num = 0x0005 } },
-    [SynComment]   = { "tide.colors.syntax.comment",      INTEGER, { .num = 0x0003 } },
-    [SynConstant]  = { "tide.colors.syntax.constant",     INTEGER, { .num = 0x000E } },
-    [SynNumber]    = { "tide.colors.syntax.number",       INTEGER, { .num = 0x000E } },
-    [SynBoolean]   = { "tide.colors.syntax.boolean",      INTEGER, { .num = 0x000E } },
-    [SynFloat]     = { "tide.colors.syntax.float",        INTEGER, { .num = 0x000E } },
-    [SynString]    = { "tide.colors.syntax.string",       INTEGER, { .num = 0x000E } },
-    [SynChar]      = { "tide.colors.syntax.character",    INTEGER, { .num = 0x000E } },
-    [SynPreProc]   = { "tide.colors.syntax.preprocessor", INTEGER, { .num = 0x0009 } },
-    [SynType]      = { "tide.colors.syntax.type",         INTEGER, { .num = 0x0008 } },
-    [SynKeyword]   = { "tide.colors.syntax.keyword",      INTEGER, { .num = 0x000F } },
-    [SynStatement] = { "tide.colors.syntax.statement",    INTEGER, { .num = 0x000A } },
-    [SynFunction]  = { "tide.colors.syntax.function",     INTEGER, { .num = 0x000B } },
-    [SynVariable]  = { "tide.colors.syntax.variable",     INTEGER, { .num = 0x000C } },
-    [SynSpecial]   = { "tide.colors.syntax.special",      INTEGER, { .num = 0x000D } },
-    [SynOperator]  = { "tide.colors.syntax.operator",     INTEGER, { .num = 0x000C } },
-};
-
-void config_init(void* disp) {
-    XrmDatabase db;
-    char *homedir  = getenv("HOME"),
-         *userfile = strmcat(homedir, "/.config/tiderc", 0),
-         *rootfile = strmcat(homedir, "/.Xdefaults", 0);
-    XrmInitialize();
-
-    /* load from xrdb or .Xdefaults */
-    if (XResourceManagerString(disp) != NULL)
-        db = XrmGetStringDatabase(XResourceManagerString(disp));
-    else
-        db = XrmGetFileDatabase(rootfile);
-    XrmMergeDatabases(db, &DB);
-
-    /* load user settings from ~/.config/tiderc */
-    db = XrmGetFileDatabase(userfile);
-    (void)XrmMergeDatabases(db, &DB);
-
-    /* cleanup */
-    free(userfile);
-    free(rootfile);
-
-    char* type;
-    XrmValue val;
-    for (size_t i = 0; i < nelem(Options); i++) {
-        if (XrmGetResource(DB, Options[i].name, NULL, &type, &val)) {
-            char* value = (char*)(val.addr);
-            size_t len = val.size;
-            switch (Options[i].type) {
-                case STRING:
-                    if (*value == '\'') value++, len -= 2;
-                    Options[i].value.str = strndup(value, len);
-                    break;
-
-                case INTEGER:
-                    Options[i].value.num = strtol(value, NULL, 0);
-                    break;
-
-                case BOOLEAN:
-                    Options[i].value.opt = !strncmp(value, "true", len);
-                    break;
-            }
-        }
-    }
-}
-
-void config_set_int(int key, int val) {
-    assert(Options[key].type == INTEGER);
-    Options[key].value.num = val;
-}
-
-void config_set_bool(int key, bool val) {
-    assert(Options[key].type == BOOLEAN);
-    Options[key].value.opt = val;
-}
-
-void config_set_str(int key, char* val) {
-    assert(Options[key].type == STRING);
-    Options[key].value.str = val;
-}
-
-int config_get_int(int key) {
-    assert(Options[key].type == INTEGER);
-    return Options[key].value.num;
-}
-
-bool config_get_bool(int key) {
-    assert(Options[key].type == BOOLEAN);
-    return Options[key].value.num;
-}
-
-char* config_get_str(int key) {
-    assert(Options[key].type == STRING);
-    return Options[key].value.str;
-}
index 01842d6f238633c7b3263ffdfe955e1a21839b36..9cae7952ac7145054607266cf3407eb4709b02ae 100644 (file)
@@ -75,7 +75,7 @@ bool utf8decode(Rune* rune, size_t* length, int byte) {
 }
 
 int runewidth(unsigned col, Rune r) {
-    size_t tabwidth = config_get_int(TabWidth);
+    size_t tabwidth = TabWidth;
     if (r == '\t') return (tabwidth - (col % tabwidth));
     int width = wcwidth(r);
     if (width < 0) width = 1;
index 5e817e344e80dd48a809d2c55a5e8cc96bf92093..19a189ea69f766609b99d99d32c7b835c7ddcc28 100644 (file)
@@ -112,7 +112,7 @@ void view_update(View* view, int clrnor, int clrsel, size_t* csrx, size_t* csry)
            last  = view->rows[view->nrows-1]->off + view->rows[view->nrows-1]->rlen;
     view->spans = colors_rewind(view->spans, first);
     size_t start = (view->spans ? view->spans->end : 0);
-    size_t scandist = config_get_int(MaxScanDist);
+    size_t scandist = MaxScanDist;
     if (scandist && first-start > scandist)
         start = first - scandist;
     view->spans = colors_scan(view->spans, &(view->buffer), start, last+1);
@@ -392,7 +392,7 @@ void view_scrollpage(View* view, int move) {
 
 void view_indent(View* view, int dir) {
     Buf* buf = &(view->buffer);
-    unsigned indoff = (buf->expand_tabs ? config_get_int(TabWidth) : 1);
+    unsigned indoff = (buf->expand_tabs ? TabWidth : 1);
     selswap(&(view->selection));
     view->selection.beg = buf_bol(buf, view->selection.beg);
     view->selection.end = buf_eol(buf, view->selection.end);
index 198e4aeb78f5985b2437c6bc0219a1768a7463d2..7f7c8d26f096f4741d204070502ccfc3b6f724ee 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -9,6 +9,9 @@
 #include <win.h>
 #include <ctype.h>
 
+static int clrfg(int id) { return Palette[Colors[id].fg]; }
+static int clrbg(int id) { return Palette[Colors[id].bg]; }
+
 static void onredraw(int height, int width);
 static void oninput(int mods, Rune key);
 static void onmousedrag(int state, int x, int y);
@@ -45,22 +48,22 @@ static void win_init(void (*errfn)(char*)) {
     for (int i = 0; i < SCROLL; i++)
         view_init(&(Regions[i].view), NULL, errfn);
     x11_init(&Config);
-    Font = x11_font_load(config_get_str(FontString));
-    Regions[SCROLL].clrnor = config_get_int(ClrScrollNor);
-    Regions[TAGS].clrnor = config_get_int(ClrTagsNor);
-    Regions[TAGS].clrsel = config_get_int(ClrTagsSel);
-    Regions[TAGS].clrcsr = config_get_int(ClrTagsCsr);
-    Regions[EDIT].clrnor = config_get_int(ClrEditNor);
-    Regions[EDIT].clrsel = config_get_int(ClrEditSel);
-    Regions[EDIT].clrcsr = config_get_int(ClrEditCsr);
+    Font = x11_font_load(FontString);
+    Regions[SCROLL].clrnor = Colors[ClrScrollNor];
+    Regions[TAGS].clrnor = Colors[ClrTagsNor];
+    Regions[TAGS].clrsel = Colors[ClrTagsSel];
+    Regions[TAGS].clrcsr = Colors[ClrTagsCsr];
+    Regions[EDIT].clrnor = Colors[ClrEditNor];
+    Regions[EDIT].clrsel = Colors[ClrEditSel];
+    Regions[EDIT].clrcsr = Colors[ClrEditCsr];
 }
 
 void win_window(char* name, bool isdialog, void (*errfn)(char*)) {
     win_init(errfn);
     if (isdialog)
-        x11_dialog(name, config_get_int(WinWidth), config_get_int(WinHeight));
+        x11_dialog(name, WinWidth, WinHeight);
     else
-        x11_window(name, config_get_int(WinWidth), config_get_int(WinHeight));
+        x11_window(name, WinWidth, WinHeight);
 }
 
 static void win_update(int xfd, void* data) {
@@ -99,10 +102,9 @@ void win_save(char* path) {
 void win_loop(void) {
     x11_show();
     x11_flip();
-    int ms = config_get_int(EventTimeout);
     event_watchfd(x11_connfd(), INPUT, win_update, NULL);
     while (x11_running()) {
-        bool pending = event_poll(ms);
+        bool pending = event_poll(Timeout);
         exec_reap();
         int nevents  = x11_events_queued();
         if (update_focus() || pending || nevents) {
@@ -240,29 +242,29 @@ static void onredraw(int width, int height) {
 
     layout(width, height);
     onupdate(); // Let the user program update the status and other content
-    view_update(win_view(TAGS),   Regions[TAGS].clrnor,   Regions[TAGS].clrsel,   &(Regions[TAGS].csrx),   &(Regions[TAGS].csry));
-    view_update(win_view(EDIT),   Regions[EDIT].clrnor,   Regions[EDIT].clrsel,   &(Regions[EDIT].csrx),   &(Regions[EDIT].csry));
+    view_update(win_view(TAGS),   Regions[TAGS].clrnor.bg,   Regions[TAGS].clrsel.bg,   &(Regions[TAGS].csrx),   &(Regions[TAGS].csry));
+    view_update(win_view(EDIT),   Regions[EDIT].clrnor.bg,   Regions[EDIT].clrsel.bg,   &(Regions[EDIT].csrx),   &(Regions[EDIT].csry));
     onlayout(); // Let the user program update the scroll bar
 
-    int clr_hbor   = config_get_int(ClrBorders) >> 8;
-    int clr_vbor   = config_get_int(ClrBorders) & 0xFF;
-    int clr_scroll = config_get_int(ClrScrollNor);
+    int clr_hbor   = Colors[ClrBorders].bg;
+    int clr_vbor   = Colors[ClrBorders].bg;
+    int clr_scroll = Colors[ClrScrollNor].bg;
 
     for (int i = 0; i < SCROLL; i++) {
         View* view = win_view(i);
-        x11_draw_rect((Regions[i].clrnor >> 8), 0, Regions[i].y - 3, width, Regions[i].height + 8);
-        x11_draw_rect(clr_hbor, 0, Regions[i].y - 3, width, 1);
+        x11_draw_rect(Palette[Regions[i].clrnor.bg], 0, Regions[i].y - 3, width, Regions[i].height + 8);
+        x11_draw_rect(Palette[clr_hbor], 0, Regions[i].y - 3, width, 1);
 
         if (i == EDIT) {
             size_t gsz = gutter_size();
             if (Ruler)
-                x11_draw_rect( config_get_int(ClrEditRul),
+                x11_draw_rect( Palette[Colors[ClrEditRul].bg],
                                ((Ruler+2) * fwidth) + gsz,
                                Regions[i].y-2,
                                1,
                                Regions[i].height+7 );
             if (ShowLineNumbers)
-                x11_draw_rect( (config_get_int(ClrGutterNor) >> 8),
+                x11_draw_rect( Palette[Colors[ClrGutterNor].bg],
                                Regions[SCROLL].width,
                                Regions[SCROLL].y-2,
                                gsz,
@@ -287,14 +289,14 @@ static void onredraw(int width, int height) {
     size_t thumboff = (size_t)((thumbreg * ScrollOffset) + (Regions[SCROLL].y - 2));
     size_t thumbsz  = (size_t)(thumbreg * ScrollVisible);
     if (thumbsz < 5) thumbsz = 5;
-    x11_draw_rect(clr_vbor, Regions[SCROLL].width, Regions[SCROLL].y - 2, 1, Regions[SCROLL].height);
-    x11_draw_rect((clr_scroll >> 8), 0, Regions[SCROLL].y - 2, Regions[SCROLL].width, thumbreg);
-    x11_draw_rect((clr_scroll & 0xFF), 0, thumboff, Regions[SCROLL].width, thumbsz);
+    x11_draw_rect(Palette[clr_vbor], Regions[SCROLL].width, Regions[SCROLL].y - 2, 1, Regions[SCROLL].height);
+    //x11_draw_rect((clr_scroll >> 8), 0, Regions[SCROLL].y - 2, Regions[SCROLL].width, thumbreg);
+    //x11_draw_rect((clr_scroll & 0xFF), 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,
+            Palette[Regions[Focused].clrcsr.bg],
             Regions[Focused].x + (Regions[Focused].csrx * fwidth),
             Regions[Focused].y + (Regions[Focused].csry * fheight),
             1, fheight);
@@ -359,10 +361,10 @@ static void scroll_actions(int btn, bool pressed, int x, int y) {
                 view_scroll(win_view(EDIT), +row);
             break;
         case MouseWheelUp:
-            view_scroll(win_view(EDIT), -(config_get_int(ScrollLines)));
+            view_scroll(win_view(EDIT), -ScrollBy);
             break;
         case MouseWheelDn:
-            view_scroll(win_view(EDIT), +(config_get_int(ScrollLines)));
+            view_scroll(win_view(EDIT), +ScrollBy);
             break;
     }
 }
@@ -398,12 +400,12 @@ static void onmousebtn(int btn, bool pressed, int x, int y) {
 
 static void onwheelup(WinRegion id, bool pressed, size_t row, size_t col) {
     if (!pressed) return;
-    view_scroll(win_view(id), -(config_get_int(ScrollLines)));
+    view_scroll(win_view(id), -ScrollBy);
 }
 
 static void onwheeldn(WinRegion id, bool pressed, size_t row, size_t col) {
     if (!pressed) return;
-    view_scroll(win_view(id), +(config_get_int(ScrollLines)));
+    view_scroll(win_view(id), +ScrollBy);
 }
 
 static void oncommand(char* cmd) {
@@ -432,10 +434,10 @@ static bool update_focus(void) {
 }
 
 static void draw_line_num(bool current, size_t x, size_t y, size_t gcols, size_t num) {
-    int color = config_get_int(ClrGutterNor);
+    int color = clrbg(ClrGutterNor);
     if (!gcols) return;
     if (current) {
-        color = config_get_int(ClrGutterSel);;
+        color = clrbg(ClrGutterSel);;
         size_t fheight = x11_font_height(Font);
         x11_draw_rect((color >> 8), x-3, y-fheight, gutter_size(), fheight);
     }
index 5289fee5a0b5037ab5843c09a05221dc609725f2..d941d72babb0fbb4f9cd00d32e9852938adac1da 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -68,7 +68,7 @@ static struct XSel {
 
 static void xftcolor(XftColor* xc, int id) {
     #define COLOR(c) ((c) | ((c) >> 8))
-    uint32_t c = config_get_int(id + Color00);
+    uint32_t c = Palette[id];
     xc->color.alpha = COLOR((c & 0xFF000000) >> 16);
     xc->color.red   = COLOR((c & 0x00FF0000) >> 8);
     xc->color.green = COLOR((c & 0x0000FF00));
@@ -103,7 +103,6 @@ void x11_init(XConfig* cfg) {
     SelTarget = XInternAtom(X.display, "UTF8_STRING", 0);
     if (SelTarget == None)
         SelTarget = XInternAtom(X.display, "STRING", 0);
-    config_init(X.display);
 }
 
 int x11_connfd(void) {
@@ -130,7 +129,7 @@ void x11_window(char* name, int width, int height) {
         X.width,
         X.height,
         0, X.depth,
-        config_get_int(Color00));
+        Palette[0]);
 
     /* register interest in the delete window message */
     Atom wmDeleteMessage = XInternAtom(X.display, "WM_DELETE_WINDOW", False);
@@ -505,11 +504,11 @@ void x11_draw_glyphs(int fg, int bg, XGlyphSpec* specs, size_t nspecs, bool eol)
         XGlyphInfo extent;
         XftTextExtentsUtf8(X.display, font, (const FcChar8*)"0", 1, &extent);
         int w = extent.xOff;
-        int h = (font->height - font->descent) + config_get_int(LineSpacing);
+        int h = (font->height - font->descent) + LineSpacing;
         xftcolor(&bgc, bg);
         size_t width = specs[nspecs-1].x - specs[0].x + w;
         if (eol) width = X.width - specs[0].x;
-        x11_draw_rect(bg, specs[0].x, specs[0].y - h, width, font->height + config_get_int(LineSpacing));
+        x11_draw_rect(bg, specs[0].x, specs[0].y - h, width, font->height + LineSpacing);
         XftColorFree(X.display, X.visual, X.colormap, &bgc);
     }
     xftcolor(&fgc, fg);
diff --git a/tide.c b/tide.c
index 221d541a2137e8dfd68e38f1e7a0ef927006eb48..c27d83fc5403192f8704289fa8eb48af5dcb8001 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -115,7 +115,7 @@ static void ondiagmsg(char* msg) {
 
 static void trim_whitespace(void) {
     Buf* buf = win_buf(EDIT);
-    if (config_get_bool(TrimOnSave) && buf_end(buf) > 0) {
+    if (TrimOnSave && buf_end(buf) > 0) {
         View* view = win_view(EDIT);
         unsigned off = 0, prev = 1;
         /* loop through the buffer till we hit the end or we stop advancing */
@@ -139,7 +139,7 @@ static void trim_whitespace(void) {
 static void quit(void) {
     static uint64_t before = 0;
     uint64_t now = getmillis();
-    if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)config_get_int(DblClickTime)) {
+    if (!win_buf(EDIT)->modified || (now-before) <= (uint64_t)ClickTime) {
         #ifndef TEST
         x11_deinit();
         #else
@@ -180,7 +180,7 @@ void onmouseleft(WinRegion id, bool pressed, size_t row, size_t col) {
     static uint64_t before = 0;
     if (!pressed) return;
     uint64_t now = getmillis();
-    count = ((now-before) <= (uint64_t)config_get_int(DblClickTime) ? count+1 : 1);
+    count = ((now-before) <= (uint64_t)ClickTime ? count+1 : 1);
     before = now;
 
     if (count == 1) {
@@ -565,9 +565,9 @@ int main(int argc, char** argv) {
     if (*argv) edit_relative(*argv);
 
     /* now create the window and start the event loop */
-    win_settext(TAGS, config_get_str(EditTagString));
-    win_setruler(config_get_int(RulerColumn));
-    win_setlinenums(config_get_bool(LineNumbers));
+    win_settext(TAGS, TagString);
+    win_setruler(RulerPos);
+    win_setlinenums(LineNums);
     win_setkeys(Bindings, oninput);
     win_loop();
     return 0;