diff options
author | Ian Moffett <ian@osmora.org> | 2025-06-23 13:40:05 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-06-23 13:40:05 -0400 |
commit | 789d714ed76df094bd34f5db0a84060061443de4 (patch) | |
tree | 47f23ef85a306ab747a3accb57e889b70763966b /usr.bin/kfgwm/window.c | |
parent | 395fb7ac0dd57f9352a4001b4456095c47a63ef3 (diff) |
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 <ian@osmora.org>
Diffstat (limited to 'usr.bin/kfgwm/window.c')
-rw-r--r-- | usr.bin/kfgwm/window.c | 29 |
1 files changed, 29 insertions, 0 deletions
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 <sys/param.h> #include <kfg/window.h> #include <kfg/font.h> +#include <stdlib.h> #include <stddef.h> #include <string.h> @@ -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) { |