]> git.mdlowis.com Git - projs/tide.git/commitdiff
overhauled color selection to make themeing easier
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 29 Jun 2017 00:54:44 +0000 (20:54 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 29 Jun 2017 00:54:44 +0000 (20:54 -0400)
XResources [deleted file]
inc/edit.h
inc/win.h
lib/config.c
lib/view.c
lib/win.c
themes/solarized-dark [new file with mode: 0644]

diff --git a/XResources b/XResources
deleted file mode 100644 (file)
index aadb689..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-! UI Settings
-#ifdef __MACH__
-tide.ui.font:         Monaco:size=10:antialias=true:autohint=true
-tide.ui.line_spacing: 0
-#else
-tide.ui.font:         Liberation Mono:pixelsize=14:antialias=true:autohint=true
-tide.ui.line_spacing: 1
-#endif
-tide.ui.tags:           'Quit Save Undo Redo Cut Copy Paste | Find '
-tide.ui.width:          640
-tide.ui.height:         480
-tide.ui.line_numbers:   true
-tide.ui.syntax_enabled: true
-tide.ui.ruler_column:   80
-tide.ui.timeout:        50
-
-! Input and Behavior Settings
-tide.input.copy_indent:   true
-tide.input.trim_on_save:  true
-tide.input.expand_tabs:   true
-tide.input.tab_width:     4
-tide.input.scroll_lines:  4
-tide.input.click_time:    500
-tide.input.max_scan_dist: 8192
-
-! Color Palette Definition (Solarized Dark)
-tide.palette.00: 0xff002b36 ! 00 (0) - Base03
-tide.palette.01: 0xff073642 ! 01 (1) - Base02
-tide.palette.02: 0xff586e75 ! 02 (2) - Base01
-tide.palette.03: 0xff657b83 ! 03 (3) - Base00
-tide.palette.04: 0xff839496 ! 04 (4) - Base0
-tide.palette.05: 0xff93a1a1 ! 05 (5) - Base1
-tide.palette.06: 0xffeee8d5 ! 06 (6) - Base2
-tide.palette.07: 0xfffdf6e3 ! 07 (7) - Base3
-tide.palette.08: 0xffb58900 ! 08 (8) - Yellow
-tide.palette.09: 0xffcb4b16 ! 09 (9) - Orange
-tide.palette.10: 0xffdc322f ! 10 (A) - Red
-tide.palette.11: 0xffd33682 ! 11 (B) - Magenta
-tide.palette.12: 0xff6c71c4 ! 12 (C) - Violet
-tide.palette.13: 0xff268bd2 ! 13 (D) - Blue
-tide.palette.14: 0xff2aa198 ! 14 (E) - Cyan
-tide.palette.15: 0xff859900 ! 15 (F) - Green
-
-!! Color Palette Definition (Solarized Light)
-!tide.palette.00: 0xfffdf6e3 ! 00 (0) - Base3
-!tide.palette.01: 0xffeee8d5 ! 01 (1) - Base2
-!tide.palette.02: 0xff93a1a1 ! 02 (2) - Base1
-!tide.palette.03: 0xff839496 ! 03 (3) - Base0
-!tide.palette.04: 0xff657b83 ! 04 (4) - Base00
-!tide.palette.05: 0xff586e75 ! 05 (5) - Base01
-!tide.palette.06: 0xff073642 ! 06 (6) - Base02
-!tide.palette.07: 0xff002b36 ! 07 (7) - Base03
-!tide.palette.08: 0xffb58900 ! 08 (8) - Yellow
-!tide.palette.09: 0xffcb4b16 ! 09 (9) - Orange
-!tide.palette.10: 0xffdc322f ! 10 (A) - Red
-!tide.palette.11: 0xffd33682 ! 11 (B) - Magenta
-!tide.palette.12: 0xff6c71c4 ! 12 (C) - Violet
-!tide.palette.13: 0xff268bd2 ! 13 (D) - Blue
-!tide.palette.14: 0xff2aa198 ! 14 (E) - Cyan
-!tide.palette.15: 0xff859900 ! 15 (F) - Green
-
-! Background and UI Colors
-tide.colors.ruler:      0x1
-tide.colors.gutter:     0x1
-tide.colors.bkg_tags:   0x1
-tide.colors.bkg_edit:   0x0
-tide.colors.bkg_scroll: 0x3
-tide.colors.bkg_thumb:  0x0
-tide.colors.border:     0x3
-
-! Base Text Colors
-tide.colors.text.cursor:   0x0007
-tide.colors.text.normal:   0x0004
-tide.colors.text.selected: 0x0400
-tide.colors.text.gutter:   0x0003
-tide.colors.text.currline: 0x0D07
-
-! Syntax Highlighting Colors               BG      FG
-tide.colors.syntax.normal:       0x0004  ! Base03  Base0
-tide.colors.syntax.comment:      0x0002  ! Base03  Base01
-tide.colors.syntax.constant:     0x000E  ! Base03  Cyan
-tide.colors.syntax.string:       0x000E  ! Base03  Cyan
-tide.colors.syntax.character:    0x000E  ! Base03  Cyan
-tide.colors.syntax.number:       0x000E  ! Base03  Cyan
-tide.colors.syntax.boolean:      0x000E  ! Base03  Cyan
-tide.colors.syntax.float:        0x000E  ! Base03  Cyan
-tide.colors.syntax.variable:     0x000D  ! Base03  Blue
-tide.colors.syntax.function:     0x000D  ! Base03  Blue
-tide.colors.syntax.keyword:      0x000F  ! Base03  Green
-tide.colors.syntax.operator:     0x000F  ! Base03  Green
-tide.colors.syntax.preprocessor: 0x0009  ! Base03  Orange
-tide.colors.syntax.type:         0x0008  ! Base03  Yellow
-tide.colors.syntax.statement:    0x000F  ! Base03  Green
-tide.colors.syntax.special:      0x000A  ! Base03  Red
index 0a359654cb937ddaeb8cad10492d7f9e9332db35..00981bd63b793452e7e0b0e3bc4473d871fd3e82 100644 (file)
@@ -150,16 +150,17 @@ typedef struct {
 } Row;
 
 typedef struct {
-    bool sync_needed;  /* whether the view needs to be synced with cursor */
-    bool sync_center;  /* cursor should be centered on screen if possible */
-    bool sync_lines;   /* whether the line numbers should be recalculated */
-    size_t nrows;      /* number of rows in the view */
-    size_t ncols;      /* number of columns in the view */
-    Row** rows;        /* array of row data structures */
-    Buf buffer;        /* the buffer used to populate the view */
-    Sel selection;     /* range of currently selected text */
-    size_t prev_csr;   /* previous cursor location */
-    SyntaxSpan* spans; /* list of colored regions */
+    bool sync_needed;   /* whether the view needs to be synced with cursor */
+    bool sync_center;   /* cursor should be centered on screen if possible */
+    bool sync_lines;    /* whether the line numbers should be recalculated */
+    size_t nrows;       /* number of rows in the view */
+    size_t ncols;       /* number of columns in the view */
+    Row** rows;         /* array of row data structures */
+    Buf buffer;         /* the buffer used to populate the view */
+    Sel selection;      /* range of currently selected text */
+    size_t prev_csr;    /* previous cursor location */
+    SyntaxSpan* spans;  /* list of colored regions */
+    int clrnor, clrsel; /* text color pairs for normal and selected text */
 } View;
 
 enum {
@@ -173,7 +174,7 @@ void view_init(View* view, char* file, void (*errfn)(char*));
 void view_reload(View* view);
 size_t view_limitrows(View* view, size_t maxrows, size_t ncols);
 void view_resize(View* view, size_t nrows, size_t ncols);
-void view_update(View* view, size_t* csrx, size_t* csry);
+void view_update(View* view, int clrnor, int clrsel, size_t* csrx, size_t* csry);
 Row* view_getrow(View* view, size_t row);
 void view_byrune(View* view, int move, bool extsel);
 void view_byword(View* view, int move, bool extsel);
@@ -228,8 +229,14 @@ enum { /* Configuration Variables */
     ScrollLines, DblClickTime, MaxScanDist, SyntaxEnabled,
     Color00, Color01, Color02, Color03, Color04, Color05, Color06, Color07,
     Color08, Color09, Color10, Color11, Color12, Color13, Color14, Color15,
-    BkgRuler, BkgGutter, BkgTags, BkgEdit, BkgScroll, BkgThumb, BkgBorder,
-    TxtCursor, TxtNormal, TxtSelected, TxtGutter, TxtCurrentLine,
+
+    ClrScrollNor, ClrGutterNor, ClrGutterSel, ClrStatusNor, ClrTagsNor,
+    ClrTagsSel, ClrTagsCsr, ClrEditNor, ClrEditSel, ClrEditCsr, ClrEditRul,
+    ClrBorders,
+
+    //BkgRuler, BkgGutter, BkgTags, BkgEdit, BkgScroll, BkgThumb, BkgBorder,
+    //TxtCursor, TxtNormal, TxtSelected, TxtGutter, TxtCurrentLine,
+
     SynNormal, SynComment, SynConstant, SynString, SynChar, SynNumber,
     SynBoolean, SynFloat, SynVariable, SynFunction, SynKeyword, SynOperator,
     SynPreProc, SynType, SynStatement, SynSpecial
index 489958975a39d767f42437d4535217a1e601c1bc..830628751b660dd8f9a8a398fadf8271672c9bf9 100644 (file)
--- a/inc/win.h
+++ b/inc/win.h
@@ -22,12 +22,10 @@ typedef struct {
 } KeyBinding;
 
 typedef struct {
-    size_t x;
-    size_t y;
-    size_t height;
-    size_t width;
-    size_t csrx;
-    size_t csry;
+    size_t x, y;
+    size_t height, width;
+    size_t csrx, csry;
+    int clrnor, clrsel, clrcsr;
     bool warp_ptr;
     View view;
 } Region;
index afea612bb892fade1bf3ebbd3eaf265c8afcd3ca..619e3df933438dd0cab51b32a5d7acfc0301880b 100644 (file)
@@ -62,21 +62,19 @@ struct {
     [Color14] = { "tide.palette.14", INTEGER, { .num = 0xff2aa198 } },
     [Color15] = { "tide.palette.15", INTEGER, { .num = 0xff859900 } },
 
-    /* Background and UI Colors */
-    [BkgRuler]  = { "tide.colors.ruler",      INTEGER, { .num = 0x01 } },
-    [BkgGutter] = { "tide.colors.gutter",     INTEGER, { .num = 0x01 } },
-    [BkgTags]   = { "tide.colors.bkg_tags",   INTEGER, { .num = 0x01 } },
-    [BkgEdit]   = { "tide.colors.bkg_edit",   INTEGER, { .num = 0x00 } },
-    [BkgScroll] = { "tide.colors.bkg_scroll", INTEGER, { .num = 0x03 } },
-    [BkgThumb]  = { "tide.colors.bkg_thumb",  INTEGER, { .num = 0x00 } },
-    [BkgBorder] = { "tide.colors.border",     INTEGER, { .num = 0x03 } },
-
-    /* Base Text Colors */
-    [TxtCursor]      = { "tide.colors.text.cursor",   INTEGER, { .num = 0x0007 } },
-    [TxtNormal]      = { "tide.colors.text.normal",   INTEGER, { .num = 0x0004 } },
-    [TxtSelected]    = { "tide.colors.text.selected", INTEGER, { .num = 0x0400 } },
-    [TxtGutter]      = { "tide.colors.text.gutter",   INTEGER, { .num = 0x0003 } },
-    [TxtCurrentLine] = { "tide.colors.text.currline", INTEGER, { .num = 0x0D07 } },
+    /* UI Colors */
+    [ClrScrollNor] = { "tide.colors.scroll.normal",   INTEGER, { .num = 0x0300 } },
+    [ClrGutterNor] = { "tide.colors.gutter.normal",   INTEGER, { .num = 0x0103 } },
+    [ClrGutterSel] = { "tide.colors.gutter.selected", INTEGER, { .num = 0x0D07 } },
+    [ClrStatusNor] = { "tide.colors.status.normal",   INTEGER, { .num = 0x0004 } },
+    [ClrTagsNor]   = { "tide.colors.tags.normal",     INTEGER, { .num = 0x0104 } },
+    [ClrTagsSel]   = { "tide.colors.tags.selected",   INTEGER, { .num = 0x0401 } },
+    [ClrTagsCsr]   = { "tide.colors.tags.cursor",     INTEGER, { .num = 0x07   } },
+    [ClrEditNor]   = { "tide.colors.edit.normal",     INTEGER, { .num = 0x0004 } },
+    [ClrEditSel]   = { "tide.colors.edit.selected",   INTEGER, { .num = 0x0400 } },
+    [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 = 0x0004 } },
index e15e9be14feb5008e22455590d88b52300da8e4a..f34451a85f5d413adbb155eae6588ee525ee5690 100644 (file)
@@ -86,8 +86,9 @@ void view_resize(View* view, size_t nrows, size_t ncols) {
     view->ncols = ncols;
 }
 
-void view_update(View* view, size_t* csrx, size_t* csry) {
+void view_update(View* view, int clrnor, int clrsel, size_t* csrx, size_t* csry) {
     if (!view->nrows) return;
+    view->clrnor = clrnor, view->clrsel = clrsel;
     size_t csr = view->selection.end;
     /* scroll the view and reflow the screen lines */
     size_t pos = view->rows[0]->off, line = view->rows[0]->line;
@@ -571,9 +572,7 @@ static size_t fill_row(View* view, unsigned row, size_t pos, size_t* line) {
     }
     clearrow(view, row);
     for (size_t x = 0; x < view->ncols;) {
-        uint32_t attr = (in_selection(view->selection, pos)
-                            ? config_get_int(TxtSelected)
-                            : config_get_int(TxtNormal));
+        uint32_t attr = (in_selection(view->selection, pos) ? view->clrsel : view->clrnor);
         Rune r = buf_get(&(view->buffer), pos++);
         x += setcell(view, row, x, attr, r);
         if (buf_iseol(&(view->buffer), pos-1)) {
index 91b34256bf258aee063e6b03fef903151988ffac..d03507e742b8b8abcc2764f1e37269d6f79a2a0b 100644 (file)
--- a/lib/win.c
+++ b/lib/win.c
@@ -36,6 +36,14 @@ static bool ShowLineNumbers = false;
 static void win_init(void (*errfn)(char*)) {
     for (int i = 0; i < SCROLL; i++)
         view_init(&(Regions[i].view), NULL, errfn);
+    Regions[STATUS].clrnor = config_get_int(ClrStatusNor);
+    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);
     x11_init(&Config);
     Font = x11_font_load(config_get_str(FontString));
 }
@@ -213,28 +221,30 @@ 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(STATUS), &(Regions[STATUS].csrx), &(Regions[STATUS].csry));
-    view_update(win_view(TAGS),   &(Regions[TAGS].csrx),   &(Regions[TAGS].csry));
-    view_update(win_view(EDIT),   &(Regions[EDIT].csrx),   &(Regions[EDIT].csry));
+    view_update(win_view(STATUS), Regions[STATUS].clrnor, Regions[STATUS].clrsel, &(Regions[STATUS].csrx), &(Regions[STATUS].csry));
+    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));
     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);
+
     for (int i = 0; i < SCROLL; i++) {
         View* view = win_view(i);
-        x11_draw_rect((i == TAGS ? config_get_int(BkgTags)
-                                 : config_get_int(BkgEdit)),
-                      0, Regions[i].y - 3, width, Regions[i].height + 8);
-        x11_draw_rect(config_get_int(BkgBorder), 0, Regions[i].y - 3, width, 1);
+        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);
 
         if (i == EDIT) {
             size_t gsz = gutter_size();
             if (Ruler)
-                x11_draw_rect( config_get_int(BkgRuler),
+                x11_draw_rect( config_get_int(ClrEditRul),
                                ((Ruler+2) * fwidth) + gsz,
                                Regions[i].y-2,
                                1,
                                Regions[i].height+7 );
             if (ShowLineNumbers)
-                x11_draw_rect( config_get_int(BkgGutter),
+                x11_draw_rect( (config_get_int(ClrGutterNor) >> 8),
                                Regions[SCROLL].width,
                                Regions[SCROLL].y-2,
                                gsz,
@@ -259,16 +269,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(config_get_int(BkgBorder),
-        Regions[SCROLL].width, Regions[SCROLL].y - 2, 1, Regions[SCROLL].height);
-    x11_draw_rect(config_get_int(BkgScroll),
-        0, Regions[SCROLL].y - 2, Regions[SCROLL].width, thumbreg);
-    x11_draw_rect(config_get_int(BkgThumb),
-        0, thumboff, Regions[SCROLL].width, thumbsz);
+    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);
 
     /* place the cursor on screen */
     if (Regions[Focused].csrx != SIZE_MAX && Regions[Focused].csry != SIZE_MAX) {
-        x11_draw_rect(config_get_int(TxtCursor),
+        x11_draw_rect(
+            Regions[Focused].clrcsr,
             Regions[Focused].x + (Regions[Focused].csrx * fwidth),
             Regions[Focused].y + (Regions[Focused].csry * fheight),
             1, fheight);
@@ -384,10 +392,10 @@ static void onwheeldn(WinRegion id, bool pressed, size_t row, size_t col) {
 }
 
 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);
     if (ShowLineNumbers) {
-        int color = config_get_int(TxtGutter);
         if (current) {
-            color = config_get_int(TxtCurrentLine);
+            color = config_get_int(ClrGutterSel);;
             size_t fheight = x11_font_height(Font);
             x11_draw_rect((color >> 8), x-3, y-fheight, gutter_size(), fheight);
         }
diff --git a/themes/solarized-dark b/themes/solarized-dark
new file mode 100644 (file)
index 0000000..168a8db
--- /dev/null
@@ -0,0 +1,53 @@
+!-------------------------------------------------------------------------------
+! Solarized Dark
+!-------------------------------------------------------------------------------
+
+! 16-color Palette Definition
+tide.palette.00: 0xff002b36 ! 00 (0) - Base03
+tide.palette.01: 0xff073642 ! 01 (1) - Base02
+tide.palette.02: 0xff586e75 ! 02 (2) - Base01
+tide.palette.03: 0xff657b83 ! 03 (3) - Base00
+tide.palette.04: 0xff839496 ! 04 (4) - Base0
+tide.palette.05: 0xff93a1a1 ! 05 (5) - Base1
+tide.palette.06: 0xffeee8d5 ! 06 (6) - Base2
+tide.palette.07: 0xfffdf6e3 ! 07 (7) - Base3
+tide.palette.08: 0xffb58900 ! 08 (8) - Yellow
+tide.palette.09: 0xffcb4b16 ! 09 (9) - Orange
+tide.palette.10: 0xffdc322f ! 10 (A) - Red
+tide.palette.11: 0xffd33682 ! 11 (B) - Magenta
+tide.palette.12: 0xff6c71c4 ! 12 (C) - Violet
+tide.palette.13: 0xff268bd2 ! 13 (D) - Blue
+tide.palette.14: 0xff2aa198 ! 14 (E) - Cyan
+tide.palette.15: 0xff859900 ! 15 (F) - Green
+
+! Colors for UI Elements and Text
+tide.colors.scroll.normal:   0x0300
+tide.colors.gutter.normal:   0x0103
+tide.colors.gutter.selected: 0x0D07
+tide.colors.status.normal:   0x0004
+tide.colors.tags.normal:     0x0104
+tide.colors.tags.selected:   0x0401
+tide.colors.tags.cursor:     0x07
+tide.colors.edit.normal:     0x0004
+tide.colors.edit.selected:   0x0400
+tide.colors.edit.cursor:     0x07
+tide.colors.edit.ruler:      0x01
+tide.colors.borders:         0x01
+
+! Syntax Highlighting Colors               BG      FG
+tide.colors.syntax.normal:       0x0004  ! Base03  Base0
+tide.colors.syntax.comment:      0x0002  ! Base03  Base01
+tide.colors.syntax.constant:     0x000E  ! Base03  Cyan
+tide.colors.syntax.string:       0x000E  ! Base03  Cyan
+tide.colors.syntax.character:    0x000E  ! Base03  Cyan
+tide.colors.syntax.number:       0x000E  ! Base03  Cyan
+tide.colors.syntax.boolean:      0x000E  ! Base03  Cyan
+tide.colors.syntax.float:        0x000E  ! Base03  Cyan
+tide.colors.syntax.variable:     0x000D  ! Base03  Blue
+tide.colors.syntax.function:     0x000D  ! Base03  Blue
+tide.colors.syntax.keyword:      0x000F  ! Base03  Green
+tide.colors.syntax.operator:     0x000F  ! Base03  Green
+tide.colors.syntax.preprocessor: 0x0009  ! Base03  Orange
+tide.colors.syntax.type:         0x0008  ! Base03  Yellow
+tide.colors.syntax.statement:    0x000F  ! Base03  Green
+tide.colors.syntax.special:      0x000A  ! Base03  Red