From 6ff660d97f6f829117a2561f54269b03e213104e Mon Sep 17 00:00:00 2001 From: rhylanscript <181093569+Rhylanscript@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:29:51 +1000 Subject: [PATCH 1/6] feat: add dialog API functions for modal interactions --- kernel/vigil/api.c | 4 ++++ kernel/vigil/api.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/kernel/vigil/api.c b/kernel/vigil/api.c index 7346951..ed9a1f5 100644 --- a/kernel/vigil/api.c +++ b/kernel/vigil/api.c @@ -10,6 +10,7 @@ #include "heap.h" #include "menu.h" #include "prompt.h" +#include "dialog.h" #include "launcher.h" // The table itself which is filled in at compile time @@ -59,6 +60,9 @@ static const vigil_api_t api = { .menu_open = menu_open, .prompt_open = prompt_open, .launcher_open_file = launcher_open_file, + + .dialog_open = dialog_open, + .launcher_close_app = launcher_close_app, }; const vigil_api_t* api_get(void) { diff --git a/kernel/vigil/api.h b/kernel/vigil/api.h index 56077af..0d3abd4 100644 --- a/kernel/vigil/api.h +++ b/kernel/vigil/api.h @@ -21,6 +21,7 @@ #include "fs.h" #include "menu.h" #include "prompt.h" +#include "dialog.h" #include "launcher.h" // bumped whenever the table changes such that old apps cant gracefully handle @@ -83,6 +84,10 @@ typedef struct { // --- launcher --- void (*launcher_open_file)(const char* path); + + // --- dialog (modal choice box) --- + void (*dialog_open)(const char* title, const char* message, const char* const* labels, int count); + void (*launcher_close_app)(void); } vigil_api_t; // returns the shared table From 0dae865c47f6869d6024d229d03457ec332fd933 Mon Sep 17 00:00:00 2001 From: rhylanscript <181093569+Rhylanscript@users.noreply.github.com> Date: Tue, 27 Oct 2026 09:31:52 +1000 Subject: [PATCH 2/6] fix: remove unused icon pixel array from hello app --- apps/hello/hello.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/hello/hello.c b/apps/hello/hello.c index 19b355a..3f86e26 100644 --- a/apps/hello/hello.c +++ b/apps/hello/hello.c @@ -14,8 +14,6 @@ static const vigil_api_t* api = 0; static int clicks = 0; static button_t click_button; -static uint32_t icon_pixels[APP_ICON_SIZE * APP_ICON_SIZE]; - static void paint(void) { uint32_t band = api->gfx_screen_height() - TITLE_BAR_HEIGHT - TASKBAR_HEIGHT; api->gfx_fill_rect(0, TITLE_BAR_HEIGHT, api->gfx_screen_width(), band, GFX_BLACK); From 48aeb0f05d6dc47c5fb960ca0970bf2fb7ed71c6 Mon Sep 17 00:00:00 2001 From: rhylanscript <181093569+Rhylanscript@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:56:12 +1000 Subject: [PATCH 3/6] feat: implement dialog ui component for modal interactions --- kernel/ui/dialog.c | 163 +++++++++++++++++++++++++++++++++++++++++++++ kernel/ui/dialog.h | 19 ++++++ 2 files changed, 182 insertions(+) create mode 100644 kernel/ui/dialog.c create mode 100644 kernel/ui/dialog.h diff --git a/kernel/ui/dialog.c b/kernel/ui/dialog.c new file mode 100644 index 0000000..b8a192a --- /dev/null +++ b/kernel/ui/dialog.c @@ -0,0 +1,163 @@ +// kernel/ui/dialog.c + +#include "dialog.h" +#include "button.h" +#include "graphics.h" +#include "font.h" +#include "keyboard.h" +#include "taskbar.h" +#include "title_bar.h" + +// --- layout (px) --- + +#define BOX_WIDTH 400 +#define BOX_HEIGHT 120 +#define BOX_PAD 16 + +#define TITLE_Y_OFFSET 10 +#define MESSAGE_Y_OFFSET 38 +#define BUTTON_Y_OFFSET 72 + +#define BUTTON_W 112 +#define BUTTON_H 32 +#define BUTTON_GAP 12 + +#define TEXT_MAX 48 + +#define BOX_COLOR ((gfx_color_t){0x30, 0x30, 0x30}) +#define BUTTON_COLOR ((gfx_color_t){0x40, 0x40, 0x40}) +#define MESSAGE_COLOR ((gfx_color_t){0xa0, 0xa0, 0xa0}) + +// --- state --- + +static int active = 0; + +static char title[TEXT_MAX]; +static char message[TEXT_MAX]; + +static button_t buttons[DIALOG_MAX_BUTTONS]; +static int button_count = 0; + +static uint32_t box_x = 0; +static uint32_t box_y = 0; + +// --- helpers --- + +static void copy_text(char* dest, const char* src) { + int i = 0; + while (src[i] != '\0' && i < TEXT_MAX - 1) { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; +} + +static void place_box(void) { + uint32_t screen_w = gfx_screen_width(); + uint32_t screen_h = gfx_screen_height(); + + box_x = 0; + if (screen_w > BOX_WIDTH) { + box_x = (screen_w - BOX_WIDTH) / 2; + } + + uint32_t band_top = TITLE_BAR_HEIGHT; + uint32_t band_height = 0; + if (screen_h > band_top + TASKBAR_HEIGHT) { + band_height = screen_h - band_top - TASKBAR_HEIGHT; + } + + box_y = band_top; + if (band_height > BOX_HEIGHT) { + box_y = band_top + (band_height - BOX_HEIGHT) / 2; + } +} + +static void place_buttons(const char* const* labels, int count) { + uint32_t row_width = (uint32_t) count * BUTTON_W + (uint32_t) (count - 1) * BUTTON_GAP; + uint32_t start_x = box_x + (BOX_WIDTH - row_width) / 2; + + for (int i = 0; i < count; i++) { + buttons[i].x = start_x + (uint32_t) i * (BUTTON_W + BUTTON_GAP); + buttons[i].y = box_y + BUTTON_Y_OFFSET; + buttons[i].width = BUTTON_W; + buttons[i].height = BUTTON_H; + buttons[i].label = labels[i]; + buttons[i].color = BUTTON_COLOR; + buttons[i].on_click = 0; + } +} + +// --- drawing --- + +static void draw_box(void) { + gfx_fill_rect(box_x, box_y, BOX_WIDTH, BOX_HEIGHT, BOX_COLOR); + gfx_draw_rect_outline(box_x, box_y, BOX_WIDTH, BOX_HEIGHT, GFX_WHITE); + + gfx_draw_string(box_x + BOX_PAD, box_y + TITLE_Y_OFFSET, title, GFX_WHITE); + gfx_draw_string(box_x + BOX_PAD, box_y + MESSAGE_Y_OFFSET, message, MESSAGE_COLOR); + + for (int i = 0; i < button_count; i++) { + button_draw(&buttons[i]); + } +} + +// --- public functions --- + +void dialog_open(const char* title_text, const char* message_text, const char* const* labels, int count) { + if (count > DIALOG_MAX_BUTTONS) { + count = DIALOG_MAX_BUTTONS; + } + if (count < 1) { + return; + } + + copy_text(title, title_text); + copy_text(message, message_text); + + place_box(); + place_buttons(labels, count); + + button_count = count; + active = 1; + draw_box(); +} + +int dialog_is_open(void) { + return active; +} + +int dialog_click(int32_t px, int32_t py) { + if (!active) { + return DIALOG_NO_PICK; + } + + int pick = button_find_at(buttons, button_count, px, py); + if (pick < 0) { + return DIALOG_NO_PICK; + } + + active = 0; + return pick; +} + +int dialog_handle_key(char c) { + if (!active) { + return DIALOG_NO_PICK; + } + + if (c == KEY_ESCAPE) { + active = 0; + return button_count - 1; + } + if (c == '\n') { + active = 0; + return 0; + } + + return DIALOG_NO_PICK; +} + +void dialog_close(void) { + active = 0; +} diff --git a/kernel/ui/dialog.h b/kernel/ui/dialog.h new file mode 100644 index 0000000..a2a0a84 --- /dev/null +++ b/kernel/ui/dialog.h @@ -0,0 +1,19 @@ +// kernel/ui/dialog.h + +#ifndef DIALOG_H +#define DIALOG_H +#include + +#define DIALOG_MAX_BUTTONS 3 +#define DIALOG_NO_PICK (-1) + +void dialog_open(const char* title, const char* message, const char* const* labels, int count); + +int dialog_is_open(void); + +int dialog_click(int32_t px, int32_t py); +int dialog_handle_key(char c); + +void dialog_close(void); + +#endif From cbd6107d8b82661b32d25a78f15b11bc7877c10e Mon Sep 17 00:00:00 2001 From: rhylanscript <181093569+Rhylanscript@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:56:49 +1000 Subject: [PATCH 4/6] feat: add close request and dialog completion callbacks to app structure --- apps/launcher/app.h | 3 ++ apps/launcher/launcher.c | 66 ++++++++++++++++++++++++++++++++++++++-- apps/launcher/launcher.h | 2 +- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/apps/launcher/app.h b/apps/launcher/app.h index e5e10cc..cbc07d9 100644 --- a/apps/launcher/app.h +++ b/apps/launcher/app.h @@ -23,6 +23,9 @@ typedef struct { void (*on_open_file)(const char* path); + int (*on_close_request)(void); + void (*on_dialog_done)(int index); + const uint32_t* icon; } app_t; diff --git a/apps/launcher/launcher.c b/apps/launcher/launcher.c index 968ef73..70bbe44 100644 --- a/apps/launcher/launcher.c +++ b/apps/launcher/launcher.c @@ -17,6 +17,7 @@ #include "loader.h" #include "shell.h" #include "shell_icon.h" +#include "dialog.h" // --- home screen layout (px) --- @@ -105,6 +106,8 @@ static void copy_app(app_t* dest, const app_t* src) { dest->on_menu_pick = src->on_menu_pick; dest->on_prompt_done = src->on_prompt_done; dest->on_open_file = src->on_open_file; + dest->on_close_request = src->on_close_request; + dest->on_dialog_done = src->on_dialog_done; dest->icon = src->icon; } @@ -222,6 +225,7 @@ static void show_home_screen(void) { running_app = 0; menu_close(); prompt_close(); + dialog_close(); mouse_left_clicked(); draw_home_screen(); } @@ -255,6 +259,26 @@ static void close_foreground_app(void) { show_home_screen(); } +static void request_close_foreground_app(void) { + const app_t* app = running_app; + if (app == 0) { + return; + } + + if (app->on_close_request != 0) { + mouse_hide_cursor(); + if (!app->on_close_request()) { + return; + } + } + + close_foreground_app(); +} + +void launcher_close_app(void) { + close_foreground_app(); +} + static void minimize_foreground_app(void) { const app_t* app = running_app; if (app == 0) { @@ -383,6 +407,32 @@ static void handle_prompt_key(char c) { } } +// --- confirm dialog --- + +static void finish_dialog(int pick) { + mouse_hide_cursor(); + redraw_running_app(); + + const app_t* app = running_app; + if (app != 0 && app->on_dialog_done != 0) { + app->on_dialog_done(pick); + } +} + +static void handle_dialog_key(char c) { + int pick = dialog_handle_key(c); + if (pick != DIALOG_NO_PICK) { + finish_dialog(pick); + } +} + +static void handle_dialog_click(int32_t x, int32_t y) { + int pick = dialog_click(x, y); + if (pick != DIALOG_NO_PICK) { + finish_dialog(pick); + } +} + // --- keyboard --- static void launcher_handle_key(char c) { @@ -391,7 +441,12 @@ static void launcher_handle_key(char c) { if (app == 0) { return; } - + + if (dialog_is_open()) { + handle_dialog_key(c); + return; + } + if (prompt_is_open()) { handle_prompt_key(c); return; @@ -449,6 +504,13 @@ void launcher_update(void) { int32_t mouse_x = mouse_get_x(); int32_t mouse_y = mouse_get_y(); + if (dialog_is_open()) { + if (clicked) { + handle_dialog_click(mouse_x, mouse_y); + } + return; + } + if (prompt_is_open()) { return; } @@ -477,7 +539,7 @@ void launcher_update(void) { title_bar_hit_t hit = title_bar_hit_test(mouse_x, mouse_y); if (hit == TITLE_BAR_HIT_CLOSE) { - close_foreground_app(); + request_close_foreground_app(); return; } if (hit == TITLE_BAR_HIT_MINIMIZE) { diff --git a/apps/launcher/launcher.h b/apps/launcher/launcher.h index 0bee343..843474a 100644 --- a/apps/launcher/launcher.h +++ b/apps/launcher/launcher.h @@ -6,11 +6,11 @@ #include "app.h" void launcher_init(void); - void launcher_update(void); void launcher_open_file(const char* path); int launcher_register_app(const app_t* app); +void launcher_close_app(void); #endif From 4da78f6c117a8c2f39ea7b6ed150274ef801d48c Mon Sep 17 00:00:00 2001 From: rhylanscript <181093569+Rhylanscript@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:56:57 +1000 Subject: [PATCH 5/6] feat: implement close dialog functionality with save and discard options --- apps/notepad/notepad.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/apps/notepad/notepad.c b/apps/notepad/notepad.c index a6f99d0..ef6fe9a 100644 --- a/apps/notepad/notepad.c +++ b/apps/notepad/notepad.c @@ -36,6 +36,10 @@ static const vigil_api_t* api = 0; #define NOTEPAD_MAX_COLS 128 #define NOTEPAD_MAX_ROWS 48 +#define CLOSE_SAVE 0 +#define CLOSE_DISCARD 1 +#define CLOSE_CANCEL 2 + // --- state --- static char text[NOTEPAD_MAX_BYTES]; @@ -558,6 +562,31 @@ static void notepad_open_file(const char* path) { open_file(path); } +// --- close dialog --- + +static const char* const close_labels[3] = { + "Save", + "Discard", + "Cancel" +}; + +static int notepad_close_request(void) { + if (!dirty) return 1; + api->dialog_open("Unsaved changes", "Save changes before closing?", close_labels, 3); + return 0; +} + +static void notepad_dialog_done(int index) { + if (index == CLOSE_SAVE) { + save_note(); + if (dirty) return; + api->launcher_close_app(); + } else if (index == CLOSE_DISCARD) { + dirty = 0; + api->launcher_close_app(); + } +} + // --- the app_t slots --- static void notepad_start(void) { @@ -664,6 +693,8 @@ int app_entry(const vigil_api_t* kernel_api, app_t* out_app) { out_app->on_tick = notepad_update_cursor; out_app->on_click = notepad_handle_click; out_app->on_open_file = notepad_open_file; + out_app->on_close_request = notepad_close_request; + out_app->on_dialog_done = notepad_dialog_done; out_app->icon = notepad_icon; return 0; } From 3add584570101b848765a6a63214a10a68e1ec3f Mon Sep 17 00:00:00 2001 From: rhylanscript <181093569+Rhylanscript@users.noreply.github.com> Date: Tue, 27 Oct 2026 16:57:05 +1000 Subject: [PATCH 6/6] chore: add dialog component to linker and build scripts --- boot/linker.ld | 4 ++++ scripts/build.bat | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/boot/linker.ld b/boot/linker.ld index a5d7b99..bed866c 100644 --- a/boot/linker.ld +++ b/boot/linker.ld @@ -35,6 +35,7 @@ SECTIONS build/loader.o(.text) build/launcher.o(.text) build/shell.o(.text) + build/dialog.o(.text) } .rodata : { @@ -68,6 +69,7 @@ SECTIONS build/loader.o(.rodata) build/launcher.o(.rodata) build/shell.o(.rodata) + build/dialog.o(.rodata) } .data : { @@ -101,6 +103,7 @@ SECTIONS build/loader.o(.data) build/launcher.o(.data) build/shell.o(.data) + build/dialog.o(.data) } .bss : { @@ -135,6 +138,7 @@ SECTIONS build/loader.o(.bss) build/launcher.o(.bss) build/shell.o(.bss) + build/dialog.o(.bss) __bss_end = .; } } diff --git a/scripts/build.bat b/scripts/build.bat index f797a13..68bc37a 100644 --- a/scripts/build.bat +++ b/scripts/build.bat @@ -152,6 +152,10 @@ echo Compiling prompt.c... i686-elf-gcc %CFLAGS% -c kernel/ui/prompt.c -o build/prompt.o if errorlevel 1 goto :error +echo Compiling dialog.c... +i686-elf-gcc %CFLAGS% -c kernel/ui/dialog.c -o build/dialog.o +if errorlevel 1 goto :error + echo Compiling title_bar.c... i686-elf-gcc %CFLAGS% -c kernel/ui/title_bar.c -o build/title_bar.o if errorlevel 1 goto :error @@ -233,7 +237,7 @@ echo ==================================== echo. echo Linking kernel objects... -i686-elf-ld -T boot/linker.ld -o build/kernel_full.elf build/stage2.o build/kernel.o build/terminal.o build/idt.o build/isr.o build/isr_asm.o build/idt_load.o build/pic.o build/irq.o build/irq_asm.o build/keyboard.o build/kstring.o build/kprintf.o build/shell.o build/ata.o build/vigil_memory.o build/fs.o build/timer.o build/heap.o build/font.o build/graphics.o build/mouse.o build/button.o build/title_bar.o build/taskbar.o build/launcher.o build/menu.o build/prompt.o build/vigil_api.o build/loader.o +i686-elf-ld -T boot/linker.ld -o build/kernel_full.elf build/stage2.o build/kernel.o build/terminal.o build/idt.o build/isr.o build/isr_asm.o build/idt_load.o build/pic.o build/irq.o build/irq_asm.o build/keyboard.o build/kstring.o build/kprintf.o build/shell.o build/ata.o build/vigil_memory.o build/fs.o build/timer.o build/heap.o build/font.o build/graphics.o build/mouse.o build/button.o build/title_bar.o build/taskbar.o build/launcher.o build/menu.o build/prompt.o build/vigil_api.o build/loader.o build/dialog.o if errorlevel 1 goto :error echo.