@vscodium/native-keymap 3.3.7-258412
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nvmrc +1 -0
- package/.release-it.yml +8 -0
- package/LICENSE +22 -0
- package/README.md +82 -0
- package/ThirdPartyNotices.txt +42 -0
- package/binding.gyp +92 -0
- package/collected-artifacts/native-keymap-darwin-arm64/native-keymap-3.3.7-258412-darwin-arm64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-darwin-arm64/native-keymap-3.3.7-258412-darwin-arm64.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-darwin-x64/native-keymap-3.3.7-258412-darwin-x64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-darwin-x64/native-keymap-3.3.7-258412-darwin-x64.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-linux-arm64/native-keymap-3.3.7-258412-linux-arm64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-linux-arm64/native-keymap-3.3.7-258412-linux-arm64.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-linux-armhf/native-keymap-3.3.7-258412-linux-armhf.tar.gz +0 -0
- package/collected-artifacts/native-keymap-linux-armhf/native-keymap-3.3.7-258412-linux-armhf.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-linux-loong64/native-keymap-3.3.7-258412-linux-loong64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-linux-loong64/native-keymap-3.3.7-258412-linux-loong64.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-linux-ppc64le/native-keymap-3.3.7-258412-linux-ppc64le.tar.gz +0 -0
- package/collected-artifacts/native-keymap-linux-ppc64le/native-keymap-3.3.7-258412-linux-ppc64le.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-linux-riscv64/native-keymap-3.3.7-258412-linux-riscv64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-linux-riscv64/native-keymap-3.3.7-258412-linux-riscv64.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-linux-s390x/native-keymap-3.3.7-258412-linux-s390x.tar.gz +0 -0
- package/collected-artifacts/native-keymap-linux-s390x/native-keymap-3.3.7-258412-linux-s390x.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-linux-x64/native-keymap-3.3.7-258412-linux-x64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-linux-x64/native-keymap-3.3.7-258412-linux-x64.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-win32-arm64/native-keymap-3.3.7-258412-win32-arm64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-win32-arm64/native-keymap-3.3.7-258412-win32-arm64.tar.gz.sha256 +1 -0
- package/collected-artifacts/native-keymap-win32-x64/native-keymap-3.3.7-258412-win32-x64.tar.gz +0 -0
- package/collected-artifacts/native-keymap-win32-x64/native-keymap-3.3.7-258412-win32-x64.tar.gz.sha256 +1 -0
- package/deps/chromium/dom_code_data.inc +618 -0
- package/deps/chromium/keyboard_codes.h +23 -0
- package/deps/chromium/macros.h +32 -0
- package/deps/chromium/x/keysym_to_unicode.cc +896 -0
- package/deps/chromium/x/keysym_to_unicode.h +26 -0
- package/index.d.ts +70 -0
- package/index.js +70 -0
- package/package.json +25 -0
- package/release/native-keymap-3.3.7-258412-darwin-arm64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-darwin-arm64.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-darwin-x64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-darwin-x64.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-linux-arm64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-linux-arm64.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-linux-armhf.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-linux-armhf.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-linux-loong64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-linux-loong64.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-linux-ppc64le.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-linux-ppc64le.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-linux-riscv64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-linux-riscv64.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-linux-s390x.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-linux-s390x.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-linux-x64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-linux-x64.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-win32-arm64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-win32-arm64.tar.gz.sha256 +1 -0
- package/release/native-keymap-3.3.7-258412-win32-x64.tar.gz +0 -0
- package/release/native-keymap-3.3.7-258412-win32-x64.tar.gz.sha256 +1 -0
- package/src/common.h +92 -0
- package/src/keyboard_mac.mm +209 -0
- package/src/keyboard_win.cc +476 -0
- package/src/keyboard_x.cc +407 -0
- package/src/keymapping.cc +147 -0
- package/src/keymapping.h +65 -0
- package/src/string_conversion.cc +67 -0
- package/src/string_conversion.h +18 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// ----------------------------------------------------------------------------------------------------------------
|
|
2
|
+
//
|
|
3
|
+
// [13.01.2022] https://source.chromium.org/chromium/chromium/src/+/main:ui/events/keycodes/keysym_to_unicode.h
|
|
4
|
+
//
|
|
5
|
+
// ----------------------------------------------------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
// Copyright 2014 The Chromium Authors. All rights reserved.
|
|
8
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
9
|
+
// found in the LICENSE file.
|
|
10
|
+
|
|
11
|
+
#ifndef UI_EVENTS_KEYCODES_KEYSYM_TO_UNICODE_H_
|
|
12
|
+
#define UI_EVENTS_KEYCODES_KEYSYM_TO_UNICODE_H_
|
|
13
|
+
|
|
14
|
+
#include <stdint.h>
|
|
15
|
+
|
|
16
|
+
namespace ui {
|
|
17
|
+
|
|
18
|
+
// Returns a Unicode character corresponding to the given |keysym|. If the
|
|
19
|
+
// |keysym| doesn't represent a printable character, returns zero. We don't
|
|
20
|
+
// support characters outside the Basic Plane, and this function returns zero
|
|
21
|
+
// in that case.
|
|
22
|
+
uint16_t GetUnicodeCharacterFromXKeySym(unsigned long keysym);
|
|
23
|
+
|
|
24
|
+
} // namespace ui
|
|
25
|
+
|
|
26
|
+
#endif // UI_EVENTS_KEYCODES_KEYSYM_TO_UNICODE_H_
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
export interface IWindowsKeyMapping {
|
|
7
|
+
vkey: string;
|
|
8
|
+
value: string;
|
|
9
|
+
withShift: string;
|
|
10
|
+
withAltGr: string;
|
|
11
|
+
withShiftAltGr: string;
|
|
12
|
+
}
|
|
13
|
+
export interface IWindowsKeyboardMapping {
|
|
14
|
+
[code: string]: IWindowsKeyMapping;
|
|
15
|
+
}
|
|
16
|
+
export interface ILinuxKeyMapping {
|
|
17
|
+
value: string;
|
|
18
|
+
withShift: string;
|
|
19
|
+
withAltGr: string;
|
|
20
|
+
withShiftAltGr: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ILinuxKeyboardMapping {
|
|
23
|
+
[code: string]: ILinuxKeyMapping;
|
|
24
|
+
}
|
|
25
|
+
export interface IMacKeyMapping {
|
|
26
|
+
value: string;
|
|
27
|
+
valueIsDeadKey: boolean;
|
|
28
|
+
withShift: string;
|
|
29
|
+
withShiftIsDeadKey: boolean;
|
|
30
|
+
withAltGr: string;
|
|
31
|
+
withAltGrIsDeadKey: boolean;
|
|
32
|
+
withShiftAltGr: string;
|
|
33
|
+
withShiftAltGrIsDeadKey: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface IMacKeyboardMapping {
|
|
36
|
+
[code: string]: IMacKeyMapping;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type IKeyboardMapping = IWindowsKeyboardMapping | ILinuxKeyboardMapping | IMacKeyboardMapping;
|
|
40
|
+
|
|
41
|
+
export function getKeyMap(): IKeyboardMapping;
|
|
42
|
+
|
|
43
|
+
export interface IWindowsKeyboardLayoutInfo {
|
|
44
|
+
name: string;
|
|
45
|
+
id: string;
|
|
46
|
+
text: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface ILinuxKeyboardLayoutInfo {
|
|
50
|
+
model: string;
|
|
51
|
+
group: number;
|
|
52
|
+
layout: string;
|
|
53
|
+
variant: string;
|
|
54
|
+
options: string;
|
|
55
|
+
rules: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface IMacKeyboardLayoutInfo {
|
|
59
|
+
id: string;
|
|
60
|
+
localizedName: string;
|
|
61
|
+
lang: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type IKeyboardLayoutInfo = IWindowsKeyboardLayoutInfo | ILinuxKeyboardLayoutInfo | IMacKeyboardLayoutInfo;
|
|
65
|
+
|
|
66
|
+
export function getCurrentKeyboardLayout(): IKeyboardLayoutInfo;
|
|
67
|
+
|
|
68
|
+
export function onDidChangeKeyboardLayout(callback: () => void): void;
|
|
69
|
+
|
|
70
|
+
export function isISOKeyboard(): boolean | undefined;
|
package/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
function NativeBinding() {
|
|
7
|
+
this._tried = false;
|
|
8
|
+
this._keymapping = null;
|
|
9
|
+
}
|
|
10
|
+
NativeBinding.prototype._init = function() {
|
|
11
|
+
if (this._tried) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
this._tried = true;
|
|
15
|
+
try {
|
|
16
|
+
this._keymapping = require('./build/Release/keymapping');
|
|
17
|
+
} catch (err) {
|
|
18
|
+
// fallback to the debug build
|
|
19
|
+
this._keymapping = require('./build/Debug/keymapping');
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
NativeBinding.prototype.getKeyMap = function() {
|
|
23
|
+
try {
|
|
24
|
+
this._init();
|
|
25
|
+
return this._keymapping.getKeyMap();
|
|
26
|
+
} catch(err) {
|
|
27
|
+
console.error(err);
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
NativeBinding.prototype.getCurrentKeyboardLayout = function() {
|
|
32
|
+
try {
|
|
33
|
+
this._init();
|
|
34
|
+
return this._keymapping.getCurrentKeyboardLayout();
|
|
35
|
+
} catch(err) {
|
|
36
|
+
console.error(err);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
NativeBinding.prototype.onDidChangeKeyboardLayout = function(callback) {
|
|
41
|
+
try {
|
|
42
|
+
this._init();
|
|
43
|
+
this._keymapping.onDidChangeKeyboardLayout(callback);
|
|
44
|
+
} catch(err) {
|
|
45
|
+
console.error(err);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
NativeBinding.prototype.isISOKeyboard = function(callback) {
|
|
49
|
+
try {
|
|
50
|
+
this._init();
|
|
51
|
+
return this._keymapping.isISOKeyboard();
|
|
52
|
+
} catch(err) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var binding = new NativeBinding();
|
|
58
|
+
|
|
59
|
+
exports.getCurrentKeyboardLayout = function() {
|
|
60
|
+
return binding.getCurrentKeyboardLayout();
|
|
61
|
+
};
|
|
62
|
+
exports.getKeyMap = function() {
|
|
63
|
+
return binding.getKeyMap();
|
|
64
|
+
};
|
|
65
|
+
exports.onDidChangeKeyboardLayout = function(callback) {
|
|
66
|
+
return binding.onDidChangeKeyboardLayout(callback);
|
|
67
|
+
};
|
|
68
|
+
exports.isISOKeyboard = function(callback) {
|
|
69
|
+
return binding.isISOKeyboard(callback);
|
|
70
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vscodium/native-keymap",
|
|
3
|
+
"version": "3.3.7-258412",
|
|
4
|
+
"description": "Get OS key mapping",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"typings": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"release": "release-it --no-increment",
|
|
9
|
+
"test": "node test/test.js"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/vscodium/native-keymap.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "Microsoft Corporation",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"release-it": "^19.1.0"
|
|
19
|
+
},
|
|
20
|
+
"release": {
|
|
21
|
+
"branches": [
|
|
22
|
+
"main"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
b2fd9877d857f2b756bd8ac107840dd63b65e8613f8764c7af38ea200e87d2af native-keymap-3.3.7-258412-darwin-arm64.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
61e81840f9c4d1b058987807cb6762e307e34dfaac5e66df01dce513cfda8137 native-keymap-3.3.7-258412-darwin-x64.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
59f5b25556c9cbbc239431138b3f6c3e21f08a8d8bba245091ec043a5297f4c7 native-keymap-3.3.7-258412-linux-arm64.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
7e328bc73cc8668f5c620cf2bbc43f906a041e9274976356052fd2f7de262a1c native-keymap-3.3.7-258412-linux-armhf.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4649674b066baebaeee2ab7affb96ead8496f12f7bbffb2f0f01c1dc4861cf3b native-keymap-3.3.7-258412-linux-loong64.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aec80a65680ef54ac5711b62038d4a754f49547b69c8128354fdeb1175cfa15a native-keymap-3.3.7-258412-linux-ppc64le.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
327ae5945d4fa49187598a9543e356bc41edf292aec559a15ba571749207cda4 native-keymap-3.3.7-258412-linux-riscv64.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
04e0bb1dead00cc3d1a7fbf069d5b0b17cf08bbe0c57d2eef55b125ed6365735 native-keymap-3.3.7-258412-linux-s390x.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ac2aa5136c94aed4b6fab4ad26f9fe755c4e7745e1251d24d46dc05cc9d87567 native-keymap-3.3.7-258412-linux-x64.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
a73eb41dbb28d49cdcfb9d9c4d3643e4aaf9cb72f61414a7765a2f3994b6518b *native-keymap-3.3.7-258412-win32-arm64.tar.gz
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1ccb734a7bc8d056d0b5ae8f88d9ab549cb19f12d1d4f66919e1091c2295b951 *native-keymap-3.3.7-258412-win32-x64.tar.gz
|
package/src/common.h
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// """
|
|
2
|
+
// Copyright Node.js contributors. All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to
|
|
6
|
+
// deal in the Software without restriction, including without limitation the
|
|
7
|
+
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
8
|
+
// sell copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in
|
|
12
|
+
// all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
19
|
+
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
20
|
+
// IN THE SOFTWARE.
|
|
21
|
+
// """
|
|
22
|
+
|
|
23
|
+
// Empty value so that macros here are able to return NULL or void
|
|
24
|
+
#define NAPI_RETVAL_NOTHING // Intentionally blank #define
|
|
25
|
+
|
|
26
|
+
#define GET_AND_THROW_LAST_ERROR(env) \
|
|
27
|
+
do { \
|
|
28
|
+
const napi_extended_error_info *error_info; \
|
|
29
|
+
napi_get_last_error_info((env), &error_info); \
|
|
30
|
+
bool is_pending; \
|
|
31
|
+
napi_is_exception_pending((env), &is_pending); \
|
|
32
|
+
/* If an exception is already pending, don't rethrow it */ \
|
|
33
|
+
if (!is_pending) { \
|
|
34
|
+
const char* error_message = error_info->error_message != NULL ? \
|
|
35
|
+
error_info->error_message : \
|
|
36
|
+
"empty error message"; \
|
|
37
|
+
napi_throw_error((env), NULL, error_message); \
|
|
38
|
+
} \
|
|
39
|
+
} while (0)
|
|
40
|
+
|
|
41
|
+
#define NAPI_ASSERT_BASE(env, assertion, message, ret_val) \
|
|
42
|
+
do { \
|
|
43
|
+
if (!(assertion)) { \
|
|
44
|
+
napi_throw_error( \
|
|
45
|
+
(env), \
|
|
46
|
+
NULL, \
|
|
47
|
+
"assertion (" #assertion ") failed: " message); \
|
|
48
|
+
return ret_val; \
|
|
49
|
+
} \
|
|
50
|
+
} while (0)
|
|
51
|
+
|
|
52
|
+
// Returns NULL on failed assertion.
|
|
53
|
+
// This is meant to be used inside napi_callback methods.
|
|
54
|
+
#define NAPI_ASSERT(env, assertion, message) \
|
|
55
|
+
NAPI_ASSERT_BASE(env, assertion, message, NULL)
|
|
56
|
+
|
|
57
|
+
// Returns empty on failed assertion.
|
|
58
|
+
// This is meant to be used inside functions with void return type.
|
|
59
|
+
#define NAPI_ASSERT_RETURN_VOID(env, assertion, message) \
|
|
60
|
+
NAPI_ASSERT_BASE(env, assertion, message, NAPI_RETVAL_NOTHING)
|
|
61
|
+
|
|
62
|
+
#define NAPI_CALL_BASE(env, the_call, ret_val) \
|
|
63
|
+
do { \
|
|
64
|
+
if ((the_call) != napi_ok) { \
|
|
65
|
+
GET_AND_THROW_LAST_ERROR((env)); \
|
|
66
|
+
return ret_val; \
|
|
67
|
+
} \
|
|
68
|
+
} while (0)
|
|
69
|
+
|
|
70
|
+
// Returns NULL if the_call doesn't return napi_ok.
|
|
71
|
+
#define NAPI_CALL(env, the_call) \
|
|
72
|
+
NAPI_CALL_BASE(env, the_call, NULL)
|
|
73
|
+
|
|
74
|
+
// Returns empty if the_call doesn't return napi_ok.
|
|
75
|
+
#define NAPI_CALL_RETURN_VOID(env, the_call) \
|
|
76
|
+
NAPI_CALL_BASE(env, the_call, NAPI_RETVAL_NOTHING)
|
|
77
|
+
|
|
78
|
+
// Returns empty if the_call doesn't return napi_ok.
|
|
79
|
+
#define NAPI_CALL_RETURN_STATUS(env, the_call) \
|
|
80
|
+
do { \
|
|
81
|
+
napi_status status = (the_call); \
|
|
82
|
+
if (status != napi_ok) { \
|
|
83
|
+
GET_AND_THROW_LAST_ERROR((env)); \
|
|
84
|
+
return status; \
|
|
85
|
+
} \
|
|
86
|
+
} while (0)
|
|
87
|
+
|
|
88
|
+
#define DECLARE_NAPI_PROPERTY(name, func) \
|
|
89
|
+
{ (name), NULL, (func), NULL, NULL, NULL, napi_default, NULL }
|
|
90
|
+
|
|
91
|
+
#define DECLARE_NAPI_GETTER(name, func) \
|
|
92
|
+
{ (name), NULL, NULL, (func), NULL, NULL, napi_default, NULL }
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
#import <Cocoa/Cocoa.h>
|
|
7
|
+
#include <Carbon/Carbon.h>
|
|
8
|
+
|
|
9
|
+
#include "string_conversion.h"
|
|
10
|
+
#include "keymapping.h"
|
|
11
|
+
#include "common.h"
|
|
12
|
+
#include "../deps/chromium/macros.h"
|
|
13
|
+
|
|
14
|
+
namespace {
|
|
15
|
+
|
|
16
|
+
std::pair<bool,std::string> ConvertKeyCodeToText(const UCKeyboardLayout* keyboard_layout, int mac_key_code, int modifiers) {
|
|
17
|
+
|
|
18
|
+
int mac_modifiers = 0;
|
|
19
|
+
if (modifiers & kShiftKeyModifierMask)
|
|
20
|
+
mac_modifiers |= shiftKey;
|
|
21
|
+
if (modifiers & kControlKeyModifierMask)
|
|
22
|
+
mac_modifiers |= controlKey;
|
|
23
|
+
if (modifiers & kAltKeyModifierMask)
|
|
24
|
+
mac_modifiers |= optionKey;
|
|
25
|
+
if (modifiers & kMetaKeyModifierMask)
|
|
26
|
+
mac_modifiers |= cmdKey;
|
|
27
|
+
|
|
28
|
+
// Convert EventRecord modifiers to format UCKeyTranslate accepts. See docs
|
|
29
|
+
// on UCKeyTranslate for more info.
|
|
30
|
+
UInt32 modifier_key_state = (mac_modifiers >> 8) & 0xFF;
|
|
31
|
+
|
|
32
|
+
UInt32 dead_key_state = 0;
|
|
33
|
+
UniCharCount char_count = 0;
|
|
34
|
+
UniChar character = 0;
|
|
35
|
+
OSStatus status = UCKeyTranslate(
|
|
36
|
+
keyboard_layout,
|
|
37
|
+
static_cast<UInt16>(mac_key_code),
|
|
38
|
+
kUCKeyActionDown,
|
|
39
|
+
modifier_key_state,
|
|
40
|
+
LMGetKbdLast(),
|
|
41
|
+
kUCKeyTranslateNoDeadKeysBit,
|
|
42
|
+
&dead_key_state,
|
|
43
|
+
1,
|
|
44
|
+
&char_count,
|
|
45
|
+
&character);
|
|
46
|
+
|
|
47
|
+
bool is_dead_key = false;
|
|
48
|
+
if (status == noErr && char_count == 0 && dead_key_state != 0) {
|
|
49
|
+
is_dead_key = true;
|
|
50
|
+
status = UCKeyTranslate(
|
|
51
|
+
keyboard_layout,
|
|
52
|
+
static_cast<UInt16>(mac_key_code),
|
|
53
|
+
kUCKeyActionDown,
|
|
54
|
+
modifier_key_state,
|
|
55
|
+
LMGetKbdLast(),
|
|
56
|
+
kUCKeyTranslateNoDeadKeysBit,
|
|
57
|
+
&dead_key_state,
|
|
58
|
+
1,
|
|
59
|
+
&char_count,
|
|
60
|
+
&character);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (status == noErr && char_count == 1 && !std::iscntrl(character)) {
|
|
64
|
+
wchar_t value = character;
|
|
65
|
+
return std::make_pair(is_dead_key, vscode_keyboard::UTF16toUTF8(&value, 1));
|
|
66
|
+
}
|
|
67
|
+
return std::make_pair(false, std::string());
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
} // namespace
|
|
71
|
+
|
|
72
|
+
namespace vscode_keyboard {
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
#define DOM_CODE(usb, evdev, xkb, win, mac, code, id) {usb, mac, code}
|
|
76
|
+
#define DOM_CODE_DECLARATION const KeycodeMapEntry usb_keycode_map[] =
|
|
77
|
+
#include "../deps/chromium/dom_code_data.inc"
|
|
78
|
+
#undef DOM_CODE
|
|
79
|
+
#undef DOM_CODE_DECLARATION
|
|
80
|
+
|
|
81
|
+
napi_value GetKeyMapImpl(napi_env env, napi_callback_info info) {
|
|
82
|
+
|
|
83
|
+
napi_value result;
|
|
84
|
+
NAPI_CALL(env, napi_create_object(env, &result));
|
|
85
|
+
|
|
86
|
+
TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
|
|
87
|
+
CFDataRef layout_data = static_cast<CFDataRef>((TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData)));
|
|
88
|
+
if (!layout_data) {
|
|
89
|
+
// TISGetInputSourceProperty returns null with Japanese keyboard layout.
|
|
90
|
+
// Using TISCopyCurrentKeyboardLayoutInputSource to fix NULL return.
|
|
91
|
+
source = TISCopyCurrentKeyboardLayoutInputSource();
|
|
92
|
+
layout_data = static_cast<CFDataRef>((TISGetInputSourceProperty(source, kTISPropertyUnicodeKeyLayoutData)));
|
|
93
|
+
if (!layout_data) {
|
|
94
|
+
// https://developer.apple.com/library/mac/documentation/TextFonts/Reference/TextInputSourcesReference/#//apple_ref/c/func/TISGetInputSourceProperty
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const UCKeyboardLayout* keyboard_layout = reinterpret_cast<const UCKeyboardLayout*>(CFDataGetBytePtr(layout_data));
|
|
100
|
+
|
|
101
|
+
size_t cnt = sizeof(usb_keycode_map) / sizeof(usb_keycode_map[0]);
|
|
102
|
+
|
|
103
|
+
napi_value true_value;
|
|
104
|
+
NAPI_CALL(env, napi_get_boolean(env, true, &true_value));
|
|
105
|
+
|
|
106
|
+
napi_value false_value;
|
|
107
|
+
NAPI_CALL(env, napi_get_boolean(env, false, &false_value));
|
|
108
|
+
|
|
109
|
+
for (size_t i = 0; i < cnt; ++i) {
|
|
110
|
+
const char *code = usb_keycode_map[i].code;
|
|
111
|
+
int native_keycode = usb_keycode_map[i].native_keycode;
|
|
112
|
+
|
|
113
|
+
if (!code || native_keycode >= 0xffff) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
napi_value entry;
|
|
118
|
+
NAPI_CALL(env, napi_create_object(env, &entry));
|
|
119
|
+
|
|
120
|
+
{
|
|
121
|
+
std::pair<bool,std::string> value = ConvertKeyCodeToText(keyboard_layout, native_keycode, 0);
|
|
122
|
+
NAPI_CALL(env, napi_set_named_property_string_utf8(env, entry, "value", value.second.c_str()));
|
|
123
|
+
NAPI_CALL(env, napi_set_named_property(env, entry, "valueIsDeadKey", value.first ? true_value : false_value));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
{
|
|
127
|
+
std::pair<bool,std::string> with_shift = ConvertKeyCodeToText(keyboard_layout, native_keycode, kShiftKeyModifierMask);
|
|
128
|
+
NAPI_CALL(env, napi_set_named_property_string_utf8(env, entry, "withShift", with_shift.second.c_str()));
|
|
129
|
+
NAPI_CALL(env, napi_set_named_property(env, entry, "withShiftIsDeadKey", with_shift.first ? true_value : false_value));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
{
|
|
133
|
+
std::pair<bool,std::string> with_alt_gr = ConvertKeyCodeToText(keyboard_layout, native_keycode, kAltKeyModifierMask);
|
|
134
|
+
NAPI_CALL(env, napi_set_named_property_string_utf8(env, entry, "withAltGr", with_alt_gr.second.c_str()));
|
|
135
|
+
NAPI_CALL(env, napi_set_named_property(env, entry, "withAltGrIsDeadKey", with_alt_gr.first ? true_value : false_value));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
{
|
|
139
|
+
std::pair<bool,std::string> with_shift_alt_gr = ConvertKeyCodeToText(keyboard_layout, native_keycode, kShiftKeyModifierMask | kAltKeyModifierMask);
|
|
140
|
+
NAPI_CALL(env, napi_set_named_property_string_utf8(env, entry, "withShiftAltGr", with_shift_alt_gr.second.c_str()));
|
|
141
|
+
NAPI_CALL(env, napi_set_named_property(env, entry, "withShiftAltGrIsDeadKey", with_shift_alt_gr.first ? true_value : false_value));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
NAPI_CALL(env, napi_set_named_property(env, result, code, entry));
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
napi_value GetCurrentKeyboardLayoutImpl(napi_env env, napi_callback_info info) {
|
|
150
|
+
|
|
151
|
+
napi_value result;
|
|
152
|
+
NAPI_CALL(env, napi_create_object(env, &result));
|
|
153
|
+
|
|
154
|
+
TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
|
|
155
|
+
CFStringRef source_id = (CFStringRef) TISGetInputSourceProperty(source, kTISPropertyInputSourceID);
|
|
156
|
+
if(source_id) {
|
|
157
|
+
NAPI_CALL(env, napi_set_named_property_string_utf8(env, result, "id", std::string([(NSString *)source_id UTF8String]).c_str()));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
TISInputSourceRef name_source = TISCopyCurrentKeyboardInputSource();
|
|
161
|
+
CFStringRef localized_name = (CFStringRef) TISGetInputSourceProperty(name_source, kTISPropertyLocalizedName);
|
|
162
|
+
if(localized_name) {
|
|
163
|
+
NAPI_CALL(env, napi_set_named_property_string_utf8(env, result, "localizedName", std::string([(NSString *)localized_name UTF8String]).c_str()));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
NSArray* languages = (NSArray *) TISGetInputSourceProperty(source, kTISPropertyInputSourceLanguages);
|
|
167
|
+
if (languages && [languages count] > 0) {
|
|
168
|
+
NSString* lang = [languages objectAtIndex:0];
|
|
169
|
+
if (lang) {
|
|
170
|
+
NAPI_CALL(env, napi_set_named_property_string_utf8(env, result, "lang", std::string([lang UTF8String]).c_str()));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
void NotificationCallback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
|
|
178
|
+
NotificationCallbackData *data = (NotificationCallbackData *)observer;
|
|
179
|
+
InvokeNotificationCallback(data);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
void RegisterKeyboardLayoutChangeListenerImpl(NotificationCallbackData *data) {
|
|
183
|
+
CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
|
|
184
|
+
|
|
185
|
+
// add an observer
|
|
186
|
+
CFNotificationCenterAddObserver(center, data, NotificationCallback,
|
|
187
|
+
kTISNotifySelectedKeyboardInputSourceChanged, NULL,
|
|
188
|
+
CFNotificationSuspensionBehaviorDeliverImmediately
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
void DisposeKeyboardLayoutChangeListenerImpl(NotificationCallbackData *data) {
|
|
193
|
+
CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
|
|
194
|
+
|
|
195
|
+
// remove the observer
|
|
196
|
+
CFNotificationCenterRemoveObserver(center, data,
|
|
197
|
+
kTISNotifySelectedKeyboardInputSourceChanged, NULL
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
napi_value IsISOKeyboardImpl(napi_env env, napi_callback_info info) {
|
|
202
|
+
if (KBGetLayoutType(LMGetKbdType()) == kKeyboardISO) {
|
|
203
|
+
return napi_fetch_boolean(env, true);
|
|
204
|
+
} else {
|
|
205
|
+
return napi_fetch_boolean(env, false);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
} // namespace vscode_keyboard
|