aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md6
-rw-r--r--graphics.c13
-rw-r--r--input_field.c7
-rw-r--r--main.c10
4 files changed, 22 insertions, 14 deletions
diff --git a/README.md b/README.md
index e98da4f..6441610 100644
--- a/README.md
+++ b/README.md
@@ -2,16 +2,16 @@
To build: `make`
-
## Todo -
- [x] "selection"
- [x] figure out whats going on with stderr and exit code
- [X] fancy highlights
- [X] scrolling
- [X] special mode if there is no stdin
-- [ ] unicode
-- [ ] fuzzy filter and sort filtering by match %
+- [x] sort filtering by match %
- [ ] cursor
+- [ ] fuzzy filter
+- [ ] unicode
- [ ] kerning
- [ ] config file
- [ ] emacs keybindings
diff --git a/graphics.c b/graphics.c
index c2a0405..bb8a4e0 100644
--- a/graphics.c
+++ b/graphics.c
@@ -224,20 +224,23 @@ void render_frame(client_state *state) {
glBindVertexArray(item->text_buffer.vao);
glUniform2f(state->offset_uniform, x + state->horizontal_spacing / 2.0f, y - state->atlas.vert_shift);
if (i == state->selected_filtered_item) {
- glUniform3f(state->color_uniform, 1.0f, 1.0f, 1.0f);
+ // draw box
glScissor(x, y, ((state->lines > 0) ? state->width : item->pixel_len + state->horizontal_spacing), state->line_height);
glClearColor(0.0f, 0.4f, 0.8f, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
- }
- glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0);
- if (i == state->selected_filtered_item) {
- glUniform3f(state->color_uniform, 1.0f, 1.0f, 1.0f);
if (state->lines > 0) {
glScissor(0, 0, state->width, input_y);
}
else {
glScissor(input_width, 0, state->width, state->line_height);
}
+
+ // draw text
+ glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0);
+ } else {
+
+ // draw text
+ glDrawElements(GL_TRIANGLES, item->text_buffer.num_elements, GL_UNSIGNED_INT, 0);
}
}
diff --git a/input_field.c b/input_field.c
index 34f3fc2..290a5bd 100644
--- a/input_field.c
+++ b/input_field.c
@@ -4,9 +4,12 @@
#include "array.h"
#include "graphics.h"
+int compare(const void *a, const void *b) {
+ return strlen(((item_display_t*)a)->item->text) > strlen(((item_display_t*)b)->item->text);
+}
+
void filter_items(client_state* state) {
if (!state->items) return;
- array_clear(state->filtered_items);
// get null terminated input buffer
size_t len = array_size(state->input_buffer);
@@ -15,11 +18,13 @@ void filter_items(client_state* state) {
input_buffer_string[len] = '\0';
// add all strings with substring
+ array_clear(state->filtered_items);
array_for_all(item_t, i, state->items) {
if (strstr(i->text, input_buffer_string) != NULL) {
array_add(state->filtered_items, (item_display_t){ .item = i });
}
}
+ qsort(state->filtered_items, array_size(state->filtered_items), sizeof(item_display_t), compare);
// select item
if (array_size(state->filtered_items) > 0) state->selected_filtered_item = 0;
diff --git a/main.c b/main.c
index e334a8f..c3b7eb0 100644
--- a/main.c
+++ b/main.c
@@ -99,11 +99,11 @@ int main(int argc, char* argv[]) {
}
void poll_events(client_state* state) {
- enum { DISPLAY_FD, KEYREPEAT_FD };
- struct pollfd fds[] = {
- [DISPLAY_FD] = { wl_display_get_fd(state->display), POLLIN },
- [KEYREPEAT_FD] = { state->key_repeat_timer_fd, POLLIN },
- };
+ enum { DISPLAY_FD, KEYREPEAT_FD };
+ struct pollfd fds[] = {
+ [DISPLAY_FD] = { wl_display_get_fd(state->display), POLLIN },
+ [KEYREPEAT_FD] = { state->key_repeat_timer_fd, POLLIN },
+ };
bool event = false;
while (!event) {