Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New approach for handling keyboard layouts and keyboard events #4724

Merged
merged 4 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .gitpod.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM gitpod/workspace-full-vnc:latest

USER root
# Install custom tools, runtime, etc.
RUN apt-get update \
# window manager
&& apt-get install -y jwm \
# electron
&& apt-get install -y libgtk-3-0 libnss3 libasound2 \
# native-keymap
&& apt-get install -y libx11-dev libxkbfile-dev \
&& apt-get clean && rm -rf /var/cache/apt/* && rm -rf /var/lib/apt/lists/* && rm -rf /tmp/*

USER gitpod
# Apply user-specific settings
RUN bash -c ". .nvm/nvm.sh \
&& nvm install 10 \
&& nvm use 10 \
&& npm install -g yarn"

# Give back control
USER root
12 changes: 10 additions & 2 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
image:
file: .gitpod.dockerfile
ports:
- port: 3000
- port: 6080
onOpen: ignore
- port: 5900
onOpen: ignore
tasks:
- init: nvm install 10 && nvm use 10 && yarn
command: yarn --cwd examples/browser start ../..
- init: yarn
command: >
jwm &
yarn --cwd examples/browser start ../..
github:
prebuilds:
pullRequestsFromForks: true
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

Breaking changes:

- [core] support native keyboard layouts [#4724](https://github.com/theia-ide/theia/pull/4724)
- [node] moved to using Node.js version 10, dropping support for Node.js version 8.
- [electron] removed cluster mode and startup timeout setting
- [dialog] `validate` and `accept` methods are now Promisified [#4764](https://github.com/theia-ide/theia/pull/4764)
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 @@ -129,6 +129,7 @@ const { app, shell, BrowserWindow, ipcMain, Menu } = electron;

const applicationName = \`${this.pck.props.frontend.config.applicationName}\`;

const nativeKeymap = require('native-keymap');
const Storage = require('electron-store');
const electronStore = new Storage();

Expand Down Expand Up @@ -213,6 +214,17 @@ app.on('ready', () => {
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 @@ -79,10 +84,12 @@
"clean": "theiaext clean",
"build": "theiaext build",
"watch": "theiaext watch",
"test": "theiaext test"
"test": "theiaext test",
"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, MaybePromise, CancellationTokenSource } 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