Adds the keyboard mapping for Linux (#29993)

This commit is contained in:
Francisco Magdaleno
2019-03-28 10:04:23 -07:00
committed by GitHub
parent a1712dcfbe
commit b70d260b3c
12 changed files with 2308 additions and 372 deletions

View File

@@ -38,6 +38,11 @@ Future<String> getAndroidScanCodes() async {
return utf8.decode(base64.decode(await http.read(scanCodesUri)));
}
Future<String> getGlfwKeyCodes() async {
final Uri keyCodesUri = Uri.parse('https://raw.githubusercontent.com/glfw/glfw/master/include/GLFW/glfw3.h');
return await http.read(keyCodesUri);
}
Future<void> main(List<String> rawArguments) async {
final ArgParser argParser = ArgParser();
argParser.addOption(
@@ -66,6 +71,19 @@ Future<void> main(List<String> rawArguments) async {
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_name_to_android_name.json'),
help: 'The path to where the Android keycode to DomKey mapping is.',
);
argParser.addOption(
'glfw-keycodes',
defaultsTo: null,
help: 'The path to where the GLFW keycodes header file should be read. '
'If --glfw-keycodes is not specified, the input will be read from the '
'correct file in the GLFW github repository.',
);
argParser.addOption(
'glfw-domkey',
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_name_to_glfw_name.json'),
help: 'The path to where the GLFW keycode to DomKey mapping is.',
);
argParser.addOption(
'data',
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_data.json'),
@@ -136,8 +154,17 @@ Future<void> main(List<String> rawArguments) async {
androidScanCodes = File(parsedArguments['android-scancodes']).readAsStringSync();
}
String glfwKeyCodes;
if (parsedArguments['glfw-keycodes'] == null) {
glfwKeyCodes = await getGlfwKeyCodes();
} else {
glfwKeyCodes = File(parsedArguments['glfw-keycodes']).readAsStringSync();
}
final String glfwToDomKey = File(parsedArguments['glfw-domkey']).readAsStringSync();
final String androidToDomKey = File(parsedArguments['android-domkey']).readAsStringSync();
data = KeyData(hidCodes, androidScanCodes, androidKeyCodes, androidToDomKey);
data = KeyData(hidCodes, androidScanCodes, androidKeyCodes, androidToDomKey, glfwKeyCodes, glfwToDomKey);
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
File(parsedArguments['data']).writeAsStringSync(encoder.convert(data.toJson()));