Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/hello/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions apps/launcher/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
66 changes: 64 additions & 2 deletions apps/launcher/launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "loader.h"
#include "shell.h"
#include "shell_icon.h"
#include "dialog.h"

// --- home screen layout (px) ---

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion apps/launcher/launcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions apps/notepad/notepad.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions boot/linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ SECTIONS
build/loader.o(.text)
build/launcher.o(.text)
build/shell.o(.text)
build/dialog.o(.text)
}

.rodata : {
Expand Down Expand Up @@ -68,6 +69,7 @@ SECTIONS
build/loader.o(.rodata)
build/launcher.o(.rodata)
build/shell.o(.rodata)
build/dialog.o(.rodata)
}

.data : {
Expand Down Expand Up @@ -101,6 +103,7 @@ SECTIONS
build/loader.o(.data)
build/launcher.o(.data)
build/shell.o(.data)
build/dialog.o(.data)
}

.bss : {
Expand Down Expand Up @@ -135,6 +138,7 @@ SECTIONS
build/loader.o(.bss)
build/launcher.o(.bss)
build/shell.o(.bss)
build/dialog.o(.bss)
__bss_end = .;
}
}
Loading
Loading