41 KiB
Bananarchy NeoUI and NeoNet SDK reference (SDK.md)
NeoUI (libneoui.so + /usr/include/neoui.h) is the native 240x320 QVGA graphical user interface SDK for Bananarchy Linux, paired with NeoNet (neonet.yab), a libcurl + POSIX socket C FFI networking library for Yabasic.
They encapsulate all low-level X11 (Xlib), Xft, Pango, libjpeg-turbo, libpng, .Xresources / ~/.xthemes/*.xth live theme resolution, offscreen Pixmap double buffering, standardized OS shell widgets, FIFO IPC, softkey chord handling (Left+Right softkey -> xdrawer), multi-tap T9 keypad input, and HTTP/HTTPS/TCP/TLS/UDP networking behind:
- A C-compatible FFI (
neoui_*) designed for both C programs and foreign-function interfaces (such as Yabasicfrnfn_call/frnfn_call$, LuaJIT FFI, Janet, Pythonctypes, etc.). - A C++20 SDK (
namespace bananarchy) providingThemeSpec,PluginTheme,NeoWindow, and direct Pango/Xft/image helpers used across all 14 built-in Bananarchy DWM plugins. - A Yabasic UI wrapper library (
neoui.yab) preinstalled in/home/user/Projects/neoui.yab(and symlinked at/usr/lib/neoui.yab), paired with a full showcase application (/home/user/Projects/neoui_demo.yab). - A Yabasic networking wrapper library (
neonet.yab) preinstalled in/home/user/Projects/neonet.yab(and symlinked at/usr/lib/neonet.yab), wrappinglibcurl.so.4and musllibcvialibffifor one-line HTTP/HTTPS requests with custom headers as well as raw TCP, TLS, and UDP socket data exchange, paired with a combined NeoNet + NeoUI demo application (/home/user/Projects/neonet_demo.yab).
1. Architecture and files
| Path on target device | Source in repository | Description |
|---|---|---|
/usr/lib/libneoui.so |
src/neoui/neoui.cpp |
Shared library (armv7 hard-float) implementing the C FFI and C++20 SDK |
/usr/include/neoui.h |
src/neoui/neoui.h |
Unified C99 and C++20 header file |
/home/user/Projects/neoui.yab |
overlay/rootfs/home/user/Projects/neoui.yab |
Yabasic native C FFI wrapper module for NeoUI (import neoui) |
/usr/lib/neoui.yab |
overlay/rootfs/usr/lib/neoui.yab |
Symlink to /home/user/Projects/neoui.yab so import neoui works from any working directory |
/home/user/Projects/neoui_demo.yab |
overlay/rootfs/home/user/Projects/neoui_demo.yab |
Interactive 3-tab Yabasic showcase demonstrating all NeoUI widgets, multi-tap input, custom drawing, modals, and live theme reload |
/home/user/Projects/neonet.yab |
overlay/rootfs/home/user/Projects/neonet.yab |
Yabasic native libcurl + socket FFI wrapper module for NeoNet (import neonet) |
/usr/lib/neonet.yab |
overlay/rootfs/usr/lib/neonet.yab |
Symlink to /home/user/Projects/neonet.yab so import neonet works from any working directory |
/home/user/Projects/neonet_demo.yab |
overlay/rootfs/home/user/Projects/neonet_demo.yab |
Interactive 3-tab Yabasic showcase combining NeoNet and NeoUI (1:HTTP/S, 2:Sockets, 3:Tools) |
Key design principles
- Zero-flicker offscreen double buffering: every NeoUI window (
240x296atX=0, Y=24, directly below the 24pxdwmtop status bar) renders into an offscreen X11Pixmapduringneoui_begin_frame()..neoui_end_frame()and copies the completed frame to the visible window in a singleXCopyAreacall. - Automatic
.Xresources/.xththeme resolution: NeoUI automatically parses the active theme from X11RESOURCE_MANAGERand~/.Xresources, derives 29 semantic color tokens and 4 proportional Pango font sizes (Small,Main,Icon,Largescaled fromtheme.baseFontSize), and hot-reloads on the fly wheneverRELOAD_THEMEarrives on/tmp/dwm_plugin_<app_name>.fifoor.Xresourceschanges on disk. - FFI-safe return types: every
extern "C"function inneoui.hreturnsint(int32),uint32_t(uint32), orconst char*(string)—nevervoid—so FFI callers like Yabasic'sfrnfn_callwork withoutvoid-return restrictions.
2. Constants and enumerations
2.1 Screen geometry (NeoGeometry)
| C constant | Yabasic constant | Value | Meaning |
|---|---|---|---|
NEO_SCREEN_W |
neoui.SCREEN_W |
240 |
Full physical display width in pixels |
NEO_SCREEN_H |
neoui.SCREEN_H |
320 |
Full physical display height in pixels |
NEO_TOPBAR_H |
neoui.TOPBAR_H |
24 |
Height of the dwm top status bar |
NEO_WIN_X |
neoui.WIN_X |
0 |
Default app window X coordinate |
NEO_WIN_Y |
neoui.WIN_Y |
24 |
Default app window Y coordinate (below top bar) |
NEO_WIN_W |
neoui.WIN_W |
240 |
Default app window width |
NEO_WIN_H |
neoui.WIN_H |
296 |
Default app window height (320 - 24) |
NEO_HEADER_H |
neoui.HEADER_H |
34 |
Standard NeoUI header height |
NEO_SOFTBAR_H |
neoui.SOFTBAR_H |
26 |
Standard bottom softkey bar height |
2.2 Theme color token IDs (NeoColorId for neoui_color(color_id))
| ID | C constant | Yabasic constant | Description |
|---|---|---|---|
0 |
NEO_COLOR_BG_MAIN |
neoui.COLOR_BG_MAIN |
Primary window background |
1 |
NEO_COLOR_BG_BAR |
neoui.COLOR_BG_BAR |
Top status bar background |
2 |
NEO_COLOR_BG_HEADER |
neoui.COLOR_BG_HEADER |
App header / tab bar background |
3 |
NEO_COLOR_BG_FOOTER |
neoui.COLOR_BG_FOOTER |
Bottom softkey bar background |
4 |
NEO_COLOR_BG_OVERLAY |
neoui.COLOR_BG_OVERLAY |
Modal / popup overlay background |
5 |
NEO_COLOR_BG_ALT_EVEN |
neoui.COLOR_BG_ALT_EVEN |
Alternating list row background (even) |
6 |
NEO_COLOR_BG_ALT_ODD |
neoui.COLOR_BG_ALT_ODD |
Alternating list row background (odd) |
7 |
NEO_COLOR_BG_INPUT |
neoui.COLOR_BG_INPUT |
Unfocused input box / slider track background |
8 |
NEO_COLOR_BG_INPUT_FOCUS |
neoui.COLOR_BG_INPUT_FOCUS |
Focused input box / active pill background |
9 |
NEO_COLOR_BG_BUTTON |
neoui.COLOR_BG_BUTTON |
Unselected button background |
10 |
NEO_COLOR_BG_SEARCH |
neoui.COLOR_BG_SEARCH |
Search bar / candidate bar background |
11 |
NEO_COLOR_BG_BUBBLE_IN |
neoui.COLOR_BG_BUBBLE_IN |
Incoming message bubble background |
12 |
NEO_COLOR_BG_BUBBLE_OUT |
neoui.COLOR_BG_BUBBLE_OUT |
Outgoing message bubble background |
13 |
NEO_COLOR_BG_TOAST |
neoui.COLOR_BG_TOAST |
Toast banner background |
14 |
NEO_COLOR_FG_MAIN |
neoui.COLOR_FG_MAIN |
Primary foreground text color |
15 |
NEO_COLOR_FG_BRIGHT |
neoui.COLOR_FG_BRIGHT |
High-contrast bright foreground color |
16 |
NEO_COLOR_FG_MUTED |
neoui.COLOR_FG_MUTED |
Muted / secondary subtitle color |
17 |
NEO_COLOR_SEL_BG |
neoui.COLOR_SEL_BG |
Selected row / button background |
18 |
NEO_COLOR_SEL_FG |
neoui.COLOR_SEL_FG |
Selected row / button foreground |
19 |
NEO_COLOR_ACCENT |
neoui.COLOR_ACCENT |
Primary theme accent color |
20 |
NEO_COLOR_ACCENT_ALT |
neoui.COLOR_ACCENT_ALT |
Secondary accent shade |
21 |
NEO_COLOR_HIGHLIGHT |
neoui.COLOR_HIGHLIGHT |
Bright highlight color |
22 |
NEO_COLOR_BORDER |
neoui.COLOR_BORDER |
Box / widget border color |
23 |
NEO_COLOR_DIVIDER |
neoui.COLOR_DIVIDER |
Divider line / scrollbar thumb color |
24 |
NEO_COLOR_SUCCESS |
neoui.COLOR_SUCCESS |
Semantic green (success / active / call) |
25 |
NEO_COLOR_INFO |
neoui.COLOR_INFO |
Semantic blue (info / link) |
26 |
NEO_COLOR_WARNING |
neoui.COLOR_WARNING |
Semantic orange (warning) |
27 |
NEO_COLOR_DANGER |
neoui.COLOR_DANGER |
Semantic red (danger / error / reject) |
28 |
NEO_COLOR_DANGER_BG |
neoui.COLOR_DANGER_BG |
Selected danger button background |
2.3 Font roles (NeoFontRole) and text color roles (NeoTextColor)
| ID | Font role (NeoFontRole) |
Yabasic | Description |
|---|---|---|---|
0 |
NEO_FONT_SMALL |
neoui.FONT_SMALL |
Small UI font (baseFontSize - 2, min 10px) |
1 |
NEO_FONT_MAIN |
neoui.FONT_MAIN |
Main UI bold font (baseFontSize, default 13px) |
2 |
NEO_FONT_ICON |
neoui.FONT_ICON |
Nerd Font icon glyph layout (baseFontSize + 2, default 15px) |
3 |
NEO_FONT_LARGE |
neoui.FONT_LARGE |
Large bold title/number font (baseFontSize + 3, default 16px) |
| ID | Text color role (NeoTextColor) |
Yabasic | Mapped theme token |
|---|---|---|---|
0 |
NEO_TEXT_WHITE |
neoui.TEXT_WHITE |
theme.fgBright |
1 |
NEO_TEXT_LIGHT |
neoui.TEXT_LIGHT |
theme.fgMain |
2 |
NEO_TEXT_MUTED |
neoui.TEXT_MUTED |
theme.fgMuted |
3 |
NEO_TEXT_YELLOW |
neoui.TEXT_YELLOW |
theme.accent |
4 |
NEO_TEXT_GREEN |
neoui.TEXT_GREEN |
theme.success |
5 |
NEO_TEXT_BLUE |
neoui.TEXT_BLUE |
theme.info |
6 |
NEO_TEXT_ORANGE |
neoui.TEXT_ORANGE |
theme.warning |
7 |
NEO_TEXT_RED |
neoui.TEXT_RED |
theme.danger |
2.4 Event types (NeoEventType) and logical keypad keys (NeoKey)
| Event ID | C constant | Yabasic constant | Description |
|---|---|---|---|
0 |
NEO_EV_NONE |
neoui.EV_NONE |
Timeout elapsed with no event |
1 |
NEO_EV_EXPOSE |
neoui.EV_EXPOSE |
Window exposed or multi-tap candidate auto-committed; redraw frame |
2 |
NEO_EV_KEY_PRESS |
neoui.EV_KEY_PRESS |
Keypad key pressed (query key via neoui_event_key()) |
3 |
NEO_EV_KEY_RELEASE |
neoui.EV_KEY_RELEASE |
Keypad key released |
4 |
NEO_EV_SOFTKEY_LEFT |
neoui.EV_SOFTKEY_LEFT |
Left softkey (Menu / F1) pressed (after chord disambiguation) |
5 |
NEO_EV_SOFTKEY_RIGHT |
neoui.EV_SOFTKEY_RIGHT |
Right softkey (Back / F2) pressed (after chord disambiguation) |
6 |
NEO_EV_SOFTKEY_CHORD |
neoui.EV_SOFTKEY_CHORD |
Both softkeys pressed together (xdrawer toggled automatically) |
7 |
NEO_EV_FIFO_CMD |
neoui.EV_FIFO_CMD |
Custom command received on /tmp/dwm_plugin_<app>.fifo (neoui_event_command()) |
8 |
NEO_EV_THEME_RELOAD |
neoui.EV_THEME_RELOAD |
Theme reloaded (RELOAD_THEME); redraw frame |
9 |
NEO_EV_CLOSE_REQ |
neoui.EV_CLOSE_REQ |
CLOSE received on FIFO |
| Key ID | C constant | Yabasic constant | Physical key |
|---|---|---|---|
0 |
NEO_KEY_NONE |
neoui.KEY_NONE |
Unmapped key |
1..4 |
NEO_KEY_UP, DOWN, LEFT, RIGHT |
neoui.KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT |
D-Pad directions |
5 |
NEO_KEY_OK |
neoui.KEY_OK |
Center OK (Return / KP_Enter) |
6 |
NEO_KEY_BACK |
neoui.KEY_BACK |
BackSpace / Delete / Escape |
7 |
NEO_KEY_CALL |
neoui.KEY_CALL |
Green Call / Send key (XF86PickupPhone / F3) |
8 |
NEO_KEY_END |
neoui.KEY_END |
Red End / Power key (XF86HangupPhone / F4) |
9 |
NEO_KEY_SOFT_LEFT |
neoui.KEY_SOFT_LEFT |
Left softkey (XF86KbdLcdMenu1 / F1) |
10 |
NEO_KEY_SOFT_RIGHT |
neoui.KEY_SOFT_RIGHT |
Right softkey (XF86KbdLcdMenu2 / F2) |
32 |
NEO_KEY_SPACE |
neoui.KEY_SPACE |
Space |
35 |
NEO_KEY_HASH |
neoui.KEY_HASH |
# key (numbersign) |
42 |
NEO_KEY_STAR |
neoui.KEY_STAR |
* key (asterisk) |
43 |
NEO_KEY_PLUS |
neoui.KEY_PLUS |
+ key (plus) |
48..57 |
NEO_KEY_0 .. NEO_KEY_9 |
neoui.KEY_0 .. neoui.KEY_9 |
Keypad digits 0–9 |
2.5 Built-in Nerd Font icon names (neoui_icon(name))
Any widget parameter accepting icon_str (or neoui_icon(name)) resolves the following symbolic names to their Nerd Font UTF-8 codepoints (or passes raw UTF-8 strings through unchanged):
- Telephony and messaging:
"phone","hangup","contacts","user","sms","reply","in_call","out_call","missed_call","sim","signal","ussd","voicemail" - Connectivity and hardware:
"wifi","bluetooth","globe","hotspot","usb","torch","sun","speaker","earpiece","mute","mic","mic_off","bell","vibrate","silent","dnd","camera","battery","lock" - Files, media, and UI actions:
"folder","file","image","music","Gamepad","term","theme","settings","search","plus","edit","trash","check","close","info","warning","star","refresh","copy","sort","eye","backspace","up","down","left","right"
3. C SDK reference (/usr/include/neoui.h)
3.1 Compiling C applications on the device
gcc -O2 myapp.c -lneoui -o myapp
3.2 C function summary
Window and daemon lifecycle
int neoui_init(const char* app_name, int preload_mode);
int neoui_init_ex(const char* app_name, const char* res_name,
const char* res_class, const char* win_title,
int x, int y, int w, int h,
int override_redirect, int preload_mode);
int neoui_shutdown(void);
int neoui_show(void);
int neoui_hide(void);
int neoui_is_visible(void);
int neoui_raise_and_grab(void);
int neoui_ungrab(void);
int neoui_width(void);
int neoui_height(void);
int neoui_begin_frame(void);
int neoui_end_frame(void);
int neoui_flush(void);
Unified .Xresources / .xth theme and icon resolution
int neoui_reload_theme(void);
int neoui_check_reload_theme(void);
int neoui_apply_theme_file(const char* xth_path);
int neoui_broadcast_theme_reload(const char* skip_plugin);
const char* neoui_theme_name(void);
const char* neoui_font_face(void);
const char* neoui_icon_font_face(void);
int neoui_base_font_size(void);
int neoui_font_size(int font_role);
uint32_t neoui_color(int color_id);
uint32_t neoui_adjust_rgb(uint32_t rgb, int delta);
uint32_t neoui_blend_rgb(uint32_t c1, uint32_t c2, int weight2_pct);
uint32_t neoui_parse_hex_rgb(const char* hex_str, uint32_t fallback_rgb);
const char* neoui_format_hex_rgb(uint32_t rgb);
const char* neoui_icon(const char* icon_name);
Drawing primitives, text, and image rendering
int neoui_clear(uint32_t rgb);
int neoui_fill_rect(int x, int y, int w, int h, uint32_t rgb);
int neoui_draw_rect(int x, int y, int w, int h, uint32_t rgb);
int neoui_draw_line(int x1, int y1, int x2, int y2, uint32_t rgb);
int neoui_set_clip(int x, int y, int w, int h);
int neoui_reset_clip(void);
int neoui_draw_text(int font_role, int color_role, int x, int y, int h,
const char* text, int max_w);
int neoui_draw_text_centered(int font_role, int color_role, int x, int y,
int w, int h, const char* text);
int neoui_draw_text_right(int font_role, int color_role, int right_x, int y,
int h, const char* text, int max_w);
int neoui_draw_text_wrapped(int font_role, int color_role, int x, int y,
int w, int h, const char* text, int scroll_line);
int neoui_text_width(int font_role, const char* text);
const char* neoui_tail_fit_text(int font_role, const char* text, int max_w);
int neoui_draw_image_file(const char* path, int x, int y, int w, int h,
int scale_mode);
Standardized OS shell widgets
int neoui_draw_header(const char* icon_str, int icon_color_role,
const char* title, const char* right_badge);
int neoui_draw_header_ex(int h, const char* icon_str, int icon_color_role,
const char* title, int title_color_role,
const char* right_badge, int right_color_role);
int neoui_draw_tabs(const char* pipe_labels, int active_idx, int y, int h);
int neoui_draw_softkeys(const char* left_label, const char* center_label,
const char* right_label);
int neoui_draw_softkeys_ex(const char* left_label, const char* center_label,
const char* right_label, int center_color_role);
int neoui_draw_list_row(int row_index, int y, int h, int is_selected,
const char* icon_str, int icon_color_role,
const char* title, const char* subtitle,
const char* right_text);
int neoui_draw_slider_row(int row_index, int y, int h, int is_selected,
const char* icon_str, int icon_color_role,
const char* label, int pct, const char* value_text);
int neoui_draw_toggle_row(int row_index, int y, int h, int is_selected,
const char* icon_str, int icon_color_role,
const char* label, int is_on,
const char* state_text);
int neoui_draw_button(int x, int y, int w, int h, int is_selected,
int is_danger, const char* icon_str, const char* label);
int neoui_draw_input_box(int x, int y, int w, int h, int is_focused,
const char* label, const char* value,
const char* placeholder, int password_mask);
int neoui_draw_progress_bar(int x, int y, int w, int h, int pct,
uint32_t fill_rgb);
int neoui_draw_scrollbar(int x, int y, int h, int total_items,
int visible_items, int scroll_offset);
int neoui_draw_modal_box(int x, int y, int w, int h, const char* icon_str,
int icon_color_role, const char* title);
int neoui_draw_confirm_dialog(const char* title, const char* line1,
const char* line2, const char* no_label,
const char* yes_label, int selected_yes);
int neoui_draw_menu_popup(const char* pipe_items, const char* pipe_icons,
int selected_idx, int max_visible_rows);
int neoui_draw_toast(const char* message);
int neoui_show_toast(const char* message, int duration_ms);
int neoui_clear_toast(void);
Event loop, keypad, and multi-tap input
int neoui_poll_event(int timeout_ms);
int neoui_next_timeout_ms(int default_timeout_ms);
int neoui_event_key(void);
int neoui_event_keycode(void);
int neoui_event_keysym(void);
const char* neoui_event_command(void);
int neoui_set_chord_xdrawer(int enabled);
int neoui_input_reset(const char* initial_text);
int neoui_input_set_text(const char* text);
const char* neoui_input_get_text(void);
int neoui_input_set_mode(int mode);
int neoui_input_get_mode(void);
int neoui_input_cycle_mode(void);
const char* neoui_input_mode_badge(void);
int neoui_input_feed_key(int neo_key);
int neoui_input_commit_tap(void);
int neoui_input_backspace(void);
int neoui_input_is_tap_active(void);
const char* neoui_input_candidate_bar(const char* idle_hint);
int neoui_draw_multitap_bar(int x, int y, int w, int h, const char* idle_hint);
System and IPC utilities
int neoui_send_plugin_cmd(const char* plugin_name, const char* cmd);
int neoui_vibrate(int duration_ms);
int neoui_now_ms(void);
3.3 Minimal C example
#include <neoui.h>
#include <stdio.h>
static void render(int sel, int enabled, int pct) {
char pct_str[16];
snprintf(pct_str, sizeof(pct_str), "%d%%", pct);
neoui_begin_frame();
neoui_draw_header("settings", NEO_TEXT_YELLOW, "My NeoUI App", neoui_theme_name());
neoui_draw_toggle_row(0, 40, 38, sel == 0, "wifi", NEO_TEXT_BLUE,
"Wireless Radio", enabled, enabled ? "ON" : "OFF");
neoui_draw_slider_row(1, 78, 38, sel == 1, "speaker", NEO_TEXT_GREEN,
"Output Level", pct, pct_str);
neoui_draw_softkeys("Toast", "Toggle", "Quit");
neoui_end_frame();
}
int main(void) {
if (!neoui_init("my_c_app", 0)) return 1;
int sel = 0, enabled = 1, pct = 70, running = 1;
render(sel, enabled, pct);
while (running) {
int ev = neoui_poll_event(250);
if (ev == NEO_EV_CLOSE_REQ || ev == NEO_EV_SOFTKEY_RIGHT) {
running = 0;
} else if (ev == NEO_EV_EXPOSE || ev == NEO_EV_THEME_RELOAD) {
render(sel, enabled, pct);
} else if (ev == NEO_EV_SOFTKEY_LEFT) {
neoui_show_toast("Hello from C!", 1800);
render(sel, enabled, pct);
} else if (ev == NEO_EV_KEY_PRESS) {
int k = neoui_event_key();
if (k == NEO_KEY_BACK) running = 0;
else if (k == NEO_KEY_UP || k == NEO_KEY_DOWN) sel = 1 - sel;
else if (k == NEO_KEY_OK && sel == 0) enabled = 1 - enabled;
else if (k == NEO_KEY_LEFT && sel == 1 && pct >= 5) pct -= 5;
else if (k == NEO_KEY_RIGHT && sel == 1 && pct <= 95) pct += 5;
render(sel, enabled, pct);
}
}
neoui_shutdown();
return 0;
}
4. C++20 SDK reference (namespace bananarchy)
When #include <neoui.h> is compiled under C++, it also exposes the bananarchy namespace used by Bananarchy's native DWM plugins (src/dwm-plugins/*.cpp and src/xdrawer/xdrawer.cpp).
4.1 Compiling C++ applications or plugins
g++ -O2 -std=c++17 myapp.cpp \
$(pkgconf --cflags --libs x11 xft fontconfig freetype2 pango pangoxft) \
-lneoui -o myapp
4.2 Core C++ classes and helpers
bananarchy::ThemeSpec:- Holds all 29 RGB color tokens (
bgMain,bgHeader,bgFooter,selBg,selFg,accent,fgMain,fgBright,fgMuted,border,divider,success,info,warning,danger, etc.),fontFace,iconFontFace, andbaseFontSize. - Methods:
loadActive(dpy, screen),loadFromFile(path),saveToFile(path),serializeXresources(),recomputeDerivedFromCore(),colorById(id),sizeSmall(),sizeMain(),sizeIcon(),sizeLarge().
- Holds all 29 RGB color tokens (
bananarchy::PluginTheme:- Manages allocated
XftColorinstances (colWhite,colLight,colMuted,colYellow,colGreen,colBlue,colOrange,colRed) andPangoLayout*instances (layoutMain,layoutSmall,layoutIcon,layoutNum) with automatic.Xresourcesmtime/size change detection (checkAndReload()).
- Manages allocated
bananarchy::NeoWindow:- RAII wrapper managing the X11
Display*,Window, offscreenPixmap,GC,XftDraw*,PangoContext*,PangoLayout*(layoutMain,layoutSmall,layoutIcon,layoutNum), andPluginTheme theme. - Methods:
bool create(resName, resClass, title, winX, winY, winW, winH, overrideRedirect, eventMask)void destroy()int drawPango(layout, color, x, y, h, text, maxW = -1, align = 0)(align:0=left,1=center,2=right)int pangoWidth(layout, text)void drawSoftbar(leftLabel, centerLabel, rightLabel, centerCol = nullptr, softbarH = 26)void drawScrollbar(x, y, h, totalItems, visibleItems, scrollOffset)void drawToast(msg, softbarH = 26)void clearBg()/void present()bool checkReloadTheme()/void reloadTheme()void bindAsActiveContext(): binds theNeoWindowinstance as the active C FFI (neoui_*) context so C++ plugins can mixNeoWindowandneoui_draw_*/neoui_poll_event/neoui_input_*helpers seamlessly.
- RAII wrapper managing the X11
- Shared C++20 TCP/TLS/HTTP and MIME helpers (
src/dwm-plugins/net_tls.h):bananarchy::NetStream: non-blocking TCP + OpenSSL (libssl/libcrypto) stream wrapper supporting plain TCP (connectTcp), implicit TLS (connectTls), and opportunisticSTARTTLSupgrade (upgradeToTls), line and chunk reading (readLine,readAll,pollAvailableLines), and raw socket descriptor access (fd()) forpoll().bananarchy::httpGet(url, &bodyOut, timeoutMs, userAgent): lightweight HTTP/HTTPSGETclient with redirect following and chunked transfer decoding (used bygps.sofor OpenStreetMap PNG tiles, Nominatim geocoding, and OSRM routing).bananarchy::md5Hex(data),bananarchy::randomHexToken(numBytes),bananarchy::base64Encode(data),bananarchy::base64Decode(in),bananarchy::decodeQuotedPrintable(in),bananarchy::decodeMimeHeader(in), andbananarchy::stripHtmlTags(in).
- Shared text, multi-tap, and image helpers in
libneoui.so:std::string formatMultiTapBar(prefix, table, activeIdx, makeUpper, maxItems = 7, maxChars = 21): formats a scrolling candidate bar window centered aroundactiveIdxso long symbol sequences (such as the 33-character1key table) never overflow the240pxviewport.std::string tailFitPangoText(layout, text, maxWidthPx): returns the UTF-8 suffix oftextthat fits withinmaxWidthPx.bool loadImageRgb24(path, &outRgb, &outW, &outH): decodes JPEG (libjpeg-turbo), PNG (libpng), or other formats (ffmpegfallback) into 24-bit RGB.void scaleRgb24ToBgrxCanvas(srcRgb, srcW, srcH, dstBgrx, canvasW, canvasH, bgPixel, scaleMode): scales 24-bit RGB into a 32-bit BGRXXImagebuffer (NEO_SCALE_FIT,NEO_SCALE_FILL, orNEO_SCALE_STRETCH).void downscaleViewfinder800x600To240x180(srcRgb, dstBgrx, zoomFactor): rotates the raw800x600GC2395camera frame 90 degrees clockwise and samples the centered 4:3 region (600x450) into the240x180viewfinder buffer.bool saveRgb24AsJpeg(path, rgb, width, height, quality = 92)std::string formatFileSize(bytes)
5. Yabasic SDK reference (neoui.yab)
Bananarchy includes /home/user/Projects/neoui.yab (symlinked to /usr/lib/neoui.yab), which wraps every C FFI function in /usr/lib/libneoui.so using Yabasic's native libffi foreign function interface (frnfn_call and frnfn_call$).
5.1 Running Yabasic NeoUI programs
- From the file manager (
xfiles): navigate to/home/user/Projects/, highlightneoui_demo.yab(or your own.yabfile), and press CenterOK(Return). - From a terminal or SSH:
DISPLAY=:0 yabasic ~/Projects/neoui_demo.yab
5.2 Importing neoui.yab
Because /usr/lib/neoui.yab is symlinked to /home/user/Projects/neoui.yab, any .yab script in any directory can import neoui with a single line:
import neoui
- All exported subroutines can be called directly (e.g.
neoui_init("myapp", 0),neoui_draw_header(...)) or qualified withneoui.(neoui.neoui_init(...)). - All module constants are accessed with the
neoui.prefix (e.g.neoui.TEXT_YELLOW,neoui.FONT_MAIN,neoui.COLOR_ACCENT,neoui.EV_KEY_PRESS,neoui.KEY_OK).
5.3 Exported Yabasic functions in neoui.yab
1. Window and frame lifecycle
neoui_init(app_name$, preload_mode)->1on success,0on errorneoui_init_ex(app_name$, res_name$, res_class$, win_title$, x, y, w, h, override_redirect, preload_mode)neoui_shutdown()neoui_show()/neoui_hide()/neoui_is_visible()neoui_raise_and_grab()/neoui_ungrab()neoui_width()/neoui_height()neoui_begin_frame()/neoui_end_frame()/neoui_flush()
2. Theme, color, and icon resolution
neoui_reload_theme()/neoui_check_reload_theme()neoui_apply_theme_file(xth_path$)/neoui_broadcast_theme_reload(skip_plugin$)neoui_theme_name$()/neoui_font_face$()/neoui_icon_font_face$()neoui_base_font_size()/neoui_font_size(font_role)neoui_color(color_id)neoui_adjust_rgb(rgb, delta)/neoui_blend_rgb(c1, c2, weight2_pct)neoui_parse_hex_rgb(hex_str$, fallback_rgb)/neoui_format_hex_rgb$(rgb)neoui_icon$(icon_name$)
3. Drawing primitives, text, and images
neoui_clear(rgb)neoui_fill_rect(x, y, w, h, rgb)/neoui_draw_rect(x, y, w, h, rgb)neoui_draw_line(x1, y1, x2, y2, rgb)neoui_set_clip(x, y, w, h)/neoui_reset_clip()neoui_draw_text(font_role, color_role, x, y, h, text$, max_w)neoui_draw_text_centered(font_role, color_role, x, y, w, h, text$)neoui_draw_text_right(font_role, color_role, right_x, y, h, text$, max_w)neoui_draw_text_wrapped(font_role, color_role, x, y, w, h, text$, scroll_line)neoui_text_width(font_role, text$)/neoui_tail_fit_text$(font_role, text$, max_w)neoui_draw_image_file(path$, x, y, w, h, scale_mode)
4. Standardized OS shell widgets
neoui_draw_header(icon_str$, icon_color_role, title$, right_badge$)neoui_draw_header_ex(h, icon_str$, icon_color_role, title$, title_color_role, right_badge$, right_color_role)neoui_draw_tabs(pipe_labels$, active_idx, y, h)neoui_draw_softkeys(left_label$, center_label$, right_label$)neoui_draw_softkeys_ex(left_label$, center_label$, right_label$, center_color_role)neoui_draw_list_row(row_index, y, h, is_selected, icon_str$, icon_color_role, title$, subtitle$, right_text$)neoui_draw_slider_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, pct, value_text$)neoui_draw_toggle_row(row_index, y, h, is_selected, icon_str$, icon_color_role, label$, is_on, state_text$)neoui_draw_button(x, y, w, h, is_selected, is_danger, icon_str$, label$)neoui_draw_input_box(x, y, w, h, is_focused, label$, value$, placeholder$, password_mask)neoui_draw_progress_bar(x, y, w, h, pct, fill_rgb)neoui_draw_scrollbar(x, y, h, total_items, visible_items, scroll_offset)neoui_draw_modal_box(x, y, w, h, icon_str$, icon_color_role, title$)neoui_draw_confirm_dialog(title$, line1$, line2$, no_label$, yes_label$, selected_yes)neoui_draw_menu_popup(pipe_items$, pipe_icons$, selected_idx, max_visible_rows)neoui_draw_toast(message$)/neoui_show_toast(message$, duration_ms)/neoui_clear_toast()
5. Event loop, keypad, and multi-tap input
neoui_poll_event(timeout_ms)neoui_event_key()/neoui_event_keycode()/neoui_event_keysym()/neoui_event_command$()neoui_set_chord_xdrawer(enabled)neoui_input_reset(initial_text$)/neoui_input_set_text(text$)/neoui_input_get_text$()neoui_input_set_mode(mode)/neoui_input_get_mode()/neoui_input_cycle_mode()/neoui_input_mode_badge$()neoui_input_feed_key(neo_key)/neoui_input_commit_tap()/neoui_input_backspace()/neoui_input_is_tap_active()neoui_input_candidate_bar$(idle_hint$)/neoui_draw_multitap_bar(x, y, w, h, idle_hint$)
6. System and IPC utilities
neoui_send_plugin_cmd(plugin_name$, cmd$)neoui_vibrate(duration_ms)neoui_now_ms()
5.4 Minimal Yabasic starter template
#!/usr/bin/yabasic
import neoui
if neoui_init("hello_neoui", 0) = 0 then
print "Failed to open X11 window"
exit 1
fi
sel = 0
count = 0
sub render()
neoui_begin_frame()
neoui_draw_header(neoui_icon$("star"), neoui.TEXT_YELLOW, "Hello NeoUI", neoui_theme_name$())
neoui_draw_list_row(0, 42, 38, sel = 0, neoui_icon$("plus"), neoui.TEXT_GREEN, "Increment Counter", "Press OK to add 1", str$(count))
neoui_draw_list_row(1, 80, 38, sel = 1, neoui_icon$("bell"), neoui.TEXT_BLUE, "Vibrate & Toast", "Test haptic feedback", "60ms")
neoui_draw_softkeys("Toast", "Select", "Quit")
neoui_end_frame()
end sub
render()
running = 1
while running
ev = neoui_poll_event(250)
if ev = neoui.EV_CLOSE_REQ or ev = neoui.EV_SOFTKEY_RIGHT then
running = 0
elsif ev = neoui.EV_EXPOSE or ev = neoui.EV_THEME_RELOAD then
render()
elsif ev = neoui.EV_SOFTKEY_LEFT then
neoui_show_toast("Theme: " + neoui_theme_name$(), 1500)
render()
elsif ev = neoui.EV_KEY_PRESS then
k = neoui_event_key()
if k = neoui.KEY_BACK then
running = 0
elsif k = neoui.KEY_UP or k = neoui.KEY_DOWN then
sel = 1 - sel
elsif k = neoui.KEY_OK then
if sel = 0 then
count = count + 1
else
neoui_vibrate(60)
neoui_show_toast("Counter = " + str$(count), 1500)
fi
fi
render()
fi
wend
neoui_shutdown()
6. NeoNet networking SDK reference for Yabasic (neonet.yab)
NeoNet (/home/user/Projects/neonet.yab, symlinked at /usr/lib/neonet.yab) is the native networking library for Yabasic on Bananarchy Linux. It wraps /usr/lib/libcurl.so.4 (OpenSSL, nghttp2, zlib, brotli, zstd, c-ares) and musl libc (open_memstream, getaddrinfo, socket, connect, send, recv, poll) via Yabasic's native libffi interface (frnfn_call, frnfn_call$, and frnbf_*).
6.1 Importing neonet.yab and running the demo
Because /usr/lib/neonet.yab is symlinked to /home/user/Projects/neonet.yab, any Yabasic program can import both neoui and neonet:
import neoui
import neonet
- From the file manager (
xfiles): navigate to/home/user/Projects/, highlightneonet_demo.yab, and press CenterOK(Return). - From a terminal or SSH:
DISPLAY=:0 yabasic ~/Projects/neonet_demo.yab
6.2 Module constants (neonet.*)
| Yabasic constant | Value | Description |
|---|---|---|
neonet.PROTO_TCP |
1 |
Raw TCP socket via libcurl (CURLOPT_CONNECT_ONLY) |
neonet.PROTO_TLS |
2 |
TLS-encrypted socket via libcurl (CURLOPT_CONNECT_ONLY with ALPN disabled for raw TLS protocols) |
neonet.PROTO_UDP |
3 |
Connectionless UDP datagram socket via musl libc (SOCK_DGRAM) |
neonet.CURLE_OK |
0 |
Operation succeeded |
neonet.CURLE_COULDNT_RESOLVE_HOST |
6 |
DNS resolution failed |
neonet.CURLE_COULDNT_CONNECT |
7 |
TCP/UDP connection refused or unreachable |
neonet.CURLE_OPERATION_TIMEDOUT |
28 |
Transfer or socket operation timed out |
neonet.CURLE_SSL_CONNECT_ERROR |
35 |
TLS handshake failed |
neonet.CURLE_PEER_FAILED_VERIFICATION |
60 |
Remote TLS certificate verification failed |
neonet.CURLE_AGAIN |
81 |
Non-blocking socket would block |
6.3 Exported Yabasic functions in neonet.yab
1. Lifecycle, version, and configuration
neonet_init(): initializeslibcurl(curl_global_init) and resets the socket table; returns1on success (0on error). Automatically called on first use if omitted.neonet_cleanup(): closes all active sockets, clears queued custom headers, and callscurl_global_cleanup().neonet_version$(): returns thelibcurland TLS/compression runtime version string (e.g."libcurl/8.23.0 OpenSSL/3.5.9 ...").neonet_strerror$(curl_code): returns the human-readable error message forcurl_code.neonet_set_timeout(timeout_ms): sets the overall transfer timeout in milliseconds (default15000).neonet_set_connect_timeout(connect_timeout_ms): sets the connection timeout in milliseconds (default8000).neonet_set_user_agent(ua$): sets the defaultUser-Agentheader (default"Bananarchy-NeoNet/1.0 (libcurl)").neonet_set_follow_redirects(enabled): enables (1, default) or disables (0) automatic HTTP3xxredirect following.neonet_set_max_redirects(max_redirs): sets the maximum number of redirects to follow (default10).neonet_set_insecure(insecure): when1, disables TLS peer and hostname certificate checks (CURLOPT_SSL_VERIFYPEER = 0,CURLOPT_SSL_VERIFYHOST = 0); when0(default), enforces strict verification.neonet_set_proxy(proxy_url$): sets an HTTP or SOCKS proxy URL (e.g."socks5h://127.0.0.1:9050", or""to disable).neonet_set_basic_auth(user_pwd$): sets HTTP Basic authentication credentials ("user:password", or""to disable).
2. Custom request headers and URL encoding
neonet_clear_headers(): clears all persistent custom HTTP headers added vianeonet_add_header().neonet_add_header(header_line$): appends a persistent custom header (e.g."Authorization: Bearer my_token"or"X-Api-Key: 12345") sent with subsequent HTTP/HTTPS requests.neonet_url_encode$(text$): percent-encodestext$viacurl_easy_escape.neonet_url_decode$(text$): decodes percent-encodedtext$viacurl_easy_unescape.
3. HTTP and HTTPS request functions
(Inline headers$ arguments accept "" for none, or multiple headers separated by | or \n, e.g. "Accept: application/json|X-Client: Bananarchy", which are merged with any persistent headers from neonet_add_header().)
neonet_get$(url$): performs an HTTP/HTTPSGETrequest and returns the response body string.neonet_get_ex$(url$, headers$): performs an HTTP/HTTPSGETrequest with inline custom headers and returns the response body string.neonet_post$(url$, body$, content_type$, headers$): performs an HTTP/HTTPSPOSTrequest withbody$, optionalcontent_type$(e.g."application/json"), and optionalheaders$, returning the response body string.neonet_put$(url$, body$, content_type$, headers$): performs an HTTP/HTTPSPUTrequest and returns the response body string.neonet_patch$(url$, body$, content_type$, headers$): performs an HTTP/HTTPSPATCHrequest and returns the response body string.neonet_delete$(url$, headers$): performs an HTTP/HTTPSDELETErequest and returns the response body string.neonet_head(url$, headers$): performs an HTTP/HTTPSHEADrequest (CURLOPT_NOBODY = 1) and returns the HTTP status code (200,404, etc.), populatingneonet_response_headers$().neonet_request$(method$, url$, body$, headers$): general-purpose HTTP/HTTPS request for any verb ("GET","POST","PUT","PATCH","DELETE","HEAD","OPTIONS"), request body, and custom headers.neonet_download(url$, dest_path$, headers$): downloadsurl$directly todest_path$on disk; returns1on HTTP2xx/3xxsuccess or0on error.
4. HTTP response metadata and header inspection
neonet_status(): returns the HTTP status code from the last transfer (e.g.200,201,404,500, or0on transport failure).neonet_last_code(): returns theCURLcodefrom the last operation (0=CURLE_OK).neonet_error$(): returns""on success, or the human-readable error string on failure.neonet_body$(): returns the last response body string.neonet_body_len(): returns the byte length of the last response body.neonet_response_headers$(): returns the raw HTTP response header block from the last transfer.neonet_header$(name$): performs a case-insensitive lookup of a response header from the last transfer (e.g.neonet_header$("content-type"),neonet_header$("server"),neonet_header$("date")).neonet_content_type$(): returnsCURLINFO_CONTENT_TYPEfromlibcurl.neonet_effective_url$(): returns the final effective URL after redirects (CURLINFO_EFFECTIVE_URL).neonet_primary_ip$(): returns the remote server IP address (CURLINFO_PRIMARY_IP).
5. TCP, TLS, and UDP socket data exchange
- Session-based socket functions:
neonet_connect(proto, host$, port): opens a socket with protocolneonet.PROTO_TCP,neonet.PROTO_TLS, orneonet.PROTO_UDPtohost$:port; returns a socket handlesock_id >= 0on success or-1on error.neonet_tcp_connect(host$, port): shorthand forneonet_connect(neonet.PROTO_TCP, host$, port).neonet_tls_connect(host$, port): shorthand forneonet_connect(neonet.PROTO_TLS, host$, port).neonet_udp_open(host$, port): shorthand forneonet_connect(neonet.PROTO_UDP, host$, port).neonet_send(sock_id, data$): sends stringdata$oversock_id; returns the number of bytes sent (>= 0) or-1on error.neonet_send_bytes(sock_id, frn_buf$, byte_len): sendsbyte_lenraw bytes from a Yabasic foreign buffer (frnbf_alloc$) oversock_id; returns bytes sent or-1on error.neonet_recv$(sock_id, max_bytes, timeout_ms): waits up totimeout_msand reads up tomax_bytesbytes as a string (neonet_last_len()returns the byte count).neonet_recv_all$(sock_id, max_bytes, timeout_ms): reads chunks from a TCP/TLS stream until EOF,max_bytes, or idle timeout, and returns the combined string.neonet_recv_bytes(sock_id, frn_buf$, max_bytes, timeout_ms): waits up totimeout_msand reads up tomax_bytesraw bytes into foreign bufferfrn_buf$, returning the number of bytes read (> 0),0on EOF/timeout, or-1on error.neonet_last_len(): returns the byte count transferred by the most recent socket or HTTP operation.neonet_close(sock_id): closes socketsock_idand releases its slot.
- One-shot socket exchange and DNS helpers:
neonet_tcp_exchange$(host$, port, payload$, timeout_ms): connects via TCP, sendspayload$, reads the response, closes the socket, and returns the response string.neonet_tls_exchange$(host$, port, payload$, timeout_ms): connects via TLS, sendspayload$, reads the response, closes the socket, and returns the response string.neonet_udp_exchange$(host$, port, payload$, timeout_ms): sends a UDP datagrampayload$tohost$:port, waits up totimeout_msfor a reply datagram, closes the socket, and returns the reply string.neonet_system_dns$(): returns the primarynameserverIP address from/etc/resolv.conf(fallback"1.1.1.1").neonet_udp_dns_a$(dns_server$, domain$, timeout_ms): sends a binary RFC 1035 UDP DNS A-record query todns_server$:53(or the system DNS ifdns_server$ = "") and returns the resolved IPv4 address string.
6.4 Minimal Yabasic NeoNet + NeoUI example
#!/usr/bin/yabasic
import neoui
import neonet
r = neonet_init()
// 1. HTTPS GET with custom headers
body$ = neonet_get_ex$("https://example.com/", "X-Bananarchy: NeoNet-1.0|Accept: text/html")
print "HTTP status: ", neonet_status(), " (", neonet_body_len(), " bytes from ", neonet_primary_ip$(), ")"
print "Server header: ", neonet_header$("server")
// 2. One-shot TCP WHOIS query (port 43)
whois$ = neonet_tcp_exchange$("whois.iana.org", 43, "example.com" + chr$(13) + chr$(10), 4000)
print "WHOIS bytes: ", neonet_last_len()
// 3. Binary UDP DNS A-record lookup (port 53)
ip$ = neonet_udp_dns_a$("", "example.com", 3000)
print "UDP DNS resolved example.com -> ", ip$
r = neonet_cleanup()