aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2025-11-04 17:29:52 -0500
committerJack Jamison <jackqjamison@gmail.com>2025-11-06 19:45:03 -0500
commit95fb3cad63941466e913775a3c080b310d45d13a (patch)
tree555cbaf4d5fd7454efbe6ab200e268c04b53ed49
parent38d43004656a2d00960484e5e5a5ece46bde840b (diff)
refactor onfig file and delete word backward
-rw-r--r--Makefile2
-rw-r--r--config.c35
-rw-r--r--config.h20
-rw-r--r--font.c2
-rw-r--r--graphics.c14
-rw-r--r--input_field.c1
-rw-r--r--keybind.c21
-rw-r--r--keybind.h1
-rw-r--r--layer_surface.c2
-rw-r--r--layout.c4
-rw-r--r--main.c3
11 files changed, 86 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index d5b6a44..35133a7 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ WLC=$(patsubst %.xml,$(OBJDIR)/%.c, $(WLPROT))
WLH=$(patsubst %.xml,$(OBJDIR)/%.h, $(WLPROT))
SRC=$(WLC) $(filter-out swenu-exes.c , $(wildcard *.c)) $(wildcard glad/*.c)
OBJ=$(patsubst %.c,$(OBJDIR)/%.o, $(notdir $(SRC)))
-HDEPS=state.h wayland.h config.h
+HDEPS=state.h wayland.h
.SILENT: $(OBJ) $(WLC) $(WLH) $(BIN) $(OBJDIR) compile_flags swenu-exes $(OBJDIR)/swenu-exes.o
diff --git a/config.c b/config.c
new file mode 100644
index 0000000..698f691
--- /dev/null
+++ b/config.c
@@ -0,0 +1,35 @@
+#include "config.h"
+
+#include <stdlib.h>
+
+config_t config = {
+ .fancy_scroll = false,
+ .min_width = 500,
+ .font_size = 16,
+ // colors
+ .text_color = {0.85, 0.85, 0.85, 1.0},
+ .highlight_color = {0.1, 0.3, 0.7, 1.0},
+ .background_color = {0.1, 0.1, 0.1, 1.0},
+ .cursor_color = {0.9, 0.9, 0.9, 0.5}
+};
+
+
+char* get_conf_file() {
+ // get from xdg config home
+ const char* xdg = getenv("XDG_CONFIG_HOME");
+ if (xdg && *xdg) {
+ }
+
+ // get from home
+ const char* home = getenv("HOME");
+ if (home && *home) {
+ }
+
+ return NULL;
+}
+
+void init_conf() {
+ /* const char* conf_dir = get_conf_file(); */
+
+ /* free(conf_dir); */
+}
diff --git a/config.h b/config.h
index 8deca15..dd1488f 100644
--- a/config.h
+++ b/config.h
@@ -8,12 +8,18 @@ typedef struct {
float r,g,b,a;
} color_t;
-static const bool fancy_scroll = false;
-static const uint32_t min_width = 500;
-static const uint32_t font_size = 16;
-static const color_t text_color = {0.85, 0.85, 0.85, 1.0};
-static const color_t highlight_color = {0.1, 0.3, 0.7, 1.0};
-static const color_t background_color = {0.1, 0.1, 0.1, 1.0};
-static const color_t cursor_color = {0.9, 0.9, 0.9, 0.5};
+typedef struct {
+ bool fancy_scroll;
+ uint32_t min_width;
+ uint32_t font_size;
+ color_t text_color;
+ color_t highlight_color;
+ color_t background_color;
+ color_t cursor_color;
+} config_t;
+
+extern config_t config;
+
+void init_conf();
#endif
diff --git a/font.c b/font.c
index 7c08bf8..b0efe94 100644
--- a/font.c
+++ b/font.c
@@ -64,7 +64,7 @@ bool freetype_init(client_state* state, const char* file) {
fprintf(stderr, "Failed to create font\n");
return false;
}
- if (FT_Set_Char_Size(state->ft_face, 0, font_size << 6, 0, 0)) {
+ if (FT_Set_Char_Size(state->ft_face, 0, config.font_size << 6, 0, 0)) {
fprintf(stderr, "Failed to set font size\n");
return false;
}
diff --git a/graphics.c b/graphics.c
index 285d3e0..f6d6721 100644
--- a/graphics.c
+++ b/graphics.c
@@ -174,7 +174,7 @@ void render_frame(client_state *state) {
// set up frame
glViewport(0, 0, state->width, state->height);
glScissor(0, 0, state->width, state->height);
- glClearColor(background_color.r,background_color.g,background_color.b,background_color.a);
+ glClearColor(config.background_color.r,config.background_color.g,config.background_color.b,config.background_color.a);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// calculate input buffer size
@@ -186,7 +186,7 @@ void render_frame(client_state *state) {
// draw rect
glUseProgram(state->box_shader);
- glUniform4f(state->b_color_uniform, highlight_color.r,highlight_color.g,highlight_color.b,highlight_color.a);
+ glUniform4f(state->b_color_uniform, config.highlight_color.r,config.highlight_color.g,config.highlight_color.b,config.highlight_color.a);
glUniform2f(state->b_screen_size_uniform, state->width, state->height);
glUniform2f(state->b_start_uniform, prompt.x, prompt.y);
glUniform2f(state->b_size_uniform, prompt.dx, prompt.dy);
@@ -198,7 +198,7 @@ void render_frame(client_state *state) {
glBindTexture(GL_TEXTURE_2D, state->atlas.texture);
glBindVertexArray(state->prompt_text_buffer.vao);
glUniform2f(state->t_screen_size_uniform, state->width, state->height);
- glUniform4f(state->t_color_uniform, text_color.r,text_color.g,text_color.b,text_color.a);
+ glUniform4f(state->t_color_uniform, config.text_color.r,config.text_color.g,config.text_color.b,config.text_color.a);
glUniform2f(state->t_offset_uniform, prompt.x + state->horizontal_spacing / 2.0f, prompt.y - state->atlas.vert_shift);
glDrawElements(GL_TRIANGLES, state->prompt_text_buffer.num_elements, GL_UNSIGNED_INT, 0);
}
@@ -210,7 +210,7 @@ void render_frame(client_state *state) {
glScissor(input.x, input.y, input.dx - state->horizontal_spacing / 2.0f, input.dy);
glBindVertexArray(state->input_buffer_grafix.vao);
glUniform2f(state->t_screen_size_uniform, state->width, state->height);
- glUniform4f(state->t_color_uniform, text_color.r,text_color.g,text_color.b,text_color.a);
+ glUniform4f(state->t_color_uniform, config.text_color.r,config.text_color.g,config.text_color.b,config.text_color.a);
glUniform2f(state->t_offset_uniform, input.x + state->horizontal_spacing / 2.0f, input.y - state->atlas.vert_shift);
glDrawElements(GL_TRIANGLES, state->input_buffer_grafix.num_elements, GL_UNSIGNED_INT, 0);
@@ -221,7 +221,7 @@ void render_frame(client_state *state) {
}
// draw cursor
glUseProgram(state->box_shader);
- glUniform4f(state->b_color_uniform, cursor_color.r,cursor_color.g,cursor_color.b,cursor_color.a);
+ glUniform4f(state->b_color_uniform, config.cursor_color.r,config.cursor_color.g,config.cursor_color.b,config.cursor_color.a);
glUniform2f(state->b_screen_size_uniform, state->width, state->height);
glUniform2f(state->b_start_uniform, input.x + atlas_get_strwidth_len(state, state->input_buffer, state->cursor_index) + state->horizontal_spacing / 2.0f, input.y);
glUniform2f(state->b_size_uniform, cursor_size, input.dy);
@@ -235,7 +235,7 @@ void render_frame(client_state *state) {
item_display_t* display = &state->filtered_items[state->selected_filtered_item];
glUseProgram(state->box_shader);
- glUniform4f(state->b_color_uniform, highlight_color.r,highlight_color.g,highlight_color.b,highlight_color.a);
+ glUniform4f(state->b_color_uniform, config.highlight_color.r,config.highlight_color.g,config.highlight_color.b,config.highlight_color.a);
glUniform2f(state->b_screen_size_uniform, state->width, state->height);
glUniform2f(state->b_start_uniform, display->r.x, display->r.y);
glUniform2f(state->b_size_uniform, display->r.dx, display->r.dy);
@@ -245,7 +245,7 @@ void render_frame(client_state *state) {
// draw options
glUseProgram(state->text_shader);
glUniform2f(state->t_screen_size_uniform, state->width, state->height);
- glUniform4f(state->t_color_uniform, text_color.r,text_color.g,text_color.b,text_color.a);
+ glUniform4f(state->t_color_uniform, config.text_color.r,config.text_color.g,config.text_color.b,config.text_color.a);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, state->atlas.texture);
for (uint32_t i = state->displayed_item_start; i < state->displayed_item_end; ++i) {
diff --git a/input_field.c b/input_field.c
index bd8b93e..d24239c 100644
--- a/input_field.c
+++ b/input_field.c
@@ -122,6 +122,7 @@ key_repeat_t type_key(client_state* state, xkb_keysym_t keysym) {
else if (alt) {
switch (keysym) {
case XKB_KEY_d: return delete_word(state);
+ case XKB_KEY_BackSpace: return delete_word_backward(state);
}
}
switch (keysym) {
diff --git a/keybind.c b/keybind.c
index 17baad1..910fd95 100644
--- a/keybind.c
+++ b/keybind.c
@@ -100,6 +100,27 @@ key_repeat_t delete_word(client_state* state) {
return KEY_REPEAT;
}
+key_repeat_t delete_word_backward(client_state* state) {
+ if (state->cursor_index) {
+ size_t startidx = state->cursor_index - 1;
+ bool hit_non_white = false;
+ for (; startidx > 0; startidx--) {
+ if (state->input_buffer[startidx] == ' ') {
+ if (hit_non_white) {
+ ++startidx;
+ break;
+ }
+ } else {
+ hit_non_white = true;
+ }
+ }
+ array_erase_range(state->input_buffer, startidx, state->cursor_index - 1);
+ state->cursor_index = startidx;
+ update_text_buffer(state);
+ }
+ return KEY_REPEAT;
+}
+
key_repeat_t delete_char(client_state* state) {
if (state->cursor_index != array_size(state->input_buffer)) {
array_erase(state->input_buffer, state->cursor_index);
diff --git a/keybind.h b/keybind.h
index edda3b4..a56e48a 100644
--- a/keybind.h
+++ b/keybind.h
@@ -27,6 +27,7 @@ key_repeat_t backward_char(client_state* state);
key_repeat_t kill_to_end(client_state* state);
key_repeat_t delete_word(client_state* state);
+key_repeat_t delete_word_backward(client_state* state);
key_repeat_t delete_char(client_state* state);
key_repeat_t delete_char_backward(client_state* state);
diff --git a/layer_surface.c b/layer_surface.c
index bc3ef56..c1d7caa 100644
--- a/layer_surface.c
+++ b/layer_surface.c
@@ -16,7 +16,7 @@ void create_surface(client_state* state) {
uint32_t desired_width = 0;
uint32_t desired_height = state->line_height;
if (state->center) {
- desired_width = MAX(state->required_width, min_width);
+ desired_width = MAX(state->required_width, config.min_width);
}
if (state->lines) {
desired_height = (state->lines + 1) * state->line_height;
diff --git a/layout.c b/layout.c
index 76ee1a5..86c4155 100644
--- a/layout.c
+++ b/layout.c
@@ -53,7 +53,7 @@ void calculate_layout(client_state* state, rect_t* prompt, rect_t* input, rect_t
}
// calculate page indices
- if (recalc_pages && !fancy_scroll) {
+ if (recalc_pages && !config.fancy_scroll) {
state->current_page = 0;
array_clear(state->page_indices);
@@ -78,7 +78,7 @@ void calculate_layout(client_state* state, rect_t* prompt, rect_t* input, rect_t
}
if (array_size(state->filtered_items) != 0) {
- if (fancy_scroll) {
+ if (config.fancy_scroll) {
// calculate fancy scroll offset
if (state->lines) {
// calc vertical scroll
diff --git a/main.c b/main.c
index 6c675b1..267fe13 100644
--- a/main.c
+++ b/main.c
@@ -4,6 +4,7 @@
#include <poll.h>
#include <unistd.h>
+#include "config.h"
#include "array.h"
#include "state.h"
#include "wayland.h"
@@ -47,6 +48,8 @@ int main(int argc, char* argv[]) {
state.page_indices = array_new(size_t, 0);
state.strstr = strstr;
+ init_conf();
+
// check locale
setlocale(LC_ALL, "");
const char *encoding = nl_langinfo(CODESET);