aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarvin Borner2020-11-01 12:35:00 +0100
committerMarvin Borner2020-11-01 12:35:00 +0100
commitf40be8b5b6227775901a99946779661d0b4439e6 (patch)
tree34c28f138f4167de258ee18db44707aa4637a68d /apps
parente0d3b1671b3f94657d70223b51285ed287c882df (diff)
Added files demo and needed functions
Diffstat (limited to 'apps')
-rw-r--r--apps/Makefile2
-rw-r--r--apps/exec.c2
-rw-r--r--apps/files.c74
-rw-r--r--apps/wm.c6
4 files changed, 81 insertions, 3 deletions
diff --git a/apps/Makefile b/apps/Makefile
index 99d60e9..28e447a 100644
--- a/apps/Makefile
+++ b/apps/Makefile
@@ -1,6 +1,6 @@
# MIT License, Copyright (c) 2020 Marvin Borner
-COBJS = init.o wm.o mandelbrot.o window.o exec.o test.o
+COBJS = init.o wm.o mandelbrot.o window.o exec.o files.o test.o
CC = ccache ../cross/opt/bin/i686-elf-gcc
LD = ccache ../cross/opt/bin/i686-elf-ld
OC = ccache ../cross/opt/bin/i686-elf-objcopy
diff --git a/apps/exec.c b/apps/exec.c
index 774362f..305e9ef 100644
--- a/apps/exec.c
+++ b/apps/exec.c
@@ -1,3 +1,5 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+
#include <gui.h>
#include <mem.h>
#include <print.h>
diff --git a/apps/files.c b/apps/files.c
new file mode 100644
index 0000000..2176a99
--- /dev/null
+++ b/apps/files.c
@@ -0,0 +1,74 @@
+// MIT License, Copyright (c) 2020 Marvin Borner
+// TODO: Fix green memory artifacts
+
+#include <gui.h>
+#include <mem.h>
+#include <print.h>
+#include <str.h>
+#include <sys.h>
+
+static struct element *root = NULL;
+
+struct dirent {
+ u32 inode_num;
+ u16 total_len;
+ u8 name_len;
+ u8 type_indicator;
+ char name[];
+};
+
+void render_list(char *path);
+void on_click(struct event_mouse *event, struct element *elem)
+{
+ (void)event;
+ char *value = ((struct element_label *)elem->data)->text;
+ u8 l = strlen(elem->attributes) + strlen(value) + 2;
+ char *full = malloc(l);
+ strcat(full, elem->attributes);
+ full[strlen(elem->attributes)] = '/';
+ strcat(full, value);
+ render_list(full);
+}
+
+// TODO: Dir iterator as kernel syscall?
+void render_list(char *path)
+{
+ static struct element *list = NULL;
+ if (list)
+ gui_remove_element(list);
+ list = gui_add_container(root, 0, 0, 600, 400, COLOR_BLACK);
+
+ struct dirent *d = read(path);
+
+ int sum = 0;
+ int calc = 0;
+ int cnt = 0;
+ do {
+ calc = (sizeof(struct dirent) + d->name_len + 4) & ~0x3;
+ sum += d->total_len;
+ d->name[d->name_len] = '\0';
+ struct element *label = gui_add_label(list, 5, cnt * (gfx_font_height(FONT_16) + 5),
+ FONT_16, d->name, COLOR_BLACK, COLOR_WHITE);
+ label->attributes = path;
+
+ if (d->type_indicator == 2) // Dir
+ label->event.on_click = on_click;
+
+ if (d->total_len != calc && sum == 1024)
+ d->total_len = calc;
+ d = (struct dirent *)((u32)d + d->total_len);
+ cnt++;
+ } while (sum < 1024); // TODO: Remove magic constants
+}
+
+int main()
+{
+ root = gui_init("Files", 600, 400, COLOR_BLACK);
+
+ render_list("/.");
+ gfx_redraw_focused(); // TODO: Remove
+
+ gui_event_loop(root);
+
+ return 0;
+}
diff --git a/apps/wm.c b/apps/wm.c
index b3cb953..05d497c 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -115,6 +115,8 @@ static void handle_keyboard(struct event_keyboard *event)
if (special_keys_pressed & SHIFT_PRESSED)
msg->ch = keymap->shift_map[event->scancode];
+ else if (special_keys_pressed & ALT_PRESSED)
+ msg->ch = keymap->alt_map[event->scancode];
else
msg->ch = keymap->map[event->scancode];
@@ -245,8 +247,7 @@ int main(int argc, char **argv)
}
switch (msg->type) {
- case GFX_NEW_CONTEXT:
- printf("New context for pid %d\n", msg->src);
+ case GFX_NEW_CONTEXT: {
struct context *ctx = msg->data;
int width = ctx->width;
int height = ctx->height;
@@ -260,6 +261,7 @@ int main(int argc, char **argv)
redraw_all();
msg_send(msg->src, GFX_NEW_CONTEXT, ctx);
break;
+ }
case GFX_REDRAW:
redraw_all();
break;