Commit: 3800192c466fd6a4dc515a09c904d8ac001b210b
Parent: 29dd100505556b43d27fd440fbee7e7201c88e67
Author: Randy Palamar
Date: Thu, 7 Nov 2024 10:01:51 -0700
fix broken -g option
while we are at it the window now starts centered on the monitor
and we set a smaller default window size for non tiling window
manager users.
Diffstat:
1 file changed, 29 insertions(+), 12 deletions(-)
diff --git a/platform_linux_x11.c b/platform_linux_x11.c
@@ -164,6 +164,11 @@ init_window(tmp_user_ctx *ctx, iv2 window_size)
glfwWindowHint(GLFW_CONTEXT_DEBUG, GLFW_TRUE);
#endif
+ /* NOTE: we initially hide the window so that it can be freely resized behind the
+ * back of the window manager prior to showing */
+ glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
+ glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
+
GLFWwindow *window = glfwCreateWindow(window_size.w, window_size.h, "vtgl", NULL, NULL);
if (!window) {
glfwTerminate();
@@ -171,7 +176,6 @@ init_window(tmp_user_ctx *ctx, iv2 window_size)
}
glfwMakeContextCurrent(window);
glfwSetWindowUserPointer(window, ctx);
- glfwSetWindowAttrib(window, GLFW_RESIZABLE, GLFW_TRUE);
/* TODO: swap interval is not needed because we will sleep on waiting for terminal input */
glfwSwapInterval(1);
@@ -412,8 +416,8 @@ main(i32 argc, char *argv[], char *envp[])
os_fatal(s8("Failed to get GLFW monitor\n"));
}
- iv2 ws;
- glfwGetMonitorWorkarea(mon, NULL, NULL, &ws.w, &ws.h);
+ iv2 monitor_size;
+ glfwGetMonitorWorkarea(mon, NULL, NULL, &monitor_size.w, &monitor_size.h);
TerminalInput input = {0};
@@ -422,22 +426,35 @@ main(i32 argc, char *argv[], char *envp[])
ctx.memory = &term_memory;
ctx.input = &input;
- GLFWwindow *window = init_window(&ctx, ws);
+ iv2 window_size = {.w = 1280, .h = 720};
+ GLFWwindow *window = init_window(&ctx, window_size);
posix_platform_process child = os_fork_child("/bin/sh");
- iv2 requested_size = vtgl_initialize(&term_memory, child.handle, cells, ws);
+ iv2 requested_size = vtgl_initialize(&term_memory, child.handle, cells, monitor_size);
if (requested_size.w > 0 && requested_size.h > 0 &&
- (requested_size.w != ws.w || requested_size.h != ws.h))
+ (requested_size.w != window_size.w || requested_size.h != window_size.h))
{
- glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
- glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
- glfwSetWindowSize(window, requested_size.w, requested_size.h);
- glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
- ws = requested_size;
+ glfwSetWindowAttrib(window, GLFW_FLOATING, GLFW_TRUE);
+ i32 x = ABS(window_size.w - requested_size.w) / 2;
+ i32 y = ABS(window_size.h - requested_size.h) / 2;
+ window_size = requested_size;
+ glfwSetWindowMonitor(window, 0, x, y, window_size.w, window_size.h, GLFW_DONT_CARE);
+ /* NOTE: resizable must be set after the window is shown; otherwise tiling window
+ * managers will forcibly resize us even if we are supposed to be floating */
+ glfwShowWindow(window);
+ glfwSetWindowAttrib(window, GLFW_RESIZABLE, GLFW_TRUE);
+ } else {
+ /* NOTE: on the other hand we should let the window be resized if no size was
+ * explicitly requested */
+ glfwSetWindowAttrib(window, GLFW_RESIZABLE, GLFW_TRUE);
+ glfwSetWindowPos(window,
+ ABS(monitor_size.w - window_size.w) / 2,
+ ABS(monitor_size.h - window_size.h) / 2);
+ glfwShowWindow(window);
}
- input.window_size = ws;
+ input.window_size = window_size;
/* TODO: remove */
{