-
Notifications
You must be signed in to change notification settings - Fork 33
feat: add mouse wheel support #445
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
Open
LukeShortCloud
wants to merge
1
commit into
ShadowBlip:main
Choose a base branch
from
LukeShortCloud:mouse-wheel-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -919,6 +919,7 @@ impl CompositeDevice { | |
| continue; | ||
| } | ||
| } | ||
| Mouse::Wheel(_) => {} | ||
| }, | ||
| Capability::Touchscreen(_) => (), | ||
| } | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ use crate::{ | |
| use super::dbus::Action; | ||
|
|
||
| /// Possible errors while doing input value translation | ||
| #[derive(Debug)] | ||
| pub enum TranslationError { | ||
| /// Translation not yet implemented | ||
| NotImplemented, | ||
|
|
@@ -138,6 +139,8 @@ impl InputValue { | |
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| // Gamepad Button -> Mouse Button | ||
| Mouse::Button(_) => Ok(self.clone()), | ||
| // Gamepad Button -> Mouse Wheel | ||
| Mouse::Wheel(_) => self.translate_button_to_wheel(target_config), | ||
| }, | ||
| // Gamepad Button -> Keyboard | ||
| Capability::Keyboard(_) => Ok(self.clone()), | ||
|
|
@@ -183,11 +186,10 @@ impl InputValue { | |
| }, | ||
| // Axis -> Mouse | ||
| Capability::Mouse(mouse) => match mouse { | ||
| // Axis -> Mouse Motion | ||
| Mouse::Motion => self | ||
| .translate_axis_to_mouse_motion(source_config, target_config), | ||
| // Axis -> Mouse Button | ||
| Mouse::Button(_) => self.translate_axis_to_button(source_config), | ||
| Mouse::Wheel(_) => Err(TranslationError::NotImplemented), | ||
| }, | ||
| // Axis -> Keyboard | ||
| Capability::Keyboard(_) => self.translate_axis_to_button(source_config), | ||
|
|
@@ -233,6 +235,7 @@ impl InputValue { | |
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| // Trigger -> Mouse Button | ||
| Mouse::Button(_) => self.translate_trigger_to_button(source_config), | ||
| Mouse::Wheel(_) => Err(TranslationError::NotImplemented), | ||
| }, | ||
| // Trigger -> Keyboard | ||
| Capability::Keyboard(_) => self.translate_trigger_to_button(source_config), | ||
|
|
@@ -266,6 +269,7 @@ impl InputValue { | |
| Capability::Mouse(mouse) => match mouse { | ||
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| Mouse::Button(_) => self.translate_dial_to_button(source_config), | ||
| Mouse::Wheel(_) => Err(TranslationError::NotImplemented), | ||
| }, | ||
| Capability::Keyboard(_) => self.translate_dial_to_button(source_config), | ||
| Capability::Touchpad(touch) => match touch { | ||
|
|
@@ -307,6 +311,7 @@ impl InputValue { | |
| Capability::Mouse(mouse) => match mouse { | ||
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| Mouse::Button(_) => Ok(self.clone()), | ||
| Mouse::Wheel(_) => self.translate_button_to_wheel(target_config), | ||
| }, | ||
| // Keyboard Key -> Keyboard | ||
| Capability::Keyboard(_) => Ok(self.clone()), | ||
|
|
@@ -340,6 +345,7 @@ impl InputValue { | |
| // Touchscreen Motion -> Mouse Motion | ||
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| Mouse::Button(_) => Err(TranslationError::NotImplemented), | ||
| Mouse::Wheel(_) => Err(TranslationError::NotImplemented), | ||
| }, | ||
| Capability::Keyboard(_) => Err(TranslationError::NotImplemented), | ||
| // Touchpad Motion -> Touchpad | ||
|
|
@@ -395,6 +401,7 @@ impl InputValue { | |
| // Touchscreen Motion -> Mouse Motion | ||
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| Mouse::Button(_) => Err(TranslationError::NotImplemented), | ||
| Mouse::Wheel(_) => Err(TranslationError::NotImplemented), | ||
| }, | ||
| Capability::Keyboard(_) => Err(TranslationError::NotImplemented), | ||
| // Touchpad Motion -> Touchpad | ||
|
|
@@ -450,6 +457,7 @@ impl InputValue { | |
| // Touchscreen Motion -> Mouse Motion | ||
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| Mouse::Button(_) => Err(TranslationError::NotImplemented), | ||
| Mouse::Wheel(_) => Err(TranslationError::NotImplemented), | ||
| }, | ||
| Capability::Keyboard(_) => Err(TranslationError::NotImplemented), | ||
| // Touchpad Motion -> Touchpad | ||
|
|
@@ -509,6 +517,7 @@ impl InputValue { | |
| Mouse::Motion => Err(TranslationError::NotImplemented), | ||
| // Touchscreen Motion -> Mouse Button | ||
| Mouse::Button(_) => Err(TranslationError::NotImplemented), | ||
| Mouse::Wheel(_) => Err(TranslationError::NotImplemented), | ||
| }, | ||
| // Touchscreen Motion -> Keyboard | ||
| Capability::Keyboard(_) => Err(TranslationError::NotImplemented), | ||
|
|
@@ -678,6 +687,37 @@ impl InputValue { | |
| } | ||
| } | ||
|
|
||
| /// Translate the button value into an axis value based on the given config | ||
| fn translate_button_to_wheel( | ||
| &self, | ||
| target_config: &CapabilityConfig, | ||
| ) -> Result<InputValue, TranslationError> { | ||
| let Some(mouse_config) = target_config.mouse.as_ref() else { | ||
| return Err(TranslationError::InvalidTargetConfig( | ||
| "No mouse config to translate button to mouse wheel".to_string(), | ||
| )); | ||
| }; | ||
| let Some(wheel) = mouse_config.wheel.as_ref() else { | ||
| return Err(TranslationError::InvalidTargetConfig( | ||
| "No mouse config found".to_string(), | ||
| )); | ||
| }; | ||
| let Some(direction) = wheel.direction.as_ref() else { | ||
| return Err(TranslationError::InvalidTargetConfig( | ||
| "No wheel direction found to translate button to mouse wheel".to_string(), | ||
| )); | ||
| }; | ||
| match direction.as_str() { | ||
| "up" => Ok(InputValue::Float(1.0)), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cases with the same return value can be combined.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I didn't know about that Rust functionality. Thanks! I'll update the code. |
||
| "down" => Ok(InputValue::Float(-1.0)), | ||
| "left" => Ok(InputValue::Float(-1.0)), | ||
| "right" => Ok(InputValue::Float(1.0)), | ||
| _ => Err(TranslationError::InvalidTargetConfig( | ||
| "Invalid mouse wheel config. Must be of value: up or down (Vertical) or left or right (Horizontal)".to_string(), | ||
| )), | ||
| } | ||
| } | ||
|
|
||
| /// Translate the button value into an axis value based on the given config | ||
| fn translate_button_to_axis( | ||
| &self, | ||
|
|
||
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
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.
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.
What value is the name attribute providing? I.e. I can't have a horizontal up or vertical left? Plane is essentially assumed.
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.
What do you mean? Are you saying there would be issues with trying to use both at the same time? The normal scroll up and down function and pushing left or right feel very different (at least on my mice). I think it would be clunky to try and and go horizontal up or vertical left.
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.
I think the name is redundant. Up and down will always be vertical, so it's not adding value. I agree that vertical left would be weird/clunky and doesn't make sense.
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.
Ah, I understand now. The
target_events.mouse.wheel.nameandtarget_events.mouse.wheel.directattributes are somewhat redundant. So maybe I can consolidate into something like this.Before:
After:
to align with similar existing target events. For example:
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.
@pastaq The
nameis the name of the capability, and the direction is used for mapping a particular direction of the wheel if the user doesn't want to map the whole axis. Relying only on the direction kind of breaks convention with how we define mapping every other type of event.E.g. axes are mapped with this convention:
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.
This isn't an analogous situation. Vertical and horizontal aren't Capabilities, they are directions. Mouse:Wheel is a Capability that can do up down left right, just like Gamepad:LeftStick. If your analogy was accurate it would be Gamepad:LeftStick: Vertical:Up, which would be equally silly. There's also not a conflict with the button click as that should be handled by Mouse:Button:Middle
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.
So you would rather see
Mouse:Wheelchanged into aVector2value? That will require some minor refactoring.