aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--apps/Makefile4
-rw-r--r--apps/wm.c9
-rw-r--r--libc/inc/assert.h2
-rw-r--r--libtxt/Makefile20
-rw-r--r--libtxt/inc/keymap.h16
-rw-r--r--libtxt/keymap.c61
-rw-r--r--res/keymaps/en.keymap3
-rwxr-xr-xrun3
9 files changed, 114 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 63d998c..c8a4ead 100644
--- a/Makefile
+++ b/Makefile
@@ -11,6 +11,8 @@ compile:
@echo "Compiled libk"
@$(MAKE) --no-print-directory -C libgui/
@echo "Compiled libgui"
+ @$(MAKE) --no-print-directory -C libtxt/
+ @echo "Compiled libtxt"
@$(MAKE) --no-print-directory -C kernel/
@echo "Compiled kernel"
@$(MAKE) --no-print-directory -C boot/
diff --git a/apps/Makefile b/apps/Makefile
index 84098c5..9ac92b7 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -5,14 +5,14 @@ CC = ../cross/opt/bin/i686-elf-gcc
LD = ../cross/opt/bin/i686-elf-ld
OC = ../cross/opt/bin/i686-elf-objcopy
-CFLAGS = -Wall -Wextra -nostdlib -nostdinc -fno-builtin -std=c99 -m32 -pedantic-errors -I../libc/inc/ -I../libgui/inc/ -fPIE -Duserspace -Os
+CFLAGS = -Wall -Wextra -nostdlib -nostdinc -fno-builtin -std=c99 -m32 -pedantic-errors -I../libc/inc/ -I../libgui/inc/ -I../libtxt/inc/ -fPIE -Duserspace -Os
all: $(COBJS)
%.o: %.c
@mkdir -p ../build/apps/
@$(CC) -c $(CFLAGS) $< -o $@
- @$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ $@ -lc -lgui
+ @$(LD) -o $(@:.o=.elf) -Tlink.ld -L../build/ $@ -lc -lgui -ltxt
@$(OC) -O binary $(@:.o=.elf) ../build/apps/$(@:.o=)
# @cp $(@:.o=.elf) ../build/apps/$(@:.o=.dbg)
diff --git a/apps/wm.c b/apps/wm.c
index ca032e7..0f7bf95 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -5,6 +5,7 @@
#include <def.h>
#include <gui.h>
#include <input.h>
+#include <keymap.h>
#include <list.h>
#include <mem.h>
#include <print.h>
@@ -23,6 +24,8 @@ static struct window cursor; // Cursor bitmap window
static struct window *focused; // The focused window
static struct list *windows; // List of all windows
+static struct keymap *keymap;
+
static int mouse_x = 0;
static int mouse_y = 0;
@@ -48,15 +51,16 @@ static struct window *window_at(int x, int y)
if (!windows->head || !windows->head->data)
return NULL;
+ struct window *ret = NULL;
struct node *iterator = windows->head;
while (iterator != NULL) {
struct window *win = iterator->data;
if (win != &root && x >= win->x && x <= win->x + (int)win->width && y >= win->y &&
y <= win->y + (int)win->height)
- return win;
+ ret = win;
iterator = iterator->next;
}
- return NULL;
+ return ret;
}
static void redraw_all()
@@ -155,6 +159,7 @@ int main(int argc, char **argv)
vbe = *(struct vbe *)argv[1];
printf("VBE: %dx%d\n", vbe.width, vbe.height);
+ keymap = keymap_parse("/res/keymaps/en.keymap");
gui_init("/font/spleen-16x32.psfu");
windows = list_new();
diff --git a/libc/inc/assert.h b/libc/inc/assert.h
index 758c91b..f4fa4b4 100644
--- a/libc/inc/assert.h
+++ b/libc/inc/assert.h
@@ -21,7 +21,7 @@
#define assert(exp) \
if (!(exp)) { \
printf("%s:%d: %s: Assertion '%s' failed\n", __FILE__, __LINE__, __func__, #exp); \
- sys1(SYS_EXIT, 1); \
+ exit(1); \
}
#else
#error "No lib target specified. Please use -Dkernel or -Duserspace"
diff --git a/libtxt/Makefile b/libtxt/Makefile
new file mode 100644
index 0000000..62a2afb
--- /dev/null
+++ b/libtxt/Makefile
@@ -0,0 +1,20 @@
+# MIT License, Copyright (c) 2020 Marvin Borner
+
+COBJS = keymap.o
+CC = ../cross/opt/bin/i686-elf-gcc
+LD = ../cross/opt/bin/i686-elf-ld
+AR = ../cross/opt/bin/i686-elf-ar
+
+CFLAGS = -Wall -Wextra -nostdlib -nostdinc -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ -I../libc/inc/ -fPIE -Duserspace -Ofast
+
+all: libgui clean
+
+%.o: %.c
+ @$(CC) -c $(CFLAGS) $< -o $@
+
+libgui: $(COBJS)
+ @mkdir -p ../build/
+ @$(AR) rcs ../build/libtxt.a $+
+
+clean:
+ @find . -name "*.o" -type f -delete
diff --git a/libtxt/inc/keymap.h b/libtxt/inc/keymap.h
new file mode 100644
index 0000000..9f1966e
--- /dev/null
+++ b/libtxt/inc/keymap.h
@@ -0,0 +1,16 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#ifndef KEYMAP_H
+#define KEYMAP_H
+
+#define KEYMAP_LENGTH 90
+
+struct keymap {
+ char map[KEYMAP_LENGTH];
+ char shift_map[KEYMAP_LENGTH];
+ char alt_map[KEYMAP_LENGTH];
+};
+
+struct keymap *keymap_parse(const char *path);
+
+#endif
diff --git a/libtxt/keymap.c b/libtxt/keymap.c
new file mode 100644
index 0000000..1da4537
--- /dev/null
+++ b/libtxt/keymap.c
@@ -0,0 +1,61 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
+#include <def.h>
+#include <keymap.h>
+#include <mem.h>
+#include <print.h>
+#include <sys.h>
+
+void map(struct keymap *keymap, int line, char ch, int index)
+{
+ switch (line) {
+ case 0:
+ keymap->map[index] = ch;
+ break;
+ case 1:
+ keymap->shift_map[index] = ch;
+ break;
+ case 2:
+ keymap->alt_map[index] = ch;
+ break;
+ default:
+ break;
+ }
+}
+
+struct keymap *keymap_parse(const char *path)
+{
+ char *keymap_src = read(path);
+ if (!keymap_src)
+ return NULL;
+ printf("%c\n", keymap_src[0]);
+ struct keymap *keymap = malloc(sizeof(*keymap));
+
+ int index = 0;
+ char ch;
+ int is_start = 0;
+ int line = 0;
+ while ((ch = keymap_src[index]) != '\0') {
+ if (ch == '"') {
+ if (keymap_src[index + 1] == '"')
+ map(keymap, line, '\0', index);
+ is_start ^= 1;
+ index++;
+ continue;
+ } else if ((ch == ' ' || ch == ',') && !is_start) {
+ index += 2;
+ continue;
+ }
+ printf("\"%c\"\n", ch);
+
+ if (ch == '\\') {
+ map(keymap, line, ch, index + 1);
+ } else if (ch == '\n') {
+ line++;
+ }
+ index++;
+ }
+
+ loop();
+ return NULL;
+}
diff --git a/res/keymaps/en.keymap b/res/keymaps/en.keymap
new file mode 100644
index 0000000..8399258
--- /dev/null
+++ b/res/keymaps/en.keymap
@@ -0,0 +1,3 @@
+"", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "\b", "\t", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\n", "", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "`", "", "\\", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "", "*", "", " ", "", "", "", "", "", "", "", "", "", "", "", "", "", "7", "8", "9", "-", "4", "5", "6", "+", "1", "2", "3", "0", ".", "", "", "\\", "", "", ""
+"", "", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "\b", "\t", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "{", "}", "\n", "", "A", "S", "D", "F", "G", "H", "J", "K", "L", ":", "\"", "~", "", "|", "Z", "X", "C", "V", "B", "N", "M", "<", ">", "?", "", "*", "", " ", "", "", "", "", "", "", "", "", "", "", "", "", "", "7", "8", "9", "-", "4", "5", "6", "+", "1", "2", "3", "0", ".", "", "", "|", "", "", ""
+"", "", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "\b", "\t", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\n", "", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'", "`", "", "\\", "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "", "*", "", " ", "", "", "", "", "", "", "", "", "", "", "", "", "", "7", "8", "9", "-", "4", "5", "6", "+", "1", "2", "3", "0", ".", "", "", "\\", "", "", ""
diff --git a/run b/run
index f0665f9..3fa2a5a 100755
--- a/run
+++ b/run
@@ -160,7 +160,8 @@ make_sync() {
output=$(make --always-make --dry-run)
echo "$output" | make_append_commands libc libk libc
echo "$output" | make_append_commands libk libgui libgui
- echo "$output" | make_append_commands libgui kernel kernel
+ echo "$output" | make_append_commands libgui libtxt libtxt
+ echo "$output" | make_append_commands libtxt kernel kernel
echo "$output" | make_append_commands kernel boot boot
echo "$output" | make_append_commands boot apps apps
tr <compile_commands.json '\n' '\r' | sed -e 's/\r]\r\[/,/g' | tr '\r' '\n' >tmp