Add NeoNet Yabasic networking FFI library, fix fcitx5 service and WM context menus, install yabasic-doc and mandoc

This commit is contained in:
Luxferre committed 2026-10-27 07:39:07 +02:00
1 parent fb3723fab4
commit 726500085a
33 files changed
+2608 -60

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ It uses a pure **X11 (`Xlibre` + `sxmo-de-dwm`)** stack (no Wayland) optimized f
## 2. Repository layout
- `src/sxmo-dwm/`: patched `dwm` window manager (`240x320` vertical `bstack` layout, 24px Pango status bar, desktop `"Menu"`/`"Names"` softkey bar, C-level `SW_LID` slider and locked-key wake handling, live `.Xresources` reload, and `.so` plugin loader via `dwm_plugin.h`).
- `src/sxmo-dmenu/`: zero-lag resident DWM menu plugin (`dmenu.so`) and `/tmp/dwm_plugin_dmenu.sock` client (`dmenu` / `xdmenu`), featuring built-in Sxmo menus (`sys`, `applications`, `scripts`, `modem`, `config`, `power`, `audio`, `notifications`, `wm`, `timezone`, `games`, `st`, `nano`, `sthotkeys`) and `fcitx5-t9` XIM input.
- `src/neoui/`: **NeoUI** `240x320` UI SDK (`neoui.h` -> `/usr/include/neoui.h`, `neoui.cpp` -> `/usr/lib/libneoui.so`) providing both a C-compatible FFI (`neoui_*`) and C++20 classes (`ThemeSpec`, `PluginTheme`, `NeoWindow`) for `.Xresources` / `~/.xthemes/*.xth` theme resolution, Xlib/Xft/Pango window and offscreen `Pixmap` double buffering, standardized OS shell widgets, keypad/softkey chord handling, and multi-tap input.
- `src/neoui/`: **NeoUI** `240x320` UI SDK (`neoui.h` -> `/usr/include/neoui.h`, `neoui.cpp` -> `/usr/lib/libneoui.so`) providing both a C-compatible FFI (`neoui_*`) and C++20 classes (`ThemeSpec`, `PluginTheme`, `NeoWindow`) for `.Xresources` / `~/.xthemes/*.xth` theme resolution, Xlib/Xft/Pango window and offscreen `Pixmap` double buffering, standardized OS shell widgets, keypad/softkey chord handling, and multi-tap input (paired with Yabasic FFI libraries `neoui.yab` and `neonet.yab` + demos `neoui_demo.yab` and `neonet_demo.yab` in `overlay/rootfs/home/user/Projects/`).
- `src/dwm-plugins/`: preloaded C++20 `240x320` DWM plugins linked against `libneoui.so` and shared headers:
- `theme.h`: header forwarding to `../neoui/neoui.h` for unified `.Xresources` / `~/.xthemes/*.xth` parsing, proportional font sizing (`theme.baseFontSize`), automatic shade derivation, and live Xft/Pango theme reloading (`PluginTheme`).
- `phone_data.h`: shared X11 geometry (`240x296` below the 24px bar), FIFO IPC (`/tmp/dwm_plugin_<name>.fifo`), softkey chord detection, Sxmo TSV contact/call/SMS parsers, and `libjpeg`/`libpng` helpers.
+6 -4
View File
@@ -21,16 +21,18 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
- 10 built-in DMG color palettes, 4 screen scaling modes (`Fit 240x216` 1.5x area-interpolated, `1:1 160x144`, `Fill 240x246`, `Full 240x296`), 10 save-state slots (`.st0`–`.st9`), automatic battery SRAM/RTC persistence, seamless `Xdrawer` focus handoff, and direct low-latency `libasound` (`hw:0,0`) audio with hardware volume synchronization and analog-stage low-pass filtering.
- Preinstalled open-source / public-domain GB and GBC games in `/usr/share/games/gb/` and `~/Games/` (`2048.gb`, `adjustris.gb`, `blastah.gb`, `brickster.gbc`, `geometrix.gbc`, `ucity.gbc`).
- **Preinstalled scripting, calculation tools, and file manager (`xfiles`) integration**:
- Added **Lua** (`lua5.5` and `lua5.4` with `/usr/bin/lua` and `/usr/bin/luac`), **GNU `bc` / `dc`**, and **Yabasic (`yabasic`)** to the default system image.
- Added **Lua** (`lua5.5` and `lua5.4` with `/usr/bin/lua` and `/usr/bin/luac`), **GNU `bc` / `dc`**, **`mandoc`**, and **Yabasic (`yabasic` and `yabasic-doc`)** to the default system image.
- Selecting any `.yab` file in **file manager (`xfiles`)** (or choosing `Run in Yabasic (Terminal)` in its actions menu) runs `yabasic` inside the `st` terminal and pauses on exit so output can be inspected.
- Added an **integrated GUI text editor (`Edit in Text Editor`)** inside `xfiles`, available as an action on any file (and automatically opened when creating a new file or pressing `Edit` in the text viewer), featuring line numbers, 2D cursor navigation, 5 multi-tap input modes (`[abc]`, `[Abc]`, `[ABC]`, `[123]`, `[Sym]`), a scrolling bottom candidate bar for long symbol tables (`1` key), and an editor menu (`Save File`, `Save & Close`, `Insert New Line`, `Insert Space`, `Duplicate Line`, `Delete Line`, `Close Without Saving`).
- **NeoUI `240x320` UI SDK (`libneoui.so` + `/usr/include/neoui.h` + `neoui.yab`)**:
- **NeoUI `240x320` UI SDK (`libneoui.so` + `/usr/include/neoui.h` + `neoui.yab`) and NeoNet (`neonet.yab`)**:
- Standardized all Bananarchy `240x320` X11/Xft/Pango UI components, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, FIFO IPC, softkey chord detection (`xdrawer`), and multi-tap input into a shared library (`/usr/lib/libneoui.so`) and header (`/usr/include/neoui.h`) with both C++20 classes and a C-compatible FFI (`neoui_*`).
- Migrated all 14 custom GUI plugins (`xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`) to use `NeoUI`.
- Added a complete Yabasic native C FFI wrapper (`~/Projects/neoui.yab`, symlinked at `/usr/lib/neoui.yab`), an interactive 3-tab showcase program (`~/Projects/neoui_demo.yab`), and full SDK documentation in `SDK.md`.
- Added a complete Yabasic native C FFI wrapper (`~/Projects/neoui.yab`, symlinked at `/usr/lib/neoui.yab`), an interactive 3-tab UI showcase program (`~/Projects/neoui_demo.yab`), a `libcurl` + socket FFI networking library for Yabasic (`~/Projects/neonet.yab`, symlinked at `/usr/lib/neonet.yab`) supporting HTTP/HTTPS requests with custom headers and raw TCP/TLS/UDP socket data exchange, a combined NeoNet + NeoUI demo (`~/Projects/neonet_demo.yab`), and full SDK documentation in `SDK.md`.
- **Camera viewfinder and capture orientation fix (`xcamera` and `bananarchy-photo`)**:
- Rotated the raw `800x600` `GC2395` sensor frames 90 degrees clockwise in both the live `240x180` 4:3 viewfinder (`downscaleViewfinder800x600To240x180`) and captured JPEG photos (`600x800` portrait output in `xcamera` and `bananarchy-photo`).
- **Menu refinements**:
- **Window management, context menu, and `fcitx5` XIM stability fixes**:
- Added direct C-level `_BANANARCHY_DWM_CMD` IPC between `dmenu` and `dwm` for instant window management (`Kill window`, `Close Terminal`, `Move to WS 1..4`, `Go to WS 1..4`, `Shift stack`, `Swap stack`, `Toggle Layout`) and restored application context menus (`Right softkey` inside `st`, `nano`, and X11 apps).
- Updated the `fcitx5` `superd` service wrapper (`bananarchy-fcitx5.sh`) and XIM environment propagation across `st`, `dmenu`, and `dwm-plugin` so T9 keypad input stays supervised and active across all terminal and menu sessions.
- Removed the non-applicable `Toggle Bar` entry from the `Config` menu.
---
+3 -2
View File
@@ -26,7 +26,7 @@ This manual covers flashing, operating, and customizing **Bananarchy Linux** (`2
- **Patched `dwm`** provides a `240x320` vertical bottom-stack (`bstack`) layout, a 24px top status bar, a transparent `"Menu"` / `"Names"` desktop softkey bar, a Conky desktop clock and status widget (which refreshes automatically when changing time, timezone, or wallpaper, or when logging out), and `< 2 ms` handling of physical slider (`SW_LID`) and wake keys.
2. **Preloaded resident DWM plugins (`< 2 ms` wakeup)**:
- Core phone applications (`dmenu`, `xdrawer`, `dialer`, `calllog`, `callscreen`, `contacts`, `sms`, `files`, `camera`, `themes`, `modem`, `networks`, `ringtones`, `wallpapers`, `music`) run as preloaded resident daemons (`dwm-plugin <name> --preload`) that sleep at 0% CPU and open instantaneously over FIFO/socket IPC.
- All UI elements share the **NeoUI SDK (`libneoui.so` + `/usr/include/neoui.h`)** and a single **XRDB theming engine** (`~/.xthemes/*.xth` -> `~/.Xresources`) with 20 preinstalled color schemes, proportional font sizing (`theme.baseFontSize`), and live reload without restarting X11. NeoUI exposes both C++20 classes and a C-compatible FFI (`neoui_*`) for building custom native or scripted (`yabasic` via `~/Projects/neoui.yab`, etc.) `240x320` GUI applications — see [SDK.md](./SDK.md) for the complete API reference and examples.
- All UI elements share the **NeoUI SDK (`libneoui.so` + `/usr/include/neoui.h`)** and a single **XRDB theming engine** (`~/.xthemes/*.xth` -> `~/.Xresources`) with 20 preinstalled color schemes, proportional font sizing (`theme.baseFontSize`), and live reload without restarting X11. NeoUI exposes both C++20 classes and a C-compatible FFI (`neoui_*`) for building custom native or scripted (`yabasic` via `~/Projects/neoui.yab` and `~/Projects/neoui_demo.yab`, paired with **NeoNet** in `~/Projects/neonet.yab` and `~/Projects/neonet_demo.yab` for `libcurl` HTTP/HTTPS and TCP/TLS/UDP socket networking) `240x320` GUI applications — see [SDK.md](./SDK.md) for the complete API reference and examples.
3. **First-class terminal (`st`) and 6-mode `fcitx5-t9` keypad input**:
- `st` is patched with HarfBuzz OpenType ligature shaping (`Fira Code` default) and live `.Xresources` reload.
- `fcitx5-t9` provides 6 keypad input modes (`abc`, `Abc`, `ABC`, `Sym`, `Ctl`, `123` + `*` long-press `Ctrl+` latch) in a fixed bottom candidate bar (`Y = 290, H = 30`).
@@ -105,7 +105,8 @@ sudo dd if=./images/bananarchy-nokia-argon.img of=/dev/sdX bs=4M status=progress
#### 3.1.1 Window tiling modes and switching combos
By default, `dwm` uses the **vertical bottom-stack (`bstack`, `TTT`)** layout so multiple `st` terminals stack **vertically (one under another)** to preserve full line width on the `240x320` portrait screen.
You can switch layouts and focus using either physical keypad multi-presses or an external keyboard (`Mod4` / `Super`):
You can switch layouts, focus, and workspaces using the **Window management menu (`Windows`)** (accessible via `Left softkey -> Windows`, or by pressing **Right softkey** inside non-terminal applications, or selecting `Windows` from the `st` terminal context menu), physical keypad multi-presses, or an external keyboard (`Mod4` / `Super`):
- **Window management menu (`WM Menu`)**: provides instant C-level window actions (`Move to WS 1`..`4`, `Shift stack`, `Swap stack`, `Toggle Layout`, `Kill window`, and `Go to WS 1`..`4`), plus `Close Terminal` in the `st` context menu.
- **Triple-press Call (green) (`3x Call`)**: cycle the active layout (`TTT` -> `[]=` -> `[D]` -> `[M]` -> `TTT`).
- **Double-press Call (green) (`2x Call`)**: move focus to the next open window (`Super+j`).
- **Triple-press End / Power (red) (`3x End`)**: launch a new `st` terminal in the active workspace.
+3 -3
View File
@@ -8,7 +8,7 @@
- **Download the recent images for your device from this link**: https://cloud.disroot.org/s/dB7bM7sRTScetDJ
- **Project philosophy**: read [The Bananarchy Manifesto](./MANIFESTO.md) for the background and goals behind the distribution.
- **User and flashing guide**: see the [user manual](./MANUAL.md) for installation, keypad navigation, and hardware details.
- **UI SDK reference**: see the [NeoUI SDK guide](./SDK.md) for building native C, C++, and Yabasic `240x320` GUI applications.
- **UI and networking SDK reference**: see the [NeoUI and NeoNet SDK guide](./SDK.md) for building native C, C++, and Yabasic `240x320` GUI and networked applications.
---
@@ -33,8 +33,8 @@ Instead of spawning slow shell scripts for everyday phone tasks, Bananarchy runs
### Input, terminal, and developer tools
- **6-mode `fcitx5-t9` keypad input**: press `#` to cycle between `abc`, `Abc`, `ABC`, `Sym` (all 32 ASCII punctuation symbols), `Ctl` (`Ctrl` sequences, arrows, `PageUp`/`PageDown`, `F1`–`F12`), and `123` numeric modes with a fixed bottom candidate bar.
- **First-class Linux terminal (`st`)**: patched with HarfBuzz OpenType ligatures (`Fira Code` as the default system and terminal font), XIM T9 input, and live theme reloading.
- **On-device development, scripting, and gaming**: preinstalled `gcc`/`g++`, `make`, `git`, GNU `coreutils`, GNU `bc`/`dc`, `nano`, `ed`, `sqlite3`, `lua` (`5.5` and `5.4`), `yabasic`, `perl`, `tcl`, the [Janet](https://janet-lang.org/) language and `jpm`, the [Bantam](https://bantam.luxferre.top/) coding agent, `frotz` (interactive fiction), standalone X11 keypad games (`Snake` and `Tetris`), and a full-featured Gambatte-based Game Boy / Game Boy Color emulator (`gambatte` / `gbemu`) with readjustable keypad controls (`B=8`, `Turbo B=5`, `A=9`, `Turbo A=6`, `D-pad`, `Start=2`, `Select=3`, `Palette=*`), 10 color palettes, save states, and file manager `.gb`/`.gbc` integration.
- **NeoUI 240x320 UI SDK (`libneoui.so` + `/usr/include/neoui.h` + `neoui.yab`)**: unified C-compatible FFI and C++20 UI SDK wrapping Xlib, Xft, Pango, `libjpeg`/`libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets (headers, tabs, softkey bars, list/toggle/slider rows, input boxes, progress bars, scrollbars, modals, popup menus, and toasts), keypad/softkey chord handling, and multi-tap text entry—usable from C, C++, or Yabasic (`~/Projects/neoui.yab` and `~/Projects/neoui_demo.yab`). See [SDK.md](./SDK.md) for full documentation.
- **On-device development, scripting, and gaming**: preinstalled `gcc`/`g++`, `make`, `git`, GNU `coreutils`, GNU `bc`/`dc`, `mandoc`, `nano`, `ed`, `sqlite3`, `lua` (`5.5` and `5.4`), `yabasic` (with full `yabasic-doc` manual and HTML documentation), `perl`, `tcl`, the [Janet](https://janet-lang.org/) language and `jpm`, the [Bantam](https://bantam.luxferre.top/) coding agent, `frotz` (interactive fiction), standalone X11 keypad games (`Snake` and `Tetris`), and a full-featured Gambatte-based Game Boy / Game Boy Color emulator (`gambatte` / `gbemu`) with readjustable keypad controls (`B=8`, `Turbo B=5`, `A=9`, `Turbo A=6`, `D-pad`, `Start=2`, `Select=3`, `Palette=*`), 10 color palettes, save states, and file manager `.gb`/`.gbc` integration.
- **NeoUI `240x320` UI SDK (`libneoui.so` + `/usr/include/neoui.h` + `neoui.yab`) and NeoNet (`neonet.yab`)**: unified C-compatible FFI and C++20 UI SDK wrapping Xlib, Xft, Pango, `libjpeg`/`libpng`, `.Xresources` / `~/.xthemes/*.xth` live theme resolution, offscreen `Pixmap` double buffering, standardized OS shell widgets (headers, tabs, softkey bars, list/toggle/slider rows, input boxes, progress bars, scrollbars, modals, popup menus, and toasts), keypad/softkey chord handling, and multi-tap text entry—usable from C, C++, or Yabasic (`~/Projects/neoui.yab` and `~/Projects/neoui_demo.yab`), paired with **NeoNet (`~/Projects/neonet.yab` and `~/Projects/neonet_demo.yab`)** for `libcurl`-based HTTP/HTTPS requests with custom headers and TCP/TLS/UDP socket exchange in Yabasic. See [SDK.md](./SDK.md) for full documentation.
---
+133 -5
View File
@@ -1,11 +1,12 @@
# Bananarchy NeoUI SDK reference (`SDK.md`)
# 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**.
**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.
It encapsulates 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`), and multi-tap T9 keypad input behind:
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:
1. A **C-compatible FFI (`neoui_*`)** designed for both C programs and foreign-function interfaces (such as **Yabasic** `frnfn_call` / `frnfn_call$`, LuaJIT FFI, Janet, Python `ctypes`, etc.).
2. A **C++20 SDK (`namespace bananarchy`)** providing `ThemeSpec`, `PluginTheme`, `NeoWindow`, and direct Pango/Xft/image helpers used across all 14 built-in Bananarchy DWM plugins.
3. A **Yabasic 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`).
3. 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`).
4. A **Yabasic networking wrapper library (`neonet.yab`)** preinstalled in `/home/user/Projects/neonet.yab` (and symlinked at `/usr/lib/neonet.yab`), wrapping `libcurl.so.4` and musl `libc` via `libffi` for 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`).
---
@@ -15,9 +16,12 @@ It encapsulates all low-level X11 (`Xlib`), `Xft`, `Pango`, `libjpeg-turbo`, `li
| :--- | :--- | :--- |
| `/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 (`import neoui`) |
| `/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 (`240x296` at `X=0, Y=24`, directly below the 24px `dwm` top status bar) renders into an offscreen X11 `Pixmap` during `neoui_begin_frame()` .. `neoui_end_frame()` and copies the completed frame to the visible window in a single `XCopyArea` call.
@@ -526,3 +530,127 @@ 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`:
```yabasic
import neoui
import neonet
```
- **From the file manager (`xfiles`)**: navigate to `/home/user/Projects/`, highlight `neonet_demo.yab`, and press **Center `OK` (`Return`)**.
- **From a terminal or SSH**:
```bash
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()`: initializes `libcurl` (`curl_global_init`) and resets the socket table; returns `1` on success (`0` on error). Automatically called on first use if omitted.
- `neonet_cleanup()`: closes all active sockets, clears queued custom headers, and calls `curl_global_cleanup()`.
- `neonet_version$()`: returns the `libcurl` and 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 for `curl_code`.
- `neonet_set_timeout(timeout_ms)`: sets the overall transfer timeout in milliseconds (default `15000`).
- `neonet_set_connect_timeout(connect_timeout_ms)`: sets the connection timeout in milliseconds (default `8000`).
- `neonet_set_user_agent(ua$)`: sets the default `User-Agent` header (default `"Bananarchy-NeoNet/1.0 (libcurl)"`).
- `neonet_set_follow_redirects(enabled)`: enables (`1`, default) or disables (`0`) automatic HTTP `3xx` redirect following.
- `neonet_set_max_redirects(max_redirs)`: sets the maximum number of redirects to follow (default `10`).
- `neonet_set_insecure(insecure)`: when `1`, disables TLS peer and hostname certificate checks (`CURLOPT_SSL_VERIFYPEER = 0`, `CURLOPT_SSL_VERIFYHOST = 0`); when `0` (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 via `neonet_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-encodes `text$` via `curl_easy_escape`.
- `neonet_url_decode$(text$)`: decodes percent-encoded `text$` via `curl_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/HTTPS `GET` request and returns the response body string.
- `neonet_get_ex$(url$, headers$)`: performs an HTTP/HTTPS `GET` request with inline custom headers and returns the response body string.
- `neonet_post$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `POST` request with `body$`, optional `content_type$` (e.g. `"application/json"`), and optional `headers$`, returning the response body string.
- `neonet_put$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `PUT` request and returns the response body string.
- `neonet_patch$(url$, body$, content_type$, headers$)`: performs an HTTP/HTTPS `PATCH` request and returns the response body string.
- `neonet_delete$(url$, headers$)`: performs an HTTP/HTTPS `DELETE` request and returns the response body string.
- `neonet_head(url$, headers$)`: performs an HTTP/HTTPS `HEAD` request (`CURLOPT_NOBODY = 1`) and returns the HTTP status code (`200`, `404`, etc.), populating `neonet_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$)`: downloads `url$` directly to `dest_path$` on disk; returns `1` on HTTP `2xx`/`3xx` success or `0` on 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`, or `0` on transport failure).
- `neonet_last_code()`: returns the `CURLcode` from 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$()`: returns `CURLINFO_CONTENT_TYPE` from `libcurl`.
- `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 protocol `neonet.PROTO_TCP`, `neonet.PROTO_TLS`, or `neonet.PROTO_UDP` to `host$:port`; returns a socket handle `sock_id >= 0` on success or `-1` on error.
- `neonet_tcp_connect(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_TCP, host$, port)`.
- `neonet_tls_connect(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_TLS, host$, port)`.
- `neonet_udp_open(host$, port)`: shorthand for `neonet_connect(neonet.PROTO_UDP, host$, port)`.
- `neonet_send(sock_id, data$)`: sends string `data$` over `sock_id`; returns the number of bytes sent (`>= 0`) or `-1` on error.
- `neonet_send_bytes(sock_id, frn_buf$, byte_len)`: sends `byte_len` raw bytes from a Yabasic foreign buffer (`frnbf_alloc$`) over `sock_id`; returns bytes sent or `-1` on error.
- `neonet_recv$(sock_id, max_bytes, timeout_ms)`: waits up to `timeout_ms` and reads up to `max_bytes` bytes 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 to `timeout_ms` and reads up to `max_bytes` raw bytes into foreign buffer `frn_buf$`, returning the number of bytes read (`> 0`), `0` on EOF/timeout, or `-1` on error.
- `neonet_last_len()`: returns the byte count transferred by the most recent socket or HTTP operation.
- `neonet_close(sock_id)`: closes socket `sock_id` and releases its slot.
- **One-shot socket exchange and DNS helpers**:
- `neonet_tcp_exchange$(host$, port, payload$, timeout_ms)`: connects via TCP, sends `payload$`, reads the response, closes the socket, and returns the response string.
- `neonet_tls_exchange$(host$, port, payload$, timeout_ms)`: connects via TLS, sends `payload$`, reads the response, closes the socket, and returns the response string.
- `neonet_udp_exchange$(host$, port, payload$, timeout_ms)`: sends a UDP datagram `payload$` to `host$:port`, waits up to `timeout_ms` for a reply datagram, closes the socket, and returns the reply string.
- `neonet_system_dns$()`: returns the primary `nameserver` IP 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 to `dns_server$:53` (or the system DNS if `dns_server$ = ""`) and returns the resolved IPv4 address string.
### 6.4 Minimal Yabasic NeoNet + NeoUI example
```yabasic
#!/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()
```
File diff suppressed because it is too large. Load diff
+629
View File
@@ -0,0 +1,629 @@
#!/usr/bin/yabasic
// ============================================================================
// neonet_demo.yab - Bananarchy NeoNet + NeoUI Showcase for Yabasic
// ============================================================================
// Demonstrates combining NeoNet (libcurl + socket FFI) with NeoUI (240x320 UI):
// - Tab 1 (1:HTTP/S): HTTP/HTTPS GET, POST, and HEAD requests with custom
// headers, status code badge, server/IP inspection, and scrollable output
// - Tab 2 (2:Sockets): Raw TLS (port 443), TCP (port 43 WHOIS), and binary
// UDP (port 53 DNS A-record) socket data exchange
// - Tab 3 (3:Tools): URL encode/decode, file download to /tmp, TLS verify
// toggle, and libcurl version/capability inspection
//
// Controls:
// - 1 / 2 / 3 (when not typing in an input box): Switch tabs
// - Up / Down: Navigate controls or scroll response viewer
// - Left / Right: Cycle HTTP method / socket protocol or switch tabs
// - OK (Enter): Execute request / toggle option / edit input
// - Left Softkey (F1): Open Presets & Actions menu
// - Right Softkey (F2) / Backspace: Delete char (in input) or Quit
// - Both Softkeys together: Open Bananarchy XDrawer overlay
// ============================================================================
import neoui
import neonet
if neoui_init("neonet_demo", 0) = 0 then
print "Failed to initialize NeoUI X11 window"
exit 1
fi
r = neonet_init()
r = neonet_set_timeout(10000)
r = neonet_set_connect_timeout(6000)
// Active tab: 0 = HTTP/S, 1 = Sockets, 2 = Tools & Info
active_tab = 0
// Tab 0 (HTTP/S) state
http_focus = 2
http_url$ = "https://example.com/"
http_method_idx = 0
dim http_methods$(3)
http_methods$(0) = "GET"
http_methods$(1) = "POST"
http_methods$(2) = "HEAD"
custom_hdr_on = 1
custom_hdr$ = "X-Bananarchy: NeoNet-1.0|Accept: */*"
show_raw_headers = 0
http_status_str$ = "Ready (press OK on Send)"
http_meta_str$ = "Custom Header: X-Bananarchy"
http_output$ = "Press OK on [Send] or open Left Softkey Menu for presets."
http_scroll = 0
// Tab 1 (Sockets) state
sock_focus = 2
sock_proto_idx = 0
dim sock_protos$(3)
sock_protos$(0) = "TLS :443 (HTTPS Raw)"
sock_protos$(1) = "TCP :43 (IANA WHOIS)"
sock_protos$(2) = "UDP :53 (DNS Query)"
sock_host$ = "example.com"
sock_status_str$ = "Ready (select protocol & Run)"
sock_output$ = "Supports raw TLS, TCP, and UDP socket data exchange."
sock_scroll = 0
// Tab 2 (Tools) state
tool_focus = 0
tls_insecure = 0
sample_raw$ = "Bananarchy 240x320 & NeoNet!"
sample_enc$ = neonet_url_encode$(sample_raw$)
dl_status$ = "Not downloaded yet"
// Modal state: 0 = None, 1 = Presets Menu
modal_mode = 0
menu_sel = 0
// Track which input box owns multi-tap buffer (0 = http_url$, 1 = sock_host$)
active_input_owner = -1
sub sync_input_box(owner_id)
if active_input_owner = owner_id then
return
fi
active_input_owner = owner_id
if owner_id = 0 then
neoui_input_reset(http_url$)
elsif owner_id = 1 then
neoui_input_reset(sock_host$)
fi
end sub
sub save_input_box()
if active_input_owner = 0 then
neoui_input_commit_tap()
http_url$ = neoui_input_get_text$()
elsif active_input_owner = 1 then
neoui_input_commit_tap()
sock_host$ = neoui_input_get_text$()
fi
end sub
sub sanitize_display_text$(s$, max_chars)
local out$, n, i, ch$, code
n = len(s$)
if n > max_chars then
n = max_chars
fi
out$ = ""
for i = 1 to n
ch$ = mid$(s$, i, 1)
code = asc(ch$)
if code = 10 or (code >= 32 and code <= 126) then
out$ = out$ + ch$
elsif code = 9 then
out$ = out$ + " "
fi
next i
return out$
end sub
sub run_http_request()
local m$, hdrs$, body$, st, blen, srv$, ip$
save_input_box()
m$ = http_methods$(http_method_idx)
if custom_hdr_on then
hdrs$ = custom_hdr$
else
hdrs$ = ""
fi
neoui_show_toast(m$ + " " + http_url$ + " ...", 500)
render_all()
neoui_flush()
if m$ = "GET" then
body$ = neonet_get_ex$(http_url$, hdrs$)
elsif m$ = "POST" then
body$ = neonet_post$(http_url$, "{\"device\":\"nokia-argon\",\"sdk\":\"NeoNet\"}", "application/json", hdrs$)
else
st = neonet_head(http_url$, hdrs$)
body$ = neonet_response_headers$()
fi
st = neonet_status()
blen = neonet_body_len()
http_scroll = 0
if neonet_last_code() <> 0 then
http_status_str$ = "ERR (" + str$(neonet_last_code()) + "): " + neonet_error$()
http_meta_str$ = "URL: " + http_url$
http_output$ = "Request failed: " + neonet_error$()
neoui_show_toast("HTTP error!", 1600)
else
srv$ = neonet_header$("server")
if srv$ = "" then
srv$ = "n/a"
fi
ip$ = neonet_primary_ip$()
http_status_str$ = m$ + " -> HTTP " + str$(st) + " (" + str$(blen) + " B)"
http_meta_str$ = "IP: " + ip$ + " Srv: " + srv$
if show_raw_headers or m$ = "HEAD" then
http_output$ = sanitize_display_text$(neonet_response_headers$(), 1800)
else
http_output$ = sanitize_display_text$(body$, 1800)
fi
neoui_show_toast("HTTP " + str$(st) + " (" + str$(blen) + " B)", 1500)
fi
end sub
sub run_socket_exchange()
local crlf$, req$, rx$, ip$, dns_srv$
save_input_box()
crlf$ = chr$(13) + chr$(10)
sock_scroll = 0
if sock_proto_idx = 0 then
neoui_show_toast("TLS connect " + sock_host$ + ":443 ...", 500)
render_all()
neoui_flush()
req$ = "HEAD / HTTP/1.1" + crlf$ + "Host: " + sock_host$ + crlf$ + "User-Agent: NeoNet-TLS/1.0" + crlf$ + "Connection: close" + crlf$ + crlf$
rx$ = neonet_tls_exchange$(sock_host$, 443, req$, 4000)
if rx$ = "" and neonet_error$() <> "" then
sock_status_str$ = "TLS Error: " + neonet_error$()
sock_output$ = "Could not complete TLS exchange with " + sock_host$ + ":443"
neoui_show_toast("TLS failed", 1500)
else
sock_status_str$ = "TLS :443 OK (" + str$(neonet_last_len()) + " B recv)"
sock_output$ = sanitize_display_text$(rx$, 1800)
neoui_show_toast("TLS recv " + str$(neonet_last_len()) + " B", 1500)
fi
elsif sock_proto_idx = 1 then
neoui_show_toast("TCP connect whois.iana.org:43 ...", 500)
render_all()
neoui_flush()
rx$ = neonet_tcp_exchange$("whois.iana.org", 43, sock_host$ + crlf$, 4000)
if rx$ = "" and neonet_error$() <> "" then
sock_status_str$ = "TCP Error: " + neonet_error$()
sock_output$ = "Could not query whois.iana.org:43"
neoui_show_toast("TCP failed", 1500)
else
sock_status_str$ = "TCP :43 OK (" + str$(neonet_last_len()) + " B recv)"
sock_output$ = sanitize_display_text$(rx$, 1800)
neoui_show_toast("TCP recv " + str$(neonet_last_len()) + " B", 1500)
fi
else
dns_srv$ = neonet_system_dns$()
neoui_show_toast("UDP DNS @" + dns_srv$ + ":53 ...", 500)
render_all()
neoui_flush()
ip$ = neonet_udp_dns_a$(dns_srv$, sock_host$, 3000)
if ip$ = "" then
sock_status_str$ = "UDP DNS Error: " + neonet_error$()
sock_output$ = "Resolver: " + dns_srv$ + ":53\nQuery: " + sock_host$ + "\nError: " + neonet_error$()
neoui_show_toast("UDP DNS failed", 1500)
else
sock_status_str$ = "UDP :53 -> " + ip$
sock_output$ = "Protocol: RFC 1035 Binary UDP Datagram\nServer: " + dns_srv$ + ":53\nQuestion: " + sock_host$ + " (IN A)\nResolved IPv4: " + ip$ + "\nPacket Size: " + str$(neonet_last_len()) + " bytes"
neoui_show_toast(sock_host$ + " -> " + ip$, 1800)
fi
fi
end sub
sub render_http_tab()
local url_disp$, hdr_state$, view_lbl$
if http_focus = 0 then
sync_input_box(0)
url_disp$ = neoui_input_get_text$()
else
url_disp$ = http_url$
fi
neoui_draw_input_box(6, 60, 228, 36, http_focus = 0, "Target URL [" + http_methods$(http_method_idx) + "]", url_disp$, "https://...", 0)
if custom_hdr_on then
hdr_state$ = "ON"
else
hdr_state$ = "OFF"
fi
neoui_draw_toggle_row(0, 98, 28, http_focus = 1, neoui_icon$("edit"), neoui.TEXT_BLUE, "Hdr: X-Bananarchy", custom_hdr_on, hdr_state$)
if show_raw_headers then
view_lbl$ = "Show:Hdrs"
else
view_lbl$ = "Show:Body"
fi
neoui_draw_button(6, 128, 72, 22, http_focus = 2, 0, neoui_icon$("globe"), "Send")
neoui_draw_button(84, 128, 72, 22, http_focus = 3, 0, neoui_icon$("sort"), "Method")
neoui_draw_button(162, 128, 72, 22, http_focus = 4, 0, neoui_icon$("eye"), view_lbl$)
neoui_fill_rect(6, 153, 228, 114, neoui_color(neoui.COLOR_BG_ALT_ODD))
if http_focus = 5 then
neoui_draw_rect(6, 153, 228, 114, neoui_color(neoui.COLOR_ACCENT))
else
neoui_draw_rect(6, 153, 228, 114, neoui_color(neoui.COLOR_BORDER))
fi
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_GREEN, 10, 155, 14, http_status_str$, 220)
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 10, 169, 14, http_meta_str$, 220)
neoui_draw_line(8, 184, 232, 184, neoui_color(neoui.COLOR_DIVIDER))
neoui_draw_text_wrapped(neoui.FONT_SMALL, neoui.TEXT_LIGHT, 10, 186, 220, 78, http_output$, http_scroll)
if http_focus = 0 then
neoui_draw_multitap_bar(0, 248, 240, 22, "0-9:Type 1:Sym #:Mode OK:Send")
fi
end sub
sub render_sockets_tab()
local host_disp$
if sock_focus = 1 then
sync_input_box(1)
host_disp$ = neoui_input_get_text$()
else
host_disp$ = sock_host$
fi
neoui_draw_list_row(0, 60, 30, sock_focus = 0, neoui_icon$("wifi"), neoui.TEXT_YELLOW, sock_protos$(sock_proto_idx), "", "< >")
neoui_draw_input_box(6, 92, 228, 36, sock_focus = 1, "Host / Domain", host_disp$, "example.com", 0)
neoui_draw_button(6, 130, 140, 22, sock_focus = 2, 0, neoui_icon$("check"), "Run Exchange")
neoui_draw_button(152, 130, 82, 22, sock_focus = 3, 0, neoui_icon$("refresh"), "Clear")
neoui_fill_rect(6, 155, 228, 112, neoui_color(neoui.COLOR_BG_ALT_ODD))
if sock_focus = 4 then
neoui_draw_rect(6, 155, 228, 112, neoui_color(neoui.COLOR_ACCENT))
else
neoui_draw_rect(6, 155, 228, 112, neoui_color(neoui.COLOR_BORDER))
fi
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_GREEN, 10, 157, 15, sock_status_str$, 220)
neoui_draw_line(8, 173, 232, 173, neoui_color(neoui.COLOR_DIVIDER))
neoui_draw_text_wrapped(neoui.FONT_SMALL, neoui.TEXT_LIGHT, 10, 175, 220, 90, sock_output$, sock_scroll)
if sock_focus = 1 then
neoui_draw_multitap_bar(0, 248, 240, 22, "0-9:Type 1:Sym #:Mode OK:Run")
fi
end sub
sub render_tools_tab()
local tls_lbl$
if tls_insecure then
tls_lbl$ = "Insecure"
else
tls_lbl$ = "Strict"
fi
neoui_draw_toggle_row(0, 62, 32, tool_focus = 0, neoui_icon$("lock"), neoui.TEXT_GREEN, "TLS Cert Check", 1 - tls_insecure, tls_lbl$)
neoui_draw_list_row(1, 96, 32, tool_focus = 1, neoui_icon$("folder"), neoui.TEXT_BLUE, "Download example.com", dl_status$, "Run")
neoui_fill_rect(6, 132, 228, 134, neoui_color(neoui.COLOR_BG_ALT_ODD))
neoui_draw_rect(6, 132, 228, 134, neoui_color(neoui.COLOR_BORDER))
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 10, 135, 15, "URL Encode / Decode FFI:", 220)
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_LIGHT, 10, 150, 14, "In : " + sample_raw$, 220)
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_MUTED, 10, 164, 14, "Enc: " + sample_enc$, 220)
neoui_draw_line(8, 181, 232, 181, neoui_color(neoui.COLOR_DIVIDER))
neoui_draw_text(neoui.FONT_SMALL, neoui.TEXT_YELLOW, 10, 184, 15, "System DNS: " + neonet_system_dns$(), 220)
neoui_draw_text_wrapped(neoui.FONT_SMALL, neoui.TEXT_MUTED, 10, 200, 220, 62, "Engine: " + neonet_version$(), 0)
end sub
sub render_all()
local badge$, mid_lbl$, right_lbl$
neoui_begin_frame()
if (active_tab = 0 and http_focus = 0) or (active_tab = 1 and sock_focus = 1) then
badge$ = neoui_input_mode_badge$()
else
badge$ = "libcurl"
fi
neoui_draw_header(neoui_icon$("globe"), neoui.TEXT_YELLOW, "NeoNet + NeoUI", badge$)
neoui_draw_tabs("1:HTTP/S|2:Sockets|3:Tools", active_tab, 34, 24)
mid_lbl$ = "Select"
right_lbl$ = "Quit"
if active_tab = 0 then
render_http_tab()
if http_focus = 0 and len(neoui_input_get_text$()) > 0 then
right_lbl$ = "Del"
fi
if http_focus = 0 or http_focus = 2 then
mid_lbl$ = "Send"
elsif http_focus = 5 then
mid_lbl$ = "Hdr/Body"
fi
elsif active_tab = 1 then
render_sockets_tab()
if sock_focus = 1 and len(neoui_input_get_text$()) > 0 then
right_lbl$ = "Del"
fi
if sock_focus = 1 or sock_focus = 2 then
mid_lbl$ = "Run"
fi
else
render_tools_tab()
fi
if modal_mode = 1 then
neoui_draw_menu_popup("HTTPS GET example.com|HTTPS HEAD example.com|TLS :443 Raw Exchange|TCP :43 WHOIS Lookup|UDP :53 DNS Resolve|Reload Theme|Quit Demo", neoui_icon$("globe") + "|" + neoui_icon$("info") + "|" + neoui_icon$("lock") + "|" + neoui_icon$("term") + "|" + neoui_icon$("wifi") + "|" + neoui_icon$("theme") + "|" + neoui_icon$("close"), menu_sel, 7)
neoui_draw_softkeys("Close", "Run", "Back")
else
neoui_draw_softkeys("Presets", mid_lbl$, right_lbl$)
fi
neoui_end_frame()
end sub
render_all()
running = 1
while running
ev = neoui_poll_event(250)
if ev = neoui.EV_CLOSE_REQ then
running = 0
elsif ev = neoui.EV_EXPOSE or ev = neoui.EV_THEME_RELOAD then
render_all()
elsif ev = neoui.EV_SOFTKEY_LEFT then
save_input_box()
if modal_mode = 0 then
modal_mode = 1
menu_sel = 0
else
modal_mode = 0
fi
render_all()
elsif ev = neoui.EV_SOFTKEY_RIGHT then
if modal_mode <> 0 then
modal_mode = 0
render_all()
elsif active_tab = 0 and http_focus = 0 and len(neoui_input_get_text$()) > 0 then
neoui_input_backspace()
http_url$ = neoui_input_get_text$()
render_all()
elsif active_tab = 1 and sock_focus = 1 and len(neoui_input_get_text$()) > 0 then
neoui_input_backspace()
sock_host$ = neoui_input_get_text$()
render_all()
else
running = 0
fi
elsif ev = neoui.EV_KEY_PRESS then
k = neoui_event_key()
if modal_mode = 1 then
if k = neoui.KEY_UP then
menu_sel = mod(menu_sel + 6, 7)
elsif k = neoui.KEY_DOWN then
menu_sel = mod(menu_sel + 1, 7)
elsif k = neoui.KEY_BACK then
modal_mode = 0
elsif k = neoui.KEY_OK then
modal_mode = 0
if menu_sel = 0 then
active_tab = 0
http_focus = 2
http_url$ = "https://example.com/"
http_method_idx = 0
show_raw_headers = 0
run_http_request()
elsif menu_sel = 1 then
active_tab = 0
http_focus = 2
http_url$ = "https://example.com/"
http_method_idx = 2
show_raw_headers = 1
run_http_request()
elsif menu_sel = 2 then
active_tab = 1
sock_focus = 2
sock_proto_idx = 0
sock_host$ = "example.com"
run_socket_exchange()
elsif menu_sel = 3 then
active_tab = 1
sock_focus = 2
sock_proto_idx = 1
sock_host$ = "example.com"
run_socket_exchange()
elsif menu_sel = 4 then
active_tab = 1
sock_focus = 2
sock_proto_idx = 2
sock_host$ = "example.com"
run_socket_exchange()
elsif menu_sel = 5 then
neoui_reload_theme()
neoui_show_toast("Theme reloaded!", 1400)
elsif menu_sel = 6 then
running = 0
fi
fi
render_all()
elsif active_tab = 0 and http_focus = 0 then
sync_input_box(0)
if k = neoui.KEY_UP then
save_input_box()
http_focus = 5
elsif k = neoui.KEY_DOWN then
save_input_box()
http_focus = 1
elsif k = neoui.KEY_OK then
run_http_request()
else
neoui_input_feed_key(k)
http_url$ = neoui_input_get_text$()
fi
render_all()
elsif active_tab = 1 and sock_focus = 1 then
sync_input_box(1)
if k = neoui.KEY_UP then
save_input_box()
sock_focus = 0
elsif k = neoui.KEY_DOWN then
save_input_box()
sock_focus = 2
elsif k = neoui.KEY_OK then
run_socket_exchange()
else
neoui_input_feed_key(k)
sock_host$ = neoui_input_get_text$()
fi
render_all()
else
if k = neoui.KEY_1 then
save_input_box()
active_tab = 0
elsif k = neoui.KEY_2 then
save_input_box()
active_tab = 1
elsif k = neoui.KEY_3 then
save_input_box()
active_tab = 2
elsif k = neoui.KEY_BACK then
running = 0
elsif active_tab = 0 then
if k = neoui.KEY_UP then
if http_focus = 5 and http_scroll > 0 then
http_scroll = http_scroll - 1
else
http_focus = mod(http_focus + 5, 6)
fi
elsif k = neoui.KEY_DOWN then
if http_focus = 5 then
http_scroll = http_scroll + 1
else
http_focus = mod(http_focus + 1, 6)
fi
elsif k = neoui.KEY_LEFT then
if http_focus = 3 then
http_method_idx = mod(http_method_idx + 2, 3)
elsif http_focus = 4 then
http_focus = 3
elsif http_focus = 5 and http_scroll > 0 then
http_scroll = 0
http_focus = 2
else
active_tab = 2
fi
elsif k = neoui.KEY_RIGHT then
if http_focus = 2 then
http_focus = 3
elsif http_focus = 3 then
http_focus = 4
else
active_tab = 1
fi
elsif k = neoui.KEY_OK then
if http_focus = 1 then
custom_hdr_on = 1 - custom_hdr_on
elsif http_focus = 2 then
run_http_request()
elsif http_focus = 3 then
http_method_idx = mod(http_method_idx + 1, 3)
elsif http_focus = 4 or http_focus = 5 then
show_raw_headers = 1 - show_raw_headers
http_scroll = 0
if show_raw_headers then
http_output$ = sanitize_display_text$(neonet_response_headers$(), 1800)
else
http_output$ = sanitize_display_text$(neonet_body$(), 1800)
fi
fi
fi
elsif active_tab = 1 then
if k = neoui.KEY_UP then
if sock_focus = 4 and sock_scroll > 0 then
sock_scroll = sock_scroll - 1
else
sock_focus = mod(sock_focus + 4, 5)
fi
elsif k = neoui.KEY_DOWN then
if sock_focus = 4 then
sock_scroll = sock_scroll + 1
else
sock_focus = mod(sock_focus + 1, 5)
fi
elsif k = neoui.KEY_LEFT then
if sock_focus = 0 then
sock_proto_idx = mod(sock_proto_idx + 2, 3)
elsif sock_focus = 3 then
sock_focus = 2
else
active_tab = 0
fi
elsif k = neoui.KEY_RIGHT then
if sock_focus = 0 then
sock_proto_idx = mod(sock_proto_idx + 1, 3)
elsif sock_focus = 2 then
sock_focus = 3
else
active_tab = 2
fi
elsif k = neoui.KEY_OK then
if sock_focus = 0 then
sock_proto_idx = mod(sock_proto_idx + 1, 3)
elsif sock_focus = 2 then
run_socket_exchange()
elsif sock_focus = 3 then
sock_output$ = ""
sock_status_str$ = "Cleared"
sock_scroll = 0
fi
fi
elsif active_tab = 2 then
if k = neoui.KEY_UP or k = neoui.KEY_DOWN then
tool_focus = 1 - tool_focus
elsif k = neoui.KEY_LEFT then
active_tab = 1
elsif k = neoui.KEY_RIGHT then
active_tab = 0
elsif k = neoui.KEY_OK then
if tool_focus = 0 then
tls_insecure = 1 - tls_insecure
r = neonet_set_insecure(tls_insecure)
if tls_insecure then
neoui_show_toast("TLS cert check disabled", 1400)
else
neoui_show_toast("TLS cert check enabled", 1400)
fi
elsif tool_focus = 1 then
neoui_show_toast("Downloading to /tmp/neonet_dl.html ...", 500)
render_all()
neoui_flush()
if neonet_download("https://example.com/", "/tmp/neonet_dl.html", "") then
dl_status$ = "Saved /tmp/neonet_dl.html (HTTP " + str$(neonet_status()) + ")"
neoui_show_toast("Saved /tmp/neonet_dl.html!", 1600)
else
dl_status$ = "Error: " + neonet_error$()
neoui_show_toast("Download failed", 1600)
fi
fi
fi
fi
render_all()
fi
fi
wend
r = neonet_cleanup()
neoui_shutdown()
+38
View File
@@ -0,0 +1,38 @@
#!/bin/sh
export HOME="${HOME:-/home/user}"
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export DISPLAY="${DISPLAY:-:0}"
export LANG=C.UTF-8
export LC_ALL=C.UTF-8
export CHARSET=UTF-8
export XMODIFIERS=@im=fcitx
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && [ -r "$XDG_RUNTIME_DIR/dbus.bus" ]; then
read -r DBUS_SESSION_BUS_ADDRESS < "$XDG_RUNTIME_DIR/dbus.bus" 2>/dev/null || true
export DBUS_SESSION_BUS_ADDRESS
fi
if [ -d /home/user/.local/x11 ]; then
export FCITX_ADDON_DIRS=/home/user/.local/lib/fcitx5:/home/user/.local/x11:/usr/lib/fcitx5
else
export FCITX_ADDON_DIRS=/home/user/.local/lib/fcitx5:/usr/lib/fcitx5
fi
for p in $(pidof fcitx5 2>/dev/null || true); do
if [ "$p" != "$$" ] && [ "$p" != "$PPID" ]; then
kill "$p" 2>/dev/null || true
fi
done
sleep 0.05
for p in $(pidof fcitx5 2>/dev/null || true); do
if [ "$p" != "$$" ] && [ "$p" != "$PPID" ]; then
kill -9 "$p" 2>/dev/null || true
fi
done
exec /usr/bin/fcitx5 -D --disable=wayland >/tmp/fcitx5.log 2>&1
@@ -93,7 +93,6 @@ trap 'rm -f "$SESSION_PID_FILE"; pkill -P $$ >/dev/null 2>&1 || true; exit 0' IN
pkill -9 -x conky >/dev/null 2>&1 || true
rm -rf /tmp/sxmo_conky_time_state /tmp/sxmo_conky_restart.lock
DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
pidof -s fcitx5 >/dev/null 2>&1 || fcitx5 -d >/tmp/fcitx5.log 2>&1 </dev/null &
sxmo_hook_start.sh >/tmp/sxmo_hook_start.log 2>&1 </dev/null &
first_iter=1
@@ -125,7 +124,7 @@ while [ "$(cat "$SESSION_PID_FILE" 2>/dev/null)" = "$$" ]; do
pkill -9 -x conky >/dev/null 2>&1 || true
rm -rf /tmp/sxmo_conky_time_state /tmp/sxmo_conky_restart.lock
DISPLAY=:0 CONKY_DPY=:0 conky -c /home/user/.config/sxmo/conky.conf -d >/dev/null 2>&1 </dev/null || true
pidof -s fcitx5 >/dev/null 2>&1 || fcitx5 -d >/tmp/fcitx5.log 2>&1 </dev/null &
pidof -s fcitx5 >/dev/null 2>&1 || superctl start fcitx5 >/dev/null 2>&1 || /usr/bin/bananarchy-fcitx5.sh </dev/null &
fi
first_iter=0
dwm >/tmp/dwm.log 2>&1 || true
Binary file not shown.
Binary file not shown.
Binary file not shown.
+78
View File
@@ -0,0 +1,78 @@
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# This script is meant to be sourced by various sxmo scripts
# and defines some common settings
export HOME="${HOME:-/home/user}"
export DISPLAY="${DISPLAY:-:0}"
export SXMO_WM="${SXMO_WM:-dwm}"
export SXMO_MENU="${SXMO_MENU:-dmenu}"
export SXMO_TERMINAL="${SXMO_TERMINAL:-st}"
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export LANG="${LANG:-C.UTF-8}"
export LC_ALL="${LC_ALL:-C.UTF-8}"
export XMODIFIERS="${XMODIFIERS:-@im=fcitx}"
export GTK_IM_MODULE="${GTK_IM_MODULE:-fcitx}"
export QT_IM_MODULE="${QT_IM_MODULE:-fcitx}"
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && [ -r "$XDG_RUNTIME_DIR/dbus.bus" ]; then
read -r DBUS_SESSION_BUS_ADDRESS < "$XDG_RUNTIME_DIR/dbus.bus" 2>/dev/null || true
export DBUS_SESSION_BUS_ADDRESS
fi
# aliases aren't expanded in bash
# shellcheck disable=SC2039,SC3044
command -v shopt > /dev/null && shopt -s expand_aliases
alias dmenu="sxmo_dmenu.sh"
alias bemenu="sxmo_dmenu.sh"
if ! command -v sxmobar > /dev/null; then
sxmobar() {
sxmo_status.sh "$@"
}
fi
confirm_menu() {
printf "No\nYes\n" | \
dmenu "$@" | \
grep -q "Yes"
}
sxmo_log() {
printf "%s %s: %s\n" "$(date +%H:%M:%S)" "${0##*/}" "$*" | tee -a "${XDG_STATE_HOME:-$HOME}"/sxmo.log 1>&2
}
sxmo_debug() {
if [ -n "$SXMO_DEBUG" ]; then
printf "%s %s DEBUG: %s\n" "$(date +%H:%M:%S)" "${0##*/}" "$*" | tee -a "${XDG_STATE_HOME:-$HOME}"/sxmo.log 1>&2
fi
}
xdg_data_path() {
filepath=$1
instance_count=${2:-1}
sep=${3:-" "}
IFS=':'
instance=0
for dir in ${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
do
if [ -e "$dir/$filepath" ]; then
if [ "$instance" -ge "$instance_count" ] && [ "$instance_count" != "0" ]; then
break
fi
if [ $instance -gt 0 ]; then
printf '%b' "${sep}"
fi
printf '%s' "${dir}/${filepath}"
instance=$((instance+1))
fi
done
}
+52
View File
@@ -0,0 +1,52 @@
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors
# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
if [ -e /tmp/dwm_plugin_dmenu.active ] && [ -p /tmp/dwm_plugin_dmenu.fifo ]; then
printf "CLOSE\n" > /tmp/dwm_plugin_dmenu.fifo 2>/dev/null || true
sleep 0.04
fi
for _pair in \
"xdrawer.pid:/tmp/dwm_plugin_xdrawer.fifo" \
"xdialer.pid:/tmp/dwm_plugin_dialer.fifo" \
"xcalllog.pid:/tmp/dwm_plugin_calllog.fifo" \
"xcontacts.pid:/tmp/dwm_plugin_contacts.fifo" \
"xsms.pid:/tmp/dwm_plugin_sms.fifo" \
"xfiles.pid:/tmp/dwm_plugin_files.fifo" \
"xcamera.pid:/tmp/dwm_plugin_camera.fifo" \
"xthemes.pid:/tmp/dwm_plugin_themes.fifo" \
"xmodem.pid:/tmp/dwm_plugin_modem.fifo" \
"xnetworks.pid:/tmp/dwm_plugin_networks.fifo" \
"xringtones.pid:/tmp/dwm_plugin_ringtones.fifo" \
"xwallpapers.pid:/tmp/dwm_plugin_wallpapers.fifo" \
"xmusic.pid:/tmp/dwm_plugin_music.fifo"; do
_pf="${_pair%%:*}"
_ff="${_pair#*:}"
if [ -f "${XDG_RUNTIME_DIR:-/run/user/10000}/$_pf" ] || [ -f "/tmp/$_pf" ]; then
if [ -p "$_ff" ]; then
printf "CLOSE\n" > "$_ff" 2>/dev/null || true
exit 0
fi
fi
done
case "${SXMO_WM:-dwm}" in
i3) i3-msg kill ;;
sway) swaymsg kill ;;
river) riverctl close ;;
dwm|*)
_wid="$(xdotool getactivewindow 2>/dev/null || true)"
xdotool key --clearmodifiers Super+Shift+c 2>/dev/null || true
if [ -n "$_wid" ]; then
sleep 0.1
if xprop -id "$_wid" WM_STATE >/dev/null 2>&1; then
xdotool windowkill "$_wid" 2>/dev/null || true
fi
fi
;;
esac
+22 -25
View File
@@ -7,6 +7,19 @@
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh
export DISPLAY="${DISPLAY:-:0}"
export SXMO_WM="${SXMO_WM:-dwm}"
_dwm_prep() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
if [ -e /tmp/dwm_plugin_dmenu.active ] && [ -p /tmp/dwm_plugin_dmenu.fifo ]; then
printf "CLOSE\n" > /tmp/dwm_plugin_dmenu.fifo 2>/dev/null || true
sleep 0.04
fi
}
swi3msg() {
case "$SXMO_WM" in
sway) swaymsg "$@" ;;
@@ -328,10 +341,8 @@ swi3togglelayout() {
}
dwmtogglelayout() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
xdotool key --clearmodifiers key Super+space
_dwm_prep
xdotool key --clearmodifiers Super+space
}
rivertogglelayout() {
@@ -349,9 +360,7 @@ swayswitchfocus() {
}
dwmswitchfocus() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
_dwm_prep
xdotool key --clearmodifiers Super+x
}
# }}}
@@ -392,9 +401,7 @@ rivernextworkspace() {
}
dwmnextworkspace() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
_dwm_prep
xdotool key --clearmodifiers Super+Shift+r
}
@@ -403,9 +410,7 @@ swi3previousworkspace() {
}
dwmpreviousworkspace() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
_dwm_prep
xdotool key --clearmodifiers Super+Shift+e
}
@@ -418,9 +423,7 @@ swi3movenextworkspace() {
}
dwmmovenextworkspace() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
_dwm_prep
xdotool key --clearmodifiers Super+r
}
@@ -429,9 +432,7 @@ swi3movepreviousworkspace() {
}
dwmmovepreviousworkspace() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
_dwm_prep
xdotool key --clearmodifiers Super+e
}
@@ -445,9 +446,7 @@ riverworkspace() {
}
dwmworkspace() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
_dwm_prep
xdotool key --clearmodifiers "Super+$1"
}
@@ -461,9 +460,7 @@ rivermoveworkspace() {
}
dwmmoveworkspace() {
if [ -z "$DISPLAY" ]; then
export DISPLAY=:0
fi
_dwm_prep
xdotool key --clearmodifiers "Super+shift+$1"
}
# }}}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
/home/user/Projects/neonet.yab
@@ -0,0 +1,7 @@
[Unit]
Description=fcitx5 input support
[Service]
Type=simple
ExecStart=/usr/bin/bananarchy-fcitx5.sh
Restart=always
@@ -78,7 +78,7 @@ superctl start dunst
[ "$(command -v sxmo_xob)" ] && superctl start sxmo_xob
pidof -s sxmo_status_xsetroot.sh >/dev/null 2>&1 || superctl start sxmo-x11-status
[ "$(command -v bonsaid)" ] && superctl start bonsaid
if ! pidof -s fcitx5 >/dev/null 2>&1 && [ "$(command -v fcitx5)" ]; then
if [ "$(command -v fcitx5)" ]; then
superctl start fcitx5
fi
[ -n "$SXMO_MONITOR" ] && xrandr --output "$SXMO_MONITOR" --primary
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+38
View File
@@ -322,6 +322,44 @@ static int list_plugins(void) {
int main(int argc, char **argv) {
signal(SIGPIPE, SIG_IGN);
if (!getenv("DISPLAY"))
setenv("DISPLAY", ":0", 0);
if (!getenv("XDG_RUNTIME_DIR"))
setenv("XDG_RUNTIME_DIR", "/run/user/10000", 0);
if (!getenv("SXMO_WM"))
setenv("SXMO_WM", "dwm", 0);
if (!getenv("SXMO_MENU"))
setenv("SXMO_MENU", "dmenu", 0);
if (!getenv("SXMO_TERMINAL"))
setenv("SXMO_TERMINAL", "st", 0);
setenv("LANG", "C.UTF-8", 1);
setenv("LC_ALL", "C.UTF-8", 1);
setenv("XMODIFIERS", "@im=fcitx", 1);
setenv("GTK_IM_MODULE", "fcitx", 1);
setenv("QT_IM_MODULE", "fcitx", 1);
if (!getenv("FCITX_ADDON_DIRS")) {
if (access("/home/user/.local/x11", F_OK) == 0)
setenv("FCITX_ADDON_DIRS", "/home/user/.local/lib/fcitx5:/home/user/.local/x11:/usr/lib/fcitx5", 0);
else
setenv("FCITX_ADDON_DIRS", "/home/user/.local/lib/fcitx5:/usr/lib/fcitx5", 0);
}
if (!getenv("DBUS_SESSION_BUS_ADDRESS")) {
const char *rdir = getenv("XDG_RUNTIME_DIR");
char bpath[256], bbuf[256];
snprintf(bpath, sizeof(bpath), "%s/dbus.bus",
(rdir && rdir[0]) ? rdir : "/run/user/10000");
FILE *bf = fopen(bpath, "r");
if (bf) {
if (fgets(bbuf, sizeof(bbuf), bf)) {
char *nl = strpbrk(bbuf, "\r\n");
if (nl)
*nl = '\0';
if (bbuf[0])
setenv("DBUS_SESSION_BUS_ADDRESS", bbuf, 1);
}
fclose(bf);
}
}
const char *plugin_name = resolve_plugin_name_from_argv0(argv[0]);
int sub_argc = argc;
char **sub_argv = argv;
+10
View File
@@ -1393,6 +1393,8 @@ bool NeoWindow::create(const char* resName, const char* resClass,
ch.res_class = const_cast<char*>(rClass.c_str());
XSetClassHint(dpy, win, &ch);
XStoreName(dpy, win, (title && title[0]) ? title : rClass.c_str());
Atom wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
XSetWMProtocols(dpy, win, &wmDelete, 1);
pix = XCreatePixmap(dpy, win, width, height, DefaultDepth(dpy, screen));
gc = XCreateGC(dpy, pix, 0, nullptr);
@@ -2660,6 +2662,14 @@ int neoui_poll_event(int timeout_ms) {
ctx->lastEventType = NEO_EV_EXPOSE;
return NEO_EV_EXPOSE;
}
if (ev.type == ClientMessage) {
Atom wmDelete = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
if (static_cast<Atom>(ev.xclient.data.l[0]) == wmDelete) {
ctx->lastEventType = NEO_EV_CLOSE_REQ;
return NEO_EV_CLOSE_REQ;
}
continue;
}
if (ev.type == VisibilityNotify && ctx->visible) {
if (ev.xvisibility.state != VisibilityUnobscured) {
XRaiseWindow(dpy, ctx->w->win);
+110 -15
View File
@@ -816,6 +816,26 @@ trigger_plugin_open(const char *plugin_spec)
spawn_detached_sh(cmd);
}
static void
send_dwm_cmd(long op, long argval)
{
if (!dpy)
return;
Atom cmd_atom = XInternAtom(dpy, "_BANANARCHY_DWM_CMD", False);
XClientMessageEvent cme;
memset(&cme, 0, sizeof(cme));
cme.type = ClientMessage;
cme.display = dpy;
cme.window = root;
cme.message_type = cmd_atom;
cme.format = 32;
cme.data.l[0] = op;
cme.data.l[1] = argval;
XSetErrorHandler(ignore_xerror);
XSendEvent(dpy, root, False, SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&cme);
XSync(dpy, False);
}
static void
send_key_to_window(Window target, KeySym ksym, unsigned int mod_state)
{
@@ -1208,6 +1228,29 @@ activate_selection(unsigned int ev_state)
}
return;
}
if (strncmp(act, "@wm:", 4) == 0) {
const char *wm_act = act + 4;
hide_menu();
menu_mode = MODE_NONE;
if (strncmp(wm_act, "move:", 5) == 0) {
send_dwm_cmd(1, atoi(wm_act + 5));
} else if (strncmp(wm_act, "view:", 5) == 0) {
send_dwm_cmd(2, atoi(wm_act + 5));
} else if (strcmp(wm_act, "focusnext") == 0) {
send_dwm_cmd(3, 1);
} else if (strcmp(wm_act, "togglelayout") == 0) {
send_dwm_cmd(4, 1);
} else if (strcmp(wm_act, "kill") == 0) {
send_dwm_cmd(5, (long)target_win);
} else if (strcmp(wm_act, "pushstack") == 0) {
send_dwm_cmd(6, 1);
} else if (strncmp(wm_act, "shiftview:", 10) == 0) {
send_dwm_cmd(7, atoi(wm_act + 10));
} else if (strncmp(wm_act, "tagpush:", 8) == 0) {
send_dwm_cmd(8, atoi(wm_act + 8));
}
return;
}
if (loop) {
spawn_detached_sh(act);
@@ -2212,12 +2255,12 @@ open_builtin_menu(const char *menu_name, int keep_idx)
if (!cls[0] || strcmp(cls, "sys") == 0) {
menu_name = "sys";
} else if (strcmp(cls, "st") == 0 || strncmp(cls, "st-", 3) == 0) {
/* launched from a terminal: also show the exact same Sys menu */
menu_name = "sys";
}
else {
/* launched from an app: show the exact same Sys menu as the desktop */
menu_name = "sys";
if (strstr(ttl, "nano"))
menu_name = "nano";
else
menu_name = "st";
} else {
menu_name = "wm";
}
}
@@ -2454,15 +2497,22 @@ open_builtin_menu(const char *menu_name, int keep_idx)
reset_session_defaults(1, "WM Menu");
for (int ws = 1; ws <= 4; ws++) {
snprintf(label, sizeof(label), "%d Move to WS %d", ws, ws);
snprintf(cmd, sizeof(cmd), "sxmo_wm.sh moveworkspace %d", ws);
add_menu_item(label, cmd, 1);
snprintf(cmd, sizeof(cmd), "@wm:move:%d", ws);
add_menu_item(label, cmd, 0);
}
snprintf(label, sizeof(label), "%s Shift stack", ICON_RLD);
add_menu_item(label, "sxmo_wm.sh switchfocus", 1);
add_menu_item(label, "@wm:focusnext", 0);
snprintf(label, sizeof(label), "%s Swap stack", ICON_A2X);
add_menu_item(label, "@wm:pushstack", 0);
snprintf(label, sizeof(label), "%s Toggle Layout", ICON_GRD);
add_menu_item(label, "sxmo_wm.sh togglelayout", 1);
add_menu_item(label, "@wm:togglelayout", 0);
snprintf(label, sizeof(label), "%s Kill window", ICON_CLS);
add_menu_item(label, "sxmo_killwindow.sh", 0);
add_menu_item(label, "@wm:kill", 0);
for (int ws = 1; ws <= 4; ws++) {
snprintf(label, sizeof(label), "%s Go to WS %d", ICON_WIN, ws);
snprintf(cmd, sizeof(cmd), "@wm:view:%d", ws);
add_menu_item(label, cmd, 0);
}
snprintf(label, sizeof(label), "%s System Menu", ICON_MNU);
add_menu_item(label, "@menu:sys", 1);
snprintf(label, sizeof(label), "%s Close Menu", ICON_CLS);
@@ -2556,7 +2606,9 @@ open_builtin_menu(const char *menu_name, int keep_idx)
snprintf(label, sizeof(label), "%s New Terminal", ICON_TRM);
add_menu_item(label, "sxmo_terminal.sh", 0);
snprintf(label, sizeof(label), "%s Close Terminal", ICON_CLS);
add_menu_item(label, "sxmo_killwindow.sh", 0);
add_menu_item(label, "@wm:kill", 0);
snprintf(label, sizeof(label), "%s Windows", ICON_WIN);
add_menu_item(label, "@menu:wm", 1);
snprintf(label, sizeof(label), "%s Type complete", ICON_ITM);
add_menu_item(label, "@key:ctrl_shift:u", 0);
snprintf(label, sizeof(label), "%s Toggle Selmode", ICON_ITM);
@@ -2606,6 +2658,8 @@ open_builtin_menu(const char *menu_name, int keep_idx)
add_menu_item(label, "@key:none:Next", 1);
snprintf(label, sizeof(label), "%s Terminal menu", ICON_MNU);
add_menu_item(label, "@menu:st", 1);
snprintf(label, sizeof(label), "%s Windows", ICON_WIN);
add_menu_item(label, "@menu:wm", 1);
snprintf(label, sizeof(label), "%s System Menu", ICON_MNU);
add_menu_item(label, "@menu:sys", 1);
snprintf(label, sizeof(label), "%s Close Menu", ICON_CLS);
@@ -2655,6 +2709,7 @@ any_other_plugin_active(void)
"xnetworks.pid",
"xringtones.pid",
"xwallpapers.pid",
"xmusic.pid",
};
const char *rdir = getenv("XDG_RUNTIME_DIR");
const char *base = (rdir && rdir[0]) ? rdir : "/run/user/10000";
@@ -2698,6 +2753,7 @@ close_other_active_plugins(void)
{ "xnetworks.pid", "/tmp/dwm_plugin_networks.fifo" },
{ "xringtones.pid", "/tmp/dwm_plugin_ringtones.fifo" },
{ "xwallpapers.pid", "/tmp/dwm_plugin_wallpapers.fifo" },
{ "xmusic.pid", "/tmp/dwm_plugin_music.fifo" },
};
const char *rdir = getenv("XDG_RUNTIME_DIR");
const char *base = (rdir && rdir[0]) ? rdir : "/run/user/10000";
@@ -2942,8 +2998,24 @@ show_menu(void)
Window fw = None;
int rev = 0;
XGetInputFocus(dpy, &fw, &rev);
if (fw != None && fw != PointerRoot && fw != win)
if (fw != None && fw != PointerRoot && fw != root && fw != win)
prevfocuswin = fw;
if (prevfocuswin == None) {
Atom net_active = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False);
Atom actual_type = None;
int actual_fmt = 0;
unsigned long nitems = 0, bytes_after = 0;
unsigned char *prop = NULL;
if (XGetWindowProperty(dpy, root, net_active, 0L, 1L, False, XA_WINDOW,
&actual_type, &actual_fmt, &nitems, &bytes_after, &prop) == Success && prop) {
if (actual_type == XA_WINDOW && actual_fmt == 32 && nitems >= 1) {
Window aw = *(Window *)prop;
if (aw != None && aw != PointerRoot && aw != root && aw != win)
prevfocuswin = aw;
}
XFree(prop);
}
}
XEvent ev;
while (XPending(dpy))
@@ -2996,13 +3068,13 @@ hide_menu(void)
XUnsetICFocus(xic);
}
XUngrabKeyboard(dpy, CurrentTime);
XUnmapWindow(dpy, win);
XSetErrorHandler(ignore_xerror);
if (!daemon_mode && prevfocuswin && prevfocuswin != win && prevfocuswin != PointerRoot) {
if (prevfocuswin && prevfocuswin != win && prevfocuswin != PointerRoot) {
XWindowAttributes wa;
if (XGetWindowAttributes(dpy, prevfocuswin, &wa) && wa.map_state == IsViewable)
XSetInputFocus(dpy, prevfocuswin, RevertToParent, CurrentTime);
}
XUnmapWindow(dpy, win);
prevfocuswin = None;
XSync(dpy, False);
@@ -3722,6 +3794,29 @@ dmenu_run_main(int argc, char *argv[])
(cur_path && cur_path[0]) ? cur_path : "/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin");
setenv("PATH", new_path, 1);
}
if (!getenv("DISPLAY"))
setenv("DISPLAY", ":0", 0);
if (!getenv("XDG_RUNTIME_DIR"))
setenv("XDG_RUNTIME_DIR", "/run/user/10000", 0);
if (!getenv("SXMO_WM"))
setenv("SXMO_WM", "dwm", 0);
if (!getenv("SXMO_MENU"))
setenv("SXMO_MENU", "dmenu", 0);
if (!getenv("SXMO_TERMINAL"))
setenv("SXMO_TERMINAL", "st", 0);
setenv("LANG", "C.UTF-8", 1);
setenv("LC_ALL", "C.UTF-8", 1);
setenv("XMODIFIERS", "@im=fcitx", 1);
setenv("GTK_IM_MODULE", "fcitx", 1);
setenv("QT_IM_MODULE", "fcitx", 1);
if (!getenv("DBUS_SESSION_BUS_ADDRESS")) {
const char *rdir = getenv("XDG_RUNTIME_DIR");
char bpath[256], bbuf[256];
snprintf(bpath, sizeof(bpath), "%s/dbus.bus",
(rdir && rdir[0]) ? rdir : "/run/user/10000");
if (read_first_line(bpath, bbuf, sizeof(bbuf)) && bbuf[0])
setenv("DBUS_SESSION_BUS_ADDRESS", bbuf, 1);
}
int lock_fd = -1;
int fifo_fd = -1;
+69 -2
View File
@@ -73,7 +73,7 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel, SchemeTabActive, SchemeTabInactive }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
NetWMWindowTypeDialog, NetClientList, NetDwmCmd, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -276,6 +276,7 @@ static void readxresources(void);
static void reload_dwm_theme(void);
static void load_plugins(void);
static void unload_plugins(void);
static long long dwm_now_ms(void);
static pid_t getparentprocess(pid_t p);
static int isdescprocess(pid_t p, pid_t c);
@@ -784,8 +785,73 @@ void
clientmessage(XEvent *e)
{
XClientMessageEvent *cme = &e->xclient;
Client *c = wintoclient(cme->window);
Client *c;
if (cme->message_type == netatom[NetDwmCmd]) {
long op = cme->data.l[0];
long argval = cme->data.l[1];
if (op == 1 && argval >= 1 && argval <= 9) {
Arg a = { .ui = 1U << (argval - 1) };
tag(&a);
} else if (op == 2 && argval >= 1 && argval <= 9) {
Arg a = { .ui = 1U << (argval - 1) };
view(&a);
} else if (op == 3) {
Arg a = { .i = (argval != 0) ? (int)argval : +1 };
focusstack(&a);
} else if (op == 4) {
Arg a = { .i = +1 };
cyclelayout(&a);
} else if (op == 5) {
static Window last_kill_win = None;
static long long last_kill_ms = 0;
Client *tc = (argval != 0) ? wintoclient((Window)argval) : NULL;
if (!tc && selmon)
tc = selmon->sel;
if (tc) {
if (selmon && selmon->sel != tc)
focus(tc);
long long now = dwm_now_ms();
int force = (tc->win == last_kill_win && (now - last_kill_ms) < 3000LL);
last_kill_win = tc->win;
last_kill_ms = now;
if (force || !sendevent(tc, wmatom[WMDelete])) {
XGrabServer(dpy);
XSetErrorHandler(xerrordummy);
XSetCloseDownMode(dpy, DestroyAll);
XKillClient(dpy, tc->win);
XSync(dpy, False);
XSetErrorHandler(xerror);
XUngrabServer(dpy);
}
} else if (argval != 0 && (Window)argval != root &&
(!selmon || ((Window)argval != selmon->barwin &&
(Window)argval != selmon->softwin))) {
XGrabServer(dpy);
XSetErrorHandler(xerrordummy);
XSetCloseDownMode(dpy, DestroyAll);
XKillClient(dpy, (Window)argval);
XSync(dpy, False);
XSetErrorHandler(xerror);
XUngrabServer(dpy);
}
} else if (op == 6) {
Arg a = { .i = +1 };
if (argval < 0)
pushup(&a);
else
pushdown(&a);
} else if (op == 7) {
Arg a = { .i = (argval < 0) ? -1 : +1 };
shiftview(&a);
} else if (op == 8) {
Arg a = { .i = (argval < 0) ? -1 : +1 };
clienttagpush(&a);
}
return;
}
c = wintoclient(cme->window);
if (!c)
return;
if (cme->message_type == netatom[NetWMState]) {
@@ -2694,6 +2760,7 @@ setup(void)
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
netatom[NetDwmCmd] = XInternAtom(dpy, "_BANANARCHY_DWM_CMD", False);
/* init cursors */
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
+34
View File
@@ -2029,6 +2029,11 @@ run(void)
while (XPending(xw.dpy)) {
xev = 1;
XNextEvent(xw.dpy, &ev);
if (ev.type == ClientMessage &&
(Atom)ev.xclient.data.l[0] == xw.wmdeletewin) {
cmessage(&ev);
continue;
}
if (XFilterEvent(&ev, None))
continue;
if (handler[ev.type])
@@ -2254,6 +2259,35 @@ run:
if (!opt_title)
opt_title = (opt_line || !opt_cmd) ? "st" : opt_cmd[0];
if (!getenv("DISPLAY"))
setenv("DISPLAY", ":0", 0);
if (!getenv("XDG_RUNTIME_DIR"))
setenv("XDG_RUNTIME_DIR", "/run/user/10000", 0);
if (!getenv("SXMO_WM"))
setenv("SXMO_WM", "dwm", 0);
setenv("LANG", "C.UTF-8", 1);
setenv("LC_ALL", "C.UTF-8", 1);
setenv("XMODIFIERS", "@im=fcitx", 1);
setenv("GTK_IM_MODULE", "fcitx", 1);
setenv("QT_IM_MODULE", "fcitx", 1);
if (!getenv("DBUS_SESSION_BUS_ADDRESS")) {
const char *rdir = getenv("XDG_RUNTIME_DIR");
char bpath[256], bbuf[256];
snprintf(bpath, sizeof(bpath), "%s/dbus.bus",
(rdir && rdir[0]) ? rdir : "/run/user/10000");
FILE *bf = fopen(bpath, "r");
if (bf) {
if (fgets(bbuf, sizeof(bbuf), bf)) {
char *nl = strpbrk(bbuf, "\r\n");
if (nl)
*nl = '\0';
if (bbuf[0])
setenv("DBUS_SESSION_BUS_ADDRESS", bbuf, 1);
}
fclose(bf);
}
}
setlocale(LC_CTYPE, "");
XSetLocaleModifiers("");
+11
View File
@@ -31,6 +31,7 @@
#include <sstream>
#include <string>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <vector>
@@ -108,6 +109,7 @@ bool writeIntFile(const std::string& path, int value) {
void runAsyncCmd(const std::string& cmd) {
pid_t pid = ::fork();
if (pid == 0) {
if (::fork() == 0) {
::setsid();
int nullfd = ::open("/dev/null", O_RDWR);
if (nullfd >= 0) {
@@ -121,6 +123,11 @@ void runAsyncCmd(const std::string& cmd) {
execl("/bin/sh", "sh", "-c", cmd.c_str(), static_cast<char*>(nullptr));
_exit(0);
}
_exit(0);
} else if (pid > 0) {
int st = 0;
(void)::waitpid(pid, &st, 0);
}
}
class AlsaControl {
@@ -674,6 +681,8 @@ static int xdrawer_run_main(int argc, char** argv) {
sigemptyset(&sa.sa_mask);
sigaction(SIGTERM, &sa, nullptr);
sigaction(SIGINT, &sa, nullptr);
signal(SIGCHLD, SIG_IGN);
signal(SIGPIPE, SIG_IGN);
bananarchy::NeoWindow neo;
if (!neo.create("xdrawer", "XDrawer", "XDrawer", kWinX, kWinY, kWinWidth,
@@ -863,6 +872,7 @@ static int xdrawer_run_main(int argc, char** argv) {
"xdialer.pid", "xcalllog.pid", "xcallscreen.pid", "xcontacts.pid",
"xsms.pid", "xfiles.pid", "xcamera.pid", "xthemes.pid",
"xmodem.pid", "xnetworks.pid", "xringtones.pid", "xwallpapers.pid",
"xmusic.pid",
};
for (const char* pf : kPids) {
int p = readIntFile(getRuntimeFile(pf), -1);
@@ -893,6 +903,7 @@ static int xdrawer_run_main(int argc, char** argv) {
closeOtherPlugin("xnetworks.pid", "/tmp/dwm_plugin_networks.fifo");
closeOtherPlugin("xringtones.pid", "/tmp/dwm_plugin_ringtones.fifo");
closeOtherPlugin("xwallpapers.pid", "/tmp/dwm_plugin_wallpapers.fifo");
closeOtherPlugin("xmusic.pid", "/tmp/dwm_plugin_music.fifo");
if (::access("/tmp/dwm_plugin_dmenu.active", F_OK) == 0) {
int dfd = ::open("/tmp/dwm_plugin_dmenu.fifo", O_WRONLY | O_NONBLOCK | O_CLOEXEC);
if (dfd >= 0) {