dbus input driver: report viewport state in user-facing values by atirna · Pull Request #7035 · openscad/openscad · GitHub
Skip to content

dbus input driver: report viewport state in user-facing values - #7035

Open
atirna wants to merge 2 commits into
openscad:masterfrom
atirna:fix/dbus-viewport-state
Open

atirna wants to merge 2 commits into
openscad:masterfrom
atirna:fix/dbus-viewport-state

Conversation

@atirna

@atirna atirna commented Sep 7, 2026 •

Copy link
Copy Markdown

extends the existing D-Bus input driver so the viewport state it reports is actually usable from outside, following the direction in #6940.

getters now speak the user-facing dialect. getRotation()/getTranslation() used to return Camera::object_rot/object_trans, the internal camera coordinates. the values Viewport Control, $vpr/$vpt and the Copy viewport values menu entries show are Camera::getVpr()/getVpt(), a different representation. so a getter and the ui could disagree about the same viewport, which is exactly the confusion reported in the issue (Viewport Control [33.30, 0, 148.20] vs dbus [56.7, 0, 211.8]). the getters now return the same values every other interface exposes.

rotateTo/translateTo now take the same values the getters return. translateTo had a worse problem: MainWindow::onTranslateEvent scaled X and Z by 0.001 * zoomValue() before applying, so translateTo(10, 20, 30) at distance 140 landed at vpt [1.4, 20, 4.2] and never round-tripped. that scaling is right for relative device motion but wrong for an absolute target, so absolute events now go through Camera::setVpt()/setVpr() (via new QGLView::setVpt/setVpr, which emit cameraChanged like the other view mutators so Viewport Control refreshes). relative translate/rotate behavior is unchanged.

missing data items: getDistance() (vpd), getFov() (vpf) and getProjection() ("PERSPECTIVE"/"ORTHOGONAL") through the same chain, plus getTranslation's out arg is now actually named translation in the introspection xml.

registration failures are honored. the driver ignored the return of registerObject()/registerService() and reported open either way, so a second OpenSCAD process showed "DBusInputDriver open" in Axes while being unreachable through the well-known name. open() now returns false and logs the reason. multi-session identity itself is deliberately not addressed here, that design question is still open in the issue.

Related to #6940. This covers viewport state; window identity and packaging remain open.

Testing

built on macOS (qt 6.11, ENABLE_QTDBUS on) and exercised the live service over the session bus with dbus-send:

  • getRotation/getTranslation match the Viewport Control panel for the same viewport (before: internal coords)
  • translateTo(10, 20, 30) followed by getTranslation returns [10, 20, 30] exactly (before: X and Z scaled by 0.001*distance)
  • rotateTo(30, 0, 150) followed by getRotation returns [30, 0, 150]
  • getDistance/getFov/getProjection return live vpd/vpf/projection
  • a second instance fails registerService and reports not-open instead of a bogus open

this is gui/session-bus behavior so there is no unit test seam for it in this repo (tests are cmdline .scad based and dont reach MainWindow/QGLView). the mechanical half (xml generates a matching adaptor/proxy, clang-format clean) is covered by the Beautify check.

Scope

  • src/gui/MainWindow.cc: getters use getVpt/getVpr, absolute input events set vpt/vpr directly, three new getter forwards
  • src/gui/QGLView.{h,cc}: setVpt/setVpr mirroring zoomFov
  • src/gui/input/{DBusInputDriver,InputDriverManager}.{h,cc}: new getters through the existing chain, registration failures honored
  • org.openscad.OpenSCAD.xml: getDistance/getFov/getProjection, arg name fix, docstrings on the two getters whose meaning changed

getRotation/getTranslation returned Camera::object_rot/object_trans
internal coordinates, which disagree with the values every other
interface exposes ($vpr/$vpt, Viewport Control, Copy viewport values).
Use Camera::getVpr()/getVpt() so the D-Bus getters agree with the UI.

translateTo()/rotateTo() now speak the same user-facing dialect:
absolute translate events were scaled by 0.001*zoom on X/Z in
MainWindow::onTranslateEvent, so they never round-tripped. Absolute
events now go through QGLView::setVpt/setVpr (new, mirroring zoomFov)
which also emit cameraChanged so Viewport Control refreshes.

Add getDistance/getFov/getProjection for the remaining viewport state,
honor registerObject/registerService failures so a second instance
reports not-open instead of a bogus open, and name getTranslation's
out arg correctly in the introspection xml.

Issue openscad#6940 (viewport state part; window identity and packaging stay
open there)

@jordanbrown0 jordanbrown0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little worried about the potential compatibility hits here.

It is not clear to me how many real DBus consumers there are, or what their usage looks like. It might be good to get feedback from @MichaelPFrey and @Lenbok, who seem to be DBus users.

If the compatibility hit is too large, the workaround does not seem onerous: deprecate the existing methods and introduce new methods with new names - probably with "2" appended.

In theory this is a compatibility hit for InputEventTranslate with viewPortRelative=false and relative=false, and for InputEventRotate with relative=false. We need to inspect other input event drivers to see if they can ever use those variants.

Comment thread src/gui/input/InputDriverManager.cc
Comment thread src/gui/MainWindow.cc
Comment thread src/gui/MainWindow.cc
Comment thread src/gui/MainWindow.cc
@atirna

atirna commented Sep 16, 2026 •

Copy link
Copy Markdown
Author

@Lenbok

Lenbok commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

This seems fine in terms of not impacting my existing use at all, which to date has only been setters rather than getters.

@coffeecanary

Copy link
Copy Markdown

Built and tested PR 7035 at commit 1c503ab61dca4abd52d64f1f01111cd92a9cab74 using the separate MSYS2 build at srcdir/builddir-pr-7035/openscad.exe.

Viewport Getters

Live D-Bus introspection exposed all expected methods, including the new getters:

  • getDistance()
  • getFov()
  • getProjection()

The initial viewport returned:

Translation: [0, 0, 0]
Rotation:    [55, 0, 25]
Distance:    140
FOV:         22.5
Projection:  PERSPECTIVE

The absolute setter/getter round trip succeeded exactly:

translateTo(10, 20, 30) -> getTranslation() = [10, 20, 30]
rotateTo(30, 0, 150)    -> getRotation()    = [30, 0, 150]

The viewport was then restored to translation [0, 0, 0] and rotation [55, 0, 25], and both restored values were confirmed through the getters.

A manually rotated and translated viewport was also compared directly with Window > Viewport Control:

Value Viewport Control D-Bus getter
Translation [10.80, -3.59, 15.70] [10.7996, -3.58939, 15.7013]
Rotation [247.70, 0.00, 355.60] [247.7, 0, 355.6]
Distance 140.00 140
FOV 22.50 22.5
Projection Perspective PERSPECTIVE

The translation difference is only display rounding; all values agree at the precision shown in the UI. This verifies on Windows that the PR fixes the old absolute translation scaling problem, uses the user-facing viewport representation, and supplies the missing distance, FOV, and projection getters.

Process Registration

Two independent PR-build processes were then started. A second process left at the startup chooser was not a valid test: the source shows that the chooser completes before MainWindow is created, the D-Bus driver is registered, and InputDriverManager::init() runs.

The second process was therefore launched with a SCAD file so it initialized fully. The first process retained ownership of org.openscad.OpenSCAD, and calls through that name continued to return the first viewport. The second process connected as :1.29 but did not leave a callable object: a direct getter call returned org.freedesktop.DBus.Error.UnknownObject. This confirms that the PR unregisters the second application object after failing to acquire the well-known service name.

In the initialized second process, Edit > Preferences > Axes is expected to show:

DBusInputDriver not open

The console-captured error was:

ERROR: DBusInputDriver: could not register service:

Qt supplied no detail after the colon. The registration failure and object cleanup are verified on Windows; the missing error detail is a remaining diagnostic limitation.

No message appeared in the GUI Console or Error Log, which is consistent with the startup order. MainWindow uses a scoped output handler during construction and clears it before InputDriverManager::init() opens the D-Bus driver. With no GUI output handler active at registration time, LOG(...) writes the error to standard error instead of either dock.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants