Commit: dfbc514f0f6261e1ba71941176544b9750a92e2f
Parent: f96a116fb8a0d2e1a05f5cf9e0a0f751c5f395c3
Author: Randy Palamar
Date: Mon, 2 Sep 2024 22:17:06 -0600
allow terminal to request a startup window size
This will be useful for the not yet implemented geometry [-g]
command line flag.
Diffstat:
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/main.c b/main.c
@@ -22,7 +22,7 @@ static do_terminal_fn *do_terminal;
typedef void init_callbacks_fn(GLCtx *);
static init_callbacks_fn *init_callbacks;
-typedef void init_term_fn(Term *, Arena *);
+typedef iv2 init_term_fn(Term *, Arena *, iv2);
static init_term_fn *init_term;
static void
@@ -91,7 +91,7 @@ error_callback(int code, const char *desc)
}
static void
-init_window(Term *t, Arena arena)
+init_window(Term *t, Arena arena, iv2 requested_size)
{
if (!glfwInit())
die("Failed to init GLFW\n");
@@ -105,7 +105,14 @@ init_window(Term *t, Arena arena)
iv2 ws;
glfwGetMonitorWorkarea(mon, NULL, NULL, &ws.w, &ws.h);
- t->gl.window_size = (v2){.w = ws.w, .h = ws.h};
+
+ if (requested_size.w != -1 && requested_size.h != -1) {
+ t->gl.window_size = (v2){.w = requested_size.w, .h = requested_size.h};
+ glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
+ glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
+ } else {
+ t->gl.window_size = (v2){.w = ws.w, .h = ws.h};
+ }
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
@@ -119,6 +126,7 @@ init_window(Term *t, Arena arena)
}
glfwMakeContextCurrent(t->gl.window);
glfwSetWindowUserPointer(t->gl.window, t);
+ glfwSetWindowAttrib(t->gl.window, GLFW_RESIZABLE, GLFW_TRUE);
/* NOTE: make sure the terminal performs a resize after initialization. The
* terminal code handles this because it also needs to communicate the size
@@ -278,9 +286,10 @@ main(void)
Arena memory = os_new_arena(16 * MEGABYTE);
Term term = {0};
+ iv2 cells = {.x = -1, .y = -1};
do_debug(NULL);
- init_term(&term, &memory);
- init_window(&term, memory);
+ iv2 requested_size = init_term(&term, &memory, cells);
+ init_window(&term, memory, requested_size);
init_callbacks(&term.gl);
os_alloc_ring_buffer(&term.views[0].log, BACKLOG_SIZE);
diff --git a/vtgl.c b/vtgl.c
@@ -765,9 +765,10 @@ scroll_callback(GLFWwindow *win, f64 xoff, f64 yoff)
}
}
-DEBUG_EXPORT void
-init_term(Term *t, Arena *a)
+DEBUG_EXPORT iv2
+init_term(Term *t, Arena *a, iv2 cells)
{
+ iv2 requested_size = {.x = -1, .y = -1};
init_fonts(t, a);
for (u32 i = 0; i < ARRAY_COUNT(t->saved_cursors); i++) {
cursor_reset(t);
@@ -775,6 +776,12 @@ init_term(Term *t, Arena *a)
cursor_alt(t, 1);
}
selection_clear(&t->selection);
+ if (cells.x != -1 && cells.y != -1) {
+ v2 cs = get_cell_size(t);
+ requested_size.x = cs.x * cells.x + 2 * g_term_pad.x;
+ requested_size.y = cs.y * cells.y + 2 * g_term_pad.y;
+ }
+ return requested_size;
}
DEBUG_EXPORT void