aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--args.c6
-rw-r--r--font.c8
-rw-r--r--input_field.c19
-rw-r--r--state.h2
5 files changed, 20 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 0b1ba9b..9f8c0f2 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/args.c b/args.c
index a856a86..73307e5 100644
--- a/args.c
+++ b/args.c
@@ -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;
diff --git a/font.c b/font.c
index a1e29be..3903698 100644
--- a/font.c
+++ b/font.c
@@ -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;
}
diff --git a/state.h b/state.h
index 7d6f203..e2335ba 100644
--- a/state.h
+++ b/state.h
@@ -94,7 +94,7 @@ typedef struct {
// arguments
int lines;
- bool allow_free_result;
+ bool exact_match;
bool center;
bool verbose;