Commit: 8d86a2a26fbc0789a81375698ca7f6050e35d6c9
Parent: 134cfd438bceb0745fa7ba38b110654067a2e16a
Author: Randy Palamar
Date: Mon, 11 Nov 2024 08:54:41 -0700
mouse_buttons -> keys
Diffstat:
4 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/debug.c b/debug.c
@@ -279,7 +279,7 @@ draw_debug_bar_chart(Term *t, DebugState *ds, TerminalInput *input, RenderCtx *r
push_s8(rc, input->mouse, fg, g_ui_debug_font_id, stream_to_s8(&txt));
}
- ButtonState *mouse_left = input->mouse_buttons + MOUSE_LEFT;
+ ButtonState *mouse_left = input->keys + MOUSE_LEFT;
if (mouse_left->ended_down && mouse_left->transitions > 0) {
if (hot_region) ds->selected_metadata = hot_region->meta;
else ds->selected_metadata = 0;
diff --git a/platform_linux_x11.c b/platform_linux_x11.c
@@ -166,19 +166,19 @@ mouse_button_callback(GLFWwindow *win, i32 button, i32 action, i32 modifiers)
switch (button) {
case GLFW_MOUSE_BUTTON_LEFT:
- button_action(input->mouse_buttons + MOUSE_LEFT, action == GLFW_PRESS);
+ button_action(input->keys + MOUSE_LEFT, action == GLFW_PRESS);
break;
case GLFW_MOUSE_BUTTON_RIGHT:
- button_action(input->mouse_buttons + MOUSE_RIGHT, action == GLFW_PRESS);
+ button_action(input->keys + MOUSE_RIGHT, action == GLFW_PRESS);
break;
case GLFW_MOUSE_BUTTON_MIDDLE:
- button_action(input->mouse_buttons + MOUSE_MIDDLE, action == GLFW_PRESS);
+ button_action(input->keys + MOUSE_MIDDLE, action == GLFW_PRESS);
break;
case GLFW_MOUSE_BUTTON_4:
- button_action(input->mouse_buttons + MOUSE_EXTENDED_0, action == GLFW_PRESS);
+ button_action(input->keys + MOUSE_EXTENDED_0, action == GLFW_PRESS);
break;
case GLFW_MOUSE_BUTTON_5:
- button_action(input->mouse_buttons + MOUSE_EXTENDED_1, action == GLFW_PRESS);
+ button_action(input->keys + MOUSE_EXTENDED_1, action == GLFW_PRESS);
break;
}
}
@@ -271,8 +271,8 @@ update_input(PlatformCtx *ctx)
input->mouse.x = mouse_x;
input->mouse.y = input->window_size.h - mouse_y;
- for (u32 i = 0; i < ARRAY_COUNT(input->mouse_buttons); i++)
- input->mouse_buttons[i].transitions = 0;
+ for (u32 i = 0; i < ARRAY_COUNT(input->keys); i++)
+ input->keys[i].transitions = 0;
input->char_stream.widx = 0;
diff --git a/vtgl.c b/vtgl.c
@@ -192,7 +192,7 @@ clear_colour(void)
/* TODO: move this elsewhere */
static b32
-pressed_this_frame(ButtonState *button)
+pressed_last_frame(ButtonState *button)
{
b32 result = (button->transitions > 1) || (button->ended_down && button->transitions == 1);
return result;
@@ -813,6 +813,7 @@ key_callback(GLFWwindow *win, i32 key, i32 sc, i32 act, i32 mods)
}
}
+ /* TODO: construct a hash table of bound keys */
switch (ENCODE_KEY(act, 0, key)) {
case ENCODE_KEY(GLFW_PRESS, 0, GLFW_KEY_ESCAPE):
case ENCODE_KEY(GLFW_REPEAT, 0, GLFW_KEY_ESCAPE):
@@ -877,7 +878,7 @@ static void
handle_keybindings(Term *t, TerminalInput *input, PlatformAPI *platform)
{
/* TODO: map other mouse buttons */
- update_selection(t, input->mouse, input->mouse_buttons + MOUSE_LEFT);
+ update_selection(t, input->mouse, input->keys + MOUSE_LEFT);
GLFWwindow *win = t->gl.window;
if (input->mouse_scroll.y) {
@@ -901,7 +902,7 @@ handle_keybindings(Term *t, TerminalInput *input, PlatformAPI *platform)
}
}
- if (pressed_this_frame(input->mouse_buttons + MOUSE_MIDDLE))
+ if (pressed_last_frame(input->keys + MOUSE_MIDDLE))
paste(t, platform, (Arg){.i = CLIPBOARD_1});
}
diff --git a/vtgl.h b/vtgl.h
@@ -56,13 +56,14 @@ enum {
CLIPBOARD_1,
};
-enum mouse_buttons {
+enum input_keys {
MOUSE_LEFT,
MOUSE_RIGHT,
MOUSE_MIDDLE,
MOUSE_EXTENDED_0,
MOUSE_EXTENDED_1,
- MOUSE_BUTTON_COUNT,
+
+ INPUT_KEY_COUNT,
};
typedef struct {
@@ -78,7 +79,7 @@ typedef struct TerminalInput {
v2 mouse;
v2 mouse_scroll;
- ButtonState mouse_buttons[MOUSE_BUTTON_COUNT];
+ ButtonState keys[INPUT_KEY_COUNT];
/* TODO: move this out of here once callbacks are removed from terminal */
Stream char_stream;