| 1 | #include "display.h" |
| 2 | |
| 3 | #include <string.h> |
| 4 | |
| 5 | int topidx = 0; |
| 6 | |
| 7 | void drawtext( |
| 8 | Display *display, Window window, GC gc, int x, int y, const char *text, int sel) { |
| 9 | XftColor *fgCol = (sel) ? &selcolor : &color; |
| 10 | if (sel) { |
| 11 | XSetForeground(display, gc, BGSEL); |
| 12 | XFillRectangle( |
| 13 | display, window, gc, 0, y - item_height + 5, window_width, item_height); |
| 14 | XSetForeground(display, gc, BGCOL); |
| 15 | } else { |
| 16 | XSetForeground(display, gc, FGSEL); |
| 17 | } |
| 18 | |
| 19 | XftDrawStringUtf8(draw, fgCol, font, x, y, (const FcChar8 *)text, strlen(text)); |
| 20 | } |
| 21 | |
| 22 | void filterdisplay( |
| 23 | Display *display, |
| 24 | Window window, |
| 25 | GC gc, |
| 26 | const char *input, |
| 27 | int sel |
| 28 | ) { |
| 29 | XClearWindow(display, window); |
| 30 | |
| 31 | |
| 32 | drawtext(display, window, gc, 10, item_height, input, 0); |
| 33 | |
| 34 | int y = item_height * 2; |
| 35 | int idx = 0; |
| 36 | |
| 37 | for (int i = 0; i < programcount; i++) { |
| 38 | if (!strcasestr(programs[i].name, input) && !strcasestr(programs[i].keys, input)) |
| 39 | continue; |
| 40 | |
| 41 | if (idx >= topidx && idx < topidx + display_items) { |
| 42 | drawtext(display, window, gc, 10, y, programs[i].name, idx == sel); |
| 43 | y += item_height; |
| 44 | } |
| 45 | idx++; |
| 46 | } |
| 47 | } |