feat: split word processor app out into standalone Window Server app

This commit is contained in:
2026-03-26 18:05:14 +01:00
parent c8d597abd2
commit cb8094bd95
12 changed files with 2033 additions and 1774 deletions
+99
View File
@@ -0,0 +1,99 @@
/*
* main.cpp
* MontaukOS Word Processor
* Copyright (c) 2026 Daniel Hammer
*/
#include "wordprocessor.hpp"
int g_win_w = INIT_W;
int g_win_h = INIT_H;
WsWindow g_win;
WordProcessorState g_wp = {};
WPFontTable g_wp_fonts = { {{nullptr}}, false };
SvgIcon g_icon_folder = {};
SvgIcon g_icon_save = {};
TrueTypeFont* g_ui_font = nullptr;
TrueTypeFont* g_ui_bold = nullptr;
void wp_load_icons() {
Color def_color = colors::ICON_COLOR;
if (!g_icon_folder.pixels)
g_icon_folder = svg_load("0:/icons/folder.svg", 16, 16, def_color);
if (!g_icon_save.pixels)
g_icon_save = svg_load("0:/icons/document-save-symbolic.svg", 16, 16, def_color);
}
void wp_cleanup_state() {
wp_free_document(&g_wp);
if (g_icon_folder.pixels) svg_free(g_icon_folder);
if (g_icon_save.pixels) svg_free(g_icon_save);
}
extern "C" void _start() {
if (!fonts::init())
montauk::exit(1);
wp_load_fonts();
wp_load_icons();
wp_init_empty_document(&g_wp);
char args[512] = {};
int arglen = montauk::getargs(args, sizeof(args));
if (arglen > 0 && args[0]) {
wp_load_file(&g_wp, args);
}
char title[64] = "Word Processor";
if (g_wp.filename[0]) {
snprintf(title, sizeof(title), "%s - Word Processor", g_wp.filename);
}
if (!g_win.create(title, INIT_W, INIT_H))
montauk::exit(1);
g_win_w = g_win.width;
g_win_h = g_win.height;
wp_render();
g_win.present();
while (true) {
Montauk::WinEvent ev;
int r = g_win.poll(&ev);
if (r < 0) break;
if (r == 0) {
montauk::sleep_ms(16);
continue;
}
if (ev.type == 3) break;
if (ev.type == 2 || ev.type == 4) {
g_win_w = g_win.width;
g_win_h = g_win.height;
wp_render();
g_win.present();
continue;
}
if (ev.type == 0 && ev.key.pressed) {
wp_handle_key(ev.key);
wp_render();
g_win.present();
continue;
}
if (ev.type == 1) {
wp_handle_mouse(ev);
wp_render();
g_win.present();
}
}
wp_cleanup_state();
g_win.destroy();
montauk::exit(0);
}