github rinkhals-community/Rinkhals untagged-ab91d864bc478734410c
Rinkhals 20260530_03_feature-z-offset-ui

pre-release3 hours ago

Caution

This is a feature-test build, not a public release. It is unstable,
under active development, and should not be flashed or used unless you
are specifically helping test the K3SysUi Z-offset UI feature in
coordination with the developers. Behavior may change without notice
between builds. If you flash this without that context, you are on your
own and may end up with a non-functioning touchscreen until the next
stable release overwrites it.

What this build adds

Restores the live Z-offset adjust button on the K3SysUi print page. Anycubic
removed the button widget from their UI but left the popup, the dispatcher
case-10 handler, the embedded SVG icon, and the underlying device RPC
machinery intact in the K3SysUi binary. This build injects a replacement
button at runtime via an LD_PRELOAD shim that hooks
QButtonGroup::addButton, constructs a fresh QPushButton, sets the
Anycubic Z-offset icon, and wires its clicked() signal directly to the
popup's show() slot via Qt's string-based connect.

The shim does its own dynamic discovery of the popup widget's offset inside
MainWindow by parsing the K3SysUi ELF symbol table and disassembling the
dispatcher lambda. Discovery is scoped to the lambda(int)#12 inside
MainWindow::AcFilePrintPageUiInit by mangled-name pattern match, then to
the bl AcDeviceLeviqGetZoffset call site inside that lambda, then to the
ldr r3, [r3, #N]; mov r0, r3; bl <show> triple that loads and displays the
popup. The discovered N is the popup offset.

Visibility mirrors the print page via a global event filter on qApp,
matching QEvent::Show/Hide against an ancestor chain registered for each
captured template button. The filter object is a bare QObject with its
per-instance vtable patched at the eventFilter slot, so we avoid Qt's moc
metadata requirement entirely.

Where it's wired in

  • New build stage build-shim-zoffset in the root Dockerfile
    cross-compiles libzoffset.so via the existing ghcr.io/jbatonnet/armv7-uclibc:rinkhals
    image (same image as the Moonraker ARMv7 build). Output ships in the SWU
    bundle under /opt/rinkhals/shims/k3sysui-zoffset/.
  • files/3-rinkhals/start.sh launches K3SysUi with
    LD_PRELOAD=$ZOFFSET_SHIM and RINKHALS_ZOFFSET_INJECT=1 after the
    per-firmware binary patches have run. The shim is loaded into the
    patched K3SysUi process.
  • The shim is inert without RINKHALS_ZOFFSET_INJECT=1. To disable
    without removing the file, edit start.sh to drop the env var.

Verified targets

KS1 firmware 2.7.2.1 on Qt 5.14.2. Other supported models
(K3, K3M, K3V2, KS1M, K2P) are not yet verified. The dynamic offset
discovery should adapt to per-build differences, but the assumption that
case 10 = Z-offset and the icon resource path are still binary-bound and
need spot-checking per model. Falls back gracefully (SIGSEGV trap, then
shim does nothing further on that group) if the assumptions don't hold.

Known caveats

  • The shim wraps every Qt construction call in a SIGSEGV/sigsetjmp
    trap. Worst case is the affected injection is abandoned and K3SysUi
    continues without the button. It should not crash K3SysUi.
  • appCheck.sh (the Anycubic watchdog) respawns K3SysUi without
    LD_PRELOAD if it dies. If K3SysUi crashes, the restarted process
    won't have the shim until the printer reboots. Not a problem in
    practice unless K3SysUi is unstable.
  • RINKHALS_ZOFFSET_LOG=1 adds startup diagnostics to
    /tmp/rinkhals/K3SysUi.log. Off by default; enable by editing
    start.sh if you're debugging.

How to test

  1. Flash this SWU on a KS1 running stock firmware 2.7.2.1.
  2. Boot, go to the print page.
  3. Tap the Z-offset icon at top-left.
  4. Z-offset popup should appear, with current value pre-filled.
  5. Navigate to another page — icon should hide. Navigate back —
    icon should reappear.
  6. Report results in the relevant developer discussion, not as
    a general issue (this is not yet a feature anyone should be using
    unless they're testing it on purpose).

Build/source

Branch: feature/K3SysUi_z_offset_UI
Tag: 20260530_03_feature-z-offset-ui
Source: files/3-rinkhals/opt/rinkhals/shims/k3sysui-zoffset/zoffset.cpp

Don't miss a new Rinkhals release

NewReleases is sending notifications on new releases.