diff --git a/public/json/fine_volume_control.json b/public/json/fine_volume_control.json index 526fa0eac..e89aaefda 100644 --- a/public/json/fine_volume_control.json +++ b/public/json/fine_volume_control.json @@ -1,22 +1,62 @@ { - "title": "Fine volume control (rev 2)", + "title": "Fine volume control (rev 3)", "rules": [ { "description": "Map volume controls to fine volume controls (Option + Shift + Volume)", + "available_since": "15.3.0", "manipulators": [ { "type": "basic", "from": { - "key_code": "f11" + "key_code": "f11", + "modifiers": { + "optional": [ + "caps_lock" + ] + } }, "to": [ { - "key_code": "volume_decrement", + "consumer_key_code": "volume_decrement", "modifiers": [ - "left_shift", - "left_option" + "left_option", + "left_shift" ] } + ], + "conditions": [ + { + "type": "variable_unless", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } + ] + }, + { + "type": "basic", + "from": { + "key_code": "f11", + "modifiers": { + "mandatory": [ + "option", + "shift" + ], + "optional": [ + "caps_lock" + ] + } + }, + "to": [ + { + "consumer_key_code": "volume_decrement" + } + ], + "conditions": [ + { + "type": "variable_unless", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } ] }, { @@ -26,29 +66,73 @@ "modifiers": { "mandatory": [ "fn" + ], + "optional": [ + "caps_lock" ] } }, "to": [ { - "key_code": "f11", + "consumer_key_code": "volume_decrement", "modifiers": [ + "left_option", + "left_shift" + ] + } + ], + "conditions": [ + { + "type": "variable_if", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } + ] + }, + { + "type": "basic", + "from": { + "key_code": "f11", + "modifiers": { + "mandatory": [ + "option", + "shift", "fn" + ], + "optional": [ + "caps_lock" ] } + }, + "to": [ + { + "consumer_key_code": "volume_decrement" + } + ], + "conditions": [ + { + "type": "variable_if", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } ] }, { "type": "basic", "from": { - "key_code": "f12" + "consumer_key_code": "volume_decrement", + "modifiers": { + "optional": [ + "caps_lock" + ] + } }, "to": [ { - "key_code": "volume_increment", + "consumer_key_code": "volume_decrement", "modifiers": [ - "left_shift", - "left_option" + "left_option", + "left_shift" ] } ] @@ -56,45 +140,105 @@ { "type": "basic", "from": { - "key_code": "f12", + "consumer_key_code": "volume_decrement", "modifiers": { "mandatory": [ - "fn" + "option", + "shift" + ], + "optional": [ + "caps_lock" ] } }, "to": [ { - "key_code": "f12", + "consumer_key_code": "volume_decrement" + } + ] + }, + { + "type": "basic", + "from": { + "key_code": "f12", + "modifiers": { + "optional": [ + "caps_lock" + ] + } + }, + "to": [ + { + "consumer_key_code": "volume_increment", "modifiers": [ - "fn" + "left_option", + "left_shift" ] } + ], + "conditions": [ + { + "type": "variable_unless", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } ] - } - ] - }, - { - "description": "Map fn + volume controls to fine volume controls (Option + Shift + Volume)", - "manipulators": [ + }, { "type": "basic", "from": { - "key_code": "f11", + "key_code": "f12", + "modifiers": { + "mandatory": [ + "option", + "shift" + ], + "optional": [ + "caps_lock" + ] + } + }, + "to": [ + { + "consumer_key_code": "volume_increment" + } + ], + "conditions": [ + { + "type": "variable_unless", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } + ] + }, + { + "type": "basic", + "from": { + "key_code": "f12", "modifiers": { "mandatory": [ "fn" + ], + "optional": [ + "caps_lock" ] } }, "to": [ { - "key_code": "volume_decrement", + "consumer_key_code": "volume_increment", "modifiers": [ - "left_shift", - "left_option" + "left_option", + "left_shift" ] } + ], + "conditions": [ + { + "type": "variable_if", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } ] }, { @@ -103,18 +247,66 @@ "key_code": "f12", "modifiers": { "mandatory": [ + "option", + "shift", "fn" + ], + "optional": [ + "caps_lock" + ] + } + }, + "to": [ + { + "consumer_key_code": "volume_increment" + } + ], + "conditions": [ + { + "type": "variable_if", + "name": "system.use_fkeys_as_standard_function_keys", + "value": true + } + ] + }, + { + "type": "basic", + "from": { + "consumer_key_code": "volume_increment", + "modifiers": { + "optional": [ + "caps_lock" ] } }, "to": [ { - "key_code": "volume_increment", + "consumer_key_code": "volume_increment", "modifiers": [ - "left_shift", - "left_option" + "left_option", + "left_shift" + ] + } + ] + }, + { + "type": "basic", + "from": { + "consumer_key_code": "volume_increment", + "modifiers": { + "mandatory": [ + "option", + "shift" + ], + "optional": [ + "caps_lock" ] } + }, + "to": [ + { + "consumer_key_code": "volume_increment" + } ] } ] diff --git a/src/json/fine_volume_control.json.js b/src/json/fine_volume_control.json.js index 27d63c1fc..020a3b540 100644 --- a/src/json/fine_volume_control.json.js +++ b/src/json/fine_volume_control.json.js @@ -4,67 +4,26 @@ function main() { console.log( JSON.stringify( { - title: 'Fine volume control (rev 2)', + title: 'Fine volume control (rev 3)', rules: [ { description: 'Map volume controls to fine volume controls (Option + Shift + Volume)', - manipulators: [ - { - type: 'basic', - from: { key_code: 'f11' }, - to: [ - { - key_code: 'volume_decrement', - modifiers: ['left_shift', 'left_option'], - }, - ], - }, - { - type: 'basic', - from: { key_code: 'f11', modifiers: { mandatory: ['fn'] } }, - to: [{ key_code: 'f11', modifiers: ['fn'] }], - }, - { - type: 'basic', - from: { key_code: 'f12' }, - to: [ - { - key_code: 'volume_increment', - modifiers: ['left_shift', 'left_option'], - }, - ], - }, - { - type: 'basic', - from: { key_code: 'f12', modifiers: { mandatory: ['fn'] } }, - to: [{ key_code: 'f12', modifiers: ['fn'] }], - }, - ], - }, - { - description: 'Map fn + volume controls to fine volume controls (Option + Shift + Volume)', - manipulators: [ - { - type: 'basic', - from: { key_code: 'f11', modifiers: { mandatory: ['fn'] } }, - to: [ - { - key_code: 'volume_decrement', - modifiers: ['left_shift', 'left_option'], - }, - ], - }, - { - type: 'basic', - from: { key_code: 'f12', modifiers: { mandatory: ['fn'] } }, - to: [ - { - key_code: 'volume_increment', - modifiers: ['left_shift', 'left_option'], - }, - ], - }, - ], + available_since: '15.3.0', + manipulators: [].concat( + // + // volume_decrement + // + + makeManipulators({ key_code: 'f11' }, 'volume_decrement'), + makeManipulators({ consumer_key_code: 'volume_decrement' }, 'volume_decrement'), + + // + // volume_increment + // + + makeManipulators({ key_code: 'f12' }, 'volume_increment'), + makeManipulators({ consumer_key_code: 'volume_increment' }, 'volume_increment') + ), }, ], }, @@ -72,6 +31,85 @@ function main() { ' ' ) ) + + function makeManipulators(from, to) { + if (from.modifiers === undefined) { + from.modifiers = { + mandatory: [], + optional: [], + } + } + + const manipulators = [] + + ;[false, true].forEach(function (fn) { + if (from.key_code === undefined && fn) { + return + } + + const normalFrom = JSON.parse(JSON.stringify(from)) + if (fn) { + normalFrom.modifiers.mandatory.push('fn') + } + if (normalFrom.modifiers.mandatory.length === 0) { + delete normalFrom.modifiers.mandatory + } + normalFrom.modifiers.optional.push('caps_lock') + + const reverseFrom = JSON.parse(JSON.stringify(from)) + reverseFrom.modifiers.mandatory.push('option') + reverseFrom.modifiers.mandatory.push('shift') + if (fn) { + reverseFrom.modifiers.mandatory.push('fn') + } + reverseFrom.modifiers.optional.push('caps_lock') + + // + // conditions + // + + var conditions = [] + if (from.key_code !== undefined) { + if (fn) { + conditions.push({ + type: 'variable_if', + name: 'system.use_fkeys_as_standard_function_keys', + value: true, + }) + } else { + conditions.push({ + type: 'variable_unless', + name: 'system.use_fkeys_as_standard_function_keys', + value: true, + }) + } + } + if (conditions.length === 0) { + conditions = undefined + } + + manipulators.push({ + type: 'basic', + from: normalFrom, + to: [ + { + consumer_key_code: to, + modifiers: ['left_option', 'left_shift'], + }, + ], + conditions: conditions, + }) + + manipulators.push({ + type: 'basic', + from: reverseFrom, + to: [{ consumer_key_code: to }], + conditions: conditions, + }) + }) + + return manipulators + } } main()