Commit: d6121f4c8f5fc54a4bba186c04dfef217286a2a0
Parent: a9efd2c999918d6fb8dc30136afb3caa597517af
Author: Randy Palamar
Date: Fri, 27 Sep 2024 02:44:07 -0600
don't reblit when mouse selection doesn't change
Diffstat:
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/util.c b/util.c
@@ -14,6 +14,13 @@ equal_uv2(uv2 a, uv2 b)
}
static b32
+equal_range(Range a, Range b)
+{
+ b32 result = equal_iv2(a.start, b.start) && equal_iv2(a.end, b.end);
+ return result;
+}
+
+static b32
is_valid_range(Range r)
{
b32 result = !equal_iv2(r.end, INVALID_RANGE_END);
diff --git a/util.h b/util.h
@@ -361,7 +361,7 @@ enum selection_states {
typedef struct {
Range range;
Range anchor;
- v2 mouse_start;
+ v2 last_mouse;
f32 click_param;
enum selection_states state;
} Selection;
diff --git a/vtgl.c b/vtgl.c
@@ -409,14 +409,17 @@ update_selection(Term *t)
glfwGetCursorPos(t->gl.window, &xpos, &ypos);
v2 mouse = {.x = xpos, .y = ypos};
- if (sel->state != SS_WORDS && (mouse.x == sel->mouse_start.x && mouse.y == sel->mouse_start.y))
+ if (sel->state != SS_WORDS && (mouse.x == sel->last_mouse.x && mouse.y == sel->last_mouse.y))
return;
+ sel->last_mouse = mouse;
iv2 new_p = mouse_to_cell_space(t, mouse);
if (t->views[t->view_idx].fb.rows[new_p.y][new_p.x].style.attr & ATTR_WDUMMY) {
ASSERT(t->views[t->view_idx].fb.rows[new_p.y][new_p.x - 1].style.attr & ATTR_WIDE);
new_p.x--;
}
+
+ Range old_range = sel->range;
if (sel->state != SS_WORDS) {
sel->range.start = sel->anchor.start;
sel->range.end = new_p;
@@ -439,7 +442,8 @@ update_selection(Term *t)
}
}
sel->range = normalize_range(sel->range);
- t->gl.flags |= NEEDS_BLIT;
+ if (!equal_range(sel->range, old_range))
+ t->gl.flags |= NEEDS_BLIT;
}
KEYBIND_FN(copy)
@@ -680,13 +684,13 @@ mouse_button_callback(GLFWwindow *win, i32 btn, i32 act, i32 mod)
f64 xpos, ypos;
glfwGetCursorPos(win, &xpos, &ypos);
t->selection.range.end = (iv2){.x = -1, .y = -1};
- t->selection.mouse_start = (v2){.x = xpos, .y = ypos};
+ t->selection.last_mouse = (v2){.x = xpos, .y = ypos};
t->selection.click_param = DOUBLE_CLICK_TIME;
if (t->selection.state != SS_WORDS)
t->selection.state++;
- iv2 cell = mouse_to_cell_space(t, t->selection.mouse_start);
+ iv2 cell = mouse_to_cell_space(t, t->selection.last_mouse);
if (t->views[t->view_idx].fb.rows[cell.y][cell.x].style.attr & ATTR_WDUMMY) {
ASSERT(t->views[t->view_idx].fb.rows[cell.y][cell.x - 1].style.attr & ATTR_WIDE);
cell.x--;