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
base: main
Are you sure you want to change the base?
Changes from all commits
af95eef
f8b98af
1df220c
abe122a
cd04302
2cf51f0
81af714
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,16 +10,17 @@ | |||||||||||
| type EggSpdtMode, | ||||||||||||
| } from "@openmouse/protocol/drivers/endgame/egg-op1-hid"; | ||||||||||||
| import { | ||||||||||||
| RAZER_BUTTON_CONTROLS, | ||||||||||||
| RAZER_BUTTON_CONTROL_LABEL, | ||||||||||||
| RAZER_BUTTON_MAPPINGS, | ||||||||||||
| RAZER_KEY_MODIFIERS, | ||||||||||||
| RAZER_LOCKED_BUTTON_CONTROL, | ||||||||||||
| RAZER_TOGGLE_CONTROLS, | ||||||||||||
| RAZER_TOGGLE_CONTROL_INFO, | ||||||||||||
| type RazerButtonControl, | ||||||||||||
| type RazerButtonMapping, | ||||||||||||
| type RazerToggleControl, | ||||||||||||
| } from "@openmouse/protocol/razer"; | ||||||||||||
| import { hidKeyUsage, isModifierCode } from "../../../shared/hid-keys"; | ||||||||||||
| import { teevolutionSensorModeUi } from "@openmouse/protocol/teevolution"; | ||||||||||||
| import type { KsnakeMacroProfile, KsnakeMacroStep } from "@openmouse/protocol/ksnake"; | ||||||||||||
| import type { WallhackMacroStep } from "@openmouse/protocol/wallhack"; | ||||||||||||
|
|
@@ -1587,26 +1588,77 @@ | |||||||||||
| * Laid out with `button-remap-list`/`button-remap-row` to match | ||||||||||||
| * `MxMasterButtonsCard`, the other remap card in this same tab. | ||||||||||||
| */ | ||||||||||||
|
|
||||||||||||
| /** OptionMenu sentinel: picking this starts a key capture instead of a mapping. */ | ||||||||||||
| const RAZER_KEY_OPTION = "__razer_key__"; | ||||||||||||
|
|
||||||||||||
| export function RazerButtonCard({ snapshot }: { snapshot: ControlSnapshot }): ReactNode { | ||||||||||||
| const locale = snapshot.preferences.locale; | ||||||||||||
| const mappings = snapshot.status?.razerButtonMappings; | ||||||||||||
| if (!mappings) return null; | ||||||||||||
| 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 [layer, setLayer] = useState(0); | ||||||||||||
| const [capturing, setCapturing] = useState<{ control: RazerButtonControl; layer: number } | null>(null); | ||||||||||||
| useEffect(() => { | ||||||||||||
| setCapturing(null); | ||||||||||||
| // A different mouse has its own layers; never carry the switch across. | ||||||||||||
| if (!snapshot.status?.razerHypershiftMappings) setLayer(0); | ||||||||||||
| }, [snapshot.activeDeviceKey, snapshot.status?.razerHypershiftMappings]); | ||||||||||||
|
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. Keyboard capture can cancel during unrelated refreshes. Capture ends whenever the Hypershift mapping object changes identity. While any change is staged, every snapshot rebuild clones that object. Any controller emit, such as a background status refresh, then ends capture silently. The user must start capture again, and the next key press does not bind. Depend on whether the mouse has a Hypershift map instead. Capture still ends when the active device changes, as intended. Suggested fix
|
||||||||||||
| useEffect(() => { | ||||||||||||
| if (!capturing) return undefined; | ||||||||||||
| const onKeyDown = (event: KeyboardEvent): void => { | ||||||||||||
| // A bare modifier is the start of a chord, not the key itself. | ||||||||||||
| if (isModifierCode(event.code)) return; | ||||||||||||
| event.preventDefault(); | ||||||||||||
| event.stopPropagation(); | ||||||||||||
| if (event.code === "Escape") { | ||||||||||||
| setCapturing(null); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
| if (event.repeat) return; | ||||||||||||
| const usage = hidKeyUsage(event.code); | ||||||||||||
| if (usage === null) return; | ||||||||||||
| const mods = (event.ctrlKey ? RAZER_KEY_MODIFIERS.ctrl ?? 0 : 0) | ||||||||||||
| | (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.control, { mods, usage }, capturing.layer); | ||||||||||||
| setCapturing(null); | ||||||||||||
| }; | ||||||||||||
| window.addEventListener("keydown", onKeyDown, true); | ||||||||||||
| return () => window.removeEventListener("keydown", onKeyDown, true); | ||||||||||||
| }, [capturing]); | ||||||||||||
| 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 }> = []; | ||||||||||||
| for (const con of RAZER_BUTTON_CONTROLS) { | ||||||||||||
| // The wheel press and the bottom button are model-specific: only a model | ||||||||||||
| // whose firmware answers for them contributes a row. | ||||||||||||
| const order: RazerButtonControl[] = ["leftClick", "scrollClick", "rightClick", "mouse4", "mouse5", "dpiButton"]; | ||||||||||||
| 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; | ||||||||||||
| rows.push({ | ||||||||||||
| key: `razer-button-${con}`, | ||||||||||||
| name: RAZER_BUTTON_CONTROL_LABEL[con], | ||||||||||||
| current, | ||||||||||||
| options: RAZER_BUTTON_MAPPINGS, | ||||||||||||
| 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]; | ||||||||||||
|
|
@@ -1632,15 +1684,35 @@ | |||||||||||
| <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} | ||||||||||||
|
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. 🟠 High Switching to Hypershift during key capture still applies the captured key to Standard, even though the prompt remains visible under Hypershift.
Suggested change
🚀 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. 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({ 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( | ||||||||||||
|
|
@@ -1656,15 +1728,27 @@ | |||||||||||
| data-pending-key={row.key} | ||||||||||||
| > | ||||||||||||
| <span>{displayText(locale, row.name)}</span> | ||||||||||||
| {row.locked ? <output>{displayText(locale, row.current)}</output> : ( | ||||||||||||
| {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)}> | ||||||||||||
| {t(locale, "common.cancel")} | ||||||||||||
| </button> | ||||||||||||
| </span> | ||||||||||||
| ) : ( | ||||||||||||
| <OptionMenu | ||||||||||||
| 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
|
||||||||||||
| disabled={busy} | ||||||||||||
| onChange={applyRazerRow} | ||||||||||||
| /> | ||||||||||||
|
|
||||||||||||
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.
Update the protocol dependency before using the new layer field.
The supplied CI run fails with TS2339 because
MouseStatusdoes not containrazerHypershiftMappings. The same error occurs in the keyboard preview andAdvancedCards.tsx. Sincenpm run buildrunstsc --noEmitfirst, this blocks the build.Update the declared dependency and lockfile to a protocol release that includes the layer status and writer support. Keep the Standard-layer fallback for models without Hypershift data.
GitHub Actions: CI / check
[error] 7041-7041: npm run build failed during TypeScript compilation: TS2339, property 'razerHypershiftMappings' does not exist on type 'MouseStatus'.
Source: Pipeline failures