commit 1a1cd75
chld
·
2026-07-13 17:48:04 +0000 UTC
parent 3f102dc
handle colors a better way
2 files changed,
+16,
-34
M
xl.c
+6,
-5
1@@ -2,10 +2,11 @@
2 #define XLND_CONFIG_H
3
4 /* colors */
5-#define XLND_BORDER_COLOR "#222222"
6-#define XLND_BG_COLOR "#080808"
7-#define XLND_INK_COLOR "#aaaaaa"
8-#define XLND_SEC_COLOR "#e74c3c"
9-#define XLND_SEC_FONT_COLOR "#080808"
10+char *cols[] = {"#222222", /* border */
11+ "#080808", /* bg */
12+ "#aaaaaa", /* font */
13+ "#e74c3c", /* selected bg */
14+ "#080808", /* selected font */
15+ NULL};
16
17 #endif
M
xl.c
+10,
-29
1@@ -73,17 +73,14 @@ int main(int ac, char **av) {
2 if (XQueryPointer(d, r, &w_r, &w_r, &x, &y, &d1, &d2, &m_r)) {
3 }
4
5- /*
6- * TODO:
7- * handle colors a better way, dear god
8- */
9-
10- XColor brd_col;
11- XParseColor(d, DefaultColormap(d, s), XLND_BORDER_COLOR, &brd_col);
12- XAllocColor(d, DefaultColormap(d, s), &brd_col);
13+ XColor col[5];
14+ for (size_t c = 0; cols[c] != NULL; c++) {
15+ XParseColor(d, DefaultColormap(d, s), cols[c], &col[c]);
16+ XAllocColor(d, DefaultColormap(d, s), &col[c]);
17+ }
18
19 Window w = XCreateSimpleWindow(d, RootWindow(d, s), x, y, wi, hi, 1,
20- brd_col.pixel, WhitePixel(d, s));
21+ col[0].pixel, WhitePixel(d, s));
22 XStoreName(d, w, "xlnd");
23 XSelectInput(d, w,
24 ExposureMask | KeyPressMask | StructureNotifyMask |
25@@ -137,22 +134,6 @@ int main(int ac, char **av) {
26 t = strtok(NULL, "\n");
27 }
28
29- XColor bg_col;
30- XParseColor(d, DefaultColormap(d, s), XLND_BG_COLOR, &bg_col);
31- XAllocColor(d, DefaultColormap(d, s), &bg_col);
32-
33- XColor fg_col;
34- XParseColor(d, DefaultColormap(d, s), XLND_INK_COLOR, &fg_col);
35- XAllocColor(d, DefaultColormap(d, s), &fg_col);
36-
37- XColor bg_sel;
38- XParseColor(d, DefaultColormap(d, s), XLND_SEC_COLOR, &bg_sel);
39- XAllocColor(d, DefaultColormap(d, s), &bg_sel);
40-
41- XColor fg_sel;
42- XParseColor(d, DefaultColormap(d, s), XLND_SEC_FONT_COLOR, &fg_sel);
43- XAllocColor(d, DefaultColormap(d, s), &fg_sel);
44-
45 while (1) {
46 XEvent ev;
47 XNextEvent(d, &ev);
48@@ -164,9 +145,9 @@ int main(int ac, char **av) {
49
50 for (int j = 0; j < (int)p_i; ++j) {
51 if (sel == j) {
52- XSetForeground(d, gc, bg_sel.pixel);
53+ XSetForeground(d, gc, col[3].pixel);
54 } else {
55- XSetForeground(d, gc, bg_col.pixel);
56+ XSetForeground(d, gc, col[1].pixel);
57 }
58
59 XFillRectangle(d, w, gc, 0, (hi * j) / (int)p_i, wi, hi / (int)p_i);
60@@ -180,9 +161,9 @@ int main(int ac, char **av) {
61 &ov);
62
63 if (sel == i) {
64- XSetForeground(d, gc, fg_sel.pixel);
65+ XSetForeground(d, gc, col[4].pixel);
66 } else {
67- XSetForeground(d, gc, fg_col.pixel);
68+ XSetForeground(d, gc, col[2].pixel);
69 }
70
71 XDrawString(d, w, gc, (wi - ov.width) / 2,