Make layer toggleable.
This commit is contained in:
@@ -1,8 +1,17 @@
|
|||||||
|
enum Layer {
|
||||||
|
mod,
|
||||||
|
fn,
|
||||||
|
mouse
|
||||||
|
}
|
||||||
|
|
||||||
class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAction> {
|
class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAction> {
|
||||||
|
|
||||||
static keyActionTypeString = 'switchLayer';
|
static keyActionTypeString = 'switchLayer';
|
||||||
|
static toggleFlag = 0x80;
|
||||||
|
|
||||||
private _layer: number;
|
isLayerToggleable: boolean;
|
||||||
|
|
||||||
|
private _layer: Layer;
|
||||||
|
|
||||||
get layer(): number {
|
get layer(): number {
|
||||||
return this._layer;
|
return this._layer;
|
||||||
@@ -15,27 +24,35 @@ class SwitchLayerAction extends KeyAction implements Serializable<SwitchLayerAct
|
|||||||
this._layer = value;
|
this._layer = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getToggleFlag() {
|
||||||
|
return this.isLayerToggleable ? SwitchLayerAction.toggleFlag : 0;
|
||||||
|
}
|
||||||
|
|
||||||
fromJsObject(jsObject: any): SwitchLayerAction {
|
fromJsObject(jsObject: any): SwitchLayerAction {
|
||||||
this.assertKeyActionType(jsObject, SwitchLayerAction.keyActionTypeString, 'SwitchLayerAction');
|
this.assertKeyActionType(jsObject, SwitchLayerAction.keyActionTypeString, 'SwitchLayerAction');
|
||||||
this.layer = jsObject.keymapId;
|
this.layer = jsObject.keymapId;
|
||||||
|
this.isLayerToggleable = jsObject.toggle;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
fromBinary(buffer: UhkBuffer): SwitchLayerAction {
|
fromBinary(buffer: UhkBuffer): SwitchLayerAction {
|
||||||
this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchLayerAction, 'SwitchLayerAction');
|
this.readAndAssertKeyActionId(buffer, KeyActionId.SwitchLayerAction, 'SwitchLayerAction');
|
||||||
this.layer = buffer.readUInt8();
|
this.layer = buffer.readUInt8();
|
||||||
|
this.isLayerToggleable = (this.layer & SwitchLayerAction.toggleFlag) !== 0;
|
||||||
|
this.layer &= ~SwitchLayerAction.toggleFlag; // Clear toggle bit.
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJsObject(): any {
|
toJsObject(): any {
|
||||||
return {
|
return {
|
||||||
keyActionType: SwitchLayerAction.keyActionTypeString,
|
keyActionType: SwitchLayerAction.keyActionTypeString,
|
||||||
layer: this.layer
|
layer: this.layer,
|
||||||
|
toggle: this.isLayerToggleable
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
toBinary(buffer: UhkBuffer) {
|
toBinary(buffer: UhkBuffer) {
|
||||||
buffer.writeUInt8(KeyActionId.SwitchLayerAction);
|
buffer.writeUInt8(KeyActionId.SwitchLayerAction);
|
||||||
buffer.writeUInt8(this.layer);
|
buffer.writeUInt8(this.layer | this.getToggleFlag());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,27 +9,4 @@ let writer = new UhkBuffer();
|
|||||||
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
let uhkConfig = JSON.parse(fs.readFileSync('uhk-config.json'));
|
||||||
let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
let keyActions = uhkConfig.keymaps[0].layers[0].modules[0].keyActions;
|
||||||
|
|
||||||
let SWITCH_LAYER_MOD = 0;
|
|
||||||
let SWITCH_LAYER_FN = 1;
|
|
||||||
let SWITCH_LAYER_MOUSE = 2;
|
|
||||||
let SWITCH_LAYER_TOGGLE = 0x80;
|
|
||||||
|
|
||||||
function serializeKeyAction(keyAction) {
|
|
||||||
switch (keyAction.actionType) {
|
|
||||||
case 'switchLayer':
|
|
||||||
serializeSwitchLayerAction(keyAction);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw 'KeyAction doesn\'t have a valid actionType property: ' + keyAction.actionType;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function serializeSwitchLayerAction(switchLayerAction) {
|
|
||||||
writer.writeUInt8({
|
|
||||||
mod : SWITCH_LAYER_MOD,
|
|
||||||
fn : SWITCH_LAYER_FN,
|
|
||||||
mouse: SWITCH_LAYER_MOD
|
|
||||||
}[switchLayerAction] | switchLayerAction.toggle ? SWITCH_LAYER_TOGGLE : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync('uhk-config.bin', writer.buffer);
|
fs.writeFileSync('uhk-config.bin', writer.buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user