summaryrefslogtreecommitdiff
path: root/src/kernel/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/window.c')
-rw-r--r--src/kernel/window.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/kernel/window.c b/src/kernel/window.c
index 80780d4..c251077 100644
--- a/src/kernel/window.c
+++ b/src/kernel/window.c
@@ -1,9 +1,11 @@
#include "paging.h"
#include "window.h"
#include "drive.h"
+#include "panic.h"
#include "task.h"
#include "util.h"
#include "pmap.h"
+#include "elf.h"
#include "log.h"
#define MAX_WINDOWS 64
@@ -91,7 +93,7 @@ static void paint_and_above(const struct window *w) {
switch_to_task_cr3();
}
-void paint_bg() {
+static void paint_bg() {
for (uint16_t y = 0; y < SCREEN_HEIGHT; ++y)
for (uint16_t x = 0; x < SCREEN_WIDTH; ++x)
VGA_MEMORY[y * SCREEN_WIDTH + x] = BACKGROUND(x, y);
@@ -213,6 +215,8 @@ static void send_action(struct window *w, struct window_action packet) {
}
}
+#define RUN_COMMAND_FILE "sys/winspace.rc"
+
enum wm_action {
WM_SHUFFLE_UP,
WM_SHUFFLE_DOWN,
@@ -220,6 +224,7 @@ enum wm_action {
WM_MOVE_RIGHT,
WM_MOVE_UP,
WM_MOVE_DOWN,
+ WM_RUN_COMMAND,
N_WM_ACTIONS
};
@@ -230,7 +235,8 @@ static struct key_packet keybinds[] = {
{.key_id = KEY_LEFT_ARROW, .modifiers = WINS},
{.key_id = KEY_RIGHT_ARROW, .modifiers = WINS},
{.key_id = KEY_UP_ARROW, .modifiers = WINS},
- {.key_id = KEY_DOWN_ARROW, .modifiers = WINS}
+ {.key_id = KEY_DOWN_ARROW, .modifiers = WINS},
+ {.key_id = KEY_SPACE, .modifiers = WINS}
};
static inline bool fuzzy_key_match(struct key_packet t, struct key_packet a) {
@@ -249,7 +255,33 @@ static inline bool fuzzy_key_match(struct key_packet t, struct key_packet a) {
return a.modifiers == t.modifiers;
}
-#include "log.h"
+static char *run_command;
+static char *run_command_pass = "";
+
+void init_win() {
+ paint_bg();
+
+ const file_id_t fid = drives->get_file(drives, RUN_COMMAND_FILE);
+ if (!fid)
+ PANIC("Couldn't open " RUN_COMMAND_FILE ".");
+
+ const uint32_t len = drives->get_file_length(drives, fid);
+ run_command = allocate_kernel_pages(len / 4096 + 1);
+ if (!run_command)
+ PANIC("Couldn't make buffer for " RUN_COMMAND_FILE " contents.");
+
+ fmcpy(run_command, drives, fid, 0, len);
+ run_command[len] = '\0';
+
+ drives->free_file(drives, fid);
+
+ for (char *c = run_command; *c; ++c)
+ if (*c == ' ') {
+ *c = '\0';
+ run_command_pass = c + 1;
+ break;
+ }
+}
void on_action(struct window_action packet) {
//logf(LOG_INFO, "Window action, top window = 0x%d from %s.", top_window, top_window->from_task->name);
@@ -305,6 +337,10 @@ void on_action(struct window_action packet) {
case WM_MOVE_DOWN:
++top_window->ypos;
paint_all();
+ break;
+ case WM_RUN_COMMAND:
+ if (!try_elf_run(drives, run_command, run_command_pass, 0))
+ PANIC("Couldn't run program listed in " RUN_COMMAND_FILE ".");
}
switch_to_task_cr3();
return;