fix: dialogs library fixes, fix mangled name exports, fix libc exported by dialogs library
This commit is contained in:
@@ -36,6 +36,7 @@ CXXFLAGS := \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fPIC \
|
||||
-fvisibility=hidden \
|
||||
-fno-rtti \
|
||||
-fno-exceptions \
|
||||
-ffunction-sections \
|
||||
@@ -74,6 +75,7 @@ LIBC_CFLAGS := \
|
||||
-fno-stack-protector \
|
||||
-fno-stack-check \
|
||||
-fPIC \
|
||||
-fvisibility=hidden \
|
||||
-ffunction-sections \
|
||||
-fdata-sections \
|
||||
-m64 \
|
||||
|
||||
@@ -20,9 +20,44 @@
|
||||
using namespace gui;
|
||||
namespace dlg = gui::dialogs;
|
||||
|
||||
#define DIALOGS_EXPORT extern "C" __attribute__((visibility("default")))
|
||||
|
||||
AppState g_app = {};
|
||||
static bool g_fonts_ready = false;
|
||||
|
||||
// WinEvent::type values (from Api/Syscall.hpp)
|
||||
static constexpr uint8_t WIN_KEY = 0;
|
||||
static constexpr uint8_t WIN_MOUSE = 1;
|
||||
static constexpr uint8_t WIN_RESIZE = 2;
|
||||
static constexpr uint8_t WIN_CLOSE = 3;
|
||||
static constexpr uint8_t WIN_SCALE = 4;
|
||||
|
||||
struct DialogCallbacks {
|
||||
void (*draw)();
|
||||
void (*on_close)();
|
||||
void (*handle_mouse)(const Montauk::WinEvent& ev);
|
||||
void (*handle_key)(const Montauk::KeyEvent& key);
|
||||
};
|
||||
|
||||
static void run_dialog_loop(const DialogCallbacks& cb) {
|
||||
while (g_app.running) {
|
||||
cb.draw();
|
||||
g_app.win.present();
|
||||
|
||||
Montauk::WinEvent ev;
|
||||
int rc = g_app.win.poll(&ev);
|
||||
if (rc < 0) { cb.on_close(); break; }
|
||||
if (rc == 0) { montauk::sleep_ms(16); continue; }
|
||||
|
||||
if (ev.type == WIN_CLOSE) { cb.on_close(); break; }
|
||||
if (ev.type == WIN_MOUSE) { cb.handle_mouse(ev); continue; }
|
||||
if (ev.type == WIN_KEY) { cb.handle_key(ev.key); }
|
||||
// WIN_RESIZE and WIN_SCALE are handled inside WsWindow::poll
|
||||
}
|
||||
}
|
||||
|
||||
static void cancel_and_stop() { dialog_cancel(""); }
|
||||
|
||||
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) {
|
||||
gui::dialogs::safe_copy(g_app.result.status, sizeof(g_app.result.status), status);
|
||||
@@ -68,7 +103,7 @@ static bool ensure_fonts(dlg::Result* result) {
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" bool dialogs_run_request(const dlg::Request* request, dlg::Result* out_result) {
|
||||
DIALOGS_EXPORT 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");
|
||||
@@ -107,53 +142,21 @@ extern "C" bool dialogs_run_request(const dlg::Request* request, dlg::Result* ou
|
||||
return true;
|
||||
}
|
||||
|
||||
if (g_app.is_print) printdialog::draw();
|
||||
else filedialog::draw();
|
||||
void (*draw_fn)() = g_app.is_print ? printdialog::draw : filedialog::draw;
|
||||
void (*mouse_fn)(const Montauk::WinEvent&) = g_app.is_print ? printdialog::handle_mouse : filedialog::handle_mouse;
|
||||
void (*key_fn)(const Montauk::KeyEvent&) = g_app.is_print ? printdialog::handle_key : filedialog::handle_key;
|
||||
|
||||
draw_fn();
|
||||
g_app.win.present();
|
||||
|
||||
while (g_app.running) {
|
||||
if (g_app.is_print) printdialog::draw();
|
||||
else filedialog::draw();
|
||||
g_app.win.present();
|
||||
|
||||
Montauk::WinEvent ev;
|
||||
int rc = g_app.win.poll(&ev);
|
||||
if (rc < 0) {
|
||||
dialog_cancel("");
|
||||
break;
|
||||
}
|
||||
if (rc == 0) {
|
||||
montauk::sleep_ms(16);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.type == 3) {
|
||||
dialog_cancel("");
|
||||
break;
|
||||
}
|
||||
|
||||
if (ev.type == 2 || ev.type == 4) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.type == 1) {
|
||||
if (g_app.is_print) printdialog::handle_mouse(ev);
|
||||
else filedialog::handle_mouse(ev);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.type == 0) {
|
||||
if (g_app.is_print) printdialog::handle_key(ev.key);
|
||||
else filedialog::handle_key(ev.key);
|
||||
}
|
||||
}
|
||||
run_dialog_loop({ draw_fn, cancel_and_stop, mouse_fn, key_fn });
|
||||
|
||||
cleanup();
|
||||
*out_result = g_app.result;
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" uint8_t dialogs_message_box(const char* title,
|
||||
DIALOGS_EXPORT uint8_t dialogs_message_box(const char* title,
|
||||
const char* message,
|
||||
uint8_t buttons) {
|
||||
if (!ensure_fonts(nullptr))
|
||||
@@ -178,36 +181,7 @@ extern "C" uint8_t dialogs_message_box(const char* title,
|
||||
messagebox::draw();
|
||||
g_app.win.present();
|
||||
|
||||
while (g_app.running) {
|
||||
messagebox::draw();
|
||||
g_app.win.present();
|
||||
|
||||
Montauk::WinEvent ev;
|
||||
int rc = g_app.win.poll(&ev);
|
||||
if (rc < 0) {
|
||||
messagebox::dismiss();
|
||||
break;
|
||||
}
|
||||
if (rc == 0) {
|
||||
montauk::sleep_ms(16);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ev.type == 3) {
|
||||
messagebox::dismiss();
|
||||
break;
|
||||
}
|
||||
if (ev.type == 2 || ev.type == 4) {
|
||||
continue;
|
||||
}
|
||||
if (ev.type == 1) {
|
||||
messagebox::handle_mouse(ev);
|
||||
continue;
|
||||
}
|
||||
if (ev.type == 0) {
|
||||
messagebox::handle_key(ev.key);
|
||||
}
|
||||
}
|
||||
run_dialog_loop({ messagebox::draw, messagebox::dismiss, messagebox::handle_mouse, messagebox::handle_key });
|
||||
|
||||
uint8_t choice = messagebox::selected_choice();
|
||||
cleanup();
|
||||
|
||||
Reference in New Issue
Block a user