Port the toolkit GUI to Windows (wxMSW, cross-built with mingw-w64)

Build: the wx-rs build script chose the platform with cfg!(), which in a
build script describes the build host, so a Linux-to-Windows build took the
GTK path. It now reads CARGO_CFG_TARGET_*, and Windows/GNU builds through
wx-config exactly like GTK, against a static wxMSW from
scripts/build-wx-windows.sh. The C++ runtime is linked statically, so the
.exe imports only Windows system DLLs. crates/alkane-gui/build.rs embeds an
application manifest (Common Controls v6, per-monitor DPI v2, UTF-8 code
page, Windows 10/11), the icon and version info.

Bridge on wxMSW (patches 0007/0008):
- the upstream frame's invisible "OSX key events" child sat above the UI on
  MSW and swallowed every click and key; it is no longer created there
- light/dark is chosen before the first window (wxMSW ignores it later) and
  follows the Windows app mode, with dark grid rules for the data view
- the generic wxDataViewCtrl gets mouse input in its inner main window, so
  drag-select and the per-cell / per-icon tooltips bind there (GTK keeps
  its native GtkTreeView paths; the icon hit-test is shared)
- sizes cross the Rust/C++ boundary in DIPs (identity on GTK), so columns,
  icons, KPI cards and the status bar scale at 125-200 %
- vector shapes go through GDI+ (anti-aliased like Cairo on GTK); selected
  rows use the themed list-view text colour like the native renderer
- the frame never opens larger than the monitor work area; title-bar icon
  from the executable; upstream menu insert no longer reads UTF-8 as UTF-16

App: OS differences live in alkane_core::platform (settings in
%APPDATA%\alkane-toolkit, owner-only secret files, NUL, console-less helper
processes). SSH password logins use SSH_ASKPASS with the toolkit itself as
the helper on every platform, replacing sshpass, which Windows lacks.
Release builds are GUI-subsystem; headless modes attach to the parent
console.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-02 18:32:44 -06:00
co-authored by Claude Opus 5.5
parent 569ef9dcd8
commit be5edfc2bf
31 changed files with 2271 additions and 267 deletions
+83 -2
View File
@@ -1,5 +1,7 @@
#include <wx/wx.h>
#include "wx/clipbrd.h"
#include "wx/display.h"
#include <algorithm>
#include <iostream>
#if defined(_WIN32) || defined(_WIN64) || defined(WIN64) || defined(WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
@@ -34,6 +36,21 @@ void setDPIAware() {
void setDPIAware() {}
#endif
#ifdef __WXMSW__
#include <wx/msw/darkmode.h>
// alkane-toolkit patch: wx's dark palette leaves wxSYS_COLOUR_3DLIGHT at its
// light value, and the generic wxDataViewCtrl (the table on MSW) draws its row
// and column rules in that colour -- bright grid lines across a dark table.
// Give it a dark-grey rule colour; everything else stays wx's default palette.
class DarkModeSettings : public wxDarkModeSettings {
public:
wxColour GetColour(wxSystemColour index) override {
if (index == wxSYS_COLOUR_3DLIGHT) return wxColour(0x3a, 0x3a, 0x3a);
return wxDarkModeSettings::GetColour(index);
}
};
#endif
enum cursor {
NO_CURSOR,
ARROW_CURSOR,
@@ -129,10 +146,19 @@ MyFrame::MyFrame(const wxString& title, const wxSize& size)
render = NULL;
handle_events = NULL;
// Needed to get App to catch key events on OSX
// alkane-toolkit patch: not on MSW. There this invisible child ends up above
// the application's own widgets in the sibling z-order, and a
// wxTRANSPARENT_WINDOW (WS_EX_TRANSPARENT) is transparent to painting only,
// not to hit-testing, so it silently swallowed every click and key press
// aimed at the real UI. On GTK later siblings stack above it, so it is kept.
#ifdef __WXMSW__
inputWin = NULL;
#else
inputWin = new wxWindow(this, wxID_ANY,
wxDefaultPosition,
wxSize(-1, -1),
wxBORDER_NONE | wxTRANSPARENT_WINDOW);
#endif
InitCursors();
Show(true);
@@ -344,12 +370,43 @@ extern "C" {
int fake_argc = 0;
char *fake_argv[1] = {NULL};
wxEntryStart(fake_argc, fake_argv);
// alkane-toolkit patch: light/dark appearance, decided before the first
// window exists because wxMSW cannot switch it afterwards (SetAppearance
// then returns CannotChange). System follows the desktop: the GTK theme's
// colour scheme, or the Windows 10/11 "app mode" setting, which wxMSW
// otherwise ignores and stays light. ALKANE_APPEARANCE=light|dark forces one.
{
wxString pref;
wxGetEnv("ALKANE_APPEARANCE", &pref);
pref.MakeLower();
wxApp::Appearance appearance = wxApp::Appearance::System;
if (pref == "dark") appearance = wxApp::Appearance::Dark;
else if (pref == "light") appearance = wxApp::Appearance::Light;
#ifdef __WXMSW__
// Same as SetAppearance(), but with our dark palette tweak (below).
if (appearance != wxApp::Appearance::Light) {
wxTheApp->MSWEnableDarkMode(appearance == wxApp::Appearance::Dark
? wxApp::DarkMode_Always
: wxApp::DarkMode_Auto,
new DarkModeSettings()); // wx takes ownership
}
#else
wxTheApp->SetAppearance(appearance);
#endif
}
wxTheApp->OnInit();
#ifdef __WINDOWS__
// Adjust the window according to the display scale factor
double scale = wxGetApp().frame->GetDPIScaleFactor();
wxGetApp().frame->SetSize(width * scale, height * scale);
// alkane-toolkit patch: title-bar/Alt-Tab icon from the executable's own
// icon resource. By wx convention the application icon group is named
// "aaaa" (first alphabetically, so Explorer shows it too); an executable
// without one keeps the default rather than showing a load-error dialog.
if (::FindResourceW(::GetModuleHandleW(NULL), L"aaaa", MAKEINTRESOURCEW(14) /* RT_GROUP_ICON */)) {
wxGetApp().frame->SetIcons(wxIconBundle(wxS("aaaa"), ::GetModuleHandleW(NULL)));
}
#else
// OSX
double scale = wxGetApp().frame->GetDPIScaleFactor();
@@ -358,6 +415,24 @@ extern "C" {
wxGetApp().frame->Move(0.0, 20.0);
}
#endif
// alkane-toolkit patch: never open larger than the monitor's work area
// (the screen minus taskbar/panels). A 1280x800 request on a 1280x800 or
// 1366x768 laptop otherwise put the bottom of the window, with the status
// bar, behind the Windows taskbar.
{
wxFrame* frame = wxGetApp().frame;
int index = wxDisplay::GetFromWindow(frame);
wxRect work = wxDisplay(index == wxNOT_FOUND ? 0u : (unsigned)index).GetClientArea();
wxRect rect = frame->GetRect();
if (rect.width > work.width || rect.height > work.height) {
rect.SetSize(wxSize(std::min(rect.width, work.width), std::min(rect.height, work.height)));
frame->SetSize(rect.GetSize());
}
if (!work.Contains(frame->GetRect())) {
frame->Move(work.x + (work.width - rect.width) / 2,
work.y + (work.height - rect.height) / 2);
}
}
}
void set_render(void (*render)()) {
@@ -602,15 +677,21 @@ extern "C" {
}
}
// alkane-toolkit patch: Rust hands UTF-8; upstream cast `help` to wxChar*,
// which is wchar_t* on MSW (garbage text), and fell off the end of a
// non-void function when `i` was out of range (undefined behaviour).
int insert_to_menu(wxMenu* menu, size_t i, char* str, char* help) {
if (i <= menu->GetMenuItemCount()) {
return menu->Insert(i, wxID_ANY, str, (help != NULL) ? (const wxChar *) help : wxEmptyString)->GetId();
return menu->Insert(i, wxID_ANY, wxString::FromUTF8(str),
help ? wxString::FromUTF8(help) : wxString())->GetId();
}
return -1;
}
void insert_submenu(wxMenu* menu, size_t i, wxMenu* subMenu, char* str, char* help) {
if (i <= menu->GetMenuItemCount()) {
menu->Insert(i, wxID_ANY, str, subMenu, (help != NULL) ? (const wxChar *) help : wxEmptyString);
menu->Insert(i, wxID_ANY, wxString::FromUTF8(str), subMenu,
help ? wxString::FromUTF8(help) : wxString());
}
}