feat: move Files to its own process; add window server messaging (multi-format clipboard, drag and drop), undo/redo, sidebar, breadcrumbs, thumbnails, file type icons, New menu and proper text fields
This commit is contained in:
1 parent
07191b1286
commit
d3e49a925d
66 files changed
+6855
-905
No files matched your search
+14
-178
@@ -9,52 +9,19 @@
|
||||
#include <montauk/user.h>
|
||||
#include <gui/clipboard.hpp>
|
||||
#include <gui/dialogs.hpp>
|
||||
#include <gui/app_catalog.hpp>
|
||||
|
||||
// ============================================================================
|
||||
// App Manifest Scanning
|
||||
// App Manifest Scanning (shared catalog code: gui/app_catalog.hpp)
|
||||
// ============================================================================
|
||||
|
||||
// Extract the basename from a readdir entry, tolerating both current
|
||||
// direct-child names and paths returned by older ramdisk kernels.
|
||||
static void extract_basename(char* out, int outSz, const char* entry) {
|
||||
// Strip trailing slash
|
||||
int len = montauk::slen(entry);
|
||||
while (len > 0 && entry[len - 1] == '/') len--;
|
||||
|
||||
// Find last slash before that
|
||||
int last_slash = -1;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (entry[i] == '/') last_slash = i;
|
||||
}
|
||||
|
||||
const char* base = (last_slash >= 0) ? entry + last_slash + 1 : entry;
|
||||
int base_len = len - (last_slash >= 0 ? last_slash + 1 : 0);
|
||||
if (base_len >= outSz) base_len = outSz - 1;
|
||||
montauk::memcpy(out, base, base_len);
|
||||
out[base_len] = '\0';
|
||||
}
|
||||
|
||||
// Return a slot for the next desktop item, doubling the array as needed.
|
||||
// Returns nullptr if allocation failed.
|
||||
static DesktopItem* next_desktop_item_slot(DesktopState* ds) {
|
||||
if (ds->desktop_item_count >= ds->desktop_item_capacity) {
|
||||
int new_cap = ds->desktop_item_capacity ? ds->desktop_item_capacity * 2 : 32;
|
||||
auto* grown = (DesktopItem*)montauk::realloc(
|
||||
ds->desktop_items, (uint64_t)new_cap * sizeof(DesktopItem));
|
||||
if (!grown) return nullptr;
|
||||
ds->desktop_items = grown;
|
||||
ds->desktop_item_capacity = new_cap;
|
||||
}
|
||||
return &ds->desktop_items[ds->desktop_item_count];
|
||||
}
|
||||
|
||||
static void desktop_add_builtin_catalog_items(DesktopState* ds) {
|
||||
int builtin_count = 0;
|
||||
const DesktopBuiltinEntry* builtins = desktop_builtin_registry(&builtin_count);
|
||||
for (int i = 0; i < builtin_count; i++) {
|
||||
if (!builtins[i].system_configuration_id) continue;
|
||||
|
||||
DesktopItem* item = next_desktop_item_slot(ds);
|
||||
DesktopItem* item = gui::app_catalog_next_slot(ds);
|
||||
if (!item) return;
|
||||
montauk::memset(item, 0, sizeof(*item));
|
||||
montauk::strncpy(item->id, builtins[i].system_configuration_id, sizeof(item->id));
|
||||
@@ -74,148 +41,7 @@ static void desktop_add_builtin_catalog_items(DesktopState* ds) {
|
||||
void desktop_scan_apps(DesktopState* ds) {
|
||||
ds->desktop_item_count = 0;
|
||||
desktop_add_builtin_catalog_items(ds);
|
||||
|
||||
// Ensure the apps directory exists
|
||||
montauk::fmkdir("0:/apps");
|
||||
|
||||
// Page through the directory with readdir_at; a single readdir call
|
||||
// returns at most one batch and would silently drop apps past it.
|
||||
constexpr int BATCH = 128;
|
||||
const char* entries[BATCH];
|
||||
int scanned = 0;
|
||||
int got;
|
||||
while ((got = montauk::readdir_at("0:/apps", entries, BATCH, scanned)) > 0) {
|
||||
scanned += got;
|
||||
|
||||
for (int i = 0; i < got; i++) {
|
||||
// Strip the directory marker and tolerate old root-relative entries.
|
||||
char dirname[64];
|
||||
extract_basename(dirname, sizeof(dirname), entries[i]);
|
||||
if (dirname[0] == '\0') continue;
|
||||
|
||||
// Try to open the manifest in this app directory
|
||||
char manifest_path[128];
|
||||
snprintf(manifest_path, sizeof(manifest_path), "0:/apps/%s/manifest.toml", dirname);
|
||||
|
||||
int fh = montauk::open(manifest_path);
|
||||
if (fh < 0) continue;
|
||||
|
||||
uint64_t sz = montauk::getsize(fh);
|
||||
if (sz == 0 || sz > 4096) { montauk::close(fh); continue; }
|
||||
|
||||
char* text = (char*)montauk::malloc(sz + 1);
|
||||
if (!text) { montauk::close(fh); continue; }
|
||||
int bytes_read = montauk::read(fh, (uint8_t*)text, 0, sz);
|
||||
montauk::close(fh);
|
||||
if (bytes_read != (int)sz) {
|
||||
montauk::mfree(text);
|
||||
continue;
|
||||
}
|
||||
text[sz] = '\0';
|
||||
|
||||
auto doc = montauk::toml::parse(text);
|
||||
montauk::mfree(text);
|
||||
|
||||
// Read manifest fields
|
||||
const char* id = doc.get_string("app.id", dirname);
|
||||
const char* name = doc.get_string("app.name", "Unknown");
|
||||
const char* binary = doc.get_string("app.binary", "");
|
||||
const char* icon_file = doc.get_string("app.icon", "");
|
||||
const char* category = doc.get_string("menu.category", "Productivity");
|
||||
// "Applications" was the old catch-all; keep older manifests out of
|
||||
// a stray custom category.
|
||||
if (!category[0] || montauk::streq(category, "Applications"))
|
||||
category = "Productivity";
|
||||
bool visible = doc.get_bool("menu.visible", true);
|
||||
bool launch_with_home = doc.get_bool("launch.pass_home_dir", true);
|
||||
const char* section_name = doc.get_string("desktop.section", "apps");
|
||||
bool admin_only = doc.get_bool("desktop.admin_only", false);
|
||||
if (id[0] == '\0' || binary[0] == '\0') {
|
||||
montauk::print("desktop: skipping app manifest with missing id or binary\n");
|
||||
doc.destroy();
|
||||
continue;
|
||||
}
|
||||
|
||||
bool duplicate = false;
|
||||
for (int existing = 0; existing < ds->desktop_item_count; existing++) {
|
||||
if (montauk::streq(ds->desktop_items[existing].id, id)) {
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (duplicate) {
|
||||
montauk::print("desktop: skipping app manifest with duplicate id\n");
|
||||
doc.destroy();
|
||||
continue;
|
||||
}
|
||||
|
||||
DesktopItemSection section = DESKTOP_ITEM_SECTION_APPS;
|
||||
if (montauk::streq(section_name, "settings")) {
|
||||
section = DESKTOP_ITEM_SECTION_SETTINGS;
|
||||
} else if (montauk::streq(section_name, "hidden")) {
|
||||
section = DESKTOP_ITEM_SECTION_HIDDEN;
|
||||
} else if (!montauk::streq(section_name, "apps")) {
|
||||
montauk::print("desktop: skipping app manifest with invalid desktop.section\n");
|
||||
doc.destroy();
|
||||
continue;
|
||||
}
|
||||
|
||||
DesktopItem* item = next_desktop_item_slot(ds);
|
||||
if (!item) {
|
||||
doc.destroy();
|
||||
return;
|
||||
}
|
||||
montauk::memset(item, 0, sizeof(*item));
|
||||
|
||||
montauk::strncpy(item->id, id, sizeof(item->id));
|
||||
montauk::strncpy(item->name, name, sizeof(item->name));
|
||||
montauk::strncpy(item->category, category, sizeof(item->category));
|
||||
item->menu_visible = visible;
|
||||
item->launch_with_home = launch_with_home;
|
||||
item->admin_only = admin_only;
|
||||
item->launch_kind = DESKTOP_ITEM_LAUNCH_EXECUTABLE;
|
||||
item->builtin_id = -1;
|
||||
item->section = section;
|
||||
|
||||
// Build full binary path: 0:/apps/<dir>/<binary>
|
||||
snprintf(item->binary_path, sizeof(item->binary_path),
|
||||
"0:/apps/%s/%s", dirname, binary);
|
||||
|
||||
// File types the app opens, used by Files for default apps and
|
||||
// "Open With". Stored lowercased as " ext1 ext2 " for whole-word
|
||||
// matching; entries that would overflow the buffer are dropped.
|
||||
if (auto* types = doc.get_array("files.types")) {
|
||||
int len = 0;
|
||||
item->file_types[len++] = ' ';
|
||||
for (int t = 0; t < types->array.count; t++) {
|
||||
auto* v = types->array.items[t];
|
||||
if (v->type != montauk::toml::Type::String || !v->str[0]) continue;
|
||||
const char* ext = v->str[0] == '.' ? v->str + 1 : v->str;
|
||||
int elen = montauk::slen(ext);
|
||||
if (elen == 0 || len + elen + 2 > (int)sizeof(item->file_types)) continue;
|
||||
for (int k = 0; k < elen; k++) {
|
||||
char ch = ext[k];
|
||||
item->file_types[len++] = (ch >= 'A' && ch <= 'Z') ? ch + 32 : ch;
|
||||
}
|
||||
item->file_types[len++] = ' ';
|
||||
}
|
||||
item->file_types[len < 2 ? 0 : len] = '\0';
|
||||
}
|
||||
|
||||
// Load icon from app directory
|
||||
item->icon = {};
|
||||
item->icon_path[0] = '\0';
|
||||
if (icon_file[0]) {
|
||||
snprintf(item->icon_path, sizeof(item->icon_path),
|
||||
"0:/apps/%s/%s", dirname, icon_file);
|
||||
Color defColor = colors::ICON_COLOR;
|
||||
item->icon = svg_load(item->icon_path, 20, 20, defColor);
|
||||
}
|
||||
|
||||
doc.destroy();
|
||||
ds->desktop_item_count++;
|
||||
}
|
||||
}
|
||||
gui::app_catalog_add_manifest_apps(ds);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
@@ -390,6 +216,11 @@ void gui::desktop_init(DesktopState* ds) {
|
||||
|
||||
// Scan 0:/apps/ for external app manifests and build the menu
|
||||
desktop_scan_apps(ds);
|
||||
ds->desktop_icon_selected = -1;
|
||||
ds->desktop_icon_press = -1;
|
||||
ds->desktop_icon_last_click = -1;
|
||||
ds->desktop_drop_icon = -1;
|
||||
desktop_icons_refresh(ds, true);
|
||||
desktop_build_menu(ds);
|
||||
|
||||
// Settings defaults
|
||||
@@ -537,6 +368,7 @@ static bool desktop_has_visible_dirty_window(const DesktopState* ds) {
|
||||
|
||||
static bool desktop_has_active_interaction(const DesktopState* ds) {
|
||||
if (ds->vol_dragging) return true;
|
||||
if (ds->drag.active) return true;
|
||||
if (desktop_brightness_dragging(ds)) return true;
|
||||
|
||||
for (int i = 0; i < ds->window_count; i++) {
|
||||
@@ -891,6 +723,10 @@ void gui::desktop_run(DesktopState* ds) {
|
||||
// Poll external windows (discover new, remove dead, update dirty)
|
||||
sceneChanged |= desktop_poll_external_windows(ds);
|
||||
|
||||
// App requests: catalog launches, dialog placement, drag and drop.
|
||||
sceneChanged |= desktop_poll_requests(ds);
|
||||
if (!ds->screen_locked) sceneChanged |= desktop_icons_refresh(ds, false);
|
||||
|
||||
// Answer or prompt for pending first-use capability requests.
|
||||
if (!ds->screen_locked) sceneChanged |= desktop_consent_poll(ds);
|
||||
|
||||
|
||||
Reference in new issue
Block a user