tAdd more options to theme - ledit - Text editor (WIP) | |
git clone git://lumidify.org/ledit.git (fast, but not encrypted) | |
git clone https://lumidify.org/git/ledit.git (encrypted, but very slow) | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 673c0ad7488286a17873fa81826e5212ac520642 | |
parent 5f298263efe3a7df06b1275446967e56ca99e62d | |
Author: lumidify <[email protected]> | |
Date: Wed, 12 Jan 2022 19:33:03 +0100 | |
Add more options to theme | |
Diffstat: | |
M Makefile | 2 +- | |
M buffer.c | 1 + | |
M buffer.h | 2 ++ | |
M keys_basic_config.h | 4 ++-- | |
M theme.c | 10 ++++++++++ | |
M theme.h | 10 ++++++++++ | |
M theme_config.h | 15 +++++++++++++-- | |
M view.c | 29 +++++++++++++++++------------ | |
M window.c | 2 +- | |
9 files changed, 57 insertions(+), 18 deletions(-) | |
--- | |
diff --git a/Makefile b/Makefile | |
t@@ -59,7 +59,7 @@ CONFIGHDR = \ | |
keys_command_config.h \ | |
keys_config.h | |
-CFLAGS_LEDIT = ${CFLAGS} -g -Wall -Wextra -D_POSIX_C_SOURCE=200809L `pkg-confi… | |
+CFLAGS_LEDIT = ${CFLAGS} -g -Wall -Wextra -pedantic -D_POSIX_C_SOURCE=200809L … | |
LDFLAGS_LEDIT = ${LDFLAGS} `pkg-config --libs x11 xkbfile pangoxft xext` -lm | |
all: ${BIN} | |
diff --git a/buffer.c b/buffer.c | |
t@@ -331,6 +331,7 @@ buffer_load_file(ledit_buffer *buffer, char *filename, siz… | |
char *file_contents; | |
FILE *file; | |
+ /* FIXME: https://wiki.sei.cmu.edu/confluence/display/c/FIO19-C.+Do+no… | |
file = fopen(filename, "r"); | |
if (!file) goto error; | |
if (fseek(file, 0, SEEK_END)) goto errorclose; | |
diff --git a/buffer.h b/buffer.h | |
t@@ -264,6 +264,8 @@ void buffer_delete_with_undo( | |
* adding the operation to the undo stack. | |
* If 'line_ret' and 'byte_ret' are not NULL, they are filled with | |
* the end position of the insertion. | |
+ * This function does not tell the views to update their line heights | |
+ * and offsets. | |
*/ | |
void buffer_insert_with_undo_base( | |
ledit_buffer *buffer, | |
diff --git a/keys_basic_config.h b/keys_basic_config.h | |
t@@ -416,9 +416,9 @@ static struct key keys_hi[] = { | |
{"ण", 0, 0, NORMAL, KEY_NONE, KEY_ENSURE_CURSOR_SHOWN, &key_search_… | |
{"ु", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &… | |
{"ू", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &… | |
- {".", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &re… | |
+ {".", 0, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSOR_SHOWN, &re… | |
{"श", ControlMask, 0, INSERT, KEY_ANY, KEY_ENSURE_CURSOR_SHOWN, &un… | |
- {"य", ControlMask, 0, INSERT, KEY_ANY, KEY_ENSURE_CURSOR_SHOWN, &re… | |
+ {"य", ControlMask, 0, INSERT, KEY_ANY, KEY_ENSURE_CURSOR_SHOWN, &re… | |
{"ब", ControlMask, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSO… | |
{"ट", ControlMask, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSO… | |
{"े", ControlMask, 0, NORMAL, KEY_NONE|KEY_NUMBER, KEY_ENSURE_CURSO… | |
diff --git a/theme.c b/theme.c | |
t@@ -17,14 +17,24 @@ theme_create(ledit_common *common) { | |
theme->text_size = TEXT_SIZE; | |
theme->text_fg_hex = TEXT_FG; | |
theme->text_bg_hex = TEXT_BG; | |
+ theme->cursor_fg_hex = CURSOR_FG; | |
+ theme->cursor_bg_hex = CURSOR_BG; | |
+ theme->selection_fg_hex = SELECTION_FG; | |
+ theme->selection_bg_hex = SELECTION_BG; | |
theme->bar_fg_hex = BAR_FG; | |
theme->bar_bg_hex = BAR_BG; | |
+ theme->bar_cursor_hex = BAR_CURSOR; | |
theme->scrollbar_fg_hex = SCROLLBAR_FG; | |
theme->scrollbar_bg_hex = SCROLLBAR_BG; | |
XftColorAllocName(common->dpy, common->vis, common->cm, TEXT_FG, &them… | |
XftColorAllocName(common->dpy, common->vis, common->cm, TEXT_BG, &them… | |
+ XftColorAllocName(common->dpy, common->vis, common->cm, CURSOR_FG, &th… | |
+ XftColorAllocName(common->dpy, common->vis, common->cm, CURSOR_BG, &th… | |
+ XftColorAllocName(common->dpy, common->vis, common->cm, SELECTION_FG, … | |
+ XftColorAllocName(common->dpy, common->vis, common->cm, SELECTION_BG, … | |
XftColorAllocName(common->dpy, common->vis, common->cm, BAR_FG, &theme… | |
XftColorAllocName(common->dpy, common->vis, common->cm, BAR_BG, &theme… | |
+ XftColorAllocName(common->dpy, common->vis, common->cm, BAR_CURSOR, &t… | |
XftColorAllocName(common->dpy, common->vis, common->cm, SCROLLBAR_FG, … | |
XftColorAllocName(common->dpy, common->vis, common->cm, SCROLLBAR_BG, … | |
return theme; | |
diff --git a/theme.h b/theme.h | |
t@@ -10,15 +10,25 @@ typedef struct { | |
int text_size; | |
XftColor text_fg; | |
XftColor text_bg; | |
+ XftColor cursor_fg; | |
+ XftColor cursor_bg; | |
+ XftColor selection_fg; | |
+ XftColor selection_bg; | |
XftColor bar_fg; | |
XftColor bar_bg; | |
+ XftColor bar_cursor; | |
XftColor scrollbar_fg; | |
XftColor scrollbar_bg; | |
const char *text_font; | |
const char *text_fg_hex; | |
const char *text_bg_hex; | |
+ const char *cursor_fg_hex; | |
+ const char *cursor_bg_hex; | |
+ const char *selection_fg_hex; | |
+ const char *selection_bg_hex; | |
const char *bar_fg_hex; | |
const char *bar_bg_hex; | |
+ const char *bar_cursor_hex; | |
const char *scrollbar_fg_hex; | |
const char *scrollbar_bg_hex; | |
} ledit_theme; | |
diff --git a/theme_config.h b/theme_config.h | |
t@@ -2,14 +2,25 @@ | |
static const char *TEXT_FONT = "Monospace"; | |
/* size used for text in points or whatever pango uses */ | |
static const int TEXT_SIZE = 12; | |
-/* foreground color of main text area */ | |
+/* text color of main text area */ | |
static const char *TEXT_FG = "#000000"; | |
/* background color of main text area */ | |
static const char *TEXT_BG = "#FFFFFF"; | |
-/* foreground color of status bar/line editor */ | |
+/* color of text under cursor */ | |
+static const char *CURSOR_FG = "#FFFFFF"; | |
+/* color of text cursor */ | |
+static const char *CURSOR_BG = "#000000"; | |
+/* color of selected text */ | |
+static const char *SELECTION_FG = "#FFFFFF"; | |
+/* color of selection */ | |
+static const char *SELECTION_BG = "#000000"; | |
+ | |
+/* text color of status bar/line editor */ | |
static const char *BAR_FG = "#000000"; | |
/* background color of status bar/line editor */ | |
static const char *BAR_BG = "#CCCCCC"; | |
+/* color of text cursor in status bar/line editor */ | |
+static const char *BAR_CURSOR = "#000000"; | |
/* FIXME: give in units other than pixels */ | |
/* scrollbar width in pixels */ | |
diff --git a/view.c b/view.c | |
t@@ -62,7 +62,10 @@ static void set_pango_text_and_highlight(ledit_view *view, … | |
static PangoLayout *get_pango_layout(ledit_view *view, size_t line); | |
/* Get an attribute list for a text highlight between the given range. */ | |
-static PangoAttrList *get_pango_attributes(ledit_view *view, size_t start_byte… | |
+static PangoAttrList *get_pango_attributes( | |
+ size_t start_byte, size_t end_byte, | |
+ XRenderColor fg, XRenderColor bg | |
+); | |
/* | |
* Set the attributes for a PangoLayout belonging to the given line index. | |
t@@ -304,11 +307,9 @@ view_cleanup(void) { | |
} | |
static PangoAttrList * | |
-get_pango_attributes(ledit_view *view, size_t start_byte, size_t end_byte) { | |
- XRenderColor fg = view->theme->text_fg.color; | |
- XRenderColor bg = view->theme->text_bg.color; | |
- PangoAttribute *attr0 = pango_attr_background_new(fg.red, fg.green, fg… | |
- PangoAttribute *attr1 = pango_attr_foreground_new(bg.red, bg.green, bg… | |
+get_pango_attributes(size_t start_byte, size_t end_byte, XRenderColor fg, XRen… | |
+ PangoAttribute *attr0 = pango_attr_foreground_new(fg.red, fg.green, fg… | |
+ PangoAttribute *attr1 = pango_attr_background_new(bg.red, bg.green, bg… | |
attr0->start_index = start_byte; | |
attr0->end_index = end_byte; | |
attr1->start_index = start_byte; | |
t@@ -330,23 +331,27 @@ set_line_layout_attrs(ledit_view *view, size_t line, Pan… | |
ledit_view_line *vl = view_get_line(view, line); | |
PangoAttrList *list = NULL; | |
if (view->sel_valid) { | |
+ XRenderColor fg = view->theme->selection_fg.color; | |
+ XRenderColor bg = view->theme->selection_bg.color; | |
ledit_range sel = view->sel; | |
sort_range(&sel.line1, &sel.byte1, &sel.line2, &sel.byte2); | |
if (sel.line1 < line && sel.line2 > line) { | |
- list = get_pango_attributes(view, 0, ll->len); | |
+ list = get_pango_attributes(0, ll->len, fg, bg); | |
} else if (sel.line1 == line && sel.line2 == line) { | |
size_t start = sel.byte1, end = sel.byte2; | |
if (start > end) | |
swap_sz(&start, &end); | |
- list = get_pango_attributes(view, start, end); | |
+ list = get_pango_attributes(start, end, fg, bg); | |
} else if (sel.line1 == line && sel.line2 > line) { | |
- list = get_pango_attributes(view, sel.byte1, ll->len); | |
+ list = get_pango_attributes(sel.byte1, ll->len, fg, bg… | |
} else if (sel.line1 < line && sel.line2 == line) { | |
- list = get_pango_attributes(view, 0, sel.byte2); | |
+ list = get_pango_attributes(0, sel.byte2, fg, bg); | |
} | |
} else if (vl->cursor_index_valid) { | |
+ XRenderColor fg = view->theme->cursor_fg.color; | |
+ XRenderColor bg = view->theme->cursor_bg.color; | |
/* FIXME: does just adding one really do the right thing? */ | |
- list = get_pango_attributes(view, vl->cursor_index, vl->cursor… | |
+ list = get_pango_attributes(vl->cursor_index, vl->cursor_index… | |
} | |
if (list != NULL) { | |
pango_layout_set_attributes(layout, list); | |
t@@ -1879,7 +1884,7 @@ view_redraw_text(ledit_view *view) { | |
h += vline->h; | |
} | |
- XSetForeground(view->buffer->common->dpy, view->window->gc, view->them… | |
+ XSetForeground(view->buffer->common->dpy, view->window->gc, view->them… | |
PangoRectangle strong, weak; | |
ledit_line *cur_line = buffer_get_line(view->buffer, view->cur_line); | |
PangoLayout *layout = get_pango_layout(view, view->cur_line); | |
diff --git a/window.c b/window.c | |
t@@ -708,7 +708,7 @@ window_redraw(ledit_window *window) { | |
0, window->text_h | |
); | |
} else if (window->bottom_text_shown) { | |
- XSetForeground(window->common->dpy, window->gc, t->bar_fg.pixe… | |
+ XSetForeground(window->common->dpy, window->gc, t->bar_cursor.… | |
/* move input method position to cursor and draw cursor */ | |
PangoRectangle strong, weak; | |
pango_layout_get_cursor_pos( |