Skip to content

Commit b70d260

Browse files
Adds the keyboard mapping for Linux (flutter#29993)
1 parent a1712dc commit b70d260

File tree

12 files changed

+2308
-372
lines changed

12 files changed

+2308
-372
lines changed

dev/manual_tests/lib/raw_keyboard.dart

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
9797
dataText.add(Text('characters: ${data.characters}'));
9898
dataText.add(Text('charactersIgnoringModifiers: ${data.charactersIgnoringModifiers}'));
9999
dataText.add(Text('modifiers: ${data.modifiers} (${_asHex(data.modifiers)})'));
100+
} else if (data is RawKeyEventDataLinux) {
101+
dataText.add(Text('keyCode: ${data.keyCode} (${_asHex(data.keyCode)})'));
102+
dataText.add(Text('scanCode: ${data.scanCode}'));
103+
dataText.add(Text('codePoint: ${data.codePoint}'));
104+
dataText.add(Text('modifiers: ${data.modifiers} (${_asHex(data.modifiers)})'));
100105
}
101106
dataText.add(Text('logical: ${_event.logicalKey}'));
102107
dataText.add(Text('physical: ${_event.physicalKey}'));

dev/tools/gen_keycodes/bin/gen_keycodes.dart

+28-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Future<String> getAndroidScanCodes() async {
3838
return utf8.decode(base64.decode(await http.read(scanCodesUri)));
3939
}
4040

41+
Future<String> getGlfwKeyCodes() async {
42+
final Uri keyCodesUri = Uri.parse('https://raw.githubusercontent.com/glfw/glfw/master/include/GLFW/glfw3.h');
43+
return await http.read(keyCodesUri);
44+
}
45+
4146
Future<void> main(List<String> rawArguments) async {
4247
final ArgParser argParser = ArgParser();
4348
argParser.addOption(
@@ -66,6 +71,19 @@ Future<void> main(List<String> rawArguments) async {
6671
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_name_to_android_name.json'),
6772
help: 'The path to where the Android keycode to DomKey mapping is.',
6873
);
74+
argParser.addOption(
75+
'glfw-keycodes',
76+
defaultsTo: null,
77+
help: 'The path to where the GLFW keycodes header file should be read. '
78+
'If --glfw-keycodes is not specified, the input will be read from the '
79+
'correct file in the GLFW github repository.',
80+
);
81+
argParser.addOption(
82+
'glfw-domkey',
83+
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_name_to_glfw_name.json'),
84+
help: 'The path to where the GLFW keycode to DomKey mapping is.',
85+
);
86+
6987
argParser.addOption(
7088
'data',
7189
defaultsTo: path.join(flutterRoot.path, 'dev', 'tools', 'gen_keycodes', 'data', 'key_data.json'),
@@ -136,8 +154,17 @@ Future<void> main(List<String> rawArguments) async {
136154
androidScanCodes = File(parsedArguments['android-scancodes']).readAsStringSync();
137155
}
138156

157+
String glfwKeyCodes;
158+
if (parsedArguments['glfw-keycodes'] == null) {
159+
glfwKeyCodes = await getGlfwKeyCodes();
160+
} else {
161+
glfwKeyCodes = File(parsedArguments['glfw-keycodes']).readAsStringSync();
162+
}
163+
164+
final String glfwToDomKey = File(parsedArguments['glfw-domkey']).readAsStringSync();
139165
final String androidToDomKey = File(parsedArguments['android-domkey']).readAsStringSync();
140-
data = KeyData(hidCodes, androidScanCodes, androidKeyCodes, androidToDomKey);
166+
167+
data = KeyData(hidCodes, androidScanCodes, androidKeyCodes, androidToDomKey, glfwKeyCodes, glfwToDomKey);
141168

142169
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
143170
File(parsedArguments['data']).writeAsStringSync(encoder.convert(data.toJson()));

0 commit comments

Comments
 (0)