summaryrefslogtreecommitdiff
path: root/userland
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-11-28 00:06:09 +0100
committerAnton Kling <anton@kling.gg>2024-11-28 00:12:17 +0100
commit54869df7835565d0983096f65326cdd2d5f4f3d8 (patch)
tree3124d37d170bb14bfcc315442e410c0b76a05cf1 /userland
parent5fdba54196c7171ddebb29aef597b965a1b1ead1 (diff)
changes
Diffstat (limited to 'userland')
-rw-r--r--userland/libc/stdio/open_memstream.c3
-rw-r--r--userland/libgui/libgui.c7
-rw-r--r--userland/minibox/utilities/init.c9
-rw-r--r--userland/minibox/utilities/sh/sh.c4
-rw-r--r--userland/terminal/term.c1
-rw-r--r--userland/test/Makefile2
-rw-r--r--userland/test/test.c9
-rw-r--r--userland/windowserver/draw.c4
-rw-r--r--userland/windowserver/ws.c65
-rw-r--r--userland/windowserver/ws.h1
10 files changed, 64 insertions, 41 deletions
diff --git a/userland/libc/stdio/open_memstream.c b/userland/libc/stdio/open_memstream.c
index c829644..b129cb6 100644
--- a/userland/libc/stdio/open_memstream.c
+++ b/userland/libc/stdio/open_memstream.c
@@ -86,6 +86,9 @@ FILE *open_memstream(char **bufp, size_t *sizep) {
fp->file_size = MEMSTREAM_DEF_SIZE;
fp->fflush = NULL;
+ fp->can_write = 1;
+ fp->can_read = 1;
+
fp->write = memstream_write;
fp->read = memstream_read;
diff --git a/userland/libgui/libgui.c b/userland/libgui/libgui.c
index 458ab07..2acd806 100644
--- a/userland/libgui/libgui.c
+++ b/userland/libgui/libgui.c
@@ -149,6 +149,7 @@ static const unsigned char font8x8_basic[128][8] = {
// Very temporary
char *random_string(void) {
int fd = open("/dev/urandom", O_RDONLY, 0);
+ assert(-1 != fd);
char *r = malloc(sizeof(char[10]));
for (int i = 0; i < 10 - 1; i++) {
char c;
@@ -310,7 +311,7 @@ void GUI_DrawRectangle(GUI_Window *w, uint32_t x, uint32_t y, uint32_t sx,
uint32_t sy, uint32_t color) {
for (u32 l = y; l < y + sy; l++) {
for (u32 s = x; s < x + sx; s++) {
- if(l*w->sx + s > w->sx*w->sy) {
+ if (l * w->sx + s > w->sx * w->sy) {
break;
}
w->bitmap_ptr[l * w->sx + s] = color;
@@ -329,7 +330,7 @@ GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy) {
// Connect to the windowserver
int ws_fd = -1;
- for (; - 1 == ws_fd;) {
+ for (; -1 == ws_fd;) {
ws_fd = open("/dev/windowserver", O_RDWR | O_NONBLOCK, 0);
}
w->ws_socket = ws_fd;
@@ -342,7 +343,7 @@ GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy) {
e.name_len = (uint8_t)strlen(str) + 1;
// Create bitmap
- w->bitmap_fd = shm_open(str, O_RDWR, 0);
+ w->bitmap_fd = shm_open(str, O_RDWR | O_CREAT, 0);
if (!((int)w->bitmap_fd >= 0)) {
printf("bitmap_fd: %x\n", w->bitmap_fd);
assert(0);
diff --git a/userland/minibox/utilities/init.c b/userland/minibox/utilities/init.c
index 07dfce7..ce65387 100644
--- a/userland/minibox/utilities/init.c
+++ b/userland/minibox/utilities/init.c
@@ -63,10 +63,13 @@ int init_main(void) {
printf("minibox init must be launched as pid1.\n");
return 1;
}
- if (fork())
- for (;;)
+ if (fork()) {
+ for (;;) {
wait(NULL);
+ msleep(10000);
+ }
+ }
char *a[] = {NULL};
- execv("/ws", a);
+ execv("/init.sh", a);
return 1;
}
diff --git a/userland/minibox/utilities/sh/sh.c b/userland/minibox/utilities/sh/sh.c
index f907cc2..e129044 100644
--- a/userland/minibox/utilities/sh/sh.c
+++ b/userland/minibox/utilities/sh/sh.c
@@ -162,7 +162,7 @@ int sh_main(int argc, char **argv) {
int fd = open(argv[1], O_RDONLY, 0);
char buffer[8192];
struct sb file;
- sb_init(&file, 256);
+ sb_init(&file);
for (;;) {
int rc = read(fd, buffer, 8192);
@@ -186,7 +186,7 @@ int sh_main(int argc, char **argv) {
char buffer[256];
printf("%s : ", getcwd(buffer, 256));
struct sb line;
- sb_init(&line, 256);
+ sb_init(&line);
get_line(&line);
{
struct TOKEN *h = lex(SB_TO_SV(line));
diff --git a/userland/terminal/term.c b/userland/terminal/term.c
index abb150c..e672b2c 100644
--- a/userland/terminal/term.c
+++ b/userland/terminal/term.c
@@ -306,7 +306,6 @@ int main(void) {
for (int i = 0; i < 250 * 150 * 4 * 4; i++) {
global_w->bitmap_ptr[i] = TERM_BACKGROUND;
}
- // memset(global_w->bitmap_ptr, 0x0, 50 * 50);
GUI_UpdateWindow(global_w);
newtty();
run();
diff --git a/userland/test/Makefile b/userland/test/Makefile
index 76cf844..8c59229 100644
--- a/userland/test/Makefile
+++ b/userland/test/Makefile
@@ -1,5 +1,5 @@
CC="i686-sb-gcc"
-CFLAGS = -O2 -Wall -Wextra -pedantic -Wimplicit-fallthrough -static
+CFLAGS = -g -Wall -Wextra -pedantic -Wimplicit-fallthrough -static
BINS=test
all: $(BINS)
diff --git a/userland/test/test.c b/userland/test/test.c
index 8b3dd67..e95ab54 100644
--- a/userland/test/test.c
+++ b/userland/test/test.c
@@ -9,6 +9,7 @@
#include <stdlib.h>
#include <string.h>
#include <tb/sha1.h>
+#include <time.h>
#if 1
void dbgln(const char *fmt) {
@@ -380,7 +381,7 @@ void strtol_test(void) {
dbgln("strtol TEST");
{
{
- char *s = "1234";
+ char *s = "1234abc";
char *e;
long r;
assert(1234 == strtol(s, &e, 10));
@@ -749,7 +750,7 @@ void dirname_test(void) {
void getline_test(void) {
dbgln("getline TEST");
- {
+ do {
char *buffer;
size_t size;
FILE *fp = open_memstream(&buffer, &size);
@@ -776,7 +777,7 @@ void getline_test(void) {
assert(0 == strcmp("bar", line_buffer));
}
free(buffer);
- }
+ } while (0);
dbgln("getline TEST PASSED");
}
@@ -873,7 +874,7 @@ void fs_test() {
dbgln("filesystem TEST PASSED");
}
-int main(void) {
+int main(int argc, char **argv) {
dbgln("START");
malloc_test();
// json_test();
diff --git a/userland/windowserver/draw.c b/userland/windowserver/draw.c
index 190707d..dd80ad1 100644
--- a/userland/windowserver/draw.c
+++ b/userland/windowserver/draw.c
@@ -5,7 +5,7 @@
void draw_wallpaper(const DISPLAY *disp) {
uint32_t *dst = disp->back_buffer;
uint32_t *src = disp->wallpaper_buffer;
- const uint32_t n = disp->size / disp->bpp;
+ const uint32_t n = disp->width * disp->height;
for (int i = 0; i < n; i++) {
*dst = *src;
dst++;
@@ -18,7 +18,7 @@ void draw_outline(DISPLAY *disp, int x, int y, int sx, int sy, int border_px,
// Top
draw_rectangle(disp, x, y, sx + border_px, border_px, color);
// Bottom
- draw_rectangle(disp, x, y + sy+border_px, sx + border_px, border_px, color);
+ draw_rectangle(disp, x, y + sy + border_px, sx + border_px, border_px, color);
// Left
draw_rectangle(disp, x, y, border_px, sy + border_px * 2, color);
// Right
diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c
index 1224e86..3adefe0 100644
--- a/userland/windowserver/ws.c
+++ b/userland/windowserver/ws.c
@@ -93,9 +93,14 @@ int next_ui_id(void) {
return r;
}
+struct DISPLAY_INFO {
+ uint32_t width;
+ uint32_t height;
+ uint8_t bpp;
+};
+
void setup_display(DISPLAY *disp, const char *path, uint64_t size) {
disp->wallpaper_color = 0x3;
- disp->size = size;
disp->vga_fd = open(path, O_RDWR, 0);
if (-1 == disp->vga_fd) {
perror("open");
@@ -107,24 +112,35 @@ void setup_display(DISPLAY *disp, const char *path, uint64_t size) {
disp->back_buffer = malloc(size + 0x1000);
disp->window = window;
+ struct DISPLAY_INFO inf;
+ int fd = open("/dev/display_info", O_READ, 0);
+ assert(fd >= 0);
+ assert(sizeof(inf) == read(fd, &inf, sizeof(inf)));
+
disp->wallpaper_fd = shm_open("wallpaper", O_RDWR, 0);
assert(disp->wallpaper_fd >= 0);
- ftruncate(disp->wallpaper_fd, size);
- void *rc = mmap(NULL, size, 0, 0, disp->wallpaper_fd, 0);
+
+ // ftruncate(disp->wallpaper_fd, inf.width * inf.height * sizeof(uint32_t));
+
+ // ftruncate(disp->wallpaper_fd, size);
+ // void *rc = mmap(NULL, size, 0, 0, disp->wallpaper_fd, 0);
+
+ disp->width = inf.width;
+ disp->height = inf.height;
+
+ disp->size = inf.width * inf.height * sizeof(uint32_t);
+ void *rc = mmap(NULL, inf.width * inf.height * sizeof(uint32_t), 0, 0,
+ disp->wallpaper_fd, 0);
assert(rc != (void *)(-1));
+
disp->wallpaper_buffer = rc;
- for (int i = 0; i < disp->size / disp->bpp; i++) {
- uint32_t *p = disp->wallpaper_buffer + i * sizeof(uint32_t);
- *p = 0x9b9b9b;
- }
+ // uint32_t *p = rc;
+ // for (int i = 0; i < disp->width * disp->height; i++) {
+ // *p = 0x9b9b9b;
+ // p++;
+ // }
}
-struct DISPLAY_INFO {
- uint32_t width;
- uint32_t height;
- uint8_t bpp;
-};
-
void setup(void) {
struct DISPLAY_INFO disp_info;
{
@@ -243,6 +259,7 @@ void parse_window_event(WINDOW *w) {
read(w->fd, bitmap_name, e.name_len);
bitmap_name[e.name_len] = '\0';
int bitmap_fd = shm_open(bitmap_name, O_RDWR, O_CREAT);
+ strlcpy(w->bitmap_name, bitmap_name, 256);
create_window(w, bitmap_fd, e.px, e.py, e.sx, e.sy);
draw();
return;
@@ -458,6 +475,13 @@ WINDOW *get_window(int fd) {
}
void kill_window(WINDOW *w) {
+ if (w == main_display.active_window) {
+ if (w->prev) {
+ main_display.active_window = w->prev;
+ } else {
+ main_display.active_window = w->next;
+ }
+ }
WINDOW *prev = w->prev;
if (prev) {
assert(prev->next == w);
@@ -467,18 +491,19 @@ void kill_window(WINDOW *w) {
next_window->prev = prev;
}
} else {
- assert(w = main_display.window);
+ assert(w == main_display.window);
main_display.window = w->next;
if (main_display.window) {
main_display.window->prev = NULL;
}
- main_display.active_window = NULL;
}
if (w == main_display.window_tail) {
assert(NULL == w->next);
main_display.window_tail = prev;
}
+ munmap(w->bitmap_ptr, w->buffer_sx * w->buffer_sy);
+ shm_unlink(w->bitmap_name);
free(w);
}
@@ -686,18 +711,8 @@ void draw(void) {
}
int main(void) {
- int serial_fd = open("/dev/serial", O_WRITE, 0);
- dup2(serial_fd, 1);
- serial_fd = 1;
// Start a terminal by default. This is just to make it easier for me
// to test the system.
- int pid = fork();
- if (0 == pid) {
- close(serial_fd);
- char *argv[] = {"/term", NULL};
- execv("/term", argv);
- assert(0);
- }
setup();
run();
return 0;
diff --git a/userland/windowserver/ws.h b/userland/windowserver/ws.h
index f76523d..b67005e 100644
--- a/userland/windowserver/ws.h
+++ b/userland/windowserver/ws.h
@@ -10,6 +10,7 @@
typedef struct {
int fd;
int bitmap_fd;
+ char bitmap_name[256];
uint32_t *bitmap_ptr;
int x;
int y;