-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/adaptive dial support #5
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f034a59
Change release type to Minor and fixed formatting
Jarex985 737ac17
fix: modifier keys not executing properly with mouse buttons, "hold" …
Jarex985 ca19b37
feat: add Adaptive Dial action with shared PI function-picker helpers
ROBdk97 3e5a749
fix: align dial touch press behavior with dial press
ROBdk97 9fe9efa
fix: color-text-secondary
ROBdk97 bd06bd6
feat: add Adaptive Dial action with shared PI function-picker helpers
ROBdk97 e78a9b8
fix: align dial touch press behavior with dial press
ROBdk97 d1020df
fix: color-text-secondary
ROBdk97 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| using System.Diagnostics; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using BarRaider.SdTools; | ||
| using BarRaider.SdTools.Payloads; | ||
| using SCStreamDeck.Common; | ||
| using SCStreamDeck.Logging; | ||
| using SCStreamDeck.Models; | ||
|
|
||
| namespace SCStreamDeck.ActionKeys; | ||
|
|
||
| /// <summary> | ||
| /// Adaptive Star Citizen dial. | ||
| /// Supports separate functions for rotate left, rotate right, and dial press. | ||
| /// </summary> | ||
| [SuppressMessage("ReSharper", "UnusedType.Global", Justification = "Stream Deck action instantiated via SDK reflection")] | ||
| [PluginActionId("com.jarex985.scstreamdeck.adaptivedial")] | ||
| public sealed class AdaptiveDial(SDConnection connection, InitialPayload payload) : SCDialActionBase(connection, payload) | ||
| { | ||
| public override async void DialRotate(DialRotatePayload payload) | ||
| { | ||
| try | ||
| { | ||
| await ProcessDialRotateAsync(payload.Ticks).ConfigureAwait(false); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Err($"{GetType().Name}: {ex.Message}", ex); | ||
| } | ||
| } | ||
|
|
||
| public override async void DialDown(DialPayload payload) | ||
| { | ||
| try | ||
| { | ||
| PlayClickSoundIfConfigured(); | ||
| await ProcessPressEventAsync(true).ConfigureAwait(false); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Err($"{GetType().Name}: {ex.Message}", ex); | ||
| } | ||
| } | ||
|
|
||
| public override async void DialUp(DialPayload payload) | ||
| { | ||
| try | ||
| { | ||
| await ProcessPressEventAsync(false).ConfigureAwait(false); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Err($"{GetType().Name}: {ex.Message}", ex); | ||
| } | ||
| } | ||
|
|
||
| public override async void TouchPress(TouchpadPressPayload payload) | ||
| { | ||
| try | ||
| { | ||
| // SDK versions may differ on TouchpadPressPayload shape; read pressed-state defensively. | ||
| bool isKeyDown = true; | ||
| object? pressedValue = payload.GetType().GetProperty("Pressed")?.GetValue(payload); | ||
| if (pressedValue is bool pressed) | ||
| { | ||
| isKeyDown = pressed; | ||
| } | ||
|
|
||
| if (isKeyDown) | ||
| { | ||
| PlayClickSoundIfConfigured(); | ||
| } | ||
|
|
||
| await ProcessPressEventAsync(isKeyDown).ConfigureAwait(false); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Err($"{GetType().Name}: {ex.Message}", ex); | ||
| } | ||
| } | ||
|
|
||
| private async Task ProcessDialRotateAsync(int ticks) | ||
| { | ||
| if (ticks == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| string? actionId = ResolveRotationFunction(Settings, ticks); | ||
| (KeybindingAction, string)? validationResult = ValidateAndResolve(actionId); | ||
| if (validationResult == null || string.IsNullOrWhiteSpace(actionId)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| int rotationSteps = Math.Abs(ticks); | ||
| string executableBinding = validationResult.Value.Item2; | ||
|
|
||
| for (int i = 0; i < rotationSteps; i++) | ||
| { | ||
| bool success = await KeybindingService.ExecutePressNoRepeatAsync(actionId, executableBinding) | ||
| .ConfigureAwait(false); | ||
| if (success) | ||
| { | ||
| LogRotateExec(actionId, ticks, executableBinding); | ||
| } | ||
| } | ||
|
ROBdk97 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| private async Task ProcessPressEventAsync(bool isKeyDown) | ||
| { | ||
| (KeybindingAction, string)? validationResult = ValidateAndResolve(Settings.PressFunction); | ||
| if (validationResult == null || string.IsNullOrWhiteSpace(Settings.PressFunction)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| (KeybindingAction action, string executableBinding) = validationResult.Value; | ||
|
|
||
| KeybindingExecutionContext context = new() | ||
| { | ||
| ActionName = Settings.PressFunction, | ||
| Binding = executableBinding, | ||
| ActivationMode = action.ActivationMode, | ||
| IsKeyDown = isKeyDown | ||
| }; | ||
|
|
||
| await ExecuteKeybindingAsync(context).ConfigureAwait(false); | ||
| } | ||
|
|
||
| internal static string? ResolveRotationFunction(Settings.DialSettings settings, int ticks) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(settings); | ||
|
|
||
| return ticks switch | ||
| { | ||
| > 0 => settings.RotateRightFunction, | ||
| < 0 => settings.RotateLeftFunction, | ||
| _ => null | ||
| }; | ||
| } | ||
|
|
||
| [ExcludeFromCodeCoverage] | ||
| private (KeybindingAction, string)? ValidateAndResolve(string? actionId) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(actionId) || !CanExecuteBindings) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| if (!KeybindingService.TryGetAction(actionId, out KeybindingAction? action) || action == null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| string? executableBinding = ResolveExecutableBinding(action); | ||
| return executableBinding == null ? null : (action, executableBinding); | ||
| } | ||
|
|
||
| internal static string? ResolveExecutableBinding(KeybindingAction action) | ||
| { | ||
| ArgumentNullException.ThrowIfNull(action); | ||
|
|
||
| if (!string.IsNullOrWhiteSpace(action.KeyboardBinding)) | ||
| { | ||
| return action.KeyboardBinding; | ||
| } | ||
|
|
||
| if (string.IsNullOrWhiteSpace(action.MouseBinding)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| InputType bindingType = action.MouseBinding.GetInputType(); | ||
| return bindingType is InputType.MouseButton or InputType.MouseWheel ? action.MouseBinding : null; | ||
| } | ||
|
|
||
| private async Task ExecuteKeybindingAsync(KeybindingExecutionContext context) | ||
| { | ||
| try | ||
| { | ||
| bool success = await KeybindingService.ExecuteAsync(context).ConfigureAwait(false); | ||
| if (success) | ||
| { | ||
| LogPressExec(context); | ||
| } | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Log.Err($"{GetType().Name}: '{context.ActionName}': {ex.Message}", ex); | ||
| } | ||
| } | ||
|
|
||
| [Conditional("DEBUG")] | ||
| private void LogPressExec(KeybindingExecutionContext context) => | ||
| Log.Debug( | ||
| $"{GetType().Name}: {(context.IsKeyDown ? "pressed" : "released")} '{context.ActionName}' ({context.ActivationMode}) → '{context.Binding}'"); | ||
|
|
||
| [Conditional("DEBUG")] | ||
| private static void LogRotateExec(string actionName, int ticks, string binding) => | ||
| Log.Debug($"{nameof(AdaptiveDial)}: rotated '{actionName}' ticks={ticks} → '{binding}'"); | ||
| } | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.