summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2023-10-23 00:49:03 +0200
committerAnton Kling <anton@kling.gg>2023-10-23 00:54:23 +0200
commite8643790b093a4b25651aff14b85c492ffcae3f2 (patch)
treed7ad995ea0271f0c512d55fe46b60f29fb3c62f4
parent3f6da777b78485a7e769c4e7f06f4c691dea0655 (diff)
WindowServer: Launch a new terminal by pressing ALT+n
-rw-r--r--userland/minibox/utilities/init.c2
-rw-r--r--userland/terminal/term.c6
-rw-r--r--userland/windowserver/ws.c34
3 files changed, 29 insertions, 13 deletions
diff --git a/userland/minibox/utilities/init.c b/userland/minibox/utilities/init.c
index 35bedf2..07dfce7 100644
--- a/userland/minibox/utilities/init.c
+++ b/userland/minibox/utilities/init.c
@@ -67,6 +67,6 @@ int init_main(void) {
for (;;)
wait(NULL);
char *a[] = {NULL};
- execv("/term", a);
+ execv("/ws", a);
return 1;
}
diff --git a/userland/terminal/term.c b/userland/terminal/term.c
index 8a2ae83..2bc4a02 100644
--- a/userland/terminal/term.c
+++ b/userland/terminal/term.c
@@ -147,12 +147,6 @@ void run() {
int main(void) {
open("/dev/serial", O_RDWR, 0);
open("/dev/serial", O_RDWR, 0);
- printf("running the terminal\n");
- int pid = fork();
- if (0 == pid) {
- char *argv[] = {NULL};
- execv("/ws", argv);
- }
global_w = GUI_CreateWindow(20, 20, 250 * 4, 150 * 4);
assert(global_w);
diff --git a/userland/windowserver/ws.c b/userland/windowserver/ws.c
index e4f1a9e..da1bdaa 100644
--- a/userland/windowserver/ws.c
+++ b/userland/windowserver/ws.c
@@ -214,8 +214,20 @@ void clamp_screen_position(int *x, int *y) {
}
int windowserver_key_events(struct KEY_EVENT ev, int *redraw) {
+ if (ev.release)
+ return 0;
if (!(ev.mode & (1 << 1)))
return 0;
+ if ('n' == ev.c) {
+ // Create a new terminal
+ int pid = fork();
+ if (0 == pid) {
+ // TODO: Close (almost) all file descriptors from parent
+ char *argv[] = {"/term", NULL};
+ execv("/term", argv);
+ assert(0);
+ }
+ }
if (!active_client)
return 0;
int x = 0;
@@ -287,17 +299,16 @@ void parse_mouse_event(int fd) {
if (mouse_y < 0)
mouse_y = 0;
if (middle_button) {
- active_client->w->x += xc;
- active_client->w->y -= yc;
- clamp_screen_position(&active_client->w->x, &active_client->w->y);
+ if (active_client) {
+ active_client->w->x += xc;
+ active_client->w->y -= yc;
+ clamp_screen_position(&active_client->w->x, &active_client->w->y);
+ }
}
update_mouse();
}
void parse_keyboard_event(int fd) {
- if (!active_client) {
- return;
- }
struct KEY_EVENT ev[250];
int redraw = 0;
for (;;) {
@@ -308,6 +319,8 @@ void parse_keyboard_event(int fd) {
for (int i = 0; i < n; i++) {
if (windowserver_key_events(ev[i], &redraw))
continue;
+ if (!active_client)
+ continue;
send_to_client(ev[i]);
}
}
@@ -369,6 +382,15 @@ void run(void) {
int main(void) {
open("/dev/serial", O_WRITE, 0);
open("/dev/serial", O_WRITE, 0);
+ // Start a terminal by default. This is just to make it easier for me
+ // to test the system.
+ int pid = fork();
+ if (0 == pid) {
+ // TODO: Close (almost) all file descriptors from parent
+ char *argv[] = {"/term", NULL};
+ execv("/term", argv);
+ assert(0);
+ }
setup();
run();
return 0;