1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00

novnc ES6 compatibility is not working. I reverse it. Spice/VNC sending ctrl+alt+fn functionality restored.

This commit is contained in:
catborise 2018-08-27 15:30:50 +03:00
parent f73271e677
commit 76e6388ec5
53 changed files with 19018 additions and 17438 deletions

View file

@ -1,42 +1,26 @@
'use strict';
/*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = Keyboard;
var _logging = require('../util/logging.js');
var Log = _interopRequireWildcard(_logging);
var _events = require('../util/events.js');
var _util = require('./util.js');
var KeyboardUtil = _interopRequireWildcard(_util);
var _keysym = require('./keysym.js');
var _keysym2 = _interopRequireDefault(_keysym);
var _browser = require('../util/browser.js');
var browser = _interopRequireWildcard(_browser);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
import * as Log from '../util/logging.js';
import { stopEvent } from '../util/events.js';
import * as KeyboardUtil from "./util.js";
import KeyTable from "./keysym.js";
import * as browser from "../util/browser.js";
//
// Keyboard event handler
//
function Keyboard(target) {
export default function Keyboard(target) {
this._target = target || null;
this._keyDownList = {}; // List of depressed keys
// (even if they are happy)
this._pendingKey = null; // Key waiting for keypress
this._keyDownList = {}; // List of depressed keys
// (even if they are happy)
this._pendingKey = null; // Key waiting for keypress
// keep these here so we can refer to them later
this._eventHandlers = {
@ -45,24 +29,18 @@ function Keyboard(target) {
'keypress': this._handleKeyPress.bind(this),
'blur': this._allKeysUp.bind(this)
};
} /*
* noVNC: HTML5 VNC client
* Copyright (C) 2012 Joel Martin
* Copyright (C) 2013 Samuel Mannehed for Cendio AB
* Licensed under MPL 2.0 or any later version (see LICENSE.txt)
*/
;
};
Keyboard.prototype = {
// ===== EVENT HANDLERS =====
onkeyevent: function () {}, // Handler for key press/release
onkeyevent: function () {}, // Handler for key press/release
// ===== PRIVATE METHODS =====
_sendKeyEvent: function (keysym, code, down) {
Log.Debug("onkeyevent " + (down ? "down" : "up") + ", keysym: " + keysym, ", code: " + code);
Log.Debug("onkeyevent " + (down ? "down" : "up") +
", keysym: " + keysym, ", code: " + code);
// Windows sends CtrlLeft+AltRight when you press
// AltGraph, which tends to confuse the hell out of
@ -70,18 +48,25 @@ Keyboard.prototype = {
// there is a way to detect AltGraph properly.
var fakeAltGraph = false;
if (down && browser.isWindows()) {
if (code !== 'ControlLeft' && code !== 'AltRight' && 'ControlLeft' in this._keyDownList && 'AltRight' in this._keyDownList) {
if ((code !== 'ControlLeft') &&
(code !== 'AltRight') &&
('ControlLeft' in this._keyDownList) &&
('AltRight' in this._keyDownList)) {
fakeAltGraph = true;
this.onkeyevent(this._keyDownList['AltRight'], 'AltRight', false);
this.onkeyevent(this._keyDownList['ControlLeft'], 'ControlLeft', false);
this.onkeyevent(this._keyDownList['AltRight'],
'AltRight', false);
this.onkeyevent(this._keyDownList['ControlLeft'],
'ControlLeft', false);
}
}
this.onkeyevent(keysym, code, down);
if (fakeAltGraph) {
this.onkeyevent(this._keyDownList['ControlLeft'], 'ControlLeft', true);
this.onkeyevent(this._keyDownList['AltRight'], 'AltRight', true);
this.onkeyevent(this._keyDownList['ControlLeft'],
'ControlLeft', true);
this.onkeyevent(this._keyDownList['AltRight'],
'AltRight', true);
}
},
@ -94,7 +79,7 @@ Keyboard.prototype = {
// Unstable, but we don't have anything else to go on
// (don't use it for 'keypress' events thought since
// WebKit sets it to the same as charCode)
if (e.keyCode && e.type !== 'keypress') {
if (e.keyCode && (e.type !== 'keypress')) {
// 229 is used for composition events
if (e.keyCode !== 229) {
return 'Platform' + e.keyCode;
@ -128,7 +113,7 @@ Keyboard.prototype = {
// to deal with virtual keyboards which omit key info
// (iOS omits tracking info on keyup events, which forces us to
// special treat that platform here)
if (code === 'Unidentified' || browser.isIOS()) {
if ((code === 'Unidentified') || browser.isIOS()) {
if (keysym) {
// If it's a virtual keyboard then it should be
// sufficient to just send press and release right
@ -137,7 +122,7 @@ Keyboard.prototype = {
this._sendKeyEvent(keysym, code, false);
}
(0, _events.stopEvent)(e);
stopEvent(e);
return;
}
@ -147,18 +132,18 @@ Keyboard.prototype = {
// possibly others).
if (browser.isMac()) {
switch (keysym) {
case _keysym2.default.XK_Super_L:
keysym = _keysym2.default.XK_Alt_L;
break;
case _keysym2.default.XK_Super_R:
keysym = _keysym2.default.XK_Super_L;
break;
case _keysym2.default.XK_Alt_L:
keysym = _keysym2.default.XK_Mode_switch;
break;
case _keysym2.default.XK_Alt_R:
keysym = _keysym2.default.XK_ISO_Level3_Shift;
break;
case KeyTable.XK_Super_L:
keysym = KeyTable.XK_Alt_L;
break;
case KeyTable.XK_Super_R:
keysym = KeyTable.XK_Super_L;
break;
case KeyTable.XK_Alt_L:
keysym = KeyTable.XK_Mode_switch;
break;
case KeyTable.XK_Alt_R:
keysym = KeyTable.XK_ISO_Level3_Shift;
break;
}
}
@ -172,10 +157,10 @@ Keyboard.prototype = {
// state change events. That gets extra confusing for CapsLock
// which toggles on each press, but not on release. So pretend
// it was a quick press and release of the button.
if (browser.isMac() && code === 'CapsLock') {
this._sendKeyEvent(_keysym2.default.XK_Caps_Lock, 'CapsLock', true);
this._sendKeyEvent(_keysym2.default.XK_Caps_Lock, 'CapsLock', false);
(0, _events.stopEvent)(e);
if (browser.isMac() && (code === 'CapsLock')) {
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
stopEvent(e);
return;
}
@ -193,7 +178,7 @@ Keyboard.prototype = {
}
this._pendingKey = null;
(0, _events.stopEvent)(e);
stopEvent(e);
this._keyDownList[code] = keysym;
@ -202,7 +187,7 @@ Keyboard.prototype = {
// Legacy event for browsers without code/key
_handleKeyPress: function (e) {
(0, _events.stopEvent)(e);
stopEvent(e);
// Are we expecting a keypress?
if (this._pendingKey === null) {
@ -213,7 +198,7 @@ Keyboard.prototype = {
var keysym = KeyboardUtil.getKeysym(e);
// The key we were waiting for?
if (code !== 'Unidentified' && code != this._pendingKey) {
if ((code !== 'Unidentified') && (code != this._pendingKey)) {
return;
}
@ -243,14 +228,17 @@ Keyboard.prototype = {
// We have no way of knowing the proper keysym with the
// information given, but the following are true for most
// layouts
if (e.keyCode >= 0x30 && e.keyCode <= 0x39) {
if ((e.keyCode >= 0x30) && (e.keyCode <= 0x39)) {
// Digit
keysym = e.keyCode;
} else if (e.keyCode >= 0x41 && e.keyCode <= 0x5a) {
} else if ((e.keyCode >= 0x41) && (e.keyCode <= 0x5a)) {
// Character (A-Z)
var char = String.fromCharCode(e.keyCode);
// A feeble attempt at the correct case
if (e.shiftKey) char = char.toUpperCase();else char = char.toLowerCase();
if (e.shiftKey)
char = char.toUpperCase();
else
char = char.toLowerCase();
keysym = char.charCodeAt();
} else {
// Unknown, give up
@ -263,14 +251,14 @@ Keyboard.prototype = {
},
_handleKeyUp: function (e) {
(0, _events.stopEvent)(e);
stopEvent(e);
var code = this._getKeyCode(e);
// See comment in _handleKeyDown()
if (browser.isMac() && code === 'CapsLock') {
this._sendKeyEvent(_keysym2.default.XK_Caps_Lock, 'CapsLock', true);
this._sendKeyEvent(_keysym2.default.XK_Caps_Lock, 'CapsLock', false);
if (browser.isMac() && (code === 'CapsLock')) {
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
return;
}
@ -322,5 +310,5 @@ Keyboard.prototype = {
this._allKeysUp();
//Log.Debug(">> Keyboard.ungrab");
}
};
},
};