-
-
Notifications
You must be signed in to change notification settings - Fork 81
Show Layer-Tap/Mod-Tap information on keys #135
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
BafS
wants to merge
12
commits into
zmkfirmware:main
Choose a base branch
from
BafS:feat/layer-tap-key-1
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.
+146
−10
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
81f388a
Show Layer-Tap information on keys
BafS b6abd80
Update design, make it work with mod-tap too
BafS 85604ac
Add indicators
BafS 5503f7c
Handle "transparent" behavior
BafS 0246fba
Change logic to not depend on behavior names
BafS 7ad3b9d
Simplify the key visual, use logic from BehaviorBindingPicker (WIP)
BafS 4624d55
Revert some unrelated changes
BafS 7b9bf07
Simplify logic and improve key UI
BafS 4ec09be
Fix spacing when multilines param
BafS 7c8619c
Revert validateBinding move
BafS 8926887
Don't truncate param
BafS a177a63
Cleanup
BafS 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
| import { HidUsageLabel } from "../keyboard/HidUsageLabel"; | ||
| import { BehaviorBindingParametersSet, BehaviorParameterValueDescription } from "@zmkfirmware/zmk-studio-ts-client/behaviors"; | ||
| import { validateValue } from "./parameters"; | ||
|
|
||
| /** | ||
| * Find the matching parameter set based on param1 value. | ||
| * This is critical for determining param2 type, as param2's type can depend on param1's value. | ||
| */ | ||
| export function findMatchingParameterSet( | ||
| param1: number | undefined, | ||
| metadata: BehaviorBindingParametersSet[], | ||
| layerIds: number[] | ||
| ): BehaviorBindingParametersSet | undefined { | ||
| return metadata.find(set => validateValue(layerIds, param1, set.param1)); | ||
| } | ||
|
|
||
| /** | ||
| * Get a readable display for a parameter value based on its metadata. | ||
| * Returns a JSX element, string, number, or null if nothing should be displayed. | ||
| * Returns null when the parameter shouldn't be displayed (empty metadata or nil type). | ||
| */ | ||
| export function getParameterDisplay( | ||
| value: number, | ||
| paramDescriptions: BehaviorParameterValueDescription[], | ||
| layers?: { id: number; name: string }[] | ||
| ): JSX.Element | string | number | null { | ||
| // If no parameter descriptions, don't display anything (matches ParameterValuePicker behavior) | ||
| if (!paramDescriptions || paramDescriptions.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| // Check if it's a constant with a name | ||
| if (paramDescriptions.every(v => v.constant !== undefined)) { | ||
| const match = paramDescriptions.find(v => v.constant === value); | ||
| if (match?.name) { | ||
| return match.name; | ||
| } | ||
| // If no match found in constants, don't display | ||
| return null; | ||
| } | ||
|
|
||
| // For single parameter descriptions, check the type | ||
| if (paramDescriptions.length === 1) { | ||
| const desc = paramDescriptions[0]; | ||
|
|
||
| if (desc.hidUsage) { | ||
| return <HidUsageLabel hid_usage={value}/>; | ||
| } | ||
|
|
||
| if (desc.layerId && layers) { | ||
| // Look up the layer name by ID | ||
| const layer = layers.find(l => l.id === value); | ||
| return layer?.name || `Layer ${value}`; | ||
| } | ||
|
|
||
| if (desc.range) { | ||
| return value; | ||
| } | ||
|
|
||
| // If it's a nil type or unrecognized, don't display | ||
| return null; | ||
| } | ||
|
|
||
| // For multiple parameter descriptions or unhandled cases, don't display | ||
| return null; | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { GetBehaviorDetailsResponse } from "@zmkfirmware/zmk-studio-ts-client/behaviors"; | ||
| import { findMatchingParameterSet, getParameterDisplay } from "../behaviors/behaviorBindingUtils"; | ||
|
|
||
| export interface KeyBinding { | ||
| param1: number; | ||
| param2: number; | ||
| } | ||
|
|
||
| export const getBindingChildren = ( | ||
| behavior: GetBehaviorDetailsResponse | undefined, | ||
| binding: KeyBinding, | ||
| layers: { id: number; name: string }[] = [] | ||
| ): JSX.Element | JSX.Element[] => { | ||
| // If no behavior metadata, try to show behavior name | ||
| if (!behavior || !behavior.metadata) { | ||
| return ( | ||
| <div className="relative text-xs opacity-50"> | ||
| {behavior?.displayName || ""} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // Find the matching parameter set for param1 (critical for getting param2 type) | ||
| const layerIds = layers.map(l => l.id); | ||
| const matchingSet = findMatchingParameterSet(binding.param1, behavior.metadata, layerIds); | ||
|
|
||
| // Get displays for both parameters | ||
| const param1Display = | ||
| getParameterDisplay(binding.param1, behavior.metadata.flatMap(m => m.param1), layers); | ||
|
|
||
| const param2Display = matchingSet ? | ||
| getParameterDisplay(binding.param2, matchingSet.param2, layers) : | ||
| null; | ||
|
|
||
| // Both parameters present and should be displayed | ||
| if (param1Display !== null && param2Display !== null) { | ||
| return [ | ||
| <div key="p2" className="relative text-s"> | ||
| {param2Display} | ||
| </div>, | ||
| <div key="p1" className="relative text-xs ml-1 mt-2"> | ||
| {param1Display} | ||
| </div> | ||
| ]; | ||
| } | ||
|
|
||
| // Only param1 should be displayed | ||
| if (param1Display !== null) { | ||
| return ( | ||
| <div className="relative text-base"> | ||
| {param1Display} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // Only param2 should be displayed (unusual but handle it) | ||
| if (param2Display !== null) { | ||
| return ( | ||
| <div className="relative text-base"> | ||
| {param2Display} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| // Nothing to display | ||
| return <div className="relative"></div>; | ||
| }; | ||
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.
The ordering here is tricky and I think could be up for discussion, but imo is fine for now