diff options
author | Marvin Borner | 2020-09-16 21:38:19 +0200 |
---|---|---|
committer | Marvin Borner | 2020-09-16 21:38:19 +0200 |
commit | 11490a493511c4f760af74c12cb7da15b2b404a2 (patch) | |
tree | 92837dcface3dbe825a6d6e90cd983e72a62578f /apps | |
parent | 857c228909603d1a27a40f2714f8b9076fabba6e (diff) |
Added *very* basic keymap parsing
Diffstat (limited to 'apps')
-rw-r--r-- | apps/window.c | 21 | ||||
-rw-r--r-- | apps/wm.c | 38 |
2 files changed, 34 insertions, 25 deletions
diff --git a/apps/window.c b/apps/window.c index 9461f93..a38d121 100644 --- a/apps/window.c +++ b/apps/window.c @@ -24,7 +24,6 @@ int main() gui_init("/font/spleen-12x24.psfu"); char *hello = "Hello, world!"; gui_write(&win, win.width / 2 - (strlen(hello) * 12) / 2, 5, COLOR_GREEN, hello); - event_register(EVENT_KEYBOARD); struct message *msg; int char_x = 0; @@ -34,25 +33,13 @@ int main() yield(); continue; } - switch (msg->type) { - case EVENT_KEYBOARD: { - struct event_keyboard *event = msg->data; - - if (event->magic != KEYBOARD_MAGIC) - break; + switch (msg->type) { + case WM_KEYBOARD: { + struct msg_keyboard *event = msg->data; if (!event->press) break; - - int key = event->scancode; - if (key == KEY_ENTER) { - char_x = 0; - char_y++; - } else if (KEY_ALPHABETIC(key)) { - gui_write_char(&win, 12 * char_x++, 24 * char_y + 5, COLOR_CYAN, - 'a'); - } - + gui_write_char(&win, 12 * char_x++, 24 * char_y + 5, COLOR_CYAN, event->ch); break; } default: @@ -29,8 +29,10 @@ static struct keymap *keymap; static int mouse_x = 0; static int mouse_y = 0; -static struct window *new_window(struct window *win, int x, int y, u16 width, u16 height, int flags) +static struct window *new_window(struct window *win, u32 pid, int x, int y, u16 width, u16 height, + int flags) { + win->pid = pid; win->x = x; win->y = y; win->width = width; @@ -82,6 +84,7 @@ static void redraw_all() memcpy(direct.fb, exchange.fb, exchange.pitch * exchange.height); } +// TODO: Send relative mouse position event to focused window static int mouse_skip = 0; static int mouse_pressed[3] = { 0 }; static void handle_mouse(struct event_mouse *event) @@ -152,10 +155,22 @@ static void handle_mouse(struct event_mouse *event) mouse_skip++; } +static void handle_keyboard(struct event_keyboard *event) +{ + if (event->magic != KEYBOARD_MAGIC || !focused) + return; + struct msg_keyboard *msg = malloc(sizeof(*msg)); + msg->ch = keymap->map[event->scancode]; + msg->press = event->press; + msg->scancode = event->scancode; + msg_send(focused->pid, WM_KEYBOARD, msg); +} + // TODO: Clean this god-function int main(int argc, char **argv) { (void)argc; + int pid = getpid(); vbe = *(struct vbe *)argv[1]; printf("VBE: %dx%d\n", vbe.width, vbe.height); @@ -163,9 +178,11 @@ int main(int argc, char **argv) gui_init("/font/spleen-16x32.psfu"); windows = list_new(); - new_window(&root, 0, 0, vbe.width, vbe.height, WF_NO_FOCUS | WF_NO_DRAG | WF_NO_RESIZE); - new_window(&exchange, 0, 0, vbe.width, vbe.height, WF_NO_FOCUS | WF_NO_DRAG | WF_NO_RESIZE); - new_window(&cursor, 0, 0, 32, 32, WF_NO_FOCUS | WF_NO_RESIZE); + new_window(&root, pid, 0, 0, vbe.width, vbe.height, + WF_NO_FOCUS | WF_NO_DRAG | WF_NO_RESIZE); + new_window(&exchange, pid, 0, 0, vbe.width, vbe.height, + WF_NO_FOCUS | WF_NO_DRAG | WF_NO_RESIZE); + new_window(&cursor, pid, 0, 0, 32, 32, WF_NO_FOCUS | WF_NO_RESIZE); memcpy(&direct, &root, sizeof(direct)); direct.fb = vbe.fb; list_add(windows, &root); @@ -181,6 +198,7 @@ int main(int argc, char **argv) redraw_all(); event_register(EVENT_MOUSE); + event_register(EVENT_KEYBOARD); struct message *msg; while (1) { @@ -190,25 +208,29 @@ int main(int argc, char **argv) } switch (msg->type) { - case MSG_NEW_WINDOW: + case WM_NEW_WINDOW: printf("New window for pid %d\n", msg->src); struct window *win = msg->data; int width = win->width ? win->width : 1000; int height = win->height ? win->height : 800; int x = win->x ? win->x : vbe.width / 2 - (width / 2); int y = win->y ? win->y : vbe.height / 2 - (height / 2); - new_window(win, x, y, width, height, win->flags); - msg_send(msg->src, MSG_NEW_WINDOW, win); + win->pid = msg->src; + new_window(win, msg->src, x, y, width, height, win->flags); + msg_send(msg->src, WM_NEW_WINDOW, win); list_add(windows, win); focused = win; redraw_all(); break; - case MSG_REDRAW: + case WM_REDRAW: redraw_all(); break; case EVENT_MOUSE: handle_mouse(msg->data); break; + case EVENT_KEYBOARD: + handle_keyboard(msg->data); + break; default: break; } |