Merge branch 'qemu_ledstate_pseudo_encoding' of https://github.com/otthou/noVNC
This commit is contained in:
@@ -22,6 +22,7 @@ export const encodings = {
|
||||
pseudoEncodingLastRect: -224,
|
||||
pseudoEncodingCursor: -239,
|
||||
pseudoEncodingQEMUExtendedKeyEvent: -258,
|
||||
pseudoEncodingQEMULedEvent: -261,
|
||||
pseudoEncodingDesktopName: -307,
|
||||
pseudoEncodingExtendedDesktopSize: -308,
|
||||
pseudoEncodingXvp: -309,
|
||||
|
||||
@@ -36,7 +36,7 @@ export default class Keyboard {
|
||||
|
||||
// ===== PRIVATE METHODS =====
|
||||
|
||||
_sendKeyEvent(keysym, code, down) {
|
||||
_sendKeyEvent(keysym, code, down, numlock = null, capslock = null) {
|
||||
if (down) {
|
||||
this._keyDownList[code] = keysym;
|
||||
} else {
|
||||
@@ -48,8 +48,8 @@ export default class Keyboard {
|
||||
}
|
||||
|
||||
Log.Debug("onkeyevent " + (down ? "down" : "up") +
|
||||
", keysym: " + keysym, ", code: " + code);
|
||||
this.onkeyevent(keysym, code, down);
|
||||
", keysym: " + keysym, ", code: " + code, + ", numlock: " + numlock + ", capslock: " + capslock);
|
||||
this.onkeyevent(keysym, code, down, numlock, capslock);
|
||||
}
|
||||
|
||||
_getKeyCode(e) {
|
||||
@@ -86,6 +86,14 @@ export default class Keyboard {
|
||||
_handleKeyDown(e) {
|
||||
const code = this._getKeyCode(e);
|
||||
let keysym = KeyboardUtil.getKeysym(e);
|
||||
let numlock = e.getModifierState('NumLock');
|
||||
let capslock = e.getModifierState('CapsLock');
|
||||
|
||||
// getModifierState for NumLock is not supported on mac and ios and always returns false.
|
||||
// Set to null to indicate unknown/unsupported instead.
|
||||
if (browser.isMac() || browser.isIOS()) {
|
||||
numlock = null;
|
||||
}
|
||||
|
||||
// Windows doesn't have a proper AltGr, but handles it using
|
||||
// fake Ctrl+Alt. However the remote end might not be Windows,
|
||||
@@ -107,7 +115,7 @@ export default class Keyboard {
|
||||
// key to "AltGraph".
|
||||
keysym = KeyTable.XK_ISO_Level3_Shift;
|
||||
} else {
|
||||
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true);
|
||||
this._sendKeyEvent(KeyTable.XK_Control_L, "ControlLeft", true, numlock, capslock);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,8 +126,8 @@ export default class Keyboard {
|
||||
// If it's a virtual keyboard then it should be
|
||||
// sufficient to just send press and release right
|
||||
// after each other
|
||||
this._sendKeyEvent(keysym, code, true);
|
||||
this._sendKeyEvent(keysym, code, false);
|
||||
this._sendKeyEvent(keysym, code, true, numlock, capslock);
|
||||
this._sendKeyEvent(keysym, code, false, numlock, capslock);
|
||||
}
|
||||
|
||||
stopEvent(e);
|
||||
@@ -157,8 +165,8 @@ export default class Keyboard {
|
||||
// while meta is held down
|
||||
if ((browser.isMac() || browser.isIOS()) &&
|
||||
(e.metaKey && code !== 'MetaLeft' && code !== 'MetaRight')) {
|
||||
this._sendKeyEvent(keysym, code, true);
|
||||
this._sendKeyEvent(keysym, code, false);
|
||||
this._sendKeyEvent(keysym, code, true, numlock, capslock);
|
||||
this._sendKeyEvent(keysym, code, false, numlock, capslock);
|
||||
stopEvent(e);
|
||||
return;
|
||||
}
|
||||
@@ -168,8 +176,8 @@ export default class Keyboard {
|
||||
// which toggles on each press, but not on release. So pretend
|
||||
// it was a quick press and release of the button.
|
||||
if ((browser.isMac() || browser.isIOS()) && (code === 'CapsLock')) {
|
||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', true, numlock, capslock);
|
||||
this._sendKeyEvent(KeyTable.XK_Caps_Lock, 'CapsLock', false, numlock, capslock);
|
||||
stopEvent(e);
|
||||
return;
|
||||
}
|
||||
@@ -182,8 +190,8 @@ export default class Keyboard {
|
||||
KeyTable.XK_Hiragana,
|
||||
KeyTable.XK_Romaji ];
|
||||
if (browser.isWindows() && jpBadKeys.includes(keysym)) {
|
||||
this._sendKeyEvent(keysym, code, true);
|
||||
this._sendKeyEvent(keysym, code, false);
|
||||
this._sendKeyEvent(keysym, code, true, numlock, capslock);
|
||||
this._sendKeyEvent(keysym, code, false, numlock, capslock);
|
||||
stopEvent(e);
|
||||
return;
|
||||
}
|
||||
@@ -199,7 +207,7 @@ export default class Keyboard {
|
||||
return;
|
||||
}
|
||||
|
||||
this._sendKeyEvent(keysym, code, true);
|
||||
this._sendKeyEvent(keysym, code, true, numlock, capslock);
|
||||
}
|
||||
|
||||
_handleKeyUp(e) {
|
||||
|
||||
51
core/rfb.js
51
core/rfb.js
@@ -260,6 +260,8 @@ export default class RFB extends EventTargetMixin {
|
||||
|
||||
this._keyboard = new Keyboard(this._canvas);
|
||||
this._keyboard.onkeyevent = this._handleKeyEvent.bind(this);
|
||||
this._remoteCapsLock = null; // Null indicates unknown or irrelevant
|
||||
this._remoteNumLock = null;
|
||||
|
||||
this._gestures = new GestureHandler();
|
||||
|
||||
@@ -993,7 +995,35 @@ export default class RFB extends EventTargetMixin {
|
||||
}
|
||||
}
|
||||
|
||||
_handleKeyEvent(keysym, code, down) {
|
||||
_handleKeyEvent(keysym, code, down, numlock, capslock) {
|
||||
// If remote state of capslock is known, and it doesn't match the local led state of
|
||||
// the keyboard, we send a capslock keypress first to bring it into sync.
|
||||
// If we just pressed CapsLock, or we toggled it remotely due to it being out of sync
|
||||
// we clear the remote state so that we don't send duplicate or spurious fixes,
|
||||
// since it may take some time to receive the new remote CapsLock state.
|
||||
if (code == 'CapsLock' && down) {
|
||||
this._remoteCapsLock = null;
|
||||
}
|
||||
if (this._remoteCapsLock !== null && capslock !== null && this._remoteCapsLock !== capslock && down) {
|
||||
Log.Debug("Fixing remote caps lock");
|
||||
|
||||
this.sendKey(KeyTable.XK_Caps_Lock, 'CapsLock', true);
|
||||
this.sendKey(KeyTable.XK_Caps_Lock, 'CapsLock', false);
|
||||
// We clear the remote capsLock state when we do this to prevent issues with doing this twice
|
||||
// before we receive an update of the the remote state.
|
||||
this._remoteCapsLock = null;
|
||||
}
|
||||
|
||||
// Logic for numlock is exactly the same.
|
||||
if (code == 'NumLock' && down) {
|
||||
this._remoteNumLock = null;
|
||||
}
|
||||
if (this._remoteNumLock !== null && numlock !== null && this._remoteNumLock !== numlock && down) {
|
||||
Log.Debug("Fixing remote num lock");
|
||||
this.sendKey(KeyTable.XK_Num_Lock, 'NumLock', true);
|
||||
this.sendKey(KeyTable.XK_Num_Lock, 'NumLock', false);
|
||||
this._remoteNumLock = null;
|
||||
}
|
||||
this.sendKey(keysym, code, down);
|
||||
}
|
||||
|
||||
@@ -2101,6 +2131,7 @@ export default class RFB extends EventTargetMixin {
|
||||
encs.push(encodings.pseudoEncodingDesktopSize);
|
||||
encs.push(encodings.pseudoEncodingLastRect);
|
||||
encs.push(encodings.pseudoEncodingQEMUExtendedKeyEvent);
|
||||
encs.push(encodings.pseudoEncodingQEMULedEvent);
|
||||
encs.push(encodings.pseudoEncodingExtendedDesktopSize);
|
||||
encs.push(encodings.pseudoEncodingXvp);
|
||||
encs.push(encodings.pseudoEncodingFence);
|
||||
@@ -2536,6 +2567,9 @@ export default class RFB extends EventTargetMixin {
|
||||
case encodings.pseudoEncodingExtendedDesktopSize:
|
||||
return this._handleExtendedDesktopSize();
|
||||
|
||||
case encodings.pseudoEncodingQEMULedEvent:
|
||||
return this._handleLedEvent();
|
||||
|
||||
default:
|
||||
return this._handleDataRect();
|
||||
}
|
||||
@@ -2713,6 +2747,21 @@ export default class RFB extends EventTargetMixin {
|
||||
return true;
|
||||
}
|
||||
|
||||
_handleLedEvent() {
|
||||
if (this._sock.rQwait("LED Status", 1)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let data = this._sock.rQshift8();
|
||||
// ScrollLock state can be retrieved with data & 1. This is currently not needed.
|
||||
let numLock = data & 2 ? true : false;
|
||||
let capsLock = data & 4 ? true : false;
|
||||
this._remoteCapsLock = capsLock;
|
||||
this._remoteNumLock = numLock;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_handleExtendedDesktopSize() {
|
||||
if (this._sock.rQwait("ExtendedDesktopSize", 4)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user