Unverified Commit 6b087c74 authored by Greg Spencer's avatar Greg Spencer Committed by GitHub

Add iOS key map generation, make macOS var naming consistent with repo (#83146)

This adds iOS key map generation that uses std::maps. It uses std::maps because on iOS if we use NSDictionaries, then when XCode loads the dylib, the initialization of those status NSDictionaries hasn't yet occurred, and it crashes the app. std::maps have a well-defined static behavior, and are correctly initialized.

I also made the naming of variables, fields, etc. consistent for macOS. We variously had macosFoo, macOSFoo, and macOsFoo. I eliminated macOsFoo and macosFoo, since the rest of the repo uses macOSFoo for lowerCamelCase names (with only a few exceptions). I used iOSFoo for iOS.
parent 62d00c6d
...@@ -9,6 +9,7 @@ import 'package:args/args.dart'; ...@@ -9,6 +9,7 @@ import 'package:args/args.dart';
import 'package:gen_keycodes/android_code_gen.dart'; import 'package:gen_keycodes/android_code_gen.dart';
import 'package:gen_keycodes/base_code_gen.dart'; import 'package:gen_keycodes/base_code_gen.dart';
import 'package:gen_keycodes/gtk_code_gen.dart'; import 'package:gen_keycodes/gtk_code_gen.dart';
import 'package:gen_keycodes/ios_code_gen.dart';
import 'package:gen_keycodes/keyboard_keys_code_gen.dart'; import 'package:gen_keycodes/keyboard_keys_code_gen.dart';
import 'package:gen_keycodes/keyboard_maps_code_gen.dart'; import 'package:gen_keycodes/keyboard_maps_code_gen.dart';
import 'package:gen_keycodes/logical_key_data.dart'; import 'package:gen_keycodes/logical_key_data.dart';
...@@ -210,7 +211,11 @@ Future<void> main(List<String> rawArguments) async { ...@@ -210,7 +211,11 @@ Future<void> main(List<String> rawArguments) async {
physicalData, physicalData,
logicalData, logicalData,
), ),
'macos': MacOsCodeGenerator( 'macos': MacOSCodeGenerator(
physicalData,
logicalData,
),
'ios': IOSCodeGenerator(
physicalData, physicalData,
logicalData, logicalData,
), ),
......
...@@ -5,11 +5,15 @@ ...@@ -5,11 +5,15 @@
#include <map> #include <map>
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by flutter/flutter@dev/tools/gen_keycodes/bin/gen_keycodes.dart and // This file is generated by
// should not be edited directly. // flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not
// be edited directly.
// //
// Edit the template dev/tools/gen_keycodes/data/fuchsia_keyboard_map_cc.tmpl instead. // Edit the template
// See dev/tools/gen_keycodes/README.md for more information. // flutter/flutter:dev/tools/gen_keycodes/data/fuchsia_keyboard_map_cc.tmpl
// instead.
//
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
/// Maps Fuchsia-specific IDs to the matching LogicalKeyboardKey. /// Maps Fuchsia-specific IDs to the matching LogicalKeyboardKey.
const std::map<int, int> g_fuchsia_to_logical_key = { const std::map<int, int> g_fuchsia_to_logical_key = {
......
...@@ -5,11 +5,15 @@ ...@@ -5,11 +5,15 @@
#include <map> #include <map>
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by flutter/flutter@dev/tools/gen_keycodes/bin/gen_keycodes.dart and // This file is generated by
// should not be edited directly. // flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not
// be edited directly.
// //
// Edit the template dev/tools/gen_keycodes/data/glfw_keyboard_map_cc.tmpl instead. // Edit the template
// See dev/tools/gen_keycodes/README.md for more information. // flutter/flutter:dev/tools/gen_keycodes/data/glfw_keyboard_map_cc.tmpl
// instead.
//
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
/// Maps GLFW-specific key codes to the matching [LogicalKeyboardKey]. /// Maps GLFW-specific key codes to the matching [LogicalKeyboardKey].
const std::map<int, int> g_glfw_to_logical_key = { const std::map<int, int> g_glfw_to_logical_key = {
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include "./KeyCodeMap_internal.h"
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by
// flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not
// be edited directly.
//
// Edit the template
// flutter/flutter:dev/tools/gen_keycodes/data/ios_key_code_map_cc.tmpl instead.
//
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
@@@MASK_CONSTANTS@@@
// Maps iOS-specific key code values representing [PhysicalKeyboardKey].
//
// iOS doesn't provide a scan code, but a virtual keycode to represent a physical key.
const std::map<uint32_t, uint32_t> keyCodeToPhysicalKey = {
@@@IOS_SCAN_CODE_MAP@@@
};
const std::map<uint32_t, uint32_t> keyCodeToLogicalKey = {
@@@IOS_KEYCODE_LOGICAL_MAP@@@
};
const std::map<uint32_t, uint32_t> keyCodeToModifierFlag = {
@@@KEYCODE_TO_MODIFIER_FLAG_MAP@@@
};
const std::map<uint32_t, uint32_t> modifierFlagToKeyCode = {
@@@MODIFIER_FLAG_TO_KEYCODE_MAP@@@
};
@@@SPECIAL_KEY_CONSTANTS@@@
\ No newline at end of file
...@@ -5,13 +5,16 @@ ...@@ -5,13 +5,16 @@
#include <map> #include <map>
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by flutter/flutter@dev/tools/gen_keycodes/bin/gen_keycodes.dart and // This file is generated by
// should not be edited directly. // flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not
// be edited directly.
// //
// Edit the template dev/tools/gen_keycodes/data/ios_keyboard_map_cc.tmpl instead. // Edit the template
// See dev/tools/gen_keycodes/README.md for more information. // flutter/flutter:dev/tools/gen_keycodes/data/ios_keyboard_map_cc.tmpl instead.
//
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
// Maps macOS-specific key code values representing [PhysicalKeyboardKey]. // Maps iOS-specific key code values representing [PhysicalKeyboardKey].
// //
// iOS doesn't provide a scan code, but a virtual keycode to represent a physical key. // iOS doesn't provide a scan code, but a virtual keycode to represent a physical key.
const std::map<int, int> g_ios_to_physical_key = { const std::map<int, int> g_ios_to_physical_key = {
......
...@@ -7,11 +7,15 @@ ...@@ -7,11 +7,15 @@
#include "./KeyCodeMap_internal.h" #include "./KeyCodeMap_internal.h"
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by flutter/flutter@dev/tools/gen_keycodes/bin/gen_keycodes.dart and // This file is generated by
// should not be edited directly. // flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not
// be edited directly.
// //
// Edit the template dev/tools/gen_keycodes/data/keyboard_map_macos_cc.tmpl instead. // Edit the template
// See dev/tools/gen_keycodes/README.md for more information. // flutter/flutter:dev/tools/gen_keycodes/data/keyboard_map_macos_cc.tmpl
// instead.
//
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
@@@MASK_CONSTANTS@@@ @@@MASK_CONSTANTS@@@
......
...@@ -11,11 +11,14 @@ ...@@ -11,11 +11,14 @@
// DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT // DO NOT EDIT -- DO NOT EDIT -- DO NOT EDIT
// This file is generated by // This file is generated by
// flutter/flutter@dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not // flutter/flutter:dev/tools/gen_keycodes/bin/gen_keycodes.dart and should not
// be edited directly. // be edited directly.
// //
// Edit the template dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl // Edit the template
// instead. See dev/tools/gen_keycodes/README.md for more information. // flutter/flutter:dev/tools/gen_keycodes/data/windows_flutter_key_map_cc.tmpl
// instead.
//
// See flutter/flutter:dev/tools/gen_keycodes/README.md for more information.
namespace flutter { namespace flutter {
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:path/path.dart' as path;
import 'base_code_gen.dart';
import 'constants.dart';
import 'logical_key_data.dart';
import 'physical_key_data.dart';
import 'utils.dart';
const List<String> kModifiersOfInterest = <String>[
'ShiftLeft',
'ShiftRight',
'ControlLeft',
'ControlRight',
'AltLeft',
'AltRight',
'MetaLeft',
'MetaRight',
];
// The name of keys that require special attention.
const List<String> kSpecialPhysicalKeys = <String>['CapsLock'];
const List<String> kSpecialLogicalKeys = <String>['CapsLock'];
String _toConstantVariableName(String variableName) {
return 'k${variableName[0].toUpperCase()}${variableName.substring(1)}';
}
/// Generates the key mapping for iOS, based on the information in the key
/// data structure given to it.
class IOSCodeGenerator extends PlatformCodeGenerator {
IOSCodeGenerator(PhysicalKeyData keyData, LogicalKeyData logicalData)
: super(keyData, logicalData);
/// This generates the map of iOS key codes to physical keys.
String get _scanCodeMap {
final StringBuffer scanCodeMap = StringBuffer();
for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.iOSScanCode != null) {
scanCodeMap.writeln(' {${toHex(entry.iOSScanCode)}, ${toHex(entry.usbHidCode)}}, // ${entry.constantName}');
}
}
return scanCodeMap.toString().trimRight();
}
String get _keyCodeToLogicalMap {
final StringBuffer result = StringBuffer();
for (final LogicalKeyEntry entry in logicalData.entries) {
zipStrict(entry.iOSKeyCodeValues, entry.iOSKeyCodeNames, (int iOSValue, String iOSName) {
result.writeln(' {${toHex(iOSValue)}, ${toHex(entry.value, digits: 11)}}, // $iOSName');
});
}
return result.toString().trimRight();
}
/// This generates the mask values for the part of a key code that defines its plane.
String get _maskConstants {
final StringBuffer buffer = StringBuffer();
for (final MaskConstant constant in maskConstants) {
buffer.writeln('/**');
buffer.write(constant.description
.map((String line) => wrapString(line, prefix: ' * '))
.join(' *\n'));
buffer.writeln(' */');
buffer.writeln('const uint64_t ${_toConstantVariableName(constant.name)} = ${toHex(constant.value, digits: 11)};');
buffer.writeln('');
}
return buffer.toString().trimRight();
}
/// This generates a map from the key code to a modifier flag.
String get _keyToModifierFlagMap {
final StringBuffer modifierKeyMap = StringBuffer();
for (final String name in kModifiersOfInterest) {
modifierKeyMap.writeln(' {${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}, kModifierFlag${lowerCamelToUpperCamel(name)}},');
}
return modifierKeyMap.toString().trimRight();
}
/// This generates a map from the modifier flag to the key code.
String get _modifierFlagToKeyMap {
final StringBuffer modifierKeyMap = StringBuffer();
for (final String name in kModifiersOfInterest) {
modifierKeyMap.writeln(' {kModifierFlag${lowerCamelToUpperCamel(name)}, ${toHex(logicalData.entryByName(name).iOSKeyCodeValues[0])}},');
}
return modifierKeyMap.toString().trimRight();
}
/// This generates some keys that needs special attention.
String get _specialKeyConstants {
final StringBuffer specialKeyConstants = StringBuffer();
for (final String keyName in kSpecialPhysicalKeys) {
specialKeyConstants.writeln('const uint64_t k${keyName}PhysicalKey = ${toHex(keyData.entryByName(keyName).usbHidCode)};');
}
for (final String keyName in kSpecialLogicalKeys) {
specialKeyConstants.writeln('const uint64_t k${lowerCamelToUpperCamel(keyName)}LogicalKey = ${toHex(logicalData.entryByName(keyName).value)};');
}
return specialKeyConstants.toString().trimRight();
}
@override
String get templatePath => path.join(dataRoot, 'ios_key_code_map_cc.tmpl');
@override
String outputPath(String platform) => path.join(PlatformCodeGenerator.engineRoot,
'shell', 'platform', 'darwin', 'ios', 'framework', 'Source', 'KeyCodeMap.mm');
@override
Map<String, String> mappings() {
// There is no iOS keycode map since iOS uses keycode to represent a physical key.
// The LogicalKeyboardKey is generated by raw_keyboard_ios.dart from the unmodified characters
// from NSEvent.
return <String, String>{
'MASK_CONSTANTS': _maskConstants,
'IOS_SCAN_CODE_MAP': _scanCodeMap,
'IOS_KEYCODE_LOGICAL_MAP': _keyCodeToLogicalMap,
'KEYCODE_TO_MODIFIER_FLAG_MAP': _keyToModifierFlagMap,
'MODIFIER_FLAG_TO_KEYCODE_MAP': _modifierFlagToKeyMap,
'SPECIAL_KEY_CONSTANTS': _specialKeyConstants,
};
}
}
...@@ -180,42 +180,42 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator { ...@@ -180,42 +180,42 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
} }
/// This generates the map of macOS key codes to physical keys. /// This generates the map of macOS key codes to physical keys.
String get _macOsScanCodeMap { String get _macOSScanCodeMap {
final StringBuffer macOsScanCodeMap = StringBuffer(); final StringBuffer macOSScanCodeMap = StringBuffer();
for (final PhysicalKeyEntry entry in keyData.entries) { for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.macOsScanCode != null) { if (entry.macOSScanCode != null) {
macOsScanCodeMap.writeln(' ${toHex(entry.macOsScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); macOSScanCodeMap.writeln(' ${toHex(entry.macOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
} }
} }
return macOsScanCodeMap.toString().trimRight(); return macOSScanCodeMap.toString().trimRight();
} }
/// This generates the map of macOS number pad key codes to logical keys. /// This generates the map of macOS number pad key codes to logical keys.
String get _macOsNumpadMap { String get _macOSNumpadMap {
final StringBuffer macOsNumPadMap = StringBuffer(); final StringBuffer macOSNumPadMap = StringBuffer();
for (final PhysicalKeyEntry entry in _numpadKeyData) { for (final PhysicalKeyEntry entry in _numpadKeyData) {
if (entry.macOsScanCode != null) { if (entry.macOSScanCode != null) {
macOsNumPadMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); macOSNumPadMap.writeln(' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
} }
} }
return macOsNumPadMap.toString().trimRight(); return macOSNumPadMap.toString().trimRight();
} }
String get _macOsFunctionKeyMap { String get _macOSFunctionKeyMap {
final StringBuffer macOsFunctionKeyMap = StringBuffer(); final StringBuffer macOSFunctionKeyMap = StringBuffer();
for (final PhysicalKeyEntry entry in _functionKeyData) { for (final PhysicalKeyEntry entry in _functionKeyData) {
if (entry.macOsScanCode != null) { if (entry.macOSScanCode != null) {
macOsFunctionKeyMap.writeln(' ${toHex(entry.macOsScanCode)}: LogicalKeyboardKey.${entry.constantName},'); macOSFunctionKeyMap.writeln(' ${toHex(entry.macOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
} }
} }
return macOsFunctionKeyMap.toString().trimRight(); return macOSFunctionKeyMap.toString().trimRight();
} }
/// This generates the map of macOS key codes to physical keys. /// This generates the map of macOS key codes to physical keys.
String get _macOsKeyCodeMap { String get _macOSKeyCodeMap {
final OutputLines<int> lines = OutputLines<int>('MacOS key code map'); final OutputLines<int> lines = OutputLines<int>('MacOS key code map');
for (final LogicalKeyEntry entry in logicalData.entries) { for (final LogicalKeyEntry entry in logicalData.entries) {
for (final int code in entry.macOsKeyCodeValues) { for (final int code in entry.macOSKeyCodeValues) {
lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},'); lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},');
} }
} }
...@@ -223,32 +223,32 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator { ...@@ -223,32 +223,32 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
} }
/// This generates the map of iOS key codes to physical keys. /// This generates the map of iOS key codes to physical keys.
String get _iosScanCodeMap { String get _iOSScanCodeMap {
final OutputLines<int> lines = OutputLines<int>('iOS scancode map'); final OutputLines<int> lines = OutputLines<int>('iOS scancode map');
for (final PhysicalKeyEntry entry in keyData.entries) { for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.iosScanCode != null) { if (entry.iOSScanCode != null) {
lines.add(entry.iosScanCode!, ' ${toHex(entry.iosScanCode)}: PhysicalKeyboardKey.${entry.constantName},'); lines.add(entry.iOSScanCode!, ' ${toHex(entry.iOSScanCode)}: PhysicalKeyboardKey.${entry.constantName},');
} }
} }
return lines.sortedJoin().trimRight(); return lines.sortedJoin().trimRight();
} }
/// This generates the map of iOS number pad key codes to logical keys. /// This generates the map of iOS number pad key codes to logical keys.
String get _iosNumpadMap { String get _iOSNumpadMap {
final OutputLines<int> lines = OutputLines<int>('iOS numpad map'); final OutputLines<int> lines = OutputLines<int>('iOS numpad map');
for (final PhysicalKeyEntry entry in _numpadKeyData) { for (final PhysicalKeyEntry entry in _numpadKeyData) {
if (entry.iosScanCode != null) { if (entry.iOSScanCode != null) {
lines.add(entry.iosScanCode!,' ${toHex(entry.iosScanCode)}: LogicalKeyboardKey.${entry.constantName},'); lines.add(entry.iOSScanCode!,' ${toHex(entry.iOSScanCode)}: LogicalKeyboardKey.${entry.constantName},');
} }
} }
return lines.sortedJoin().trimRight(); return lines.sortedJoin().trimRight();
} }
/// This generates the map of macOS key codes to physical keys. /// This generates the map of macOS key codes to physical keys.
String get _iosKeyCodeMap { String get _iOSKeyCodeMap {
final OutputLines<int> lines = OutputLines<int>('iOS key code map'); final OutputLines<int> lines = OutputLines<int>('iOS key code map');
for (final LogicalKeyEntry entry in logicalData.entries) { for (final LogicalKeyEntry entry in logicalData.entries) {
for (final int code in entry.iosKeyCodeValues) { for (final int code in entry.iOSKeyCodeValues) {
lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},'); lines.add(code, ' $code: LogicalKeyboardKey.${entry.constantName},');
} }
} }
...@@ -335,13 +335,13 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator { ...@@ -335,13 +335,13 @@ class KeyboardMapsCodeGenerator extends BaseCodeGenerator {
'ANDROID_NUMPAD_MAP': _androidNumpadMap, 'ANDROID_NUMPAD_MAP': _androidNumpadMap,
'FUCHSIA_SCAN_CODE_MAP': _fuchsiaHidCodeMap, 'FUCHSIA_SCAN_CODE_MAP': _fuchsiaHidCodeMap,
'FUCHSIA_KEY_CODE_MAP': _fuchsiaKeyCodeMap, 'FUCHSIA_KEY_CODE_MAP': _fuchsiaKeyCodeMap,
'MACOS_SCAN_CODE_MAP': _macOsScanCodeMap, 'MACOS_SCAN_CODE_MAP': _macOSScanCodeMap,
'MACOS_NUMPAD_MAP': _macOsNumpadMap, 'MACOS_NUMPAD_MAP': _macOSNumpadMap,
'MACOS_FUNCTION_KEY_MAP': _macOsFunctionKeyMap, 'MACOS_FUNCTION_KEY_MAP': _macOSFunctionKeyMap,
'MACOS_KEY_CODE_MAP': _macOsKeyCodeMap, 'MACOS_KEY_CODE_MAP': _macOSKeyCodeMap,
'IOS_SCAN_CODE_MAP': _iosScanCodeMap, 'IOS_SCAN_CODE_MAP': _iOSScanCodeMap,
'IOS_NUMPAD_MAP': _iosNumpadMap, 'IOS_NUMPAD_MAP': _iOSNumpadMap,
'IOS_KEY_CODE_MAP': _iosKeyCodeMap, 'IOS_KEY_CODE_MAP': _iOSKeyCodeMap,
'GLFW_KEY_CODE_MAP': _glfwKeyCodeMap, 'GLFW_KEY_CODE_MAP': _glfwKeyCodeMap,
'GLFW_NUMPAD_MAP': _glfwNumpadMap, 'GLFW_NUMPAD_MAP': _glfwNumpadMap,
'GTK_KEY_CODE_MAP': _gtkKeyCodeMap, 'GTK_KEY_CODE_MAP': _gtkKeyCodeMap,
......
...@@ -207,13 +207,13 @@ class LogicalKeyData { ...@@ -207,13 +207,13 @@ class LogicalKeyData {
physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) { physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) {
final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName); final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName);
assert(physicalEntry.macOsScanCode != null, assert(physicalEntry.macOSScanCode != null,
'Physical entry $physicalKeyName does not have a macOsScanCode.'); 'Physical entry $physicalKeyName does not have a macOSScanCode.');
final LogicalKeyEntry? logicalEntry = data[logicalKeyName]; final LogicalKeyEntry? logicalEntry = data[logicalKeyName];
assert(logicalEntry != null, assert(logicalEntry != null,
'Unable to find logical entry by name $logicalKeyName.'); 'Unable to find logical entry by name $logicalKeyName.');
logicalEntry!.macOsKeyCodeNames.add(physicalEntry.name); logicalEntry!.macOSKeyCodeNames.add(physicalEntry.name);
logicalEntry.macOsKeyCodeValues.add(physicalEntry.macOsScanCode!); logicalEntry.macOSKeyCodeValues.add(physicalEntry.macOSScanCode!);
}); });
} }
...@@ -227,13 +227,13 @@ class LogicalKeyData { ...@@ -227,13 +227,13 @@ class LogicalKeyData {
physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) { physicalToLogical.forEach((String physicalKeyName, String logicalKeyName) {
final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName); final PhysicalKeyEntry physicalEntry = physicalKeyData.entryByName(physicalKeyName);
assert(physicalEntry.iosScanCode != null, assert(physicalEntry.iOSScanCode != null,
'Physical entry $physicalKeyName does not have an iosScanCode.'); 'Physical entry $physicalKeyName does not have an iosScanCode.');
final LogicalKeyEntry? logicalEntry = data[logicalKeyName]; final LogicalKeyEntry? logicalEntry = data[logicalKeyName];
assert(logicalEntry != null, assert(logicalEntry != null,
'Unable to find logical entry by name $logicalKeyName.'); 'Unable to find logical entry by name $logicalKeyName.');
logicalEntry!.iosKeyCodeNames.add(physicalEntry.name); logicalEntry!.iOSKeyCodeNames.add(physicalEntry.name);
logicalEntry.iosKeyCodeValues.add(physicalEntry.iosScanCode!); logicalEntry.iOSKeyCodeValues.add(physicalEntry.iOSScanCode!);
}); });
} }
...@@ -414,10 +414,10 @@ class LogicalKeyEntry { ...@@ -414,10 +414,10 @@ class LogicalKeyEntry {
required this.name, required this.name,
this.keyLabel, this.keyLabel,
}) : webNames = <String>[], }) : webNames = <String>[],
macOsKeyCodeNames = <String>[], macOSKeyCodeNames = <String>[],
macOsKeyCodeValues = <int>[], macOSKeyCodeValues = <int>[],
iosKeyCodeNames = <String>[], iOSKeyCodeNames = <String>[],
iosKeyCodeValues = <int>[], iOSKeyCodeValues = <int>[],
gtkNames = <String>[], gtkNames = <String>[],
gtkValues = <int>[], gtkValues = <int>[],
windowsNames = <String>[], windowsNames = <String>[],
...@@ -441,10 +441,10 @@ class LogicalKeyEntry { ...@@ -441,10 +441,10 @@ class LogicalKeyEntry {
: value = map['value'] as int, : value = map['value'] as int,
name = map['name'] as String, name = map['name'] as String,
webNames = _toNonEmptyArray<String>(map['names']['web']), webNames = _toNonEmptyArray<String>(map['names']['web']),
macOsKeyCodeNames = _toNonEmptyArray<String>(map['names']['macOs']), macOSKeyCodeNames = _toNonEmptyArray<String>(map['names']['macos']),
macOsKeyCodeValues = _toNonEmptyArray<int>(map['values']?['macOs']), macOSKeyCodeValues = _toNonEmptyArray<int>(map['values']?['macos']),
iosKeyCodeNames = _toNonEmptyArray<String>(map['names']['ios']), iOSKeyCodeNames = _toNonEmptyArray<String>(map['names']['ios']),
iosKeyCodeValues = _toNonEmptyArray<int>(map['values']?['ios']), iOSKeyCodeValues = _toNonEmptyArray<int>(map['values']?['ios']),
gtkNames = _toNonEmptyArray<String>(map['names']['gtk']), gtkNames = _toNonEmptyArray<String>(map['names']['gtk']),
gtkValues = _toNonEmptyArray<int>(map['values']?['gtk']), gtkValues = _toNonEmptyArray<int>(map['values']?['gtk']),
windowsNames = _toNonEmptyArray<String>(map['names']['windows']), windowsNames = _toNonEmptyArray<String>(map['names']['windows']),
...@@ -470,19 +470,19 @@ class LogicalKeyEntry { ...@@ -470,19 +470,19 @@ class LogicalKeyEntry {
/// The names of the key codes that corresponds to this logical key on macOS, /// The names of the key codes that corresponds to this logical key on macOS,
/// created from the corresponding physical keys. /// created from the corresponding physical keys.
final List<String> macOsKeyCodeNames; final List<String> macOSKeyCodeNames;
/// The key codes that corresponds to this logical key on macOS, created from /// The key codes that corresponds to this logical key on macOS, created from
/// the physical key list substituted with the key mapping. /// the physical key list substituted with the key mapping.
final List<int> macOsKeyCodeValues; final List<int> macOSKeyCodeValues;
/// The names of the key codes that corresponds to this logical key on iOS, /// The names of the key codes that corresponds to this logical key on iOS,
/// created from the corresponding physical keys. /// created from the corresponding physical keys.
final List<String> iosKeyCodeNames; final List<String> iOSKeyCodeNames;
/// The key codes that corresponds to this logical key on iOS, created from the /// The key codes that corresponds to this logical key on iOS, created from the
/// physical key list substituted with the key mapping. /// physical key list substituted with the key mapping.
final List<int> iosKeyCodeValues; final List<int> iOSKeyCodeValues;
/// The list of names that GTK gives to this key (symbol names minus the /// The list of names that GTK gives to this key (symbol names minus the
/// prefix). /// prefix).
...@@ -528,15 +528,15 @@ class LogicalKeyEntry { ...@@ -528,15 +528,15 @@ class LogicalKeyEntry {
'keyLabel': keyLabel, 'keyLabel': keyLabel,
'names': <String, dynamic>{ 'names': <String, dynamic>{
'web': webNames, 'web': webNames,
'macOs': macOsKeyCodeNames, 'macos': macOSKeyCodeNames,
'ios': iosKeyCodeNames, 'ios': iOSKeyCodeNames,
'gtk': gtkNames, 'gtk': gtkNames,
'windows': windowsNames, 'windows': windowsNames,
'android': androidNames, 'android': androidNames,
}, },
'values': <String, List<int>>{ 'values': <String, List<int>>{
'macOs': macOsKeyCodeValues, 'macos': macOSKeyCodeValues,
'ios': iosKeyCodeValues, 'ios': iOSKeyCodeValues,
'gtk': gtkValues, 'gtk': gtkValues,
'windows': windowsValues, 'windows': windowsValues,
'android': androidValues, 'android': androidValues,
......
...@@ -31,16 +31,16 @@ String _toConstantVariableName(String variableName) { ...@@ -31,16 +31,16 @@ String _toConstantVariableName(String variableName) {
/// Generates the key mapping for macOS, based on the information in the key /// Generates the key mapping for macOS, based on the information in the key
/// data structure given to it. /// data structure given to it.
class MacOsCodeGenerator extends PlatformCodeGenerator { class MacOSCodeGenerator extends PlatformCodeGenerator {
MacOsCodeGenerator(PhysicalKeyData keyData, LogicalKeyData logicalData) MacOSCodeGenerator(PhysicalKeyData keyData, LogicalKeyData logicalData)
: super(keyData, logicalData); : super(keyData, logicalData);
/// This generates the map of macOS key codes to physical keys. /// This generates the map of macOS key codes to physical keys.
String get _scanCodeMap { String get _scanCodeMap {
final StringBuffer scanCodeMap = StringBuffer(); final StringBuffer scanCodeMap = StringBuffer();
for (final PhysicalKeyEntry entry in keyData.entries) { for (final PhysicalKeyEntry entry in keyData.entries) {
if (entry.macOsScanCode != null) { if (entry.macOSScanCode != null) {
scanCodeMap.writeln(' @${toHex(entry.macOsScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}'); scanCodeMap.writeln(' @${toHex(entry.macOSScanCode)} : @${toHex(entry.usbHidCode)}, // ${entry.constantName}');
} }
} }
return scanCodeMap.toString().trimRight(); return scanCodeMap.toString().trimRight();
...@@ -49,8 +49,8 @@ class MacOsCodeGenerator extends PlatformCodeGenerator { ...@@ -49,8 +49,8 @@ class MacOsCodeGenerator extends PlatformCodeGenerator {
String get _keyCodeToLogicalMap { String get _keyCodeToLogicalMap {
final StringBuffer result = StringBuffer(); final StringBuffer result = StringBuffer();
for (final LogicalKeyEntry entry in logicalData.entries) { for (final LogicalKeyEntry entry in logicalData.entries) {
zipStrict(entry.macOsKeyCodeValues, entry.macOsKeyCodeNames, (int macOsValue, String macOsName) { zipStrict(entry.macOSKeyCodeValues, entry.macOSKeyCodeNames, (int macOSValue, String macOSName) {
result.writeln(' @${toHex(macOsValue)} : @${toHex(entry.value, digits: 11)}, // $macOsName'); result.writeln(' @${toHex(macOSValue)} : @${toHex(entry.value, digits: 11)}, // $macOSName');
}); });
} }
return result.toString().trimRight(); return result.toString().trimRight();
...@@ -75,7 +75,7 @@ class MacOsCodeGenerator extends PlatformCodeGenerator { ...@@ -75,7 +75,7 @@ class MacOsCodeGenerator extends PlatformCodeGenerator {
String get _keyToModifierFlagMap { String get _keyToModifierFlagMap {
final StringBuffer modifierKeyMap = StringBuffer(); final StringBuffer modifierKeyMap = StringBuffer();
for (final String name in kModifiersOfInterest) { for (final String name in kModifiersOfInterest) {
modifierKeyMap.writeln(' @${toHex(logicalData.entryByName(name).macOsKeyCodeValues[0])} : @(kModifierFlag${lowerCamelToUpperCamel(name)}),'); modifierKeyMap.writeln(' @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])} : @(kModifierFlag${lowerCamelToUpperCamel(name)}),');
} }
return modifierKeyMap.toString().trimRight(); return modifierKeyMap.toString().trimRight();
} }
...@@ -84,7 +84,7 @@ class MacOsCodeGenerator extends PlatformCodeGenerator { ...@@ -84,7 +84,7 @@ class MacOsCodeGenerator extends PlatformCodeGenerator {
String get _modifierFlagToKeyMap { String get _modifierFlagToKeyMap {
final StringBuffer modifierKeyMap = StringBuffer(); final StringBuffer modifierKeyMap = StringBuffer();
for (final String name in kModifiersOfInterest) { for (final String name in kModifiersOfInterest) {
modifierKeyMap.writeln(' @(kModifierFlag${lowerCamelToUpperCamel(name)}) : @${toHex(logicalData.entryByName(name).macOsKeyCodeValues[0])},'); modifierKeyMap.writeln(' @(kModifierFlag${lowerCamelToUpperCamel(name)}) : @${toHex(logicalData.entryByName(name).macOSKeyCodeValues[0])},');
} }
return modifierKeyMap.toString().trimRight(); return modifierKeyMap.toString().trimRight();
} }
......
...@@ -231,8 +231,8 @@ class PhysicalKeyData { ...@@ -231,8 +231,8 @@ class PhysicalKeyData {
linuxScanCode: linuxScanCode == 0 ? null : linuxScanCode, linuxScanCode: linuxScanCode == 0 ? null : linuxScanCode,
xKbScanCode: xKbScanCode == 0 ? null : xKbScanCode, xKbScanCode: xKbScanCode == 0 ? null : xKbScanCode,
windowsScanCode: windowsScanCode == 0 ? null : windowsScanCode, windowsScanCode: windowsScanCode == 0 ? null : windowsScanCode,
macOsScanCode: macScanCode == 0xffff ? null : macScanCode, macOSScanCode: macScanCode == 0xffff ? null : macScanCode,
iosScanCode: (usbHidCode & 0x070000) == 0x070000 ? (usbHidCode ^ 0x070000) : null, iOSScanCode: (usbHidCode & 0x070000) == 0x070000 ? (usbHidCode ^ 0x070000) : null,
name: name, name: name,
chromiumCode: chromiumCode, chromiumCode: chromiumCode,
); );
...@@ -267,8 +267,8 @@ class PhysicalKeyEntry { ...@@ -267,8 +267,8 @@ class PhysicalKeyEntry {
required this.linuxScanCode, required this.linuxScanCode,
required this.xKbScanCode, required this.xKbScanCode,
required this.windowsScanCode, required this.windowsScanCode,
required this.macOsScanCode, required this.macOSScanCode,
required this.iosScanCode, required this.iOSScanCode,
required this.chromiumCode, required this.chromiumCode,
required this.glfwKeyCodes, required this.glfwKeyCodes,
}); });
...@@ -283,8 +283,8 @@ class PhysicalKeyEntry { ...@@ -283,8 +283,8 @@ class PhysicalKeyEntry {
linuxScanCode: map['scanCodes']['linux'] as int?, linuxScanCode: map['scanCodes']['linux'] as int?,
xKbScanCode: map['scanCodes']['xkb'] as int?, xKbScanCode: map['scanCodes']['xkb'] as int?,
windowsScanCode: map['scanCodes']['windows'] as int?, windowsScanCode: map['scanCodes']['windows'] as int?,
macOsScanCode: map['scanCodes']['macos'] as int?, macOSScanCode: map['scanCodes']['macos'] as int?,
iosScanCode: map['scanCodes']['ios'] as int?, iOSScanCode: map['scanCodes']['ios'] as int?,
glfwKeyCodes: (map['keyCodes']?['glfw'] as List<dynamic>?)?.cast<int>() ?? <int>[], glfwKeyCodes: (map['keyCodes']?['glfw'] as List<dynamic>?)?.cast<int>() ?? <int>[],
); );
} }
...@@ -299,9 +299,9 @@ class PhysicalKeyEntry { ...@@ -299,9 +299,9 @@ class PhysicalKeyEntry {
/// The Windows scan code of the key from Chromium's header file. /// The Windows scan code of the key from Chromium's header file.
final int? windowsScanCode; final int? windowsScanCode;
/// The macOS scan code of the key from Chromium's header file. /// The macOS scan code of the key from Chromium's header file.
final int? macOsScanCode; final int? macOSScanCode;
/// The iOS scan code of the key from UIKey's documentation (USB Hid table) /// The iOS scan code of the key from UIKey's documentation (USB Hid table)
final int? iosScanCode; final int? iOSScanCode;
/// The list of Android scan codes matching this key, created by looking up /// The list of Android scan codes matching this key, created by looking up
/// the Android name in the Chromium data, and substituting the Android scan /// the Android name in the Chromium data, and substituting the Android scan
/// code value. /// code value.
...@@ -330,8 +330,8 @@ class PhysicalKeyEntry { ...@@ -330,8 +330,8 @@ class PhysicalKeyEntry {
'linux': linuxScanCode, 'linux': linuxScanCode,
'xkb': xKbScanCode, 'xkb': xKbScanCode,
'windows': windowsScanCode, 'windows': windowsScanCode,
'macos': macOsScanCode, 'macos': macOSScanCode,
'ios': iosScanCode, 'ios': iOSScanCode,
}, },
'keyCodes': <String, List<int>>{ 'keyCodes': <String, List<int>>{
'glfw': glfwKeyCodes, 'glfw': glfwKeyCodes,
...@@ -380,9 +380,9 @@ class PhysicalKeyEntry { ...@@ -380,9 +380,9 @@ class PhysicalKeyEntry {
String toString() { String toString() {
return """'$constantName': (name: "$name", usbHidCode: ${toHex(usbHidCode)}, """ return """'$constantName': (name: "$name", usbHidCode: ${toHex(usbHidCode)}, """
'linuxScanCode: ${toHex(linuxScanCode)}, xKbScanCode: ${toHex(xKbScanCode)}, ' 'linuxScanCode: ${toHex(linuxScanCode)}, xKbScanCode: ${toHex(xKbScanCode)}, '
'windowsKeyCode: ${toHex(windowsScanCode)}, macOsScanCode: ${toHex(macOsScanCode)}, ' 'windowsKeyCode: ${toHex(windowsScanCode)}, macOSScanCode: ${toHex(macOSScanCode)}, '
'windowsScanCode: ${toHex(windowsScanCode)}, chromiumSymbolName: $chromiumCode ' 'windowsScanCode: ${toHex(windowsScanCode)}, chromiumSymbolName: $chromiumCode '
'iOSScanCode: ${toHex(iosScanCode)})'; 'iOSScanCode: ${toHex(iOSScanCode)})';
} }
static int compareByUsbHidCode(PhysicalKeyEntry a, PhysicalKeyEntry b) => static int compareByUsbHidCode(PhysicalKeyEntry a, PhysicalKeyEntry b) =>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment