Skip to content

Commit

Permalink
feat(common): ldml scancodes 🙀
Browse files Browse the repository at this point in the history
For: #9403

- improve how forms are read in the XML structure
- warnings when custom (non-default-import) scancodes are loaded
- error, as usual, when an unknown form is present
  • Loading branch information
srl295 committed Sep 22, 2023
1 parent 3a677da commit 44f061f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ export class LDMLKeyboardXMLSourceFileReader {
}
}
}
if(source?.keyboard3?.forms?.form) {
boxXmlArray(source?.keyboard3?.forms, 'form');
for(let form of source?.keyboard3?.forms?.form) {
boxXmlArray(form, 'scanCodes');
}
}
if(source?.keyboard3?.keys?.flicks) {
for(let flicks of source?.keyboard3?.keys?.flicks) {
boxXmlArray(flicks, 'flick');
Expand Down
14 changes: 14 additions & 0 deletions common/web/types/src/ldml-keyboard/ldml-keyboard-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface LKKeyboard {
names?: LKNames;
settings?: LKSettings;
keys?: LKKeys;
forms?: LKForms;
displays?: LKDisplays;
layers?: LKLayers[];
vkeys?: LKVkeys;
Expand Down Expand Up @@ -194,6 +195,19 @@ export interface LKDisplays {
displayOptions?: LKDisplayOptions;
};

export interface LKForms {
form?: LKForm[];
};

export interface LKForm {
id?: string;
scanCodes?: LKScanCodes[];
};

export interface LKScanCodes {
codes?: string;
};

/**
* Utilities for determining the import status of items
*/
Expand Down
8 changes: 7 additions & 1 deletion developer/src/kmc-ldml/src/compiler/layr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { constants } from '@keymanapp/ldml-keyboard-constants';
import { KMXPlus } from '@keymanapp/common-types';
import { KMXPlus, LDMLKeyboard } from '@keymanapp/common-types';
import { CompilerMessages } from './messages.js';
import { SectionCompiler } from "./section-compiler.js";
import { translateLayerAttrToModifier, validModifier } from '../util/util.js';
Expand All @@ -22,6 +22,12 @@ export class LayrCompiler extends SectionCompiler {
let totalLayerCount = 0;
let hardwareLayers = 0;
// let touchLayers = 0;
this.keyboard3.forms?.form?.forEach((form) => {
// Just check whether it's NOT an implied import
if (!LDMLKeyboard.ImportStatus.isImpliedImport(form)) {
this.callbacks.reportMessage(CompilerMessages.Hint_UnsupportedCustomForm({id: form.id}));
}
});
this.keyboard3.layers?.forEach((layers) => {
const { form } = layers;
if (form === 'touch') {
Expand Down
4 changes: 4 additions & 0 deletions developer/src/kmc-ldml/src/compiler/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,9 @@ export class CompilerMessages {
m(this.ERROR_DisplayNeedsToOrId, `display ${CompilerMessages.toOrId(o)} needs to= or id=, but not both`);
static ERROR_DisplayNeedsToOrId = SevError | 0x0022;

static Hint_UnsupportedCustomForm = (o:{id: string}) =>
m(this.HINT_UnsupportedCustomForm, `Custom <form id="${o.id}"> element is not supported.`);
static HINT_UnsupportedCustomForm = SevHint | 0x0023;
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE keyboard3 SYSTEM "../../../../../../../resources/standards-data/ldml-keyboards/techpreview/dtd/ldmlKeyboard3.dtd">
<keyboard3 locale="und" conformsTo="techpreview">
<names>
<name value="layr-error-custom-form" />
</names>

<keys>
<key id="grave" to="`" />
<key id="one" to="1" />
</keys>
<forms>
<!-- warning, custom scancodes -->
<form id="zzz">
<scanCodes codes="01 02 03 04" />
</form>
</forms>
<layers form="zzz"> <!-- INVALID: 'zzz' is not a valid form. -->
<layer id="base">
<row keys="grave one" />
</layer>
</layers>
</keyboard3>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE keyboard3 SYSTEM "../../../../../../../resources/standards-data/ldml-keyboards/techpreview/dtd/ldmlKeyboard3.dtd">
<keyboard3 locale="und" conformsTo="techpreview">
<names>
<name value="layr-hint-custom-form" />
</names>

<keys>
<key id="grave" to="`" />
<key id="one" to="1" />
</keys>
<forms>
<!-- warning, custom scancodes -->
<form id="us">
<scanCodes codes="01 02 03 04" />
</form>
</forms>
<layers form="us"> <!-- INVALID: 'holographic' is not a valid form. -->
<layer id="base">
<!-- beware: this is mapping ` and 1! -->
<row keys="grave one" />
</layer>
</layers>
</keyboard3>
19 changes: 18 additions & 1 deletion developer/src/kmc-ldml/test/test-layr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ describe('layr', function () {
errors: [
CompilerMessages.Error_MustBeAtLeastOneLayerElement(),
],
}
},
{
// warning on custom form
subpath: 'sections/layr/hint-custom-form.xml',
warnings: [
CompilerMessages.Hint_UnsupportedCustomForm({id: "us"}),
],
},
{
// error on unknown form
subpath: 'sections/layr/error-custom-form.xml',
warnings: [
CompilerMessages.Hint_UnsupportedCustomForm({id: "zzz"}),
],
errors: [CompilerMessages.Error_InvalidHardware({
form: 'zzz',
}),],
},
]);
});

0 comments on commit 44f061f

Please sign in to comment.