-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add SpaceMouse support for Linux via libspnav #20619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This change introduces support for 3Dconnexion SpaceMouse devices on Linux within the 3DConnexion plugin. Key changes: - Added `LinuxSpacenavClient.py`, which uses `ctypes` to interface with the system-provided `libspnav.so.0` library. This client handles opening a connection to the `spacenavd` daemon and polling for motion and button events. - Modified `NavlibClient.py` to include platform detection. On Linux, it now uses `LinuxSpacenavClient` for device input. On Windows and macOS, it continues to use the existing `pynavlib`. - Updated the plugin initialization in `plugins/3DConnexion/__init__.py` to gracefully handle cases where `libspnav.so.0` might be missing or `spacenavd` is not accessible on Linux, disabling the plugin in such scenarios. - The core camera manipulation logic in `NavlibClient.py` has been adapted to accept transformation matrices from either `pynavlib` or the new Linux client, aiming for consistent behavior. - Placeholder adaptations for some `pynavlib`-specific methods have been added for the Linux path, returning `None` or basic Python types where `pynav.*` types were previously used. This implementation relies on you having `spacenavd` (version 0.6 or newer recommended) installed and running, along with `libspnav0` (or equivalent). Testing for this feature is currently manual, involving checking device response for camera manipulation (pan, zoom, rotate) within Cura on a Linux environment with a configured SpaceMouse. Output:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for 3Dconnexion SpaceMouse devices on Linux by adding a new Linux client that interfaces with libspnav and adapting existing navigation logic to use it. Key changes include:
- Adding LinuxSpacenavClient.py to handle ctypes integration with libspnav.
- Updating NavlibClient.py with Linux-specific event polling, return type adjustments, and conditional initialization.
- Modifying the plugin registration in init.py to disable the plugin gracefully on Linux when initialization fails.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
plugins/3DConnexion/init.py | Adjusts plugin registration to check Linux client availability and disable the plugin on failure. |
plugins/3DConnexion/NavlibClient.py | Integrates Linux support with conditional initialization and adjusted return types for Linux paths. |
plugins/3DConnexion/LinuxSpacenavClient.py | Provides a new client that uses ctypes to interface with libspnav for polling motion and button events. |
Comments suppressed due to low confidence (1)
plugins/3DConnexion/init.py:38
- Catching BaseException is too broad and may hide critical exceptions; consider catching Exception instead.
except BaseException as exception:
|
||
def get_camera_matrix(self) -> "pynav.NavlibMatrix": | ||
def get_camera_matrix(self) -> "pynav.NavlibMatrix" or Matrix: # Adjusted return type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using 'or' to denote a union type in type annotations is non-standard; consider using Union[pynav.NavlibMatrix, Matrix] for clarity.
def get_camera_matrix(self) -> "pynav.NavlibMatrix" or Matrix: # Adjusted return type | |
def get_camera_matrix(self) -> Union["pynav.NavlibMatrix", Matrix]: # Adjusted return type |
Copilot uses AI. Check for mistakes.
self._scene_radius = 1.0 # Used in set_camera_matrix, ensure it exists | ||
|
||
|
||
if self._platform_system == "Linux": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The repeated platform checks for "Linux" throughout the file could be centralized to improve maintainability.
if self._platform_system == "Linux": | |
if self._is_linux(): |
Copilot uses AI. Check for mistakes.
Test Results23 783 tests 23 781 ✅ 46s ⏱️ Results for commit 4698089. |
This change introduces support for 3Dconnexion SpaceMouse devices on Linux within the 3DConnexion plugin. This PR has been created with: https://jules.google.com/ and is untested
Key changes:
LinuxSpacenavClient.py
, which usesctypes
to interface with thesystem-provided
libspnav.so.0
library. This client handles opening aconnection to the
spacenavd
daemon and polling for motion and buttonevents.
NavlibClient.py
to include platform detection. On Linux, itnow uses
LinuxSpacenavClient
for device input. On Windows and macOS,it continues to use the existing
pynavlib
.plugins/3DConnexion/__init__.py
to gracefully handle cases where
libspnav.so.0
might be missing orspacenavd
is not accessible on Linux, disabling the plugin in suchscenarios.
NavlibClient.py
has been adaptedto accept transformation matrices from either
pynavlib
or the newLinux client, aiming for consistent behavior.
pynavlib
-specific methods have beenadded for the Linux path, returning
None
or basic Python types wherepynav.*
types were previously used.This implementation relies on you having
spacenavd
(version 0.6 or newer recommended) installed and running, along withlibspnav0
(or equivalent).Testing for this feature is currently manual, involving checking device response for camera manipulation (pan, zoom, rotate) within Cura on a Linux environment with a configured SpaceMouse.
Should fix: #20578