Skip to content

Commit

Permalink
#4079: New approach for handling keyboard layouts and keyboard events
Browse files Browse the repository at this point in the history
Signed-off-by: Miro Spönemann <miro.spoenemann@typefox.io>
  • Loading branch information
spoenemann committed Apr 1, 2019
1 parent 6365339 commit 84c7660
Show file tree
Hide file tree
Showing 50 changed files with 2,439 additions and 1,315 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ env:
- NODE_OPTIONS="--max_old_space_size=4096"
addons:
apt:
update: true
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- oracle-java9-set-default
- libsecret-1-dev
- libx11-dev
- libxkbfile-dev
chrome: stable
before_script:
- export DISPLAY=:99.0; sh -e /etc/init.d/xvfb start ;
Expand Down
1 change: 1 addition & 0 deletions configs/base.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"downlevelIteration": true,
"resolveJsonModule": true,
"module": "commonjs",
"moduleResolution": "node",
"target": "es5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const applicationName = \`${this.pck.props.frontend.config.applicationName}\`;
if (isMaster) {
const nativeKeymap = require('native-keymap');
const Storage = require('electron-store');
const electronStore = new Storage();
Expand Down Expand Up @@ -214,6 +215,17 @@ if (isMaster) {
newWindow.on('resize', saveWindowStateDelayed);
newWindow.on('move', saveWindowStateDelayed);
// Notify the renderer process on keyboard layout change
nativeKeymap.onDidChangeKeyboardLayout(() => {
if (!newWindow.isDestroyed()) {
const newLayout = {
info: nativeKeymap.getCurrentKeyboardLayout(),
mapping: nativeKeymap.getKeyMap()
};
newWindow.webContents.send('keyboardLayoutChanged', newLayout);
}
});
if (!!theUrl) {
newWindow.loadURL(theUrl);
}
Expand Down
2 changes: 1 addition & 1 deletion dev-packages/application-manager/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import cp = require('child_process');
export function rebuild(target: 'electron' | 'browser', modules: string[]) {
const nodeModulesPath = path.join(process.cwd(), 'node_modules');
const browserModulesPath = path.join(process.cwd(), '.browser_modules');
const modulesToProcess = modules || ['@theia/node-pty', 'nsfw', 'find-git-repositories'];
const modulesToProcess = modules || ['@theia/node-pty', 'nsfw', 'native-keymap', 'find-git-repositories'];

if (target === 'electron' && !fs.existsSync(browserModulesPath)) {
const dependencies: {
Expand Down
11 changes: 9 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"inversify": "^4.14.0",
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"native-keymap": "^1.2.5",
"nsfw": "^1.2.2",
"perfect-scrollbar": "^1.3.0",
"react": "^16.4.1",
Expand All @@ -56,6 +57,10 @@
{
"frontend": "lib/browser/window/browser-window-module",
"frontendElectron": "lib/electron-browser/window/electron-window-module"
},
{
"frontend": "lib/browser/keyboard/browser-keyboard-module",
"frontendElectron": "lib/electron-browser/keyboard/electron-keyboard-module"
}
],
"keywords": [
Expand All @@ -80,10 +85,12 @@
"build": "theiaext build",
"watch": "theiaext watch",
"test": "theiaext test",
"docs": "theiaext docs"
"docs": "theiaext docs",
"generate-layout": "electron ./scripts/generate-layout"
},
"devDependencies": {
"@theia/ext-scripts": "^0.5.0"
"@theia/ext-scripts": "^0.5.0",
"minimist": "^1.2.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
Expand Down
53 changes: 53 additions & 0 deletions packages/core/scripts/generate-layout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/********************************************************************************
* Copyright (C) 2019 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

const parseArgs = require('minimist');
const nativeKeymap = require('native-keymap');
const fs = require('fs');
const electron = require('electron');

/*
* Usage:
* yarn generate-layout [--info] [--pretty] [--output file]
*
* --info Print the keyboard layout information; if omitted, the full
* keyboard layout with info and mapping is printed.
* --pretty Pretty-print the JSON output.
* --output file Write the output to the given file instead of stdout.
*/
const args = parseArgs(process.argv);
const printInfo = args.info;
const prettyPrint = args.pretty;
const outFile = args.output;

let output;
if (printInfo) {
output = nativeKeymap.getCurrentKeyboardLayout();
} else {
output = {
info: nativeKeymap.getCurrentKeyboardLayout(),
mapping: nativeKeymap.getKeyMap()
};
}

const stringOutput = JSON.stringify(output, undefined, prettyPrint ? 2 : undefined);
if (outFile) {
fs.writeFileSync(outFile, stringOutput);
} else {
console.log(stringOutput);
}

electron.app.quit();
2 changes: 1 addition & 1 deletion packages/core/src/browser/dialogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { injectable, inject } from 'inversify';
import { Disposable } from '../common';
import { Key } from './keys';
import { Key } from './keyboard/keys';
import { Widget, BaseWidget, Message } from './widgets';

@injectable()
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/browser/frontend-application-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import { QuickPickServiceImpl } from './quick-open/quick-pick-service-impl';
import { QuickPickService, quickPickServicePath } from '../common/quick-pick-service';
import { ContextKeyService } from './context-key-service';
import { ResourceContextKey } from './resource-context-key';
import { KeyboardLayoutService } from './keyboard/keyboard-layout-service';

export const frontendApplicationModule = new ContainerModule((bind, unbind, isBound, rebind) => {
const themeService = ThemeService.get();
Expand Down Expand Up @@ -144,6 +145,7 @@ export const frontendApplicationModule = new ContainerModule((bind, unbind, isBo
bind(MenuModelRegistry).toSelf().inSingletonScope();
bindContributionProvider(bind, MenuContribution);

bind(KeyboardLayoutService).toSelf().inSingletonScope();
bind(KeybindingRegistry).toSelf().inSingletonScope();
bindContributionProvider(bind, KeybindingContext);
bindContributionProvider(bind, KeybindingContribution);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/frontend-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export class FrontendApplication {
* - consider treat commands, keybindings and menus as frontend application contributions
*/
this.commands.onStart();
this.keybindings.onStart();
await this.keybindings.onStart();
this.menus.onStart();
for (const contribution of this.contributions.getContributions()) {
if (contribution.onStart) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

export * from './shell';
export * from './frontend-application';
export * from './keyboard';
export * from './opener-service';
export * from './browser';
export * from './context-menu-renderer';
Expand All @@ -31,7 +32,6 @@ export * from './saveable';
export * from './storage-service';
export * from './preferences';
export * from './keybinding';
export * from './keys';
export * from './status-bar';
export * from './label-provider';
export * from './widget-open-handler';
Expand Down
Loading

0 comments on commit 84c7660

Please sign in to comment.