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/window.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'usr.bin/kfgwm/window.c') diff --git a/usr.bin/kfgwm/window.c b/usr.bin/kfgwm/window.c index 8954553..3908302 100644 --- a/usr.bin/kfgwm/window.c +++ b/usr.bin/kfgwm/window.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -158,6 +159,34 @@ kfg_win_draw(struct kfg_window *parent, struct kfg_window *wp) return 0; } +/* + * Create a new default window + * + * @x: X position for this window + * @y: Y position for this window + * @w: Window width + * @h: Window height + */ +struct kfg_window * +kfg_win_new(struct kfg_window *parent, kfgpos_t x, kfgpos_t y) +{ + struct kfg_window *wp; + + if ((wp = malloc(sizeof(*wp))) == NULL) { + return NULL; + } + + wp->x = x; + wp->y = y; + wp->width = 250; + wp->height = 150; + wp->fb_pitch = parent->fb_pitch; + wp->framebuf = parent->framebuf; + wp->bg = KFG_DARK; + wp->border_bg = KFG_RED; + return wp; +} + int kfg_win_putstr(struct kfg_window *wp, struct kfg_text *tp) { -- cgit v1.2.3