diff options
| author | Riley Beckett <rbeckettvt@gmail.com> | 2025-10-19 00:26:59 -0400 |
|---|---|---|
| committer | Riley Beckett <rbeckettvt@gmail.com> | 2025-10-19 00:26:59 -0400 |
| commit | 56c5a1da4de4a7511882b2a9d4bae608aca1e61b (patch) | |
| tree | e041ad1554d1f3c66f06e199ee9a93ff74d91f86 | |
| parent | be014d7b8df14596530ef8f9e7d7a8afae281c5c (diff) | |
change allow-free-result to exact-match
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | args.c | 6 | ||||
| -rw-r--r-- | font.c | 8 | ||||
| -rw-r--r-- | input_field.c | 19 | ||||
| -rw-r--r-- | state.h | 2 |
5 files changed, 20 insertions, 19 deletions
@@ -10,7 +10,7 @@ WLC=$(patsubst %.xml,$(OBJDIR)/%.c, $(WLPROT)) WLH=$(patsubst %.xml,$(OBJDIR)/%.h, $(WLPROT)) SRC=$(WLC) $(wildcard *.c) $(wildcard glad/*.c) OBJ=$(patsubst %.c,$(OBJDIR)/%.o, $(notdir $(SRC))) -HDEPS=state.h wayland.h +HDEPS=state.h wayland.h config.h .SILENT: $(OBJ) $(WLC) $(WLH) $(BIN) $(OBJDIR) compile_flags @@ -58,6 +58,6 @@ uninstall: rm -rf $(PREFIX)/usr/bin/$(BIN) run: all - ./$(BIN) + ./swenu-run.sh .PHONY: all clean run compile_flags install uninstall @@ -9,14 +9,14 @@ void parse_args(client_state* state, int argc, char* argv[]) { static struct option long_opts[] = { {"lines", required_argument, 0, 'l'}, {"center", no_argument, 0, 'c'}, - {"allow-free-result", no_argument, 0, 'a'}, + {"exact-match", no_argument, 0, 'e'}, {"verbose", no_argument, 0, 'v'}, {0, 0, 0, 0} }; int opt; int long_index = 0; - while ((opt = getopt_long(argc, argv, "l:cav", long_opts, &long_index)) != -1) { + while ((opt = getopt_long(argc, argv, "l:cev", long_opts, &long_index)) != -1) { switch (opt) { case 'l': state->lines = atoi(optarg); @@ -25,7 +25,7 @@ void parse_args(client_state* state, int argc, char* argv[]) { state->center = true; break; case 'a': - state->allow_free_result = true; + state->exact_match = true; break; case 'v': state->verbose = true; @@ -151,8 +151,10 @@ int atlas_get_strwidth(client_state* state, const char* str) { } void atlas_calc_item_widths(client_state* state) { - array_for_all(item_t, item, state->items) { - item->pixel_len = atlas_get_strwidth(state, item->text); - state->required_width = MAX(state->required_width, item->pixel_len + state->line_height / 2.0f); + if (state->items) { + array_for_all(item_t, item, state->items) { + item->pixel_len = atlas_get_strwidth(state, item->text); + state->required_width = MAX(state->required_width, item->pixel_len + state->line_height / 2.0f); + } } } diff --git a/input_field.c b/input_field.c index 31ae627..1601204 100644 --- a/input_field.c +++ b/input_field.c @@ -5,6 +5,7 @@ #include "graphics.h" void filter_items(client_state* state) { + if (!state->items) return; array_clear(state->filtered_items); // get null terminated input buffer @@ -12,14 +13,14 @@ void filter_items(client_state* state) { char input_buffer_string[len + 1]; memcpy(input_buffer_string, state->input_buffer, len); input_buffer_string[len] = '\0'; - + // add all strings with substring for (uint32_t i = 0; i < array_size(state->items); ++i) { if (strstr(state->items[i].text, input_buffer_string) != NULL) { array_add(state->filtered_items, i); } } - + // select item if (array_size(state->filtered_items) > 0) state->selected_filtered_item = 0; else state->selected_filtered_item = -1; @@ -54,7 +55,7 @@ bool type_key(client_state* state, xkb_keysym_t keysym) { array_free(state->input_buffer); state->input_buffer = array_new(char, len); memcpy(state->input_buffer, selected, len); - + update_text_buffer(state); } return true; @@ -105,15 +106,13 @@ bool type_key(client_state* state, xkb_keysym_t keysym) { } void submit_line(client_state* state) { - if (state->selected_filtered_item == -1) { - if (state->allow_free_result) { - printf("%.*s\n", (int)array_size(state->input_buffer), state->input_buffer); - } else { - return; - } - } else { + if (state->exact_match) { + if (state->selected_filtered_item == -1) return; printf("%s\n", state->items[state->filtered_items[state->selected_filtered_item]].text); } + else { + printf("%.*s\n", (int)array_size(state->input_buffer), state->input_buffer); + } state->running = false; state->exit_code = EXIT_SUCCESS; } @@ -94,7 +94,7 @@ typedef struct { // arguments int lines; - bool allow_free_result; + bool exact_match; bool center; bool verbose; |
