summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-06-04 00:03:45 -0400
committerIan Moffett <ian@osmora.org>2025-06-04 00:03:45 -0400
commit27a3e69356db7d50603e675d8ecc81df86dab594 (patch)
tree6b11f3b290f81ba7c3f79cb631a46425ab3a6cca
parent6a9e551dbf0426172317f75e811e5e49f2161317 (diff)
usr.bin: kfgwm: Add initial WM sourcesmain
- Add basic structures and defines for describing a window - Add basic window drawing routines - Draw demo/test window Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--usr.bin/Makefile1
-rw-r--r--usr.bin/kfgwm/Makefile6
-rw-r--r--usr.bin/kfgwm/include/kfg/types.h39
-rw-r--r--usr.bin/kfgwm/include/kfg/window.h60
-rw-r--r--usr.bin/kfgwm/kfgwm.c85
-rw-r--r--usr.bin/kfgwm/window.c132
-rw-r--r--usr.bin/osh/osh.c2
7 files changed, 325 insertions, 0 deletions
diff --git a/usr.bin/Makefile b/usr.bin/Makefile
index 3744a2f..3fb6a73 100644
--- a/usr.bin/Makefile
+++ b/usr.bin/Makefile
@@ -8,3 +8,4 @@ all:
make -C osh/ $(ARGS)
make -C kmsg/ $(ARGS)
make -C fetch/ $(ARGS)
+ make -C kfgwm/ $(ARGS)
diff --git a/usr.bin/kfgwm/Makefile b/usr.bin/kfgwm/Makefile
new file mode 100644
index 0000000..a0fb49a
--- /dev/null
+++ b/usr.bin/kfgwm/Makefile
@@ -0,0 +1,6 @@
+include user.mk
+
+CFILES = $(shell find . -name "*.c")
+
+$(ROOT)/base/usr/bin/kfgwm:
+ gcc $(CFILES) -Iinclude/ -o $@ $(INTERNAL_CFLAGS)
diff --git a/usr.bin/kfgwm/include/kfg/types.h b/usr.bin/kfgwm/include/kfg/types.h
new file mode 100644
index 0000000..43d8074
--- /dev/null
+++ b/usr.bin/kfgwm/include/kfg/types.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef KFG_TYPES_H_
+#define KFG_TYPES_H_
+
+#include <sys/types.h>
+
+typedef uint32_t kfgpos_t;
+typedef uint32_t kfgdim_t;
+typedef uint32_t kfgpixel_t;
+
+#endif /* !KFG_TYPES_H_ */
diff --git a/usr.bin/kfgwm/include/kfg/window.h b/usr.bin/kfgwm/include/kfg/window.h
new file mode 100644
index 0000000..058e4b7
--- /dev/null
+++ b/usr.bin/kfgwm/include/kfg/window.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef KFG_WINDOW_H_
+#define KFG_WINDOW_H_
+
+#include <kfg/types.h>
+
+#define KFG_RED 0x6E0C24
+#define KFG_YELLOW 0xF0A401
+#define KFG_WHITE 0xF2E5BC
+#define KFG_DARK 0x1D2021
+#define KFG_BLUE 0x076678
+#define KFG_AQUA 0x427B58
+
+/* Default dimensions */
+#define KFG_BORDER_WIDTH 1
+#define KFG_BORDER_HEIGHT 1
+#define KFG_TITLE_HEIGHT 10
+
+struct kfg_window {
+ kfgpos_t x;
+ kfgpos_t y;
+ kfgdim_t width;
+ kfgdim_t height;
+ kfgdim_t fb_pitch;
+ kfgpixel_t bg;
+ kfgpixel_t border_bg;
+ kfgpixel_t *framebuf;
+};
+
+int kfg_win_draw(struct kfg_window *parent, struct kfg_window *wp);
+
+#endif /* !KFG_WINDOW_H_ */
diff --git a/usr.bin/kfgwm/kfgwm.c b/usr.bin/kfgwm/kfgwm.c
new file mode 100644
index 0000000..eb28a8e
--- /dev/null
+++ b/usr.bin/kfgwm/kfgwm.c
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/mman.h>
+#include <sys/types.h>
+#include <sys/fbdev.h>
+#include <kfg/window.h>
+#include <fcntl.h>
+#include <stddef.h>
+#include <unistd.h>
+
+int
+main(void)
+{
+ int fb_fd, fbattr_fd, prot;
+ size_t fb_size;
+ uint32_t *framep;
+ struct fbattr fbattr;
+ struct kfg_window root_win, test_win;
+
+ fb_fd = open("/dev/fb0", O_RDWR);
+ if (fb_fd < 0) {
+ return fb_fd;
+ }
+
+ fbattr_fd = open("/ctl/fb0/attr", O_RDONLY);
+ if (fbattr_fd < 0) {
+ close(fb_fd);
+ return fbattr_fd;
+ }
+
+ read(fbattr_fd, &fbattr, sizeof(fbattr));
+ close(fbattr_fd);
+
+ fb_size = fbattr.height * fbattr.pitch;
+ 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.x = 150;
+ test_win.y = 85;
+ test_win.width = 425;
+ test_win.height = 350;
+ test_win.fb_pitch = fbattr.pitch;
+ test_win.framebuf = framep;
+ test_win.bg = KFG_DARK;
+ test_win.border_bg = KFG_RED;
+
+ kfg_win_draw(&root_win, &test_win);
+ for (;;);
+}
diff --git a/usr.bin/kfgwm/window.c b/usr.bin/kfgwm/window.c
new file mode 100644
index 0000000..7e36f05
--- /dev/null
+++ b/usr.bin/kfgwm/window.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/errno.h>
+#include <sys/cdefs.h>
+#include <kfg/window.h>
+#include <stddef.h>
+
+__always_inline static inline size_t
+pixel_index(struct kfg_window *wp, kfgpos_t x, kfgpos_t y)
+{
+ return x + y * (wp->fb_pitch / 4);
+}
+
+static void
+draw_win(struct kfg_window *parent, struct kfg_window *wp)
+{
+ kfgpixel_t *framep;
+ kfgpixel_t x_i, y_i; /* Start */
+ kfgpixel_t x_end, y_end; /* End */
+ kfgpixel_t brush = wp->bg;
+ kfgpixel_t rx, ry; /* Starts at 0 */
+ kfgpixel_t rx_end, ry_end; /* Starts at 0 */
+ size_t i;
+
+ framep = parent->framebuf;
+ x_i = wp->x;
+ y_i = wp->y;
+ x_end = x_i + wp->width;
+ y_end = y_i + wp->height;
+
+ for (kfgpos_t x = x_i; x < x_end; ++x) {
+ for (kfgpos_t y = y_i; y < y_i+KFG_TITLE_HEIGHT; ++y) {
+ rx = (x - x_i);
+ ry = (y - y_i);
+
+ if (rx <= KFG_BORDER_WIDTH && (rx % 2) == 0)
+ brush = KFG_WHITE;
+ else
+ brush = KFG_AQUA;
+
+ i = pixel_index(parent, x, y);
+ framep[i] = brush;
+ }
+ }
+
+ y_i = wp->y + KFG_TITLE_HEIGHT;
+ for (kfgpos_t x = x_i; x < x_end; ++x) {
+ for (kfgpos_t y = y_i; y < y_end; ++y) {
+ rx = (x - x_i);
+ ry = (y - y_i);
+
+ if (rx <= KFG_BORDER_WIDTH)
+ brush = wp->border_bg;
+ else if (ry <= KFG_BORDER_HEIGHT)
+ brush = wp->border_bg;
+ else if (rx >= (wp->width - KFG_BORDER_WIDTH))
+ brush = wp->border_bg;
+ else if (ry >= (wp->height - KFG_BORDER_HEIGHT))
+ brush = wp->border_bg;
+ else
+ brush = wp->bg;
+
+ i = pixel_index(parent, x, y);
+ framep[i] = brush;
+ }
+ }
+}
+
+/*
+ * Draw a window on the screen
+ *
+ * @parent: Parent window
+ * @wp: New window to draw
+ *
+ * TODO: Double buffering and multiple windows.
+ */
+int
+kfg_win_draw(struct kfg_window *parent, struct kfg_window *wp)
+{
+ kfgpos_t start_x, start_y;
+ kfgpos_t end_x, end_y;
+ kfgpos_t max_x, max_y;
+ kfgdim_t width, height;
+
+ if (parent == NULL) {
+ return -EINVAL;
+ }
+ if (parent->framebuf == NULL) {
+ return -EINVAL;
+ }
+
+ max_x = wp->x + parent->width;
+ max_y = wp->y + parent->height;
+
+ /* Don't overflow the framebuffer! */
+ if ((wp->x + wp->width) > max_x) {
+ wp->x = max_x;
+ }
+ if ((wp->y + wp->height) > max_y) {
+ wp->y = max_y;
+ }
+
+ draw_win(parent, wp);
+ return 0;
+}
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index 583f29a..120145f 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -52,6 +52,7 @@
"shutdown - Power off the machine\n" \
"kmsg - Print kernel message buffer\n" \
"fetch - System information\n" \
+ "kfg - Start up kfgwm\n" \
"exit - Exit the shell\n"
#define PROMPT "[root::osmora]~ "
@@ -190,6 +191,7 @@ struct command cmds[] = {
{"shutdown", NULL, cmd_shutdown},
{"kmsg", "/usr/bin/kmsg", NULL},
{"fetch", "/usr/bin/fetch", NULL},
+ {"kfg", "/usr/bin/kfgwm", NULL},
{NULL, NULL}
};