Skip to content

Commit 871777b

Browse files
author
Kelven Yang
committed
bug 12976: The new keyboard framework sends only raw keyboard events, it turned out that it does not work with Xen/KVM hypervisors(only VMware supports standard raw keyboard events), Xen/KVM accept only cooked keyboard events, to maintain cross hypervisor compability, US english keyboard will be handled in the new JsCookedKeyboardMapper class
1 parent c3e0f06 commit 871777b

1 file changed

Lines changed: 100 additions & 1 deletion

File tree

‎console-proxy/js/ajaxviewer.js‎

Lines changed: 100 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,103 @@ JsX11KeyboardMapper.prototype.inputFeed = function(eventType, code, modifiers) {
232232
}
233233
}
234234

235+
/////////////////////////////////////////////////////////////////////////////
236+
//JsCookedKeyboardMapper
237+
// For Xen/KVM hypervisors, it accepts "cooked" keyborad events
238+
//
239+
function JsCookedKeyboardMapper() {
240+
KeyboardMapper.apply(this, arguments);
241+
242+
this.jsX11KeysymMap = [];
243+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_CAPSLOCK] = AjaxViewer.X11_KEY_CAPSLOCK;
244+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_BACKSPACE] = AjaxViewer.X11_KEY_BACKSPACE;
245+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_TAB] = AjaxViewer.X11_KEY_TAB;
246+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_ENTER] = AjaxViewer.X11_KEY_ENTER;
247+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_ESCAPE] = AjaxViewer.X11_KEY_ESCAPE;
248+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_INSERT] = AjaxViewer.X11_KEY_INSERT;
249+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_DELETE] = AjaxViewer.X11_KEY_DELETE;
250+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_HOME] = AjaxViewer.X11_KEY_HOME;
251+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_END] = AjaxViewer.X11_KEY_END;
252+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_PAGEUP] = AjaxViewer.X11_KEY_PAGEUP;
253+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_PAGEDOWN] = AjaxViewer.X11_KEY_PAGEDOWN;
254+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_LEFT] = AjaxViewer.X11_KEY_LEFT;
255+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_UP] = AjaxViewer.X11_KEY_UP;
256+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_RIGHT] = AjaxViewer.X11_KEY_RIGHT;
257+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_DOWN] = AjaxViewer.X11_KEY_DOWN;
258+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F1] = AjaxViewer.X11_KEY_F1;
259+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F2] = AjaxViewer.X11_KEY_F2;
260+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F3] = AjaxViewer.X11_KEY_F3;
261+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F4] = AjaxViewer.X11_KEY_F4;
262+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F5] = AjaxViewer.X11_KEY_F5;
263+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F6] = AjaxViewer.X11_KEY_F6;
264+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F7] = AjaxViewer.X11_KEY_F7;
265+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F8] = AjaxViewer.X11_KEY_F8;
266+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F9] = AjaxViewer.X11_KEY_F9;
267+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F10] = AjaxViewer.X11_KEY_F10;
268+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F11] = AjaxViewer.X11_KEY_F11;
269+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_F12] = AjaxViewer.X11_KEY_F12;
270+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_SHIFT] = AjaxViewer.X11_KEY_SHIFT;
271+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_CTRL] = AjaxViewer.X11_KEY_CTRL;
272+
this.jsX11KeysymMap[AjaxViewer.JS_KEY_ALT] = AjaxViewer.X11_KEY_ALT;
273+
}
274+
275+
JsCookedKeyboardMapper.prototype = new KeyboardMapper();
276+
JsCookedKeyboardMapper.prototype.inputFeed = function(eventType, code, modifiers) {
277+
if(eventType == AjaxViewer.KEY_DOWN || eventType == AjaxViewer.KEY_UP) {
278+
279+
// special handling for Alt + Ctrl + Ins, convert it into Alt-Ctrl-Del
280+
if(code == AjaxViewer.JS_KEY_INSERT) {
281+
if((modifiers & AjaxViewer.ALT_KEY_MASK) != 0 && (modifiers & AjaxViewer.CTRL_KEY_MASK) != 0) {
282+
this.mappedInput.push({type : eventType, code: 0xffff, modifiers: modifiers});
283+
return;
284+
}
285+
}
286+
287+
var X11Keysym = code;
288+
if(this.jsX11KeysymMap[code] != undefined) {
289+
X11Keysym = this.jsX11KeysymMap[code];
290+
if(typeof this.jsX11KeysymMap[code] == "boolean") {
291+
return;
292+
} else if($.isArray(X11Keysym)) {
293+
for(var i = 0; i < X11Keysym.length; i++) {
294+
if(X11Keysym[i].type == eventType) {
295+
this.mappedInput.push(X11Keysym[i]);
296+
}
297+
}
298+
} else {
299+
this.mappedInput.push({type : eventType, code: X11Keysym, modifiers: modifiers});
300+
}
301+
}
302+
303+
// special handling for ALT/CTRL key
304+
if(eventType == AjaxViewer.KEY_UP && (code == AjaxViewer.JS_KEY_ALT || code == code == AjaxViewer.JS_KEY_CTRL))
305+
this.mappedInput.push({type : eventType, code: this.jsX11KeysymMap[code], modifiers: modifiers});
306+
307+
} else if(eventType == AjaxViewer.KEY_PRESS) {
308+
var X11Keysym = code;
309+
310+
// special handling for * and + key on number pad
311+
if(code == AjaxViewer.JS_NUMPAD_MULTIPLY) {
312+
this.mappedInput.push({type : AjaxViewer.KEY_DOWN, code: AjaxViewer.X11_KEY_SHIFT, modifiers: modifiers});
313+
this.mappedInput.push({type : AjaxViewer.KEY_DOWN, code: 42, modifiers: modifiers});
314+
this.mappedInput.push({type : AjaxViewer.KEY_UP, code: 42, modifiers: modifiers});
315+
this.mappedInput.push({type : AjaxViewer.KEY_UP, code: AjaxViewer.X11_KEY_SHIFT, modifiers: modifiers});
316+
return;
317+
}
318+
319+
if(code == AjaxViewer.JS_NUMPAD_PLUS) {
320+
this.mappedInput.push({type : AjaxViewer.KEY_DOWN, code: AjaxViewer.X11_KEY_SHIFT, modifiers: modifiers});
321+
this.mappedInput.push({type : AjaxViewer.KEY_DOWN, code: 43, modifiers: modifiers});
322+
this.mappedInput.push({type : AjaxViewer.KEY_UP, code: 43, modifiers: modifiers});
323+
this.mappedInput.push({type : AjaxViewer.KEY_UP, code: AjaxViewer.X11_KEY_SHIFT, modifiers: modifiers});
324+
return;
325+
}
326+
327+
this.mappedInput.push({type : AjaxViewer.KEY_DOWN, code: X11Keysym, modifiers: modifiers});
328+
this.mappedInput.push({type : AjaxViewer.KEY_UP, code: X11Keysym, modifiers: modifiers});
329+
}
330+
}
331+
235332
/////////////////////////////////////////////////////////////////////////////
236333
// class AjaxViewer
237334
//
@@ -373,6 +470,7 @@ AjaxViewer.JS_KEY_BACK_SLASH = 220; // \
373470
AjaxViewer.JS_KEY_CLOSE_BRACKET = 221; // ]
374471
AjaxViewer.JS_KEY_SINGLE_QUOTE = 222; // '
375472
AjaxViewer.JS_NUMPAD_PLUS = 43;
473+
AjaxViewer.JS_NUMPAD_MULTIPLY = 42;
376474
AjaxViewer.JS_KEY_NUM8 = 56;
377475

378476
// keycode from Japanese keyboard
@@ -561,7 +659,8 @@ AjaxViewer.prototype = {
561659

562660
setupKeyboardTranslationTable : function() {
563661
this.keyboardMappers = [];
564-
this.keyboardMappers[AjaxViewer.KEYBOARD_TYPE_ENGLISH] = new JsX11KeyboardMapper();
662+
// this.keyboardMappers[AjaxViewer.KEYBOARD_TYPE_ENGLISH] = new JsX11KeyboardMapper();
663+
this.keyboardMappers[AjaxViewer.KEYBOARD_TYPE_ENGLISH] = new JsCookedKeyboardMapper();
565664

566665
// setup Japanese keyboard translation table
567666
var mapper = new JsX11KeyboardMapper();

0 commit comments

Comments
 (0)