Repository navigation
Rewrite the native addon in Rust, prebuilt for 15 targets - #2
Merged
Merged
Conversation
- Replace the C/C++ N-API addon (libX11 + libXmu) with Rust: napi-rs 3 for the bindings, x11rb for the X11 protocol. No system libraries or compiler are needed at install time. - Ship prebuilt binaries in the package (prebuilds/<platform>-<arch>[-musl]), picked at runtime: Linux glibc 2.17+ (x64, arm64, arm, ppc64le, s390x, riscv64), Linux musl (x64, arm64, arm), FreeBSD x64, macOS x64/arm64, Windows x64/ia32/arm64. - Same JS API; fixes from 1.x: promises reject with Error objects, getWindowsBy* return [] instead of throwing, close*Sync return true, win_icon_name is set, transitions animate y, no double free in getActiveWindow. - Regression tests: Rust unit tests, an API suite (exports, validation, error messages, binary loader) and an X11 suite that drives a real WM with its own fixture windows. - CI cross-builds every Linux target with cargo-zigbuild and tests it in a container of that arch (QEMU when needed), builds and tests FreeBSD in a VM, runs the API suite on macOS and Windows, and publishes on v* tags. - TypeScript 7. Co-Authored-By: Claude Opus 5.5 <[email protected]>
From review of the Rust rewrite: - windowMoveResizeTransition: an await_time no Duration can hold (Infinity, 1e300) panicked on the libuv thread and aborted Node. It now rejects with CAN_NOT_MOVE_RESIZE_WINDOW before touching the window. - Window geometry: abs_x/abs_y of a window on another screen than the default one came out as 0,0. Translate to the window's own root, as the C addon did (one extra round trip, only for such windows). Transitions start from the window's own root too. - windowMinimize: send WM_CHANGE_STATE to the root of the window's screen, like XIconifyWindow, so that screen's WM receives it. Tests: a Rust unit test and an API test for the pause, and X11 tests on a second Xvfb screen with its own openbox (WMCTRLJS_SCREEN1), now set up in CI. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Drop the Json wrapper and its unsafe ToNapiValue impl: sync functions return serde_json::Value, async jobs implement ScopedTask and resolve through the safe Env::to_js_value. - unsafe_code is denied crate-wide and forbidden in wm.rs (it cannot be forbidden at the crate root: #[napi] expands to code that allows it). - Clippy forbids unwrap, expect, panic!, unreachable!, todo!, unimplemented!, indexing/slicing, string slicing and unchecked arithmetic; clippy.toml relaxes the panic lints in tests only. - What the lints found: transitions now step with saturating arithmetic and lazily (pad 1 towards i32::MAX overflowed, or allocated every step up front), and lookups use get() instead of indexing. - Any panic left (in a dependency) is caught at the N-API boundary and reported as INTERNAL_ERROR (43) instead of aborting Node. Co-Authored-By: Claude Opus 5.5 <[email protected]>
X has one input focus per display, and openbox takes it when it starts
managing screen 1. Under QEMU in CI it came up in the middle of the
activation tests and left screen 0 without an active window
("activating a minimized window restores it" timed out on ppc64le).
The setup hook now waits for both WMs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Xvfb and openbox ran in the background with the ssh session's output, so the session stayed open after the tests passed and the step never ended. Jobs now also time out after 30 minutes, and a new push to a PR cancels its older runs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prebuilds/<platform>-<arch>[-musl]/wmctrljs.node), and the right one is picked at runtime.Errorobjects,getWindowsBy*return[],close*Syncreturntrue,win_icon_nameis now set, transitions animate y, and the double free ingetActiveWindowis gone.Targets
Tests
api.test(112): exports, argument validation and error messages for every function, plus the binary loader (glibc/musl selection, missing-binary message). Needs no X server.x11.test(41): every function against a real window manager. It only acts on fixture windows it spawns itself (native/examples/fixture.rs).Verified locally before pushing
cargo checkonly. This PR's CI is the first real run for them.Notes
opt-level = "s", not"z": at"z"the ppc64le build panics in x11rb's packet reader. Opt-level 3 and"s"both pass, and"s"is only 0.7% bigger than"z".optionalDependenciespackages are the fallback if size becomes a concern.v*tags needs theNPM_TOKENsecret.🤖 Generated with Claude Code