diff options
author | Marvin Borner | 2021-03-14 16:06:57 +0100 |
---|---|---|
committer | Marvin Borner | 2021-03-14 16:06:57 +0100 |
commit | 6dec7db5158447b66f31a3f786ce2916cab83cec (patch) | |
tree | 2dbc3e52d90dab4aae8021773f09b6b72a74b8cb /libgui | |
parent | 2f8328f2a41b77eea297ee7fc28818331d4e6c54 (diff) |
Maaany fixes :)
I don't have the motivation to write better commit messages...
Diffstat (limited to 'libgui')
-rw-r--r-- | libgui/gfx.c | 9 | ||||
-rw-r--r-- | libgui/gui.c | 18 | ||||
-rw-r--r-- | libgui/inc/gfx.h | 7 | ||||
-rw-r--r-- | libgui/inc/gui.h | 3 | ||||
-rw-r--r-- | libgui/inc/msg.h | 24 | ||||
-rw-r--r-- | libgui/msg.c | 22 |
6 files changed, 50 insertions, 33 deletions
diff --git a/libgui/gfx.c b/libgui/gfx.c index d9457c7..dad8b88 100644 --- a/libgui/gfx.c +++ b/libgui/gfx.c @@ -98,10 +98,11 @@ static void draw_rectangle(struct context *ctx, vec2 pos1, vec2 pos2, u32 c) struct context *gfx_new_ctx(struct context *ctx) { - struct message msg = { 0 }; - assert(msg_send(pidof(WM_PATH), GFX_NEW_CONTEXT, ctx) > 0); - assert(msg_receive(&msg) > 0); - memcpy(ctx, msg.data, sizeof(*ctx)); + /* struct message msg = { 0 }; */ + assert(0); + /* assert(msg_send(pidof(WM_PATH), GFX_NEW_CONTEXT, ctx) > 0); */ + /* assert(msg_receive(&msg) > 0); */ + /* memcpy(ctx, msg.data, sizeof(*ctx)); */ return ctx; } diff --git a/libgui/gui.c b/libgui/gui.c index 2083f23..bc8adb1 100644 --- a/libgui/gui.c +++ b/libgui/gui.c @@ -2,24 +2,30 @@ #include <def.h> #include <gui.h> +#include <msg.h> #include <print.h> #define WM_PATH "/bin/wm" s32 gui_new_window(struct gui_window *win) { - struct message msg = { 0 }; - if (msg_send(pidof(WM_PATH), GUI_NEW_WINDOW, win) > 0 && msg_receive(&msg) > 0 && - msg.type == (GUI_NEW_WINDOW | MSG_SUCCESS)) + struct message_new_window msg = { 0 }; + if (msg_send(pidof(WM_PATH), GUI_NEW_WINDOW, &msg, sizeof(msg)) > 0 && + msg_receive(&msg, sizeof(msg)) > 0 && + msg.header.type == (GUI_NEW_WINDOW | MSG_SUCCESS)) { + win->id = msg.id; + win->ctx = msg.ctx; return win->id; + } return -1; } s32 gui_redraw_window(u32 id) { - struct message msg = { 0 }; - if (msg_send(pidof(WM_PATH), GUI_REDRAW_WINDOW, &id) > 0 && msg_receive(&msg) > 0 && - msg.type == (GUI_REDRAW_WINDOW | MSG_SUCCESS)) + struct message_redraw_window msg = { .id = id }; + if (msg_send(pidof(WM_PATH), GUI_REDRAW_WINDOW, &msg, sizeof(msg)) > 0 && + msg_receive(&msg, sizeof(msg)) > 0 && + msg.header.type == (GUI_REDRAW_WINDOW | MSG_SUCCESS)) return id; return -1; } diff --git a/libgui/inc/gfx.h b/libgui/inc/gfx.h index 4a358ca..f3555a4 100644 --- a/libgui/inc/gfx.h +++ b/libgui/inc/gfx.h @@ -5,7 +5,6 @@ #define GFX_H #include <def.h> -#include <msg.h> #include <sys.h> #include <vec.h> #include <vesa.h> @@ -82,8 +81,8 @@ int gfx_font_width(enum font_type); * Wrappers */ -#define gfx_redraw() \ - (msg_send(pidof(WM_PATH), GFX_REDRAW, NULL)) // TODO: Partial redraw (optimization) -#define gfx_redraw_focused() (msg_send(pidof(WM_PATH), GFX_REDRAW_FOCUSED, NULL)) +/* #define gfx_redraw() \ */ +/* (msg_send(pidof(WM_PATH), GFX_REDRAW, NULL)) // TODO: Partial redraw (optimization) */ +/* #define gfx_redraw_focused() (msg_send(pidof(WM_PATH), GFX_REDRAW_FOCUSED, NULL)) */ #endif diff --git a/libgui/inc/gui.h b/libgui/inc/gui.h index 460bf88..d160333 100644 --- a/libgui/inc/gui.h +++ b/libgui/inc/gui.h @@ -8,8 +8,7 @@ struct gui_window { u32 id; - struct context *ctx; - vec2 *pos; + struct context ctx; }; s32 gui_new_window(struct gui_window *win); diff --git a/libgui/inc/msg.h b/libgui/inc/msg.h index db00460..7cbfa2c 100644 --- a/libgui/inc/msg.h +++ b/libgui/inc/msg.h @@ -4,16 +4,28 @@ #define MSG_H #include <def.h> +#include <gfx.h> #define MSG_MAGIC 0x42042069 #define MSG_SUCCESS (1 << 29) #define MSG_FAILURE (1 << 30) -struct message { +struct message_header { u32 magic; - int src; - int type; - void *data; + u32 src; + u32 type; + u32 size; +}; + +struct message_new_window { + struct message_header header; + u32 id; + struct context ctx; +}; + +struct message_redraw_window { + struct message_header header; + u32 id; }; enum message_type { @@ -32,7 +44,7 @@ enum message_type { GUI_MAX }; -int msg_send(u32 pid, enum message_type, void *data); -int msg_receive(struct message *msg); +int msg_send(u32 pid, enum message_type type, void *data, u32 size); +int msg_receive(void *buf, u32 size); #endif diff --git a/libgui/msg.c b/libgui/msg.c index 8448e73..3f58267 100644 --- a/libgui/msg.c +++ b/libgui/msg.c @@ -5,23 +5,23 @@ #include <print.h> #include <sys.h> -int msg_send(u32 pid, enum message_type type, void *data) +int msg_send(u32 pid, enum message_type type, void *data, u32 size) { - struct message msg = { 0 }; - assert((signed)pid != -1); + assert((signed)pid != -1 && size >= sizeof(struct message_header)); char path[32] = { 0 }; sprintf(path, "/proc/%d/msg", pid); - msg.magic = MSG_MAGIC; - msg.src = getpid(); - msg.type = type; - msg.data = data; - return write(path, &msg, 0, sizeof(msg)); + struct message_header *header = data; + header->magic = MSG_MAGIC; + header->src = getpid(); + header->type = type; + return write(path, data, 0, size); } -int msg_receive(struct message *msg) +int msg_receive(void *buf, u32 size) { - int ret = read("/proc/self/msg", msg, 0, sizeof(*msg)); - if (msg->magic == MSG_MAGIC && ret == sizeof(*msg)) + int ret = read("/proc/self/msg", buf, 0, size); + struct message_header *header = buf; + if (header->magic == MSG_MAGIC) return ret; else return -1; |