diff options
author | Benji Dial <benji6283@gmail.com> | 2021-02-17 00:13:06 -0500 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2021-02-17 00:13:06 -0500 |
commit | 642c3c69a69220170e2f68c2bf6c898e6cb5b20b (patch) | |
tree | 853c4f59c859912f73ede4ab36d89d2b3e9ed0f0 | |
parent | be05b9b23f988f934af2fd49976fd97c22dfc19a (diff) | |
download | portland-os-642c3c69a69220170e2f68c2bf6c898e6cb5b20b.tar.gz |
win+space, mkpopup
-rw-r--r-- | fs-skel/sys/startup.rc | 2 | ||||
-rw-r--r-- | fs-skel/sys/winspace.rc | 1 | ||||
-rw-r--r-- | makefile | 8 | ||||
-rw-r--r-- | src/kernel/main.c | 2 | ||||
-rw-r--r-- | src/kernel/window.c | 42 | ||||
-rw-r--r-- | src/kernel/window.h | 2 | ||||
-rw-r--r-- | src/user/meminfo/meminfo.c | 2 | ||||
-rw-r--r-- | src/user/mkpopup/main.c | 36 | ||||
-rw-r--r-- | src/user/popups/info.c | 7 |
9 files changed, 88 insertions, 14 deletions
diff --git a/fs-skel/sys/startup.rc b/fs-skel/sys/startup.rc index 3d038c5..aa514b1 100644 --- a/fs-skel/sys/startup.rc +++ b/fs-skel/sys/startup.rc @@ -1 +1 @@ -bin/terminal bin/highway
\ No newline at end of file +bin/mkpopup Press Win+Space to open a terminal.\nPress Win+Arrow Key to move a window around.\nPress Win+Page Up/Down to shuffle windows.\nPress Escape to close this window.
\ No newline at end of file diff --git a/fs-skel/sys/winspace.rc b/fs-skel/sys/winspace.rc new file mode 100644 index 0000000..3d038c5 --- /dev/null +++ b/fs-skel/sys/winspace.rc @@ -0,0 +1 @@ +bin/terminal bin/highway
\ No newline at end of file @@ -36,7 +36,7 @@ out/fs/man/%.man: src/man/%.pre python3 tools/man-gen.py $< $@ out/fs: out/fs/bin/init out/fs/bin/highway out/fs/bin/meminfo \ - out/fs/bin/terminal out/fs/bin/hello + out/fs/bin/terminal out/fs/bin/hello out/fs/bin/mkpopup touch out/fs cp -r fs-skel/* out/fs/ @@ -112,4 +112,8 @@ obj/terminal.elf: obj/terminal/main.o obj/libfont.so obj/knob.so \ ld -T src/user/runtimes/c/elf.ld $^ -o $@ obj/hello.elf: obj/hello/hello.ao - ld -T src/user/runtimes/asm/elf.ld $^ -o $@
\ No newline at end of file + ld -T src/user/runtimes/asm/elf.ld $^ -o $@ + +obj/mkpopup.elf: obj/mkpopup/main.o obj/popups.so obj/libfont.so \ + obj/knob.so obj/c.rto + ld -T src/user/runtimes/c/elf.ld $^ -o $@
\ No newline at end of file diff --git a/src/kernel/main.c b/src/kernel/main.c index 1fd3182..92315ce 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -40,7 +40,7 @@ void main() { init_kbd(); init_idt(); - paint_bg(); + init_win(); logf(LOG_INFO, "Kernel initialization done."); logf(LOG_INFO, "Available kernel memory: %dk", kernel_pages_left * 4); 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; diff --git a/src/kernel/window.h b/src/kernel/window.h index 0aa9b0f..a226c11 100644 --- a/src/kernel/window.h +++ b/src/kernel/window.h @@ -9,7 +9,7 @@ struct window; -void paint_bg(); +void init_win(); struct window *new_window(uint16_t width, uint16_t height, const void *pixel_buffer); void del_window(struct window *w); diff --git a/src/user/meminfo/meminfo.c b/src/user/meminfo/meminfo.c index 124a136..4dbd6bf 100644 --- a/src/user/meminfo/meminfo.c +++ b/src/user/meminfo/meminfo.c @@ -15,7 +15,7 @@ redo: "kernel memory free: %uk\n" "userspace memory free: %uk / %uk\n" "Escape to quit, F5 to refresh.", - 0x10, 0x08, + 0x10, 0x07, _kernel_dynamic_area_left() * 4, _total_userspace_left() * 4, _total_userspace_size() * 4 diff --git a/src/user/mkpopup/main.c b/src/user/mkpopup/main.c new file mode 100644 index 0000000..5b56889 --- /dev/null +++ b/src/user/mkpopup/main.c @@ -0,0 +1,36 @@ +#include <popups/info.h> + +#include <knob/heap.h> + +#include <stdbool.h> +#include <stdint.h> + +void main(const char *text) { + uint32_t required_new_length = 0; + bool needs_new = false; + for (const char *c = text; c[0]; ++c) { + ++required_new_length; + if ((c[0] == '\\') && (c[1] == 'n')) { + ++c; + needs_new = true; + } + } + + if (needs_new) { + char *new_text = get_block(required_new_length); + const char *ci; + char *co; + for (ci = text, co = new_text; *ci; ++ci, ++co) + if ((ci[0] == '\\') && (ci[1] == 'n')) { + *co = '\n'; + ++ci; + } + else + *co = *ci; + text = new_text; + } + + struct popup p; + info_popup(&p, text, 0x10, 0x07); + make_modal(&p); +}
\ No newline at end of file diff --git a/src/user/popups/info.c b/src/user/popups/info.c index 9a24ad5..5b3f6ae 100644 --- a/src/user/popups/info.c +++ b/src/user/popups/info.c @@ -11,9 +11,6 @@ #define PADDING 6 #define FONT "berry" -#define BG_COLOR 0x07 -#define FG_COlOR 0x10 - static const struct font_info *info_font = 0; static const struct key_packet info_quits[] = { @@ -48,7 +45,7 @@ void info_popup(struct popup *into, const char *msg, uint8_t fg, uint8_t bg) { for (uint32_t y = 0; y < height; ++y) for (uint32_t x = 0; x < pitch; ++x) - pixbuf[y * pitch + x] = BG_COLOR; + pixbuf[y * pitch + x] = bg; uint32_t my = 0; uint32_t mx = 0; @@ -59,7 +56,7 @@ void info_popup(struct popup *into, const char *msg, uint8_t fg, uint8_t bg) { mx = 0; } else - put_char(info_font, *msg, pixbuf + (my * info_font->space_height + PADDING) * pitch + mx++ * info_font->space_width + PADDING, pitch, BG_COLOR, FG_COlOR); + put_char(info_font, *msg, pixbuf + (my * info_font->space_height + PADDING) * pitch + mx++ * info_font->space_width + PADDING, pitch, bg, fg); } into->pixbuf = pixbuf; |