Repository navigation
feat(razer): a layer switch so Hypershift bindings can be edited #1799
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
Changes from all commits
af95eef
f8b98af
1df220c
abe122a
cd04302
2cf51f0
81af714
54e4278
acaa495
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1616,13 +1616,22 @@ const RAZER_KEY_OPTION = "__razer_key__"; | |||||
|
|
||||||
| export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): ReactNode { | ||||||
| const locale = snapshot.preferences.locale; | ||||||
| const mappings = snapshot.status?.razerButtonMappings; | ||||||
| const standard = snapshot.status?.razerButtonMappings; | ||||||
| // Written values only: this firmware answers a class `0x02` read with | ||||||
| // whichever layer was written last, so a "read" of Hypershift is the Standard | ||||||
| // value and must not be shown as if it were the layer's contents. | ||||||
| const hypershift = snapshot.status?.razerHypershiftMappings; | ||||||
| const layerWritable = snapshot.status?.razerHypershiftWritable === true; | ||||||
| // Only the models whose firmware was checked for the key encoding offer it — | ||||||
| // the Viper Mini stores `02 02 <mods> <usage>` where the older clients have | ||||||
| // no keyboard write at all. | ||||||
| const keyCapable = control.supportsRazerKeyMapping(); | ||||||
| const [capturing, setCapturing] = useState<RazerButtonControl | null>(null); | ||||||
| useEffect(() => setCapturing(null), [snapshot.activeDeviceKey]); | ||||||
| const [layer, setLayer] = useState(0); | ||||||
| const [capturing, setCapturing] = useState<{ control: RazerButtonControl; layer: number } | null>(null); | ||||||
| useEffect(() => { | ||||||
| setCapturing(null); | ||||||
| setLayer(0); | ||||||
| }, [snapshot.activeDeviceKey]); | ||||||
| useEffect(() => { | ||||||
| if (!capturing) return undefined; | ||||||
| const onKeyDown = (event: KeyboardEvent): void => { | ||||||
|
|
@@ -1641,13 +1650,14 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re | |||||
| | (event.shiftKey ? RAZER_KEY_MODIFIERS.shift ?? 0 : 0) | ||||||
| | (event.altKey ? RAZER_KEY_MODIFIERS.alt ?? 0 : 0) | ||||||
| | (event.metaKey ? RAZER_KEY_MODIFIERS.meta ?? 0 : 0); | ||||||
| control.applyRazerKeyMapping(capturing, { mods, usage }); | ||||||
| control.applyRazerKeyMapping(capturing.control, { mods, usage }, capturing.layer); | ||||||
| setCapturing(null); | ||||||
| }; | ||||||
| window.addEventListener("keydown", onKeyDown, true); | ||||||
| return () => window.removeEventListener("keydown", onKeyDown, true); | ||||||
| }, [capturing]); | ||||||
| if (!mappings) return null; | ||||||
| if (!standard) return null; | ||||||
| const mappings = layer === 1 ? (hypershift ?? {}) : standard; | ||||||
| const busy = snapshot.settingInProgress; | ||||||
| const rows: Array<{ key: string; name: string; current: string; options: readonly string[]; locked: boolean }> = []; | ||||||
| // The wheel press and the bottom button are model-specific: only a model | ||||||
|
|
@@ -1656,18 +1666,21 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re | |||||
| const options = (snapshot.status?.razerButtonOptions ?? RAZER_BUTTON_MAPPINGS) as readonly string[]; | ||||||
| for (const con of order) { | ||||||
| const current = mappings[con]; | ||||||
| if (!current) continue; | ||||||
| // On Hypershift a control nobody has written to yet is unknown, not absent: | ||||||
| // keep the row so it can be set, and show it as unread. | ||||||
| if (!current && layer === 0) continue; | ||||||
| if (layer === 1 && con === RAZER_LOCKED_BUTTON_CONTROL) continue; | ||||||
| rows.push({ | ||||||
| key: `razer-button-${con}`, | ||||||
| name: RAZER_BUTTON_CONTROL_LABEL[con], | ||||||
| current, | ||||||
| current: current ?? "", | ||||||
| options, | ||||||
| // Left Click is fixed on the Standard layer — Synapse enforces the same | ||||||
| // restriction, and the driver throws rather than send it. | ||||||
| locked: con === RAZER_LOCKED_BUTTON_CONTROL, | ||||||
| }); | ||||||
| } | ||||||
| for (const con of RAZER_TOGGLE_CONTROLS) { | ||||||
| for (const con of layer === 1 ? [] : RAZER_TOGGLE_CONTROLS) { | ||||||
| const current = mappings[con]; | ||||||
| if (!current) continue; | ||||||
| const info = RAZER_TOGGLE_CONTROL_INFO[con]; | ||||||
|
|
@@ -1693,22 +1706,35 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re | |||||
| <div className="setting-heading compact"> | ||||||
| <div><h2>{t(locale, "adv.mapping")}</h2></div> | ||||||
| </div> | ||||||
| {layerWritable ? ( | ||||||
| <Segmented | ||||||
| id="razer-button-layer" | ||||||
| ariaLabel={t(locale, "adv.razerLayer")} | ||||||
| options={[ | ||||||
| { value: 0, label: t(locale, "adv.razerLayerStandard") }, | ||||||
| { value: 1, label: t(locale, "adv.razerLayerHypershift") }, | ||||||
| ]} | ||||||
| value={layer} | ||||||
| onChange={setLayer} | ||||||
|
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. Cancel capture when the selected layer changes. If capture starts on Normal and the user clicks Hypershift, Clear
|
||||||
| /> | ||||||
| ) : null} | ||||||
| <div className="button-remap-list"> | ||||||
| {rows.map((row) => { | ||||||
| const staged = snapshot.pending.keys.includes(row.key); | ||||||
|
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. 🟡 Medium Hypershift edits are staged under keys such as 🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
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. Use the displayed layer in the row pending key. A Hypershift edit is staged as Use a layer-aware pending key for the highlight and
|
||||||
| const known = row.options.includes(row.current); | ||||||
| const known = row.current !== "" && row.options.includes(row.current); | ||||||
| const rowControl = row.key.startsWith("razer-button-") | ||||||
| ? row.key.slice("razer-button-".length) as RazerButtonControl | ||||||
| : null; | ||||||
| const applyRazerRow = (value: string): void => { | ||||||
| if (value === RAZER_KEY_OPTION && rowControl) { | ||||||
| setCapturing(rowControl); | ||||||
| setCapturing({ control: rowControl, layer }); | ||||||
| return; | ||||||
| } | ||||||
| if (row.key.startsWith("razer-button-")) { | ||||||
| control.applyRazerButtonMapping( | ||||||
| row.key.slice("razer-button-".length) as RazerButtonControl, | ||||||
| value as RazerButtonMapping, | ||||||
| layer, | ||||||
| ); | ||||||
| } else { | ||||||
| control.applyRazerToggleControl( | ||||||
|
|
@@ -1724,7 +1750,7 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re | |||||
| data-pending-key={row.key} | ||||||
| > | ||||||
| <span>{displayText(locale, row.name)}</span> | ||||||
| {row.locked ? <output>{displayText(locale, row.current)}</output> : capturing !== null && capturing === rowControl ? ( | ||||||
| {row.locked ? <output>{displayText(locale, row.current)}</output> : capturing !== null && capturing?.control === rowControl ? ( | ||||||
| <span className="button-remap-capture"> | ||||||
| <small className="setting-note">{t(locale, "adv.pressKey")}</small> | ||||||
| <button type="button" className="ghost" onClick={() => setCapturing(null)}> | ||||||
|
|
@@ -1736,13 +1762,15 @@ export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): Re | |||||
| id={row.key} | ||||||
| ariaLabel={displayText(locale, row.name)} | ||||||
| options={[ | ||||||
| ...(known ? [] : [{ value: row.current, label: row.current, disabled: true }]), | ||||||
| ...(known | ||||||
| ? [] | ||||||
| : [{ value: row.current, label: row.current || t(locale, "adv.razerLayerUnknown"), disabled: true }]), | ||||||
| ...row.options.map((option) => ({ value: option, label: option })), | ||||||
| ...(keyCapable && rowControl | ||||||
| ? [{ value: RAZER_KEY_OPTION, label: t(locale, "adv.keyboardShortcut") }] | ||||||
| : []), | ||||||
| ]} | ||||||
| value={row.current} | ||||||
| value={row.current || null} | ||||||
|
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. Select the unread option with its empty-string value. If a Hypershift control has no written value, its unread option has Pass
|
||||||
| value={row.current || null} | |
| value={row.current} |
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @src/features/devices/cards/AdvancedCards.tsx around line 1773:
Unread Hypershift bindings render as `—` instead of the translated unknown-layer message. Their placeholder option has value `""`, but passing `null` prevents `OptionMenu` from selecting it; pass `row.current` so the placeholder is displayed.
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.
🟠 High
cards/AdvancedCards.tsx:1692Switching to Hypershift during key capture still applies the captured key to Standard, even though the prompt remains visible under Hypershift.
onChange={setLayer}leavescapturing.layerunchanged, and the prompt checks only the control; cancel capture when the selected layer changes.🚀 Reply "fix it for me" or copy this AI Prompt for your agent: