feat: make dialogs a shared library
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# Makefile for shared dialogs (standalone Window Server app) on MontaukOS
|
||||
# Makefile for libdialogs shared library on MontaukOS
|
||||
# Copyright (c) 2026 Daniel Hammer
|
||||
|
||||
MAKEFLAGS += -rR
|
||||
@@ -6,16 +6,23 @@ MAKEFLAGS += -rR
|
||||
|
||||
TOOLCHAIN_PREFIX := $(shell cd ../../.. && pwd)/toolchain/local/bin/x86_64-elf-
|
||||
ifneq ($(wildcard $(TOOLCHAIN_PREFIX)gcc),)
|
||||
CC := $(TOOLCHAIN_PREFIX)gcc
|
||||
CXX := $(TOOLCHAIN_PREFIX)g++
|
||||
LD := $(TOOLCHAIN_PREFIX)ld
|
||||
STRIP := $(TOOLCHAIN_PREFIX)strip
|
||||
else
|
||||
CC := gcc
|
||||
CXX := g++
|
||||
LD := ld
|
||||
STRIP := strip
|
||||
endif
|
||||
|
||||
PROG_INC := ../../include
|
||||
LINK_LD := ../../link.ld
|
||||
BINDIR := ../../bin
|
||||
OBJDIR := obj
|
||||
LIBDIR := ../../lib
|
||||
LIBOUTDIR := ../../bin/os
|
||||
OBJDIR := obj
|
||||
LEGACY_APPDIR := ../../bin/apps/dialogs
|
||||
LIBC_SRC := ../../lib/libc/libc.c
|
||||
GCC_INCLUDE := $(shell $(CC) -print-file-name=include)
|
||||
|
||||
CXXFLAGS := \
|
||||
-std=gnu++20 \
|
||||
@@ -28,7 +35,7 @@ CXXFLAGS := \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fno-PIC \
|
||||
-fPIC \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-ffunction-sections \
|
||||
@@ -40,6 +47,7 @@ CXXFLAGS := \
|
||||
-mno-red-zone \
|
||||
-mcmodel=small \
|
||||
-MMD -MP \
|
||||
-DGUI_DIALOGS_LIBRARY_BUILD \
|
||||
-I $(PROG_INC) \
|
||||
-isystem $(PROG_INC)/libc \
|
||||
-I ../../lib/bearssl/inc \
|
||||
@@ -47,33 +55,60 @@ CXXFLAGS := \
|
||||
-isystem ../../../kernel/freestnd-cxx-hdrs/x86_64/include
|
||||
|
||||
LDFLAGS := \
|
||||
-nostdlib \
|
||||
-static \
|
||||
-Wl,--build-id=none \
|
||||
-Wl,--gc-sections \
|
||||
-Wl,-m,elf_x86_64 \
|
||||
-z max-page-size=0x1000 \
|
||||
-T $(LINK_LD)
|
||||
-shared \
|
||||
--build-id=none \
|
||||
--gc-sections \
|
||||
--hash-style=sysv \
|
||||
-u dialogs_run_request \
|
||||
-m elf_x86_64 \
|
||||
-z max-page-size=0x1000
|
||||
|
||||
LIBC_CFLAGS := \
|
||||
-std=gnu11 \
|
||||
-g -O2 -pipe \
|
||||
-Wall \
|
||||
-Wno-unused-parameter \
|
||||
-nostdinc \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fPIC \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-m64 \
|
||||
-march=x86-64 \
|
||||
-msse \
|
||||
-msse2 \
|
||||
-mno-red-zone \
|
||||
-mcmodel=small \
|
||||
-isystem $(PROG_INC)/libc \
|
||||
-isystem $(GCC_INCLUDE)
|
||||
|
||||
SRCS := main.cpp filedialog.cpp printdialog.cpp stb_truetype_impl.cpp font_data.cpp
|
||||
OBJS := $(addprefix $(OBJDIR)/,$(SRCS:.cpp=.o))
|
||||
LIBC_PIC_OBJ := $(OBJDIR)/libc_pic.o
|
||||
|
||||
TARGET := $(BINDIR)/apps/dialogs/dialogs.elf
|
||||
LIBS := $(LIBDIR)/tls/libtls.a $(LIBDIR)/bearssl/libbearssl.a $(LIBDIR)/libc/liblibc.a
|
||||
TARGET := $(LIBOUTDIR)/libdialogs.lib
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJS) $(LINK_LD) Makefile $(LIBS)
|
||||
mkdir -p $(BINDIR)/apps/dialogs
|
||||
$(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
|
||||
$(TARGET): $(OBJS) $(LIBC_PIC_OBJ) Makefile
|
||||
mkdir -p $(LIBOUTDIR)
|
||||
rm -rf $(LEGACY_APPDIR)
|
||||
$(LD) $(LDFLAGS) $(OBJS) $(LIBC_PIC_OBJ) -o $@
|
||||
$(STRIP) --strip-debug $@
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp Makefile
|
||||
mkdir -p $(OBJDIR)
|
||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||
|
||||
$(LIBC_PIC_OBJ): $(LIBC_SRC) Makefile
|
||||
mkdir -p $(OBJDIR)
|
||||
$(CC) $(LIBC_CFLAGS) -c $(LIBC_SRC) -o $@
|
||||
|
||||
-include $(OBJS:.o=.d)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJDIR) $(TARGET)
|
||||
rm -rf $(OBJDIR) $(TARGET) $(LEGACY_APPDIR)
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
#include <gui/canvas.hpp>
|
||||
#include <montauk/user.h>
|
||||
|
||||
extern "C" {
|
||||
#include <stdio.h>
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
using namespace gui;
|
||||
@@ -1200,4 +1204,4 @@ void cleanup() {
|
||||
free_file_icons(&g_file);
|
||||
}
|
||||
|
||||
} // namespace filedialog
|
||||
} // namespace filedialog
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <gui/gui.hpp>
|
||||
#include <gui/dialogs.hpp>
|
||||
|
||||
@@ -53,4 +54,4 @@ void handle_mouse(const Montauk::WinEvent& ev);
|
||||
void handle_key(const Montauk::KeyEvent& key);
|
||||
void cleanup();
|
||||
|
||||
} // namespace filedialog
|
||||
} // namespace filedialog
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* main.cpp
|
||||
* Shared modal dialogs for MontaukOS desktop apps
|
||||
* libdialogs entry point for shared modal dialogs
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
#include "filedialog.hpp"
|
||||
#include "printdialog.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include <stdio.h>
|
||||
}
|
||||
|
||||
using namespace gui;
|
||||
namespace dlg = gui::dialogs;
|
||||
|
||||
AppState g_app = {};
|
||||
static bool g_fonts_ready = false;
|
||||
|
||||
void dialog_finish(const char* status, const char* path, const char* job_id, const char* message,
|
||||
const char* printer_uri, const char* printer_name, uint32_t copies) {
|
||||
@@ -34,7 +31,6 @@ void dialog_finish(const char* status, const char* path, const char* job_id, con
|
||||
gui::dialogs::safe_copy(g_app.result.printer_name, sizeof(g_app.result.printer_name), printer_name);
|
||||
g_app.result.copies = copies;
|
||||
gui::dialogs::safe_copy(g_app.result.message, sizeof(g_app.result.message), message);
|
||||
gui::dialogs::write_result_file(g_app.request.result_path, &g_app.result);
|
||||
g_app.running = false;
|
||||
}
|
||||
|
||||
@@ -51,17 +47,37 @@ void cleanup() {
|
||||
g_app.win.destroy();
|
||||
}
|
||||
|
||||
extern "C" void _start() {
|
||||
if (!fonts::init()) montauk::exit(1);
|
||||
static void set_error_result(dlg::Result* result, const char* message) {
|
||||
if (!result) return;
|
||||
dlg::reset_result(result);
|
||||
dlg::safe_copy(result->status, sizeof(result->status), "error");
|
||||
dlg::safe_copy(result->message, sizeof(result->message), message);
|
||||
}
|
||||
|
||||
char argbuf[256] = {};
|
||||
if (montauk::getargs(argbuf, sizeof(argbuf)) <= 0 || !argbuf[0]) montauk::exit(1);
|
||||
if (!gui::dialogs::read_request_file(argbuf, &g_app.request)) montauk::exit(1);
|
||||
extern "C" bool dialogs_run_request(const dlg::Request* request, dlg::Result* out_result) {
|
||||
if (!request || !out_result) return false;
|
||||
|
||||
set_error_result(out_result, "dialog failed");
|
||||
|
||||
if (!g_fonts_ready) {
|
||||
if (!fonts::init()) {
|
||||
set_error_result(out_result, "failed to initialize dialog fonts");
|
||||
return true;
|
||||
}
|
||||
g_fonts_ready = true;
|
||||
}
|
||||
|
||||
if (request->kind != dlg::REQUEST_KIND_FILE && request->kind != dlg::REQUEST_KIND_PRINT) {
|
||||
set_error_result(out_result, "unsupported dialog request");
|
||||
return true;
|
||||
}
|
||||
|
||||
g_app = AppState {};
|
||||
g_app.request = *request;
|
||||
g_app.running = true;
|
||||
gui::dialogs::reset_result(&g_app.result);
|
||||
dlg::reset_result(&g_app.result);
|
||||
|
||||
g_app.is_print = g_app.request.kind == gui::dialogs::REQUEST_KIND_PRINT;
|
||||
g_app.is_print = g_app.request.kind == dlg::REQUEST_KIND_PRINT;
|
||||
const int init_w = g_app.is_print ? printdialog::PRINT_INIT_W : filedialog::FILE_INIT_W;
|
||||
const int init_h = g_app.is_print ? printdialog::PRINT_INIT_H : filedialog::FILE_INIT_H;
|
||||
const char* title = g_app.request.title[0] ? g_app.request.title : (g_app.is_print ? "Print" : "Open");
|
||||
@@ -69,7 +85,11 @@ extern "C" void _start() {
|
||||
if (g_app.is_print) printdialog::init(g_app.request);
|
||||
else filedialog::init(g_app.request);
|
||||
|
||||
if (!g_app.win.create(title, init_w, init_h)) montauk::exit(1);
|
||||
if (!g_app.win.create(title, init_w, init_h)) {
|
||||
cleanup();
|
||||
set_error_result(out_result, "failed to create dialog window");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (g_app.is_print) printdialog::draw();
|
||||
else filedialog::draw();
|
||||
@@ -113,5 +133,6 @@ extern "C" void _start() {
|
||||
}
|
||||
|
||||
cleanup();
|
||||
montauk::exit(0);
|
||||
}
|
||||
*out_result = g_app.result;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
[app]
|
||||
name = "Dialogs"
|
||||
binary = "dialogs.elf"
|
||||
icon = "system-file-manager.svg"
|
||||
|
||||
[menu]
|
||||
category = "System"
|
||||
visible = false
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <montauk/syscall.h>
|
||||
#include <gui/gui.hpp>
|
||||
#include <gui/dialogs.hpp>
|
||||
|
||||
@@ -37,4 +38,4 @@ void handle_mouse(const Montauk::WinEvent& ev);
|
||||
void handle_key(const Montauk::KeyEvent& key);
|
||||
void cleanup();
|
||||
|
||||
} // namespace printdialog
|
||||
} // namespace printdialog
|
||||
|
||||
Reference in New Issue
Block a user