Commit: 9d6b945e72e4b3523cac1452d7f567abea8454d6
Parent: 4633fa50525ccf12d23a198bc9c26870b77df03a
Author: Randy Palamar
Date: Fri, 15 Nov 2024 18:29:52 -0700
move os_set_term_size into the platform struct
Diffstat:
4 files changed, 44 insertions(+), 46 deletions(-)
diff --git a/os_unix.c b/os_unix.c
@@ -269,14 +269,13 @@ os_child_exited(iptr pid)
return r == pid && WIFEXITED(status);
}
-static void
-os_set_term_size(iptr child, u32 rows, u32 cols, i32 x, i32 y)
+static PLATFORM_SET_TERMINAL_SIZE_FN(posix_set_terminal_size)
{
struct winsize ws;
- ws.ws_col = cols;
+ ws.ws_col = columns;
ws.ws_row = rows;
- ws.ws_xpixel = x;
- ws.ws_ypixel = y;
+ ws.ws_xpixel = window_width;
+ ws.ws_ypixel = window_height;
if (ioctl(child, TIOCSWINSZ, &ws) < 0)
os_write_err_msg(s8("os_set_term_size\n"));
}
diff --git a/platform_linux_x11.c b/platform_linux_x11.c
@@ -435,16 +435,17 @@ main(i32 argc, char *argv[], char *envp[])
#endif
}
+ linux_ctx.memory.platform_api.add_file_watch = linux_add_file_watch;
linux_ctx.memory.platform_api.allocate_ring_buffer = posix_allocate_ring_buffer;
- linux_ctx.memory.platform_api.read = posix_read;
- linux_ctx.memory.platform_api.write = posix_write;
- linux_ctx.memory.platform_api.get_file_stats = posix_get_file_stats;
- linux_ctx.memory.platform_api.read_file = posix_read_file;
linux_ctx.memory.platform_api.get_clipboard = x11_get_clipboard;
linux_ctx.memory.platform_api.set_clipboard = x11_set_clipboard;
+ linux_ctx.memory.platform_api.get_file_stats = posix_get_file_stats;
+ linux_ctx.memory.platform_api.read_file = posix_read_file;
+ linux_ctx.memory.platform_api.read = posix_read;
+ linux_ctx.memory.platform_api.set_terminal_size = posix_set_terminal_size;
linux_ctx.memory.platform_api.get_window_title = x11_get_window_title;
linux_ctx.memory.platform_api.set_window_title = x11_set_window_title;
- linux_ctx.memory.platform_api.add_file_watch = linux_add_file_watch;
+ linux_ctx.memory.platform_api.write = posix_write;
linux_ctx.memory.platform_api.path_separator = '/';
linux_ctx.platform_memory = arena_from_memory_block(posix_alloc(2 * MEGABYTE));
diff --git a/vtgl.c b/vtgl.c
@@ -242,7 +242,7 @@ get_terminal_top_left(Term *t)
}
static void
-resize(Term *t, iv2 window_size)
+resize(Term *t, PlatformAPI *platform, iv2 window_size)
{
GLCtx *gl = &t->gl;
gl->window_size = window_size;
@@ -289,7 +289,7 @@ resize(Term *t, iv2 window_size)
gl->flags |= UPDATE_RENDER_BUFFER;
}
- os_set_term_size(t->child, t->size.h, t->size.w, ws.w, ws.h);
+ platform->set_terminal_size(t->child, t->size.h, t->size.w, ws.w, ws.h);
ShaderParameters *sp = &gl->shader_parameters;
sp->cell_size = (uv2){.w = cs.w, .h = cs.h};
@@ -1149,12 +1149,8 @@ DEBUG_EXPORT VTGL_FRAME_STEP_FN(vtgl_frame_step)
reload_all_shaders(memory);
}
- if (!equal_iv2(input->window_size, t->gl.window_size))
- t->gl.flags |= NEEDS_RESIZE;
-
- if (t->gl.flags & NEEDS_RESIZE)
- resize(t, input->window_size);
-
+ if (t->gl.flags & NEEDS_RESIZE || !equal_iv2(input->window_size, t->gl.window_size))
+ resize(t, &memory->platform_api, input->window_size);
/* NOTE: handle this stuff first since it is based on what the user saw last frame */
BEGIN_NAMED_BLOCK(mouse_and_keyboard_input);
diff --git a/vtgl.h b/vtgl.h
@@ -2,50 +2,52 @@
#ifndef _VTGL_H_
#define _VTGL_H_
+/* NOTE: for now we will do the callback route but this will change if we do multithreading */
+#define PLATFORM_FILE_WATCH_CALLBACK_FN(name) void name(u8 *path, void *user_ctx)
+typedef PLATFORM_FILE_WATCH_CALLBACK_FN(platform_file_watch_callback_fn);
+
+#define PLATFORM_ADD_FILE_WATCH_FN(name) void name(u8 *path, platform_file_watch_callback_fn *fn, \
+ void *user_ctx)
+typedef PLATFORM_ADD_FILE_WATCH_FN(platform_add_file_watch_fn);
+
#define PLATFORM_ALLOCATE_RING_BUFFER_FN(name) void name(RingBuf *rb, size capacity)
typedef PLATFORM_ALLOCATE_RING_BUFFER_FN(platform_allocate_ring_buffer_fn);
-#define PLATFORM_WRITE_FN(name) b32 name(iptr file, s8 raw, size offset)
-typedef PLATFORM_WRITE_FN(platform_write_fn);
+#define PLATFORM_CLIPBOARD_FN(name) b32 name(Stream *buffer, u32 clipboard)
+typedef PLATFORM_CLIPBOARD_FN(platform_clipboard_fn);
-/* TODO: this should possibly just take a stream buffer */
-#define PLATFORM_READ_FN(name) size name(iptr file, s8 buffer, size offset)
-typedef PLATFORM_READ_FN(platform_read_fn);
+#define PLATFORM_GET_FILESTATS_FN(name) FileStats name(u8 *path)
+typedef PLATFORM_GET_FILESTATS_FN(platform_get_file_stats_fn);
#define PLATFORM_READ_FILE_FN(name) b32 name(u8 *path, Stream *buffer, size file_size)
typedef PLATFORM_READ_FILE_FN(platform_read_file_fn);
-#define PLATFORM_GET_FILESTATS_FN(name) FileStats name(u8 *path)
-typedef PLATFORM_GET_FILESTATS_FN(platform_get_file_stats_fn);
+/* TODO: this should possibly just take a stream buffer */
+#define PLATFORM_READ_FN(name) size name(iptr file, s8 buffer, size offset)
+typedef PLATFORM_READ_FN(platform_read_fn);
-#define PLATFORM_CLIPBOARD_FN(name) b32 name(Stream *buffer, u32 clipboard)
-typedef PLATFORM_CLIPBOARD_FN(platform_clipboard_fn);
+#define PLATFORM_SET_TERMINAL_SIZE_FN(name) void name(iptr child, i32 rows, i32 columns, \
+ i32 window_width, i32 window_height)
+typedef PLATFORM_SET_TERMINAL_SIZE_FN(platform_set_terminal_size_fn);
#define PLATFORM_WINDOW_TITLE_FN(name) void name(Stream *buffer)
typedef PLATFORM_WINDOW_TITLE_FN(platform_window_title_fn);
-/* NOTE: for now we will do the callback route but this will change if we do multithreading */
-#define PLATFORM_FILE_WATCH_CALLBACK_FN(name) void name(u8 *path, void *user_ctx)
-typedef PLATFORM_FILE_WATCH_CALLBACK_FN(platform_file_watch_callback_fn);
-
-#define PLATFORM_ADD_FILE_WATCH_FN(name) void name(u8 *path, platform_file_watch_callback_fn *fn, void *user_ctx)
-typedef PLATFORM_ADD_FILE_WATCH_FN(platform_add_file_watch_fn);
+#define PLATFORM_WRITE_FN(name) b32 name(iptr file, s8 raw, size offset)
+typedef PLATFORM_WRITE_FN(platform_write_fn);
typedef struct {
+ platform_add_file_watch_fn *add_file_watch;
platform_allocate_ring_buffer_fn *allocate_ring_buffer;
- platform_read_fn *read;
- platform_write_fn *write;
-
- platform_get_file_stats_fn *get_file_stats;
- platform_read_file_fn *read_file;
-
- platform_clipboard_fn *get_clipboard;
- platform_clipboard_fn *set_clipboard;
-
- platform_window_title_fn *get_window_title;
- platform_window_title_fn *set_window_title;
-
- platform_add_file_watch_fn *add_file_watch;
+ platform_clipboard_fn *get_clipboard;
+ platform_clipboard_fn *set_clipboard;
+ platform_get_file_stats_fn *get_file_stats;
+ platform_read_file_fn *read_file;
+ platform_read_fn *read;
+ platform_set_terminal_size_fn *set_terminal_size;
+ platform_window_title_fn *get_window_title;
+ platform_window_title_fn *set_window_title;
+ platform_write_fn *write;
u8 path_separator;
} PlatformAPI;