diff options
author | Anton Kling <anton@kling.gg> | 2024-03-25 21:02:58 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-03-25 21:04:10 +0100 |
commit | 3deb2df8e62a5f0a5535ee734a5aa13b0959f53f (patch) | |
tree | af8841076c95ae3de7dcd4a006026be2607a0fbf /userland | |
parent | 6baa733f5682f660143c851a635a53dc2c2df7ae (diff) |
Random changes
Diffstat (limited to 'userland')
-rw-r--r-- | userland/irc/irc.c | 3 | ||||
-rw-r--r-- | userland/libc/Makefile | 4 | ||||
-rw-r--r-- | userland/libc/include/sys/mman.h | 1 | ||||
-rw-r--r-- | userland/libc/include/syscall.h | 1 | ||||
-rw-r--r-- | userland/libc/sys/mman/munmap.c | 6 | ||||
-rw-r--r-- | userland/libgui/libgui.c | 13 | ||||
-rw-r--r-- | userland/libgui/libgui.h | 7 | ||||
-rw-r--r-- | userland/terminal/term.c | 14 | ||||
-rw-r--r-- | userland/windowserver/Makefile | 5 | ||||
-rw-r--r-- | userland/windowserver/ws.c | 136 | ||||
-rw-r--r-- | userland/windowserver/ws.h | 1 |
11 files changed, 133 insertions, 58 deletions
diff --git a/userland/irc/irc.c b/userland/irc/irc.c index 297c332..6bdbce5 100644 --- a/userland/irc/irc.c +++ b/userland/irc/irc.c @@ -259,7 +259,8 @@ void handle_msg(struct irc_server *server, struct sv msg) { sb_append_sv(&user_list_message, channel); sb_append(&user_list_message, ": "); sb_append_sv(&user_list_message, command_parameters); - irc_add_message(server, channel, C_TO_SV("*"), SB_TO_SV(user_list_message)); + irc_add_message(server, channel, C_TO_SV("*"), + SB_TO_SV(user_list_message)); sb_free(&user_list_message); } } diff --git a/userland/libc/Makefile b/userland/libc/Makefile index 62d4973..c818200 100644 --- a/userland/libc/Makefile +++ b/userland/libc/Makefile @@ -2,8 +2,8 @@ CC="i686-sb-gcc" AR="i686-sb-ar" AS="i686-sb-as" #CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type -CFLAGS = -ggdb -ffreestanding -Ofast -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type -OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o +CFLAGS = -ggdb -ffreestanding -Wall -Wextra -pedantic -Wimplicit-fallthrough -I./include/ -static -I../../include/ -Wno-int-conversion -Wno-unused-parameter -Wno-return-type +OBJ=crt0.o libc.o malloc/malloc.o pty.o sys/mman/mmap.o sys/mman/munmap.o memset.o assert.o stdio/snprintf.o stdio/vfprintf.o string/memcpy.o string/memcmp.o string/strcmp.o ubsan.o string/strcpy.o isspace.o stdio/puts.o stdio/putchar.o dirent/opendir.o dirent/readdir.o dirent/closedir.o unistd/getopt.o dirent/scandir.o dirent/alphasort.o stdio/printf.o stdio/vdprintf.o stdio/vprintf.o stdio/dprintf.o stdio/vprintf.o string/strlen.o string/strnlen.o stdio/stdin.o stdio/getchar.o stdio/fgetc.o arpa/inet/htons.o arpa/inet/htonl.o stdio/fread.o stdio/fwrite.o stdio/fopen.o stdio/fclose.o stdio/fseek.o ctype/isascii.o stdio/fprintf.o stdlib/atoi.o stdlib/strtol.o ctype/toupper.o ctype/tolower.o string/strcat.o string/strchr.o string/sscanf.o sys/stat/stat.o stdlib/getenv.o string/strrchr.o stdio/ftell.o stdio/tmpfile.o stdio/fgets.o stdio/feof.o stdio/fscanf.o stdio/ungetc.o string/strncmp.o stdio/fputc.o string/strncpy.o stdio/remove.o stdio/ferror.o stdio/fputs.o stdlib/rand.o stdlib/srand.o unistd/getpid.o stdlib/strtoul.o stdio/fflush.o stdlib/abort.o string/strcspn.o time/localtime.o time/time.o time/clock_gettime.o time/gmtime.o time/strftime.o string/strpbrk.o ctype/isdigit.o ctype/isalpha.o ctype/isxdigit.o ctype/ispunct.o stdio/setvbuf.o stdio/fileno.o stdio/putc.o stdio/sprintf.o stdlib/abs.o string/strspn.o stdlib/qsort.o string/memmove.o setjmp/longjmp.o setjmp/setjmp.o libgen/basename.o string/strdup.o string/strndup.o string/strlcpy.o stdlib/atexit.o stdio/open_memstream.o libgen/dirname.o unistd/unlink.o string/strstr.o string/strcasecmp.o string/strncasecmp.o stdlib/mkstemp.o string/strtok.o unistd/execvp.o unistd/_exit.o ctype/isalnum.o time/ctime_r.o stdlib/strtold.o sys/time/gettimeofday.o stdio/fgetpos.o stdio/fsetpos.o ctype/isprint.o stdlib/system.o stdio/tmpnam.o unistd/msleep.o stdlib/atof.o stdlib/strtod.o stdio/rename.o sys/stat/mkdir.o unistd/uptime.o unistd/ftruncate.o sys/socket/recvfrom.o sys/socket/sendto.o signal/kill.o signal/sigaction.o unistd/chdir.o unistd/getcwd.o stdio/getdelim.o stdio/getline.o unistd/isatty.o sys/socket/listen.o stdlib/realpath.o systemcall.o sys/random/randomfill.o fcntl/open.o unistd/write.o unistd/pwrite.o all: libc.a %.o: %.c diff --git a/userland/libc/include/sys/mman.h b/userland/libc/include/sys/mman.h index 7dfe29a..7cba68f 100644 --- a/userland/libc/include/sys/mman.h +++ b/userland/libc/include/sys/mman.h @@ -12,4 +12,5 @@ void *mmap(void *addr, size_t length, int prot, int flags, int fd, size_t offset); +int munmap(void *addr, size_t length); #endif diff --git a/userland/libc/include/syscall.h b/userland/libc/include/syscall.h index d89ead5..e375079 100644 --- a/userland/libc/include/syscall.h +++ b/userland/libc/include/syscall.h @@ -60,6 +60,7 @@ #define SYS_QUEUE_CREATE 49 #define SYS_QUEUE_ADD 50 #define SYS_QUEUE_WAIT 51 +#define SYS_MUNMAP 52 int syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx, uint32_t esi, uint32_t edi); diff --git a/userland/libc/sys/mman/munmap.c b/userland/libc/sys/mman/munmap.c new file mode 100644 index 0000000..940ea46 --- /dev/null +++ b/userland/libc/sys/mman/munmap.c @@ -0,0 +1,6 @@ +#include <sys/mman.h> +#include <syscall.h> + +int munmap(void *addr, size_t length) { + RC_ERRNO(syscall(SYS_MUNMAP, addr, length,0, 0, 0)); +} diff --git a/userland/libgui/libgui.c b/userland/libgui/libgui.c index a344778..2a8361d 100644 --- a/userland/libgui/libgui.c +++ b/userland/libgui/libgui.c @@ -256,6 +256,19 @@ void GUI_EventLoop(GUI_Window *w, void (*event_handler)(WS_EVENT ev)) { } } +void GUI_Resize(GUI_Window *w, uint32_t sx, uint32_t sy) { + ftruncate(w->bitmap_fd, sx * sy * sizeof(uint32_t)); + w->sx = sx; + w->sy = sy; + char buffer[sizeof(uint8_t) + sizeof(uint32_t) * 2]; + uint8_t l = 2; + memcpy(buffer, &l, sizeof(l)); + memcpy(buffer + sizeof(uint8_t), &sx, sizeof(sx)); + memcpy(buffer + sizeof(uint8_t) + sizeof(uint32_t), &sy, sizeof(sy)); + int len = sizeof(uint8_t) + sizeof(uint32_t) * 2; + write(w->ws_socket, buffer, len); +} + GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy) { GUI_Window *w = malloc(sizeof(GUI_Window)); if (!w) diff --git a/userland/libgui/libgui.h b/userland/libgui/libgui.h index cb8d9a7..1c3ac95 100644 --- a/userland/libgui/libgui.h +++ b/userland/libgui/libgui.h @@ -5,6 +5,7 @@ #define WINDOWSERVER_EVENT_KEYPRESS 0 #define WINDOWSERVER_EVENT_WINDOW_EXIT 1 +#define WINDOWSERVER_EVENT_WINDOW_RESIZE 2 typedef struct { int ws_socket; @@ -25,7 +26,10 @@ struct KEY_EVENT { typedef struct { int type; - struct KEY_EVENT ev; + union { + struct KEY_EVENT ev; + int vector[2]; + }; } WS_EVENT; GUI_Window *GUI_CreateWindow(uint32_t x, uint32_t y, uint32_t sx, uint32_t sy); @@ -35,4 +39,5 @@ void GUI_OverwriteFont(GUI_Window *w, uint32_t px, uint32_t py, const uint32_t color); void GUI_ClearScreen(GUI_Window *w, uint32_t color); void GUI_EventLoop(GUI_Window *w, void (*event_handler)(WS_EVENT ev)); +void GUI_Resize(GUI_Window *w, uint32_t sx, uint32_t sy); #endif diff --git a/userland/terminal/term.c b/userland/terminal/term.c index b734bb5..4824a59 100644 --- a/userland/terminal/term.c +++ b/userland/terminal/term.c @@ -100,6 +100,8 @@ void newtty(void) { openpty(&m, &s, NULL, NULL, NULL); int pid = fork(); if (0 == pid) { + close(global_w->ws_socket); + close(global_w->bitmap_fd); dup2(s, 0); dup2(s, 1); dup2(s, 2); @@ -242,6 +244,18 @@ void run() { if (0 >= (rc = read(global_w->ws_socket, &e, sizeof(e)))) { continue; } + if (WINDOWSERVER_EVENT_WINDOW_EXIT == e.type) { + close(global_w->ws_socket); + exit(0); + return; + } +// if (WINDOWSERVER_EVENT_WINDOW_RESIZE == e.type) { +// GUI_Resize(global_w, e.vector[0], e.vector[1]); +// continue; +// } + if (WINDOWSERVER_EVENT_KEYPRESS != e.type) { + continue; + } if (1 == e.ev.release) { continue; } diff --git a/userland/windowserver/Makefile b/userland/windowserver/Makefile index 0adbdaa..d267350 100644 --- a/userland/windowserver/Makefile +++ b/userland/windowserver/Makefile @@ -1,6 +1,5 @@ CC="i686-sb-gcc" -#CFLAGS = -ggdb -ffreestanding -O2 -Wall -Wextra -pedantic -mgeneral-regs-only -Wimplicit-fallthrough -CFLAGS = -ggdb -ffreestanding -Ofast -Wall -Wextra -pedantic -mgeneral-regs-only -Wimplicit-fallthrough +CFLAGS = -ggdb -O0 -Wall -Wextra -Wimplicit-fallthrough BIN=ws LIB=-lgcc INC=-I../libgui/ @@ -14,4 +13,4 @@ clean: rm $(OBJ) ws $(BIN): $(OBJ) - $(CC) -flto -o $(BIN) $(CFLAGS) $(OBJ) $(LIB) + $(CC) -o $(BIN) $(CFLAGS) $(OBJ) $(LIB) diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c index ceb4f64..6d01048 100644 --- a/userland/windowserver/ws.c +++ b/userland/windowserver/ws.c @@ -3,6 +3,7 @@ #include "font.h" #include <assert.h> #include <fcntl.h> +#include <math.h> #include <poll.h> #include <socket.h> #include <stddef.h> @@ -15,12 +16,46 @@ #define WINDOW_SERVER_SOCKET "/windowserver" +#define RET_CLICKED(_x, _y, _sx, _sy, _id) \ + if (contains(_x, _y, _sx, _sy, mouse_x, mouse_y)) { \ + if (mouse_left_down) { \ + active_id = _id; \ + } else if (mouse_left_up) { \ + if (_id == active_id) { \ + return 1; \ + } \ + } \ + } else { \ + if (_id == active_id && mouse_left_up) { \ + active_id = -1; \ + } \ + } \ + return 0; + +// Taken from drivers/keyboard.c +struct KEY_EVENT { + char c; + uint8_t mode; // (shift (0 bit)) (alt (1 bit)) + uint8_t release; // 0 pressed, 1 released +}; + +typedef struct { + int type; + union { + struct KEY_EVENT ev; + int vector[2]; + }; +} WS_EVENT; + WINDOW *window; int mouse_x = 0; int mouse_y = 0; -int mouse_down = 0; -int mouse_up = 0; +int mouse_left_down = 0; +int mouse_left_up = 0; +int mouse_right_down = 0; +int mouse_right_up = 0; + int active_id = -1; int ui_id = 0; @@ -37,13 +72,6 @@ uint64_t mouse_fd_poll; void draw(void); -// Taken from drivers/keyboard.c -struct KEY_EVENT { - char c; - uint8_t mode; // (shift (0 bit)) (alt (1 bit)) - uint8_t release; // 0 pressed, 1 released -}; - int create_socket(void) { struct sockaddr_un address; int fd = socket(AF_UNIX, 0, 0); @@ -216,14 +244,27 @@ void parse_window_event(WINDOW *w) { int bitmap_fd = shm_open(bitmap_name, O_RDWR, O_CREAT); create_window(w, bitmap_fd, e.px, e.py, e.sx, e.sy); draw(); + return; + } + if (2 == event_type) { + uint32_t vec[2]; + for (; 0 == read(w->fd, vec, sizeof(vec));) + ; + void *rc = + mmap(NULL, vec[0] * vec[1] * sizeof(uint32_t), 0, 0, w->bitmap_fd, 0); + if ((void *)-1 == rc) { + return; + } + w->sx = vec[0]; + w->sy = vec[1]; + w->buffer_sx = vec[0]; + w->buffer_sy = vec[1]; + munmap(w->bitmap_ptr, 0); + w->bitmap_ptr = rc; + return; } } -typedef struct { - int type; - struct KEY_EVENT ev; -} WS_EVENT; - void send_key_event_to_window(struct KEY_EVENT ev) { WS_EVENT e = { .type = 0, @@ -309,6 +350,14 @@ struct mouse_event { uint8_t y; }; +void send_resize(WINDOW *w, int x, int y) { + WS_EVENT e = { + .type = WINDOWSERVER_EVENT_WINDOW_RESIZE, + .vector = {x, y}, + }; + write(w->fd, &e, sizeof(e)); +} + void parse_mouse_event(int fd) { int16_t xc = 0; int16_t yc = 0; @@ -346,12 +395,20 @@ void parse_mouse_event(int fd) { if (mouse_y < 0) { mouse_y = 0; } - if (mouse_down && !left_button) { - mouse_up = 1; + if (mouse_left_down && !left_button) { + mouse_left_up = 1; + } else { + mouse_left_up = 0; + } + + if (mouse_right_down && !right_button) { + mouse_right_up = 1; } else { - mouse_up = 0; + mouse_right_up = 0; } - mouse_down = left_button; + mouse_right_down = right_button; + + mouse_left_down = left_button; if (middle_button) { if (main_display.active_window) { main_display.active_window->x += xc; @@ -360,10 +417,13 @@ void parse_mouse_event(int fd) { &main_display.active_window->y); } } - if (right_button) { + if (mouse_right_down) { if (main_display.active_window) { - main_display.active_window->sx += xc; - main_display.active_window->sy -= yc; + int new_sx = main_display.active_window->sx + xc; + int new_sy = main_display.active_window->sy - yc; + new_sx = max(0, new_sx); + new_sy = max(0, new_sy); + send_resize(main_display.active_window, new_sx, new_sy); } } draw(); @@ -474,20 +534,7 @@ int draw_button(DISPLAY *disp, int x, int y, int sx, int sy, uint32_t border, draw_rectangle(disp, x + 1, y + 1, sx, sy, filled); draw_outline(disp, x, y, sx, sy, 1, border); - if (contains(x, y, sx, sy, mouse_x, mouse_y)) { - if (mouse_down) { - active_id = id; - } else if (mouse_up) { - if (id == active_id) { - return 1; - } - } - } else { - if (id == active_id && mouse_up) { - active_id = -1; - } - } - return 0; + RET_CLICKED(x, y, sx, sy, id) } int draw_window(DISPLAY *disp, WINDOW *w, int id) { @@ -542,20 +589,7 @@ int draw_window(DISPLAY *disp, WINDOW *w, int id) { } } - if (contains(px, py, sx, sy, mouse_x, mouse_y)) { - if (mouse_down) { - active_id = id; - } else if (mouse_up) { - if (id == active_id) { - return 1; - } - } - } else { - if (id == active_id && mouse_up) { - active_id = -1; - } - } - return 0; + RET_CLICKED(x, y, sx, sy, id) } void update_display(const DISPLAY *disp) { @@ -647,8 +681,8 @@ void draw(void) { } } if (ui_state) { - mouse_down = 0; - mouse_up = 0; + mouse_left_down = 0; + mouse_left_up = 0; ui_state = 0; draw(); } else { diff --git a/userland/windowserver/ws.h b/userland/windowserver/ws.h index 9978b9c..f76523d 100644 --- a/userland/windowserver/ws.h +++ b/userland/windowserver/ws.h @@ -5,6 +5,7 @@ #define WINDOWSERVER_EVENT_KEYPRESS 0 #define WINDOWSERVER_EVENT_WINDOW_EXIT 1 +#define WINDOWSERVER_EVENT_WINDOW_RESIZE 2 typedef struct { int fd; |