XMapWindow(x->display, x->self);
}
-static void x11_event_loop(XConf* x) {
+static void x11_event_loop(XConf* x, void (*redraw)(XConf* x)) {
+ if (redraw) redraw(x);
for (XEvent e;;) {
XNextEvent(x->display, &e);
if (x->eventfns[e.type])
x->eventfns[e.type](x, &e);
for (int status; waitpid(-1, &status, WNOHANG) > 0;);
+ if (redraw) redraw(x);
}
}
return str;
}
-int by_score(const void* a, const void* b) {
+static int by_score(const void* a, const void* b) {
Choice* ca = ((Choice*)a);
Choice* cb = ((Choice*)b);
if (ca->score < cb->score)
return strcmp(ca->string, cb->string);
}
-void load_choices(void) {
+static void load_choices(void) {
char* choice_text;
Choice choice = {0};
vec_init(&Choices, sizeof(Choice));
vec_sort(&Choices, by_score);
}
-char* find_match_start(char *str, int ch) {
+static char* find_match_start(char *str, int ch) {
for (; *str; str++)
if (tolower(*str) == tolower(ch))
return str;
return NULL;
}
-bool match(char *string, size_t offset, size_t *start, size_t *end) {
+static bool match(char *string, size_t offset, size_t *start, size_t *end) {
char* q = Query;
char* s = find_match_start(&string[offset], *q);
char* e = s;
return true;
}
-void score(void) {
+static void score(void) {
for (unsigned int i = 0; i < vec_size(&Choices); i++) {
Choice* choice = (Choice*)vec_at(&Choices, i);
float qlen = (float)QueryIdx;
static void xkeypress(XConf* x, XEvent* e) {
(void)x, (void)e;
+ score();
}
static void xbtnpress(XConf* x, XEvent* e) {
}
static void redraw(XConf* x) {
- draw_rect(x, 0x0, 0, 0, x->width, x->height);
+ draw_rect(x, 0x00, 0, 0, x->width, x->height);
XCopyArea(x->display, x->pixmap, x->self, x->gc, 0, 0, x->width, x->height, 0, 0);
XFlush(x->display);
-
}
-void filter(void) {
+static void filter(void) {
XConf x = {0};
x11_init(&x);
- x11_mkwin(&x, 1, 1, 0);
+ x11_mkwin(&x, 1, 1, 0
+ | StructureNotifyMask
+ | KeyPressMask
+ | ButtonPressMask
+ | ExposureMask
+ );
x11_init_gc(&x);
x11_show(&x);
x.eventfns[KeyPress] = xkeypress;
x.eventfns[ButtonPress] = xbtnpress;
x.eventfns[ConfigureNotify] = xresize;
- redraw(&x);
- while (true) {
- x11_event_loop(&x);
- redraw(&x);
- }
+ x11_event_loop(&x, redraw);
}
int main(void) {