Skip to content

Commit

Permalink
digusting bodge to get dynamic number of macros showing in keycode list
Browse files Browse the repository at this point in the history
  • Loading branch information
Xelus22 committed Nov 13, 2023
1 parent ee4443b commit 2452a19
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
24 changes: 19 additions & 5 deletions src/components/panes/configure-panes/keycode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import {
getSelectedDefinition,
getSelectedKeyDefinitions,
} from 'src/store/definitionsSlice';
import {getSelectedConnectedDevice} from 'src/store/devicesSlice';
import {getSelectedConnectedDevice,
getSelectedKeyboardAPI,
} from 'src/store/devicesSlice';
import {
getSelectedKey,
getSelectedKeymap,
Expand Down Expand Up @@ -114,8 +116,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 +149,21 @@ export const KeycodePane: FC = () => {
const disableFastRemap = useAppSelector(getDisableFastRemap);
const selectedKeyDefinitions = useAppSelector(getSelectedKeyDefinitions);
const {basicKeyToByte} = useAppSelector(getBasicKeyToByte);
const [numMacros, setNumMacros] = useState(16);

const api = useAppSelector(getSelectedKeyboardAPI);
if (!api) {
return null;
}
api.getMacroCount().then((nMacros) =>{
setNumMacros(nMacros);
console.log("numMacros: ", numMacros);
})
// let numMacros = async() => await new Promise(resolve => api.getMacroCount());

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

// 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
37 changes: 18 additions & 19 deletions src/utils/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,23 @@ function buildLayerMenu(): IKeycodeMenu {
};
}

export function getKeycodes(): IKeycodeMenu[] {
function generateMacros(numMacros: number = 16): IKeycode[] {
const macroTemplate: IKeycode = {name: 'M0', code: 'MACRO(0)', title: 'Macro 0'};
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 +750,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 2452a19

Please sign in to comment.