From 789d714ed76df094bd34f5db0a84060061443de4 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Mon, 23 Jun 2025 13:40:05 -0400 Subject: usr.bin: kfgwm: Allocate new windows with malloc() As malloc() has been recently introduced into the Hyra libc, we should take advantage of it to allow us to share windows between functions without relying on the stack. Signed-off-by: Ian Moffett --- usr.bin/kfgwm/kfgwm.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'usr.bin/kfgwm/kfgwm.c') diff --git a/usr.bin/kfgwm/kfgwm.c b/usr.bin/kfgwm/kfgwm.c index 3240a0b..5a9e7b8 100644 --- a/usr.bin/kfgwm/kfgwm.c +++ b/usr.bin/kfgwm/kfgwm.c @@ -33,6 +33,7 @@ #include #include #include +#include #include static struct fbattr fbattr; @@ -42,23 +43,15 @@ static void test_win(struct kfg_window *root, kfgpos_t x, kfgpos_t y, const char *str) { struct kfg_text text; - struct kfg_window test_win; - - test_win.x = x; - test_win.y = y; - test_win.width = 250; - test_win.height = 150; - test_win.fb_pitch = fbattr.pitch; - test_win.framebuf = framep; - test_win.bg = KFG_DARK; - test_win.border_bg = KFG_RED; + struct kfg_window *test_win; + test_win = kfg_win_new(root, x, y); text.text = str; text.x = 0; text.y = 0; - kfg_win_draw(root, &test_win); - kfg_win_putstr(&test_win, &text); + kfg_win_draw(root, test_win); + kfg_win_putstr(test_win, &text); } int @@ -66,7 +59,7 @@ main(void) { int fb_fd, fbattr_fd, prot; size_t fb_size; - struct kfg_window root_win; + struct kfg_window *root_win; fb_fd = open("/dev/fb0", O_RDWR); if (fb_fd < 0) { @@ -86,16 +79,17 @@ main(void) prot = PROT_READ | PROT_WRITE; framep = mmap(NULL, fb_size, prot, MAP_SHARED, fb_fd, 0); - root_win.x = 0; - root_win.y = 0; - root_win.width = fbattr.width; - root_win.height = fbattr.height; - root_win.fb_pitch = fbattr.pitch; - root_win.framebuf = framep; - root_win.bg = KFG_RED; - root_win.border_bg = KFG_RED; - test_win(&root_win, 40, 85, "Hello, World!"); - test_win(&root_win, 150, 20, "Mrow!"); + root_win = malloc(sizeof(*root_win)); + root_win->x = 0; + root_win->y = 0; + root_win->width = fbattr.width; + root_win->height = fbattr.height; + root_win->fb_pitch = fbattr.pitch; + root_win->framebuf = framep; + root_win->bg = KFG_RED; + root_win->border_bg = KFG_RED; + test_win(root_win, 40, 85, "Hello, World!"); + test_win(root_win, 150, 20, "Mrow!"); for (;;); } -- cgit v1.2.3