#include <vec.h>
#include <libx11.h>
-enum { /* Color Names */
- Red, Purple, Orange,
- EditBg, EditFg, EditSel,
- TagsBg, TagsFg, TagsSel,
- ScrollBg, ScrollFg,
- VerBdr, HorBdr, Point,
- ClrCount
-};
-
-/* List of font patterns available to the editor */
-static char* Fonts[2] = {
- "Verdana:size=12",
- "Liberation Mono:size=12"
-};
-
-int ScrollWidth = 8; /* width in pixels of the scrollbar */
-
-static int Palette[ClrCount] = {
-#if 0 /* Original Acme Colors */
- [EditBg] = 0xFFFFEA, /* Edit region background */
- [EditFg] = 0x000000, /* Edit region text */
- [EditSel] = 0xEEEE9E, /* Edit region selection */
- [TagsBg] = 0xEAFFFF, /* Tags region background */
- [TagsFg] = 0x000000, /* Tags region text */
- [TagsSel] = 0x9EEEEE, /* Tags region selection */
- [ScrollBg] = 0x99994C, /* Scroll region background */
- [ScrollFg] = 0xFFFFEA, /* Scroll region foreground */
- [VerBdr] = 0x99994C, /* Vertical border */
- [HorBdr] = 0x000000, /* Horizontal border */
- [Point] = 0xEFEFDA, /* Point background */
- [Purple] = 0x6666CC, /* Purple */
- [Red] = 0xCC0000, /* Red */
- [Orange] = 0xFF7700, /* Orange */
-#else
- [EditBg] = 0xF5F5F0, /* Edit region background */
- [EditFg] = 0x222222, /* Edit region text */
- [EditSel] = 0xAACCEE, /* Edit region selection */
-
- [TagsBg] = 0xF5F5F0, /* Tags region background */
- [TagsFg] = 0x222222, /* Tags region text */
- [TagsSel] = 0xAACCEE, /* Tags region selection */
-
- [ScrollBg] = 0x959590, /* Scroll region background */
- [ScrollFg] = 0xF5F5F0, /* Scroll region foreground */
-
- [VerBdr] = 0x959590, /* Vertical border */
- [HorBdr] = 0x222222, /* Horizontal border */
-
- [Point] = 0xD5D5D0, /* Point background */
- [Purple] = 0x6666CC, /* Purple */
- [Red] = 0xCC0000, /* Red */
- [Orange] = 0xFF7700, /* Orange */
-#endif
-};
-
-#pragma GCC diagnostic pop
+#define WindowBg 0xF5F5F0
+#define ChoiceBg 0xAACCEE
+#define ChoiceFg 0x222222
+#define ScrollBg 0x959590
+#define ScrollFg 0xF5F5F0
+#define HorBdr 0x222222
+#define ScrollWidth 8
+#define Font "Verdana:size=12"
static void xkeypress(XConf* x, XEvent* e);
static void xbtnpress(XConf* x, XEvent* e);
return false;
s2 = s1, e2 = e1; // Init s2 and e2 before use below
- /* next find the longest match. If multiple, take the left most one */
- while (find_match(string, Query, ++offset, &s1, &e1) && ((e1-s1) <= (e2-s2)))
+ /* next find the longest match. If multiple, take the right most one */
+ while (find_match(string, Query, ++offset, &s1, &e1) && ((e1-s1) >= (e2-s2)))
s1 = s2, e1 = e2;
/* return the best match */
Xutf8LookupString(x->xic, &(e->xkey), buf, sizeof(buf), &key, &status);
else
XLookupString(&(e->xkey), buf, sizeof(buf), &key, 0);
+
if (key == XK_Return)
{
x->state = QUITTING;
size_t start = (size_t)((float)Offset / (float)vec_size(&Choices) * scroll_height);
size_t size = (size_t)((float)nlines / (float)vec_size(&Choices) * scroll_height);
- x11_draw_rect(x, Palette[EditBg], 0, 0, x->width, x->height);
- x11_draw_rect(x, Palette[TagsBg], 0, 0, x->width, fheight + 4);
- x11_draw_rect(x, Palette[HorBdr], 0, fheight + 4, x->width, 1);
- x11_draw_rect(x, Palette[ScrollBg], 0, fheight + 5, ScrollWidth+1, scroll_height);
- x11_draw_rect(x, Palette[ScrollFg], 0, fheight + 5 + start, ScrollWidth, (size ? size : 5));
+ x11_draw_rect(x, WindowBg, 0, 0, x->width, x->height);
+ x11_draw_rect(x, WindowBg, 0, 0, x->width, fheight + 4);
+ x11_draw_rect(x, HorBdr, 0, fheight + 4, x->width, 1);
+ x11_draw_rect(x, ScrollBg, 0, fheight + 5, ScrollWidth+1, scroll_height);
+ x11_draw_rect(x, ScrollFg, 0, fheight + 5 + start, ScrollWidth, (size ? size : 5));
/* get size of the query when printed */
XGlyphInfo glyphinfo;
/* draw the query and the cursor to the query region */
int posx = 2 + glyphinfo.width + offset;
- x11_draw_rect(x, Palette[TagsFg], posx-1, 2, 3, 3);
- x11_draw_rect(x, Palette[TagsFg], posx, 2, 1, fheight);
- x11_draw_rect(x, Palette[TagsFg], posx-1, 2+fheight-3, 3, 3);
- x11_draw_string(x, x->font, offset + 2, fheight, Palette[TagsFg], Query);
+ x11_draw_rect(x, ChoiceFg, posx-1, 2, 3, 3);
+ x11_draw_rect(x, ChoiceFg, posx, 2, 1, fheight);
+ x11_draw_rect(x, ChoiceFg, posx-1, 2+fheight-3, 3, 3);
+ x11_draw_string(x, x->font, offset + 2, fheight, ChoiceFg, Query);
/* draw the scored and sorted results */
if (vec_size(&Choices))
for (int i = Offset, y = 2 * fheight + 4; ((size_t)i < vec_size(&Choices)) && ((size_t)i <= Offset+nlines); i++, y += fheight)
{
if ((size_t)i == ChoiceIdx)
- x11_draw_rect(x, Palette[EditSel], ScrollWidth+3, y - x->font->ascent, x->width, fheight);
- x11_draw_string(x, x->font, ScrollWidth+3, y, Palette[TagsFg], ((Choice*)vec_at(&Choices, i))->string);
+ x11_draw_rect(x, ChoiceBg, ScrollWidth+3, y - x->font->ascent, x->width, fheight);
+ x11_draw_string(x, x->font, ScrollWidth+3, y, ChoiceFg, ((Choice*)vec_at(&Choices, i))->string);
}
}
else
{
- x11_draw_string(x, x->font, ScrollWidth+3, 2 * fheight + 4, Palette[TagsFg], "Loading...");
+ x11_draw_string(x, x->font, ScrollWidth+3, 2 * fheight + 4, ChoiceFg, "Loading...");
}
x11_flip(x);
}
);
x11_init_gc(x);
x11_centerwin(x);
- if (!(x->font = x11_font_load(x, Fonts[0])))
+ if (!(x->font = x11_font_load(x, Font)))
{
perror("unable to load base font");
exit(EXIT_FAILURE);