summaryrefslogtreecommitdiff
path: root/userland/windowserver/ws.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-23 20:10:01 +0200
committerAnton Kling <anton@kling.gg>2023-10-23 20:10:01 +0200
commit3f44d16f5297a0f7d63f98e48eba46c1e2538a3e (patch)
tree91ab1f4b0e3eca45d3f6bc125379e3c1ae290a1f /userland/windowserver/ws.c
parent6382172ac01ef17913c54177e556706d6ae2ec7f (diff)
WindowServer/LibGUI: Add a eventloop
This can be used by any program does nothing until it gets user input.
Diffstat (limited to 'userland/windowserver/ws.c')
-rw-r--r--userland/windowserver/ws.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c
index 2211b00..3d6e10f 100644
--- a/userland/windowserver/ws.c
+++ b/userland/windowserver/ws.c
@@ -1,13 +1,12 @@
-#include <fcntl.h>
-#include <poll.h>
-#include <stddef.h>
-#include <stdint.h>
-//#include <sys/mman.h>
+#include "ws.h"
#include "draw.h"
#include "font.h"
-#include "ws.h"
#include <assert.h>
+#include <fcntl.h>
+#include <poll.h>
#include <socket.h>
+#include <stddef.h>
+#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
@@ -193,7 +192,7 @@ typedef struct {
struct KEY_EVENT ev;
} WS_EVENT;
-void send_to_window(struct KEY_EVENT ev) {
+void send_key_event_to_window(struct KEY_EVENT ev) {
WS_EVENT e = {
.type = 0,
.ev = ev,
@@ -221,6 +220,13 @@ int windowserver_key_events(struct KEY_EVENT ev, int *redraw) {
return 0;
if (!(ev.mode & (1 << 1)))
return 0;
+ if ('q' == ev.c) {
+ WS_EVENT e = {
+ .type = WINDOWSERVER_EVENT_WINDOW_EXIT,
+ };
+ write(main_display.active_window->fd, &e, sizeof(e));
+ return 1;
+ }
if ('n' == ev.c) {
// Create a new terminal
int pid = fork();
@@ -230,6 +236,7 @@ int windowserver_key_events(struct KEY_EVENT ev, int *redraw) {
execv("/term", argv);
assert(0);
}
+ return 1;
}
if (!main_display.active_window)
return 0;
@@ -344,7 +351,7 @@ void parse_keyboard_event(int fd) {
continue;
if (!main_display.active_window)
continue;
- send_to_window(ev[i]);
+ send_key_event_to_window(ev[i]);
}
}
if (redraw)