Skip to content

Commit

Permalink
Add proper number of dynamic macros (#207)
Browse files Browse the repository at this point in the history
* digusting bodge to get dynamic number of macros showing in keycode list

* fix

* fix 2
  • Loading branch information
Xelus22 authored Nov 22, 2023
1 parent ee4443b commit d76f990
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
13 changes: 9 additions & 4 deletions src/components/panes/configure-panes/keycode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import {
updateKey as updateKeyAction,
updateSelectedKey,
} from 'src/store/keymapSlice';
import {
getMacroCount,
} from 'src/store/macrosSlice';
import {
disableGlobalHotKeys,
enableGlobalHotKeys,
Expand Down Expand Up @@ -114,8 +117,8 @@ const KeycodeDesc = styled.div`
}
`;

const generateKeycodeCategories = (basicKeyToByte: Record<string, number>) =>
getKeycodes().concat(getOtherMenu(basicKeyToByte));
const generateKeycodeCategories = (basicKeyToByte: Record<string, number>, numMacros: number = 16) =>
getKeycodes(numMacros).concat(getOtherMenu(basicKeyToByte));

const maybeFilter = <M extends Function>(maybe: boolean, filter: M) =>
maybe ? () => true : filter;
Expand Down Expand Up @@ -147,9 +150,11 @@ export const KeycodePane: FC = () => {
const disableFastRemap = useAppSelector(getDisableFastRemap);
const selectedKeyDefinitions = useAppSelector(getSelectedKeyDefinitions);
const {basicKeyToByte} = useAppSelector(getBasicKeyToByte);
const macroCount = useAppSelector(getMacroCount);

const KeycodeCategories = useMemo(
() => generateKeycodeCategories(basicKeyToByte),
[basicKeyToByte],
() => generateKeycodeCategories(basicKeyToByte, macroCount),
[basicKeyToByte, macroCount],
);

// TODO: improve typing so we can get rid of this
Expand Down
2 changes: 1 addition & 1 deletion src/utils/key-to-byte/v12.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default {
_QK_LAYER_TAP_TOGGLE_MAX: 0x52df,
_QK_LAYER_MOD_MASK: 0x1f,
_QK_MACRO: 0x7700,
_QK_MACRO_MAX: 0x770f,
_QK_MACRO_MAX: 0x777f,
_QK_KB: 0x7e00,
_QK_KB_MAX: 0x7eff,
KC_NO: 0x0000,
Expand Down
36 changes: 17 additions & 19 deletions src/utils/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,22 @@ function buildLayerMenu(): IKeycodeMenu {
};
}

export function getKeycodes(): IKeycodeMenu[] {
function generateMacros(numMacros: number = 16): IKeycode[] {
let res: IKeycode[] = [];
for (let idx = 0; idx < numMacros; idx++) {
const newName = `M${idx}`;
const newCode = `MACRO(${idx})`;
const newTitle = `Macro ${idx}`;
res = [
...res,
{name: newName, title: newTitle, code: newCode},
];
}
return res;
}


export function getKeycodes(numMacros = 16): IKeycodeMenu[] {
return [
{
id: 'basic',
Expand Down Expand Up @@ -734,24 +749,7 @@ export function getKeycodes(): IKeycodeMenu[] {
id: 'macro',
label: 'Macro',
width: 'label',
keycodes: [
{name: 'M0', code: 'MACRO(0)', title: 'Macro 0'},
{name: 'M1', code: 'MACRO(1)', title: 'Macro 1'},
{name: 'M2', code: 'MACRO(2)', title: 'Macro 2'},
{name: 'M3', code: 'MACRO(3)', title: 'Macro 3'},
{name: 'M4', code: 'MACRO(4)', title: 'Macro 4'},
{name: 'M5', code: 'MACRO(5)', title: 'Macro 5'},
{name: 'M6', code: 'MACRO(6)', title: 'Macro 6'},
{name: 'M7', code: 'MACRO(7)', title: 'Macro 7'},
{name: 'M8', code: 'MACRO(8)', title: 'Macro 8'},
{name: 'M9', code: 'MACRO(9)', title: 'Macro 9'},
{name: 'M10', code: 'MACRO(10)', title: 'Macro 10'},
{name: 'M11', code: 'MACRO(11)', title: 'Macro 11'},
{name: 'M12', code: 'MACRO(12)', title: 'Macro 12'},
{name: 'M13', code: 'MACRO(13)', title: 'Macro 13'},
{name: 'M14', code: 'MACRO(14)', title: 'Macro 14'},
{name: 'M15', code: 'MACRO(15)', title: 'Macro 15'},
],
keycodes: generateMacros(numMacros)
},
buildLayerMenu(),
{
Expand Down

0 comments on commit d76f990

Please sign in to comment.