diff --git a/public/devices/xiaomi-mi-gaming-mouse.png b/public/devices/xiaomi-mi-gaming-mouse.png new file mode 100644 index 00000000..74df4297 Binary files /dev/null and b/public/devices/xiaomi-mi-gaming-mouse.png differ diff --git a/src/device/controller.ts b/src/device/controller.ts index fedcaac1..1dda1de6 100644 --- a/src/device/controller.ts +++ b/src/device/controller.ts @@ -98,6 +98,8 @@ import { ensureDriverModules, driverModules, type DriverModules } from "./driver import type { MagneticButtonStatus, MouseLighting, MouseStatus } from "@openmouse/protocol/drivers/mouse-types"; import type { KsnakeMacroProfile } from "@openmouse/protocol/ksnake"; import type { WallhackCurvePoint, WallhackMacroStep } from "@openmouse/protocol/wallhack"; +import type { XiaomiBinding, XiaomiMacroEvent } from "@openmouse/protocol/xiaomi"; +import { XIAOMI_BUTTON_NAMES, XIAOMI_KEY_COMBOS, XIAOMI_MACRO_EVENT_SIZE } from "@openmouse/protocol/xiaomi"; import { cloneM2NexProfile, loadM2NexProfiles, @@ -143,6 +145,7 @@ import type { WLMouseHidClient } from "@openmouse/protocol/drivers/wlmouse/hid"; import type { WLMouseBeastX4kHidClient } from "@openmouse/protocol/drivers/wlmouse/beast-x-4k-hid"; import type { DareuHidClient } from "@openmouse/protocol/drivers/dareu/hid"; import type { IncottHidClient } from "@openmouse/protocol/drivers/incott/hid"; +import type { XiaomiHidClient } from "@openmouse/protocol/drivers/xiaomi/hid"; import type { IncottMacro } from "@openmouse/protocol/incott"; import { BASILISK_V3_PRO_BLUETOOTH, HID_FILTERS } from "./hid-filters"; import { VENDOR_ID } from "@openmouse/protocol/drivers/vendors"; @@ -272,7 +275,7 @@ const needsOpenClasses = (): Array | undefined> => CM()?.MchoseHidClient, CM()?.MchoseDockHidClient, CM()?.MchoseA5ProMaxHidClient, CM()?.MchoseV3HidClient, CM()?.MicrosoftHidClient, CM()?.DareuHidClient, CM()?.IncottHidClient, CM()?.BytechHidClient, CM()?.RapooHidClient, CM()?.FaterHidClient, CM()?.CoolerMasterHidClient, CM()?.RedragonM690ProHidClient, CM()?.AjazzHidClient, - CM()?.HitscanHidClient, + CM()?.HitscanHidClient, CM()?.XiaomiHidClient, ]; const pulsarClasses = (): Array | undefined> => [CM()?.PulsarHidClient, CM()?.PulsarProHidClient, CM()?.PulsarXs1HidClient]; @@ -300,6 +303,7 @@ const keychron4kClient = (): Keychron4kHidClient | null => activeAs(CM()?.Keychr const wlmouse4kClient = (): WLMouseBeastX4kHidClient | null => activeAs(CM()?.WLMouseBeastX4kHidClient); const wallhackMouseClient = (): WallhackMouseHidClient | null => activeAs(CM()?.WallhackMouseHidClient); const incottClient = (): IncottHidClient | null => activeAs(CM()?.IncottHidClient); +const xiaomiMacroClient = (): XiaomiHidClient | null => activeAs(CM()?.XiaomiHidClient); /** Pulsar is the only family with the collection-explorer onboarding path. */ const pulsarClient = (): PulsarClient | null => active !== null ? activeAs(...pulsarClasses()) : null; @@ -329,6 +333,10 @@ let ksnakeMacrosError: string | null = null; let wallhackMacros: (WallhackMacroStep[] | null)[] | null = null; let wallhackMacrosLoading = false; let wallhackMacrosError: string | null = null; +let xiaomiMacros: (XiaomiMacroEvent[] | null)[] | null = null; +let xiaomiBindings: (XiaomiBinding | null)[] | null = null; +let xiaomiMacrosLoading = false; +let xiaomiMacrosError: string | null = null; let wallhackCurves: Record<"classic" | "natural" | "jump" | "custom", WallhackCurvePoint[]> | null = null; let wallhackCurvesLoading = false; let wallhackCurvesError: string | null = null; @@ -588,6 +596,14 @@ const wallhackMacrosCache: SnapshotCloneCache = { + source: undefined, + output: undefined, +}; +const xiaomiBindingsCache: SnapshotCloneCache = { + source: undefined, + output: undefined, +}; const wallhackCurvesCache: SnapshotCloneCache = { source: undefined, output: undefined, @@ -603,6 +619,18 @@ function cloneWallhackMacrosSnapshot( return source?.map((steps) => steps?.map((step) => ({ ...step, event: { ...step.event } })) ?? null) ?? null; } +function cloneXiaomiMacrosSnapshot( + source: typeof xiaomiMacros, +): typeof xiaomiMacros { + return source?.map((events) => events?.map((event) => ({ ...event })) ?? null) ?? null; +} + +function cloneXiaomiBindingsSnapshot( + source: typeof xiaomiBindings, +): typeof xiaomiBindings { + return source?.map((binding) => (binding ? { ...binding } : null)) ?? null; +} + function cloneWallhackCurvesSnapshot( source: typeof wallhackCurves, ): typeof wallhackCurves { @@ -675,6 +703,10 @@ function buildSnapshot(): ControlSnapshot { wallhackMacros: cachedSnapshotClone(wallhackMacrosCache, wallhackMacros, cloneWallhackMacrosSnapshot), wallhackMacrosLoading, wallhackMacrosError, + xiaomiMacros: cachedSnapshotClone(xiaomiMacrosCache, xiaomiMacros, cloneXiaomiMacrosSnapshot), + xiaomiBindings: cachedSnapshotClone(xiaomiBindingsCache, xiaomiBindings, cloneXiaomiBindingsSnapshot), + xiaomiMacrosLoading, + xiaomiMacrosError, wallhackCurves: cachedSnapshotClone(wallhackCurvesCache, wallhackCurves, cloneWallhackCurvesSnapshot), wallhackCurvesLoading, wallhackCurvesError, @@ -1466,6 +1498,132 @@ export function clearWallhackMacroSlot(slot: number): void { }); } +/** Read the eight Xiaomi Mi Gaming Mouse button bindings and macro bodies. */ +export function loadXiaomiMacros(): void { + if (xiaomiMacrosLoading || xiaomiMacros !== null) return; + const client = xiaomiMacroClient(); + if (!client) { + xiaomiMacrosError = st("macro.notReady"); + emit(); + return; + } + xiaomiMacrosLoading = true; + xiaomiMacrosError = null; + emit(); + void (async () => { + try { + const macros: (XiaomiMacroEvent[] | null)[] = []; + const bindings: (XiaomiBinding | null)[] = []; + for (let button = 0; button < 8; button++) { + const binding = await client.readBinding(button); + bindings.push({ ...binding }); + if (binding.mode === XIAOMI_KEY_COMBOS.MACROS_NO_DELAY || binding.mode === XIAOMI_KEY_COMBOS.MACROS_WITH_DELAY) { + macros.push((await client.readMacro(button)).map((event) => ({ ...event }))); + } else { + macros.push(null); + } + } + if (xiaomiMacroClient() !== client) return; + xiaomiMacros = macros; + xiaomiBindings = bindings; + xiaomiMacrosError = null; + } catch (error) { + xiaomiMacrosError = error instanceof Error ? error.message : String(error); + } finally { + xiaomiMacrosLoading = false; + emit(); + } + })(); +} + +function setXiaomiBinding(button: number, binding: XiaomiBinding): void { + xiaomiBindings = (xiaomiBindings ?? [null, null, null, null, null, null, null, null]).map( + (entry, index) => (index === button ? { ...binding } : entry), + ); +} + +/** Stage a custom key-combo write for one Xiaomi button (0-7). */ +export function applyXiaomiCustomCombo(button: number, modifiers: number, key: number): void { + const client = xiaomiMacroClient(); + if (!client) { + setReadStatus(st("macro.notReady")); + emit(); + return; + } + stageChange({ + key: `xiaomi-combo-${button}`, + label: `Button ${button + 1} combo`, + command: `Save Xiaomi button ${button + 1} combo`, + progress: `Saving Xiaomi button ${button + 1} combo…`, + apply: async () => { + const live = xiaomiMacroClient(); + if (!live) throw new Error(st("ctl.gone")); + await live.setBinding(button, XIAOMI_KEY_COMBOS.CUSTOM_KEY_COMBO, modifiers, key); + if (xiaomiMacroClient() === live) { + setXiaomiBinding(button, { mode: XIAOMI_KEY_COMBOS.CUSTOM_KEY_COMBO, modifiers, key }); + emit(); + } + }, + }); +} + +/** Stage a macro write for one Xiaomi button (0-7). */ +export function applyXiaomiMacro(button: number, mode: number, events: readonly XiaomiMacroEvent[]): void { + const client = xiaomiMacroClient(); + if (!client) { + setReadStatus(st("macro.notReady")); + emit(); + return; + } + const snapshot = events.map((event) => ({ ...event })); + stageChange({ + key: `xiaomi-macro-${button}`, + label: `Button ${button + 1} macro`, + command: `Save Xiaomi button ${button + 1} macro`, + progress: `Saving Xiaomi button ${button + 1} macro…`, + apply: async () => { + const live = xiaomiMacroClient(); + if (!live) throw new Error(st("ctl.gone")); + await live.setMacro(button, mode, snapshot); + if (xiaomiMacroClient() === live) { + xiaomiMacros = (xiaomiMacros ?? [null, null, null, null, null, null, null, null]).map((entry, index) => + index === button ? snapshot.map((event) => ({ ...event })) : entry, + ); + setXiaomiBinding(button, { mode, macroSize: snapshot.length * XIAOMI_MACRO_EVENT_SIZE }); + emit(); + } + }, + }); +} + +/** Stage clearing the macro bound to one Xiaomi button (0-7). */ +export function clearXiaomiMacro(button: number): void { + const client = xiaomiMacroClient(); + if (!client) { + setReadStatus(st("macro.notReady")); + emit(); + return; + } + stageChange({ + key: `xiaomi-macro-${button}`, + label: `Clear button ${button + 1} macro`, + command: `Clear Xiaomi button ${button + 1} macro`, + progress: `Clearing Xiaomi button ${button + 1} macro…`, + apply: async () => { + const live = xiaomiMacroClient(); + if (!live) throw new Error(st("ctl.gone")); + await live.setMacro(button, XIAOMI_KEY_COMBOS.MACROS_NO_DELAY, []); + if (xiaomiMacroClient() === live) { + xiaomiMacros = (xiaomiMacros ?? [null, null, null, null, null, null, null, null]).map((entry, index) => + index === button ? null : entry, + ); + setXiaomiBinding(button, { mode: XIAOMI_KEY_COMBOS.MACROS_NO_DELAY, macroSize: 0 }); + emit(); + } + }, + }); +} + function readCapabilities(): DeviceCapabilities { const razer = activeAs(CM()?.RazerHidClient); const dm = dmClient(); @@ -6797,6 +6955,13 @@ export function applyDeviceButtonMapping(button: string, action: string): void { // remap to anything else supersedes it, and must do so even when stageChange // drops the remap as "already matches", or Apply would still bind Macro. if (action !== "Macro") dropPendingChange(`incott-macro-${button}`); + // A staged Xiaomi combo/macro write is superseded by any preset remap. The + // combo/macro keys use the wire button index, not the display name. + const xiaomiButtonIndex = XIAOMI_BUTTON_NAMES.indexOf(button as (typeof XIAOMI_BUTTON_NAMES)[number]); + if (xiaomiButtonIndex !== -1) { + dropPendingChange(`xiaomi-combo-${xiaomiButtonIndex}`); + dropPendingChange(`xiaomi-macro-${xiaomiButtonIndex}`); + } stageChange({ key: `button-${button}`, label: `${button}: ${action}`, diff --git a/src/device/driver-classes.ts b/src/device/driver-classes.ts index 11d6cac2..5a195874 100644 --- a/src/device/driver-classes.ts +++ b/src/device/driver-classes.ts @@ -76,7 +76,8 @@ export type DriverModules = typeof import("@openmouse/protocol/drivers/endgame/e & typeof import("@openmouse/protocol/drivers/coolermaster/hid") & typeof import("@openmouse/protocol/drivers/ajazz/hid") & typeof import("@openmouse/protocol/drivers/redragon/m690-pro-hid") - & typeof import("@openmouse/protocol/drivers/hitscan/hid"); + & typeof import("@openmouse/protocol/drivers/hitscan/hid") + & typeof import("@openmouse/protocol/drivers/xiaomi/hid"); let loaded: DriverModules | null = null; let loading: Promise | null = null; @@ -143,6 +144,7 @@ export function ensureDriverModules(): Promise { import("@openmouse/protocol/drivers/ajazz/hid"), import("@openmouse/protocol/drivers/redragon/m690-pro-hid"), import("@openmouse/protocol/drivers/hitscan/hid"), + import("@openmouse/protocol/drivers/xiaomi/hid"), ]).then((mods) => (loaded = Object.assign({}, ...mods) as DriverModules)); return loading; } diff --git a/src/device/types.ts b/src/device/types.ts index 481a95e1..39609387 100644 --- a/src/device/types.ts +++ b/src/device/types.ts @@ -5,6 +5,7 @@ import type { KsnakeMacroProfile } from "@openmouse/protocol/ksnake"; import type { KeychronNapeLayerKeymap } from "@openmouse/protocol/keychron"; import type { LogitechReprogrammableControl } from "@openmouse/protocol/logitech"; import type { WallhackCurvePoint, WallhackMacroStep } from "@openmouse/protocol/wallhack"; +import type { XiaomiBinding, XiaomiMacroEvent } from "@openmouse/protocol/xiaomi"; import type { DpiStageCapabilities, DpiStagePlan, OnboardProfile } from "@openmouse/protocol/drivers/logitech/onboard-profiles"; import type { InterfacePreferences } from "../features/settings/interface-preferences"; import type { PreviewMode } from "./preview/preview-modes"; @@ -315,6 +316,16 @@ export interface ControlSnapshot { wallhackMacros: (WallhackMacroStep[] | null)[] | null; wallhackMacrosLoading: boolean; wallhackMacrosError: string | null; + /** + * Xiaomi Mi Gaming Mouse per-button macro slots (8), read from the device. + * A slot is null when the button is not bound to a macro mode. Macros are + * saved per button through applyXiaomiMacro. + */ + xiaomiMacros: (XiaomiMacroEvent[] | null)[] | null; + /** Per-button binding state (mode/modifiers/key) for the eight Xiaomi buttons. */ + xiaomiBindings: (XiaomiBinding | null)[] | null; + xiaomiMacrosLoading: boolean; + xiaomiMacrosError: string | null; wallhackCurves: Record<"classic" | "natural" | "jump" | "custom", WallhackCurvePoint[]> | null; wallhackCurvesLoading: boolean; wallhackCurvesError: string | null; diff --git a/src/features/devices/OverviewPage.tsx b/src/features/devices/OverviewPage.tsx index 81b34d0e..ef338819 100644 --- a/src/features/devices/OverviewPage.tsx +++ b/src/features/devices/OverviewPage.tsx @@ -51,6 +51,7 @@ import { ButtonMappingCard, KsnakeMacroCard, WallhackMacroCard, + XiaomiMacroCard, PowerModeCard, OnboardProfileCard, PulsarProCard, @@ -401,6 +402,7 @@ export function Workspace({ show(has.ksnakeMacros, ["macro"]) ? : null, show(has.wallhackMacros, ["macro"]) ? : null, show(has.incottMacros, ["macro"]) ? : null, + show(has.xiaomiMacros, ["macro"]) ? : null, ].filter((node) => node !== null); const advanced = [ diff --git a/src/features/devices/cards/AdvancedCards.tsx b/src/features/devices/cards/AdvancedCards.tsx index afd85a6d..7a1197ed 100644 --- a/src/features/devices/cards/AdvancedCards.tsx +++ b/src/features/devices/cards/AdvancedCards.tsx @@ -23,6 +23,14 @@ import { import { teevolutionSensorModeUi } from "@openmouse/protocol/teevolution"; import type { KsnakeMacroProfile, KsnakeMacroStep } from "@openmouse/protocol/ksnake"; import type { WallhackMacroStep } from "@openmouse/protocol/wallhack"; +import { + XIAOMI_BUTTON_NAMES, + XIAOMI_KEY_CODES, + XIAOMI_KEY_COMBOS, + XIAOMI_KEY_MODIFIERS, + xiaomiBindingLabel, + type XiaomiMacroEvent, +} from "@openmouse/protocol/xiaomi"; import { isPulsarProProtocol } from "../../../device/traits"; import { isNoirKsnakeStatus } from "../../../device/noir.ts"; import { @@ -2355,6 +2363,471 @@ export function KsnakeMacroCard({ snapshot }: { snapshot: ControlSnapshot }): Re ); } +/** + * Xiaomi Mi Gaming Mouse button bindings: each of the eight bindable buttons + * gets either a custom key combo (modifier mask + HID key) or a macro (a list + * of press/release events, optionally with a per-event delay before it). + */ +const XIAOMI_MODIFIER_BITS: ReadonlyArray<{ bit: number; label: string }> = [ + { bit: XIAOMI_KEY_MODIFIERS.LEFT_CTRL, label: "Ctrl" }, + { bit: XIAOMI_KEY_MODIFIERS.LEFT_SHIFT, label: "Shift" }, + { bit: XIAOMI_KEY_MODIFIERS.LEFT_ALT, label: "Alt" }, + { bit: XIAOMI_KEY_MODIFIERS.LEFT_WIN, label: "Win" }, + { bit: XIAOMI_KEY_MODIFIERS.RIGHT_CTRL, label: "R-Ctrl" }, + { bit: XIAOMI_KEY_MODIFIERS.RIGHT_SHIFT, label: "R-Shift" }, + { bit: XIAOMI_KEY_MODIFIERS.RIGHT_ALT, label: "R-Alt" }, + { bit: XIAOMI_KEY_MODIFIERS.RIGHT_WIN, label: "R-Win" }, +]; + +const XIAOMI_KEY_CODE_BY_EVENT_CODE: Readonly> = { + ...Object.fromEntries("ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("").map((letter, index) => [`Key${letter}`, XIAOMI_KEY_CODES.A + index])), + ...Object.fromEntries(["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"].map((digit, index) => [`Digit${digit}`, XIAOMI_KEY_CODES.ONE + index])), + Enter: XIAOMI_KEY_CODES.ENTER, + Escape: XIAOMI_KEY_CODES.ESCAPE, + Backspace: XIAOMI_KEY_CODES.BACKSPACE, + Tab: XIAOMI_KEY_CODES.TAB, + Space: XIAOMI_KEY_CODES.SPACE, + Minus: XIAOMI_KEY_CODES.SUB, + Equal: XIAOMI_KEY_CODES.EQUAL, + BracketLeft: XIAOMI_KEY_CODES.SQR_BRKT_OPEN, + BracketRight: XIAOMI_KEY_CODES.SQR_BRKT_CLOSE, + Backslash: XIAOMI_KEY_CODES.BACKSLASH, + Semicolon: XIAOMI_KEY_CODES.SEMICOLON, + Quote: XIAOMI_KEY_CODES.APOSTROPHE, + Backquote: XIAOMI_KEY_CODES.BACKTICK, + Comma: XIAOMI_KEY_CODES.COMMA, + Period: XIAOMI_KEY_CODES.DOT, + Slash: XIAOMI_KEY_CODES.SLASH, + CapsLock: XIAOMI_KEY_CODES.CAPS_LOCK, + ...Object.fromEntries(Array.from({ length: 12 }, (_, index) => [`F${index + 1}`, XIAOMI_KEY_CODES.F1 + index])), + PrintScreen: XIAOMI_KEY_CODES.PRINT_SCREEN, + ScrollLock: XIAOMI_KEY_CODES.SCROLL_LOCK, + Pause: XIAOMI_KEY_CODES.PAUSE, + Insert: XIAOMI_KEY_CODES.INSERT, + Home: XIAOMI_KEY_CODES.HOME, + PageUp: XIAOMI_KEY_CODES.PAGE_UP, + Delete: XIAOMI_KEY_CODES.DELETE, + End: XIAOMI_KEY_CODES.END, + PageDown: XIAOMI_KEY_CODES.PAGE_DOWN, + ArrowRight: XIAOMI_KEY_CODES.RIGHT_ARROW, + ArrowLeft: XIAOMI_KEY_CODES.LEFT_ARROW, + ArrowDown: XIAOMI_KEY_CODES.DOWN_ARROW, + ArrowUp: XIAOMI_KEY_CODES.UP_ARROW, + NumLock: XIAOMI_KEY_CODES.NUM_LOCK, + NumpadDivide: XIAOMI_KEY_CODES.NUMPAD_DIV, + NumpadMultiply: XIAOMI_KEY_CODES.NUMPAD_MULT, + NumpadSubtract: XIAOMI_KEY_CODES.NUMPAD_SUB, + NumpadAdd: XIAOMI_KEY_CODES.NUMPAD_ADD, + NumpadEnter: XIAOMI_KEY_CODES.NUMPAD_ENTER, + ...Object.fromEntries(Array.from({ length: 9 }, (_, index) => [`Numpad${index + 1}`, XIAOMI_KEY_CODES.NUMPAD_1 + index])), + Numpad0: XIAOMI_KEY_CODES.NUMPAD_0, + NumpadDecimal: XIAOMI_KEY_CODES.NUMPAD_DOT, + ControlLeft: XIAOMI_KEY_CODES.LEFT_CTRL, + ShiftLeft: XIAOMI_KEY_CODES.LEFT_SHIFT, + AltLeft: XIAOMI_KEY_CODES.LEFT_ALT, + MetaLeft: XIAOMI_KEY_CODES.LEFT_WIN, + OSLeft: XIAOMI_KEY_CODES.LEFT_WIN, + ControlRight: XIAOMI_KEY_CODES.RIGHT_CTRL, + ShiftRight: XIAOMI_KEY_CODES.RIGHT_SHIFT, + AltRight: XIAOMI_KEY_CODES.RIGHT_ALT, + MetaRight: XIAOMI_KEY_CODES.RIGHT_WIN, + OSRight: XIAOMI_KEY_CODES.RIGHT_WIN, +}; + +const XIAOMI_KEY_CODE_NAMES: Readonly> = Object.fromEntries( + Object.entries(XIAOMI_KEY_CODES).map(([name, code]) => [code, name.replace(/_/g, " ")]), +); + +function xiaomiKeyCodeLabel(code: number): string { + return XIAOMI_KEY_CODE_NAMES[code] ?? `0x${code.toString(16)}`; +} + +function xiaomiMacroEventLabel(event: XiaomiMacroEvent): string { + return `${event.state === 0 ? "Press" : "Release"} · ${xiaomiKeyCodeLabel(event.key)}`; +} + +export function XiaomiMacroCard({ snapshot }: { snapshot: ControlSnapshot }): ReactNode { + const status = snapshot.status; + const locale = snapshot.preferences.locale; + const macroCapable = status?.ui?.family === "xiaomi"; + const bindings = snapshot.xiaomiBindings ?? null; + const macros = snapshot.xiaomiMacros ?? null; + + const [button, setButton] = useState(0); + const [mode, setMode] = useState<"combo" | "macro">("combo"); + const [modifiers, setModifiers] = useState(0); + const [key, setKey] = useState(XIAOMI_KEY_CODES.A); + const [timing, setTiming] = useState<"no-delay" | "with-delay">("no-delay"); + const [events, setEvents] = useState([]); + const [isRecording, setIsRecording] = useState(false); + const [recordedEvents, setRecordedEvents] = useState([]); + const recordedEventsRef = useRef([]); + const recordingClockRef = useRef(null); + const recorderFocusRef = useRef(null); + + const staged = snapshot.pending.keys.includes(`xiaomi-combo-${button}`) + || snapshot.pending.keys.includes(`xiaomi-macro-${button}`); + const disabled = snapshot.settingInProgress || snapshot.pending.busy; + const controlsDisabled = disabled || isRecording; + + // Prepare the editor from the device snapshot whenever the selected button + // changes or a read/apply completes. + useEffect(() => { + if (!bindings || !macros) return; + const binding = bindings[button]; + if (!binding) return; + if (binding.mode === XIAOMI_KEY_COMBOS.MACROS_NO_DELAY || binding.mode === XIAOMI_KEY_COMBOS.MACROS_WITH_DELAY) { + setMode("macro"); + setTiming(binding.mode === XIAOMI_KEY_COMBOS.MACROS_WITH_DELAY ? "with-delay" : "no-delay"); + setEvents((macros[button] ?? []).map((event) => ({ ...event }))); + } else if (binding.mode === XIAOMI_KEY_COMBOS.CUSTOM_KEY_COMBO) { + setMode("combo"); + setModifiers(binding.modifiers ?? 0); + setKey(binding.key ?? XIAOMI_KEY_CODES.A); + } else { + setMode("combo"); + setModifiers(0); + setKey(XIAOMI_KEY_CODES.A); + } + }, [bindings, macros, button]); + + useEffect(() => { + if (macroCapable + && snapshot.xiaomiMacros === null + && !snapshot.xiaomiMacrosLoading + && snapshot.xiaomiMacrosError === null) { + control.loadXiaomiMacros(); + } + }, [macroCapable, snapshot.xiaomiMacros, snapshot.xiaomiMacrosLoading, snapshot.xiaomiMacrosError]); + + const appendRecordedEvent = (event: XiaomiMacroEvent): void => { + const now = performance.now(); + const previous = recordingClockRef.current; + recordingClockRef.current = now; + const delayMs = previous === null + ? 0 + : Math.min(65535, Math.max(0, Math.round(now - previous))); + // Xiaomi stores the delay before each event, so the interval measured + // before the new event belongs to the new event itself. + const next = [...recordedEventsRef.current, { ...event, delayMs }]; + recordedEventsRef.current = next; + setRecordedEvents(next); + }; + + const finishRecording = (): void => { + const next = timing === "no-delay" + ? recordedEventsRef.current.map((event) => ({ ...event, delayMs: 0 })) + : recordedEventsRef.current.map((event) => ({ ...event })); + setIsRecording(false); + setEvents(next); + setRecordedEvents([]); + recordedEventsRef.current = []; + recordingClockRef.current = null; + }; + + const cancelRecording = (): void => { + setIsRecording(false); + setRecordedEvents([]); + recordedEventsRef.current = []; + recordingClockRef.current = null; + }; + + const startRecording = (): void => { + if (disabled || isRecording) return; + recordedEventsRef.current = []; + setRecordedEvents([]); + recordingClockRef.current = performance.now(); + setIsRecording(true); + }; + + useEffect(() => { + if (!isRecording) return undefined; + + // The Record button keeps focus after it is clicked. Keyboard events then + // target that button, and the recorder-control guard (correctly) ignores + // them as UI input. Move focus to a neutral capture surface so the first + // physical key pressed after starting a recording is captured. + recorderFocusRef.current?.focus(); + + const isRecorderControl = (target: EventTarget | null): boolean => ( + target instanceof Element && Boolean(target.closest("[data-macro-recorder-control]")) + ); + + const onKeyDown = (event: KeyboardEvent): void => { + if (isRecorderControl(event.target)) return; + if (event.code === "Escape") { + event.preventDefault(); + event.stopPropagation(); + finishRecording(); + return; + } + if (event.repeat) return; + const code = XIAOMI_KEY_CODE_BY_EVENT_CODE[event.code]; + if (code === undefined) return; + event.preventDefault(); + event.stopPropagation(); + appendRecordedEvent({ key: code, state: 0, delayMs: 0 }); + }; + + const onKeyUp = (event: KeyboardEvent): void => { + if (isRecorderControl(event.target)) return; + const code = XIAOMI_KEY_CODE_BY_EVENT_CODE[event.code]; + if (code === undefined) return; + event.preventDefault(); + event.stopPropagation(); + appendRecordedEvent({ key: code, state: 1, delayMs: 0 }); + }; + + window.addEventListener("keydown", onKeyDown, true); + window.addEventListener("keyup", onKeyUp, true); + return () => { + window.removeEventListener("keydown", onKeyDown, true); + window.removeEventListener("keyup", onKeyUp, true); + }; + }, [isRecording]); + + if (!status || !macroCapable) return null; + + const updateEvent = (index: number, change: Partial): void => { + setEvents((current) => current.map((event, eventIndex) => eventIndex === index ? { ...event, ...change } : event)); + }; + const addEvent = (): void => { + setEvents((current) => [...current, { key: XIAOMI_KEY_CODES.A, state: 0, delayMs: 0 }]); + }; + const removeEvent = (index: number): void => { + setEvents((current) => current.filter((_, eventIndex) => eventIndex !== index)); + }; + const saveMacro = (): void => { + const macroMode = timing === "with-delay" ? XIAOMI_KEY_COMBOS.MACROS_WITH_DELAY : XIAOMI_KEY_COMBOS.MACROS_NO_DELAY; + const next = timing === "no-delay" + ? events.map((event) => ({ ...event, delayMs: 0 })) + : events.map((event) => ({ ...event })); + control.applyXiaomiMacro(button, macroMode, next); + }; + + if (snapshot.xiaomiMacrosLoading) { + return ( +
+

{t(locale, "macro.build")}

+

{t(locale, "macro.xmLoading")}

+
+ ); + } + + if (snapshot.xiaomiMacrosError !== null) { + return ( +
+

{t(locale, "macro.build")}

+

{displayText(locale, snapshot.xiaomiMacrosError)}

+
+
+ ); + } + + if (!bindings || !macros) return null; + + return ( +
+
+
+

{t(locale, "macro.build")}

+

{t(locale, "macro.xmLead")}

+
+
+ + setMode(next)} + /> + {mode === "combo" ? ( +
+

{t(locale, "macro.xmComboHint")}

+
+ {t(locale, "macro.xmModifiers")} + {XIAOMI_MODIFIER_BITS.map(({ bit, label }) => ( + + ))} +
+ +
+ +
+
+ ) : ( + <> +

{t(locale, "macro.xmMacroHint")}

+ setTiming(next)} + /> +
+
+
+
+ {isRecording ? ( +
+ + +
+ ) : ( +
+ + +
+ )} +
+
+ {isRecording ? ( +
+
+ {t(locale, "macro.xmLiveEvents")} + {tp(locale, "macro.xmEvents", { n: recordedEvents.length })} +
+ {recordedEvents.length === 0 ? ( +

{t(locale, "macro.xmRecordingEmpty")}

+ ) : ( +
    + {recordedEvents.map((event, index) => ( +
  1. + {displayText(locale, String(index + 1).padStart(2, "0"))} + {displayText(locale, xiaomiMacroEventLabel(event))} + {displayText(locale, event.delayMs > 0 + ? `+${event.delayMs} ms` + : index === recordedEvents.length - 1 ? "Waiting…" : "Next")} +
  2. + ))} +
+ )} +
+ ) : ( +
+ {events.length === 0 ? ( +
+ {t(locale, "macro.xmNoEvents")} + {t(locale, "macro.xmNoEventsHint")} +
+ ) : null} + {events.map((event, index) => ( +
+ {displayText(locale, String(index + 1).padStart(2, "0"))} + + + + {displayText(locale, xiaomiKeyCodeLabel(event.key))} + +
+ ))} +
+ )} +
+ + +
+ + )} +
+ {t(locale, "macro.xmHelpToggle")} +

{t(locale, "macro.xmHelpBody")}

+
+
+ ); +} + /** * WALLHACK M-001 onboard macros: 4 slots of up to 30 steps, read from the * device and saved per slot. Manual step editor (no live recorder yet): diff --git a/src/features/devices/cards/availability.ts b/src/features/devices/cards/availability.ts index 3a80b0b1..b9213a5a 100644 --- a/src/features/devices/cards/availability.ts +++ b/src/features/devices/cards/availability.ts @@ -49,6 +49,7 @@ export interface CardAvailability { onboardProfiles: boolean; buttonMapping: boolean; ksnakeMacros: boolean; + xiaomiMacros: boolean; wallhackScanning: boolean; wallhackCurves: boolean; wallhackMacros: boolean; @@ -104,6 +105,7 @@ const NOTHING: CardAvailability = { onboardProfiles: false, buttonMapping: false, ksnakeMacros: false, + xiaomiMacros: false, wallhackScanning: false, wallhackCurves: false, wallhackMacros: false, @@ -174,6 +176,9 @@ function computeCardAvailability(snapshot: ControlSnapshot): CardAvailability { // with local slots because this firmware does not expose a reliable macro // read through the browser. ksnakeMacros: ui?.family === "ksnake" || isNoirKsnake, + // The Xiaomi Mi Gaming Mouse exposes per-button custom combos and macros + // through the vendor control interface. + xiaomiMacros: ui?.family === "xiaomi", // WALLHACK M-001 extras. Curves and macros need mouse firmware 57+; the // cards surface the device error when an older board refuses the read. wallhackScanning: ui?.family === "wallhack-mouse" && status.sensorScanningMode != null, diff --git a/src/features/devices/workspace-tabs.test.ts b/src/features/devices/workspace-tabs.test.ts index d279304f..812fd349 100644 --- a/src/features/devices/workspace-tabs.test.ts +++ b/src/features/devices/workspace-tabs.test.ts @@ -89,3 +89,8 @@ test("the macro tab also follows the Incott macro capability", () => { const tabs = availableWorkspaceTabs(true, availability({ incottMacros: true })); assert.deepEqual(tabs, ["overview", "performance", "macro", "advanced"]); }); + +test("the macro tab also follows the Xiaomi macro capability", () => { + const tabs = availableWorkspaceTabs(true, availability({ xiaomiMacros: true })); + assert.deepEqual(tabs, ["overview", "performance", "macro", "advanced"]); +}); diff --git a/src/features/devices/workspace-tabs.ts b/src/features/devices/workspace-tabs.ts index 3bf73144..daa23b07 100644 --- a/src/features/devices/workspace-tabs.ts +++ b/src/features/devices/workspace-tabs.ts @@ -15,7 +15,7 @@ export function availableWorkspaceTabs( return WORKSPACE_TAB_ORDER.filter((tab) => { if (tab === "lighting") return !options.hideLighting && (has.lighting || has.teevolutionDpiLighting); if (tab === "buttons") return hasButtons; - if (tab === "macro") return has.ksnakeMacros || has.wallhackMacros || has.incottMacros; + if (tab === "macro") return has.ksnakeMacros || has.wallhackMacros || has.incottMacros || has.xiaomiMacros; if (tab === "profiles") return hasProfiles; return true; }); diff --git a/src/i18n/index.ts b/src/i18n/index.ts index 2ff16e5b..9ef687fb 100644 --- a/src/i18n/index.ts +++ b/src/i18n/index.ts @@ -1265,6 +1265,37 @@ const en = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.controls": "M2-NEX profile controls", "m2nex.overline": "PROFILE", "m2nex.label": "M2-NEX", diff --git a/src/i18n/locales/ar.ts b/src/i18n/locales/ar.ts index 4c084ae6..accedf61 100644 --- a/src/i18n/locales/ar.ts +++ b/src/i18n/locales/ar.ts @@ -1190,6 +1190,37 @@ export const ar: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/de.ts b/src/i18n/locales/de.ts index 49457545..39b2f13a 100644 --- a/src/i18n/locales/de.ts +++ b/src/i18n/locales/de.ts @@ -1192,6 +1192,37 @@ export const de: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/es.ts b/src/i18n/locales/es.ts index 89fcde6c..adf085a9 100644 --- a/src/i18n/locales/es.ts +++ b/src/i18n/locales/es.ts @@ -1192,6 +1192,37 @@ export const es: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/fr.ts b/src/i18n/locales/fr.ts index 79091c59..e3982889 100644 --- a/src/i18n/locales/fr.ts +++ b/src/i18n/locales/fr.ts @@ -1192,6 +1192,37 @@ export const fr: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/ja.ts b/src/i18n/locales/ja.ts index 3a794cdb..fc6c53bc 100644 --- a/src/i18n/locales/ja.ts +++ b/src/i18n/locales/ja.ts @@ -1192,6 +1192,37 @@ export const ja: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/ko.ts b/src/i18n/locales/ko.ts index 06656ee6..8fa98602 100644 --- a/src/i18n/locales/ko.ts +++ b/src/i18n/locales/ko.ts @@ -1192,6 +1192,37 @@ export const ko: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/pt.ts b/src/i18n/locales/pt.ts index f37767de..26598f5e 100644 --- a/src/i18n/locales/pt.ts +++ b/src/i18n/locales/pt.ts @@ -1192,6 +1192,37 @@ export const pt: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index 77928a2e..8189fd2c 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -1192,6 +1192,37 @@ export const ru: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/tr.ts b/src/i18n/locales/tr.ts index e8b861d4..158ec0c8 100644 --- a/src/i18n/locales/tr.ts +++ b/src/i18n/locales/tr.ts @@ -1186,6 +1186,37 @@ export const tr: Record = { "macro.whDelta": "Mesafe", "macro.whAdd": "Adım ekle", "macro.whMaxSteps": "Bir yuva 30 adım alır.", + "macro.xmLead": "Bir düğme seçin, ardından özel tuş kombinasyonu veya makro oluşturun. Kaydetme doğrudan fareye yazar.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Düğme", + "macro.xmCombo": "Özel kombinasyon", + "macro.xmMacro": "Makro", + "macro.xmTiming": "Zamanlama", + "macro.xmNoDelay": "Gecikmesiz", + "macro.xmWithDelay": "Gecikmeli", + "macro.xmModifiers": "Değiştiriciler", + "macro.xmKey": "Tuş", + "macro.xmSaveCombo": "Kombinasyonu kaydet", + "macro.xmClear": "Makroyu temizle", + "macro.xmDelayBefore": "Önceki gecikme", + "macro.xmAddEvent": "Olay ekle", + "macro.xmRemoveEvent": "{n} olayını kaldır", + "macro.xmNoEvents": "Bu makroda olay yok", + "macro.xmNoEventsHint": "Başlamak için girdi kaydedin veya bir olayı manuel ekleyin.", + "macro.xmRecord": "Girdi kaydet", + "macro.xmStop": "Kaydı durdur", + "macro.xmPress": "Bas", + "macro.xmRelease": "Bırak", + "macro.xmEvents": "{n} olay", + "macro.xmRecording": "Girdi kaydediliyor", + "macro.xmRecorderHint": "Klavye girdisini kaydedin veya bir olayı manuel ekleyin.", + "macro.xmEventsHint": "{n} olay · Durdurmak için Esc", + "macro.xmLiveEvents": "Canlı olay listesi", + "macro.xmRecordingEmpty": "İlk olayı eklemek için bir tuşa basın.", + "macro.xmHelpToggle": "Yardıma mı ihtiyacınız var?", + "macro.xmHelpBody": "Özel kombinasyon, düğmeye basıldığında bir tuşu ve en fazla sekiz değiştiriciyi gönderir. Makro, basma ve bırakma olaylarının listesidir; gecikmeli modda her olay tetiklenmeden önce gecikmesini bekler. Klavye kodları standart HID kullanım değerlerini kullanır.", + "macro.xmComboHint": "Tuş ve seçili değiştiriciler, düğmeye basıldığında gönderilir.", + "macro.xmMacroHint": "Her olay bir tuş basması veya bırakmasıdır. Gecikmeli modda her olayın önceki gecikmesi uygulanır.", "m2nex.controls": "M2-NEX profil kontrolleri", "m2nex.overline": "PROFİL", "m2nex.label": "M2-NEX", diff --git a/src/i18n/locales/vi.ts b/src/i18n/locales/vi.ts index 750784d9..f7909634 100644 --- a/src/i18n/locales/vi.ts +++ b/src/i18n/locales/vi.ts @@ -1197,6 +1197,37 @@ export const vi: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/i18n/locales/zh.ts b/src/i18n/locales/zh.ts index c2642929..10472e67 100644 --- a/src/i18n/locales/zh.ts +++ b/src/i18n/locales/zh.ts @@ -1192,6 +1192,37 @@ export const zh: Record = { "macro.whDelta": "Distance", "macro.whAdd": "Add step", "macro.whMaxSteps": "A slot holds 30 steps.", + "macro.xmLead": "Choose a button, then build a custom key combo or a macro. Saving writes it straight to the mouse.", + "macro.xmLoading": "Reading the eight button bindings…", + "macro.xmButton": "Button", + "macro.xmCombo": "Custom combo", + "macro.xmMacro": "Macro", + "macro.xmTiming": "Timing", + "macro.xmNoDelay": "No delay", + "macro.xmWithDelay": "With delay", + "macro.xmModifiers": "Modifiers", + "macro.xmKey": "Key", + "macro.xmSaveCombo": "Save combo", + "macro.xmClear": "Clear macro", + "macro.xmDelayBefore": "Delay before", + "macro.xmAddEvent": "Add event", + "macro.xmRemoveEvent": "Remove event {n}", + "macro.xmNoEvents": "No events in this macro", + "macro.xmNoEventsHint": "Record input or add an event manually to get started.", + "macro.xmRecord": "Record input", + "macro.xmStop": "Stop recording", + "macro.xmPress": "Press", + "macro.xmRelease": "Release", + "macro.xmEvents": "{n} events", + "macro.xmRecording": "Recording input", + "macro.xmRecorderHint": "Record keyboard input or add an event manually.", + "macro.xmEventsHint": "{n} events · Press Esc to stop", + "macro.xmLiveEvents": "Live event list", + "macro.xmRecordingEmpty": "Press a key to add the first event.", + "macro.xmHelpToggle": "Need help?", + "macro.xmHelpBody": "A custom combo sends a key plus up to eight modifiers when the button is pressed. A macro is a list of press and release events; in with-delay mode each event waits its delay before it fires. Keyboard codes use standard HID usage values.", + "macro.xmComboHint": "The key plus the selected modifiers is sent when the button is pressed.", + "macro.xmMacroHint": "Each event is a key press or release. In with-delay mode the delay before each event is honored.", "m2nex.macrosUnavailable": "The connected M2-NEX driver does not expose onboard macro access yet.", "m2nex.saveDone": "{name} saved from the current mouse settings.", "m2nex.applyBlocked": "Apply or discard the current changes before applying a profile.", diff --git a/src/shared/device-images.test.ts b/src/shared/device-images.test.ts index f3a4efd8..33a84848 100644 --- a/src/shared/device-images.test.ts +++ b/src/shared/device-images.test.ts @@ -90,6 +90,14 @@ test("ATK ZERO resolves by name", () => { assert.equal(deviceImage(null, "ATK ZERO"), CDN + "atk-zero.png"); }); +test("Xiaomi Mi Gaming Mouse resolves by name (wired and wireless PIDs)", () => { + // TEMPORARY: served from the repo override (see LOCAL_OVERRIDES in + // device-images.ts) until the render is uploaded to R2. + assert.equal(deviceImage(null, "Mi Gaming Mouse"), "/devices/xiaomi-mi-gaming-mouse.png"); + assert.equal(deviceImage(dev(0x2717, 0x5009), "Mi Gaming Mouse"), "/devices/xiaomi-mi-gaming-mouse.png"); + assert.equal(deviceImage(dev(0x2717, 0x500b), "Mi Gaming Mouse"), "/devices/xiaomi-mi-gaming-mouse.png"); +}); + test("Dareu A950 PRO Mg resolves by name", () => { assert.equal(deviceImage(null, "Dareu A950 PRO Mg"), CDN + "dareu-a950-pro-mg.png"); }); diff --git a/src/shared/device-images.ts b/src/shared/device-images.ts index 4c7bd8b9..b2a16720 100644 --- a/src/shared/device-images.ts +++ b/src/shared/device-images.ts @@ -187,6 +187,9 @@ function computeDeviceImageFilename(displayName: string): string { if (/\bm1\s*[-_]?\s*nex\b/i.test(displayName)) return "noir-m1-nex.png"; if (/\bnoir\s*e1\b/i.test(displayName)) return "noir-e1.png"; if (/fantech/i.test(displayName)) return "unknown-device.png"; + // The driver reports the model as "Mi Gaming Mouse" for both the wired + // (0x5009) and wireless (0x500b) PIDs, so one name rule covers both. + if (/mi\s*gaming\s*mouse/i.test(displayName)) return "xiaomi-mi-gaming-mouse.png"; return "unknown-device.png"; } @@ -218,6 +221,9 @@ const LOCAL_OVERRIDES: Readonly> = { // The keyboard placeholder: a black keyboard silhouette with a question mark, // the keyboard twin of unknown-device.png. Served locally until it is in the bucket. "unknown-keyboard.png": "/devices/unknown-keyboard.png", + // Rendered from the reference app's animation frames (black background + // removed); served locally until the R2 upload happens. + "xiaomi-mi-gaming-mouse.png": "/devices/xiaomi-mi-gaming-mouse.png", }; export type DeviceImageKind = "mouse" | "keyboard"; diff --git a/src/styles/areas/library.css b/src/styles/areas/library.css index 520b81a8..fb3a8b85 100644 --- a/src/styles/areas/library.css +++ b/src/styles/areas/library.css @@ -119,7 +119,7 @@ #finalmouse-profiles .profile-rename { margin-top: 8px; } #finalmouse-profiles .profile-rename input { min-width: 0; flex: 1; } -:is(#ksnake-macro-settings, #wallhack-macro-settings, #incott-macro-settings) { grid-column: 1 / -1; gap: 16px; } +:is(#ksnake-macro-settings, #wallhack-macro-settings, #incott-macro-settings, #xiaomi-macro-settings) { grid-column: 1 / -1; gap: 16px; } .ksnake-macro-lead { margin-top: 4px; color: var(--text-3); font-size: var(--fs-meta); font-weight: 400; line-height: 1.5; } .ksnake-macro-notice { padding: 12px; background: var(--well); border-radius: var(--r-sm); color: var(--text-2); font-size: var(--fs-meta); line-height: 1.5; } .ksnake-macro-slot-picker { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; color: var(--text-2); font-size: var(--fs-meta); } @@ -171,6 +171,21 @@ .ksnake-macro-delete { display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-sm); color: var(--text-3); } .ksnake-macro-delete:hover:not(:disabled) { color: var(--bad); background: var(--glint); } .ksnake-macro-delete:disabled { opacity: .4; } +/* Xiaomi macros reuse the K-snake recorder and step rows; only the combo + editor (modifier grid + key picker) and the action row are their own. */ +.xiaomi-macro-combo { display: grid; gap: 12px; } +.xiaomi-macro-modifiers { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0; padding: 12px; border: 1px solid var(--line-1); border-radius: var(--r-md); } +.xiaomi-macro-modifiers legend { padding-inline: 6px; color: var(--text-3); font-size: var(--fs-meta); } +.xiaomi-macro-modifier { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: var(--fs-meta); } +.xiaomi-macro-key-picker { display: grid; gap: 8px; min-width: 0; color: var(--text-3); font-size: var(--fs-meta); } +.xiaomi-macro-key-picker select { min-width: min(240px, 100%); max-width: 100%; } +.xiaomi-macro-actions { flex-wrap: wrap; justify-content: flex-start; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line-1); } +.xiaomi-macro-actions > button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 32px; height: auto; padding: 7px 12px; border-radius: var(--r-sm); background: var(--btn); box-shadow: var(--btn-shadow); color: var(--text-1); font-size: 12px; font-weight: 600; } +.xiaomi-macro-actions > button:hover:not(:disabled) { background: var(--btn-hover); } +.xiaomi-macro-actions > button:disabled { opacity: .45; cursor: default; } +.xiaomi-macro-actions > .xiaomi-macro-save { background: var(--accent); box-shadow: var(--primary-shadow); color: var(--on-accent); } +.xiaomi-macro-actions > .xiaomi-macro-save:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 90%, var(--text-1)); } +.xiaomi-macro-step { grid-template-columns: 28px minmax(100px, 1fr) minmax(100px, 1fr) 76px minmax(80px, 1fr) 32px; } /* Incott macros reuse the K-snake recorder and rows; only the library, the button grid and a wrapping step row are their own. */ .incott-macro-library > label { flex: 1 1 200px; }