aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorMarvin Borner2020-08-25 22:11:04 +0200
committerMarvin Borner2020-08-25 22:11:04 +0200
commitec5c4a7398fcfcfb5a809292cbe029b1bb69a320 (patch)
treedc1cba8e1fa543c2a0f98955a35d0d7e40762d02 /apps
parentd2017fca3efefdb4d514f2b356855a0fda1fccfd (diff)
Added mouse driver and better event system
Diffstat (limited to 'apps')
-rw-r--r--apps/wm.c63
1 files changed, 50 insertions, 13 deletions
diff --git a/apps/wm.c b/apps/wm.c
index c6a1a31..1e1a8bc 100644
--- a/apps/wm.c
+++ b/apps/wm.c
@@ -1,5 +1,7 @@
// MIT License, Copyright (c) 2020 Marvin Borner
+#include <assert.h>
+#include <cpu.h>
#include <def.h>
#include <gui.h>
#include <input.h>
@@ -15,7 +17,10 @@ struct window *direct; // Direct video memory window
struct window *root; // Root window (wallpaper etc.)
struct window *exchange; // Exchange buffer
struct window *focused; // The focused window
-struct list *windows;
+struct list *windows; // List of all windows
+
+int mouse_x = 0;
+int mouse_y = 0;
static struct window *new_window(int x, int y, u16 width, u16 height)
{
@@ -30,6 +35,18 @@ static struct window *new_window(int x, int y, u16 width, u16 height)
return win;
}
+static void redraw_all()
+{
+ if (windows->head && windows->head->data) {
+ struct node *iterator = windows->head;
+ do {
+ struct window *win = iterator->data;
+ gui_win_on_win(exchange, win, win->x, win->y);
+ } while ((iterator = iterator->next) != NULL);
+ memcpy(direct->fb, exchange->fb, exchange->pitch * exchange->height);
+ }
+}
+
int main(int argc, char **argv)
{
(void)argc;
@@ -56,6 +73,7 @@ int main(int argc, char **argv)
/* gui_load_wallpaper(root, "/wall.bmp"); */
event_register(EVENT_KEYBOARD);
+ event_register(EVENT_MOUSE);
struct message *msg;
while (1) {
@@ -73,22 +91,41 @@ int main(int argc, char **argv)
list_add(windows, win);
focused = win;
break;
- case EVENT_KEYBOARD:
- printf("Keypress %d!\n", msg->data);
- focused->x += 50;
- if (windows->head && windows->head->data) {
- struct node *iterator = windows->head;
- do {
- struct window *win = iterator->data;
- gui_win_on_win(exchange, win, win->x, win->y);
- } while ((iterator = iterator->next) != NULL);
- memcpy(direct->fb, exchange->fb,
- exchange->pitch * exchange->height);
- }
+ case EVENT_KEYBOARD: {
+ struct event_keyboard *event = msg->data;
+ assert(event->magic == KEYBOARD_MAGIC);
+ printf("Keypress %d %s!\n", event->scancode,
+ event->press ? "pressed" : "released");
+ /* focused->x += 50; */
+ /* redraw_all(); */
+ break;
+ }
+ case EVENT_MOUSE: {
+ struct event_mouse *event = msg->data;
+ assert(event->magic == MOUSE_MAGIC);
+ mouse_x += event->diff_x;
+ mouse_y -= event->diff_y;
+
+ if (mouse_x < 0)
+ mouse_x = 0;
+ else if (mouse_x > vbe->width - 1)
+ mouse_x = vbe->width - 1;
+
+ if (mouse_y < 0)
+ mouse_y = 0;
+ else if (mouse_y > vbe->height - 1)
+ mouse_y = vbe->height - 1;
+
+ focused->x = mouse_x;
+ focused->y = mouse_y;
+ redraw_all();
+ printf("%d %d\n", mouse_x, mouse_y);
break;
+ }
default:
printf("Unknown WM request %d from pid %d\n", msg->type, msg->src);
}
+ yield();
};
return 0;