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

Update spice-html5

This commit is contained in:
catborise 2020-01-23 15:49:43 +03:00
parent 34394c2b5e
commit 562fe5c3dc
36 changed files with 59278 additions and 1325 deletions

View file

@ -18,6 +18,8 @@
along with spice-html5. If not, see <http://www.gnu.org/licenses/>.
*/
import { KeyNames } from './atKeynames.js';
/*----------------------------------------------------------------------------
** Utility settings and functions for Spice
**--------------------------------------------------------------------------*/
@ -112,129 +114,142 @@ function arraybuffer_to_str(buf) {
}
/*----------------------------------------------------------------------------
** Converting keycodes to AT scancodes is very hard.
** luckly there are some resources on the web and in the Xorg driver that help
** us figure out what browser dependent keycodes match to what scancodes.
**
** This will most likely not work for non US keyboard and browsers other than
** modern Chrome and FireFox.
** Converting browser keycodes to AT scancodes is very hard.
** Spice transmits keys using the original AT scan codes, often
** described as 'Scan Code Set 1'.
** There is a confusion of other scan codes; Xorg synthesizes it's
** own in the same atKeynames.c file that has the XT codes.
** Scan code set 2 and 3 are more common, and use different values.
** Further, there is no formal specification for keycodes
** returned by browsers, so we have done our mapping largely with
** empirical testing.
** There has been little rigorous testing with International keyboards,
** and this would be an easy area for non English speakers to contribute.
**--------------------------------------------------------------------------*/
var common_scanmap = [];
common_scanmap['Q'.charCodeAt(0)] = KEY_Q;
common_scanmap['W'.charCodeAt(0)] = KEY_W;
common_scanmap['E'.charCodeAt(0)] = KEY_E;
common_scanmap['R'.charCodeAt(0)] = KEY_R;
common_scanmap['T'.charCodeAt(0)] = KEY_T;
common_scanmap['Y'.charCodeAt(0)] = KEY_Y;
common_scanmap['U'.charCodeAt(0)] = KEY_U;
common_scanmap['I'.charCodeAt(0)] = KEY_I;
common_scanmap['O'.charCodeAt(0)] = KEY_O;
common_scanmap['P'.charCodeAt(0)] = KEY_P;
common_scanmap['A'.charCodeAt(0)] = KEY_A;
common_scanmap['S'.charCodeAt(0)] = KEY_S;
common_scanmap['D'.charCodeAt(0)] = KEY_D;
common_scanmap['F'.charCodeAt(0)] = KEY_F;
common_scanmap['G'.charCodeAt(0)] = KEY_G;
common_scanmap['H'.charCodeAt(0)] = KEY_H;
common_scanmap['J'.charCodeAt(0)] = KEY_J;
common_scanmap['K'.charCodeAt(0)] = KEY_K;
common_scanmap['L'.charCodeAt(0)] = KEY_L;
common_scanmap['Z'.charCodeAt(0)] = KEY_Z;
common_scanmap['X'.charCodeAt(0)] = KEY_X;
common_scanmap['C'.charCodeAt(0)] = KEY_C;
common_scanmap['V'.charCodeAt(0)] = KEY_V;
common_scanmap['B'.charCodeAt(0)] = KEY_B;
common_scanmap['N'.charCodeAt(0)] = KEY_N;
common_scanmap['M'.charCodeAt(0)] = KEY_M;
common_scanmap[' '.charCodeAt(0)] = KEY_Space;
common_scanmap[13] = KEY_Enter;
common_scanmap[27] = KEY_Escape;
common_scanmap[8] = KEY_BackSpace;
common_scanmap[9] = KEY_Tab;
common_scanmap[16] = KEY_ShiftL;
common_scanmap[17] = KEY_LCtrl;
common_scanmap[18] = KEY_Alt;
common_scanmap[20] = KEY_CapsLock;
common_scanmap[144] = KEY_NumLock;
common_scanmap[112] = KEY_F1;
common_scanmap[113] = KEY_F2;
common_scanmap[114] = KEY_F3;
common_scanmap[115] = KEY_F4;
common_scanmap[116] = KEY_F5;
common_scanmap[117] = KEY_F6;
common_scanmap[118] = KEY_F7;
common_scanmap[119] = KEY_F8;
common_scanmap[120] = KEY_F9;
common_scanmap[121] = KEY_F10;
common_scanmap[122] = KEY_F11;
common_scanmap[123] = KEY_F12;
/* These extended scancodes do not line up with values from atKeynames */
common_scanmap[42] = 99;
common_scanmap[19] = 101; // Break
common_scanmap[111] = 0xE035; // KP_Divide
common_scanmap[106] = 0xE037; // KP_Multiply
common_scanmap[36] = 0xE047; // Home
common_scanmap[38] = 0xE048; // Up
common_scanmap[33] = 0xE049; // PgUp
common_scanmap[37] = 0xE04B; // Left
common_scanmap[39] = 0xE04D; // Right
common_scanmap[35] = 0xE04F; // End
common_scanmap[40] = 0xE050; // Down
common_scanmap[34] = 0xE051; // PgDown
common_scanmap[45] = 0xE052; // Insert
common_scanmap[46] = 0xE053; // Delete
common_scanmap[44] = 0x2A37; // Print
/* The following appear to be keycodes that work in most browsers */
common_scanmap['1'.charCodeAt(0)] = KeyNames.KEY_1;
common_scanmap['2'.charCodeAt(0)] = KeyNames.KEY_2;
common_scanmap['3'.charCodeAt(0)] = KeyNames.KEY_3;
common_scanmap['4'.charCodeAt(0)] = KeyNames.KEY_4;
common_scanmap['5'.charCodeAt(0)] = KeyNames.KEY_5;
common_scanmap['6'.charCodeAt(0)] = KeyNames.KEY_6;
common_scanmap['7'.charCodeAt(0)] = KeyNames.KEY_7;
common_scanmap['8'.charCodeAt(0)] = KeyNames.KEY_8;
common_scanmap['9'.charCodeAt(0)] = KeyNames.KEY_9;
common_scanmap['0'.charCodeAt(0)] = KeyNames.KEY_0;
common_scanmap[145] = KeyNames.KEY_ScrollLock;
common_scanmap[103] = KeyNames.KEY_KP_7;
common_scanmap[104] = KeyNames.KEY_KP_8;
common_scanmap[105] = KeyNames.KEY_KP_9;
common_scanmap[100] = KeyNames.KEY_KP_4;
common_scanmap[101] = KeyNames.KEY_KP_5;
common_scanmap[102] = KeyNames.KEY_KP_6;
common_scanmap[107] = KeyNames.KEY_KP_Plus;
common_scanmap[97] = KeyNames.KEY_KP_1;
common_scanmap[98] = KeyNames.KEY_KP_2;
common_scanmap[99] = KeyNames.KEY_KP_3;
common_scanmap[96] = KeyNames.KEY_KP_0;
common_scanmap[109] = KeyNames.KEY_Minus;
common_scanmap[110] = KeyNames.KEY_KP_Decimal;
common_scanmap[191] = KeyNames.KEY_Slash;
common_scanmap[190] = KeyNames.KEY_Period;
common_scanmap[188] = KeyNames.KEY_Comma;
common_scanmap[220] = KeyNames.KEY_BSlash;
common_scanmap[192] = KeyNames.KEY_Tilde;
common_scanmap[222] = KeyNames.KEY_Quote;
common_scanmap[219] = KeyNames.KEY_LBrace;
common_scanmap[221] = KeyNames.KEY_RBrace;
/* These are not common between ALL browsers but are between Firefox and DOM3 */
common_scanmap['1'.charCodeAt(0)] = KEY_1;
common_scanmap['2'.charCodeAt(0)] = KEY_2;
common_scanmap['3'.charCodeAt(0)] = KEY_3;
common_scanmap['4'.charCodeAt(0)] = KEY_4;
common_scanmap['5'.charCodeAt(0)] = KEY_5;
common_scanmap['6'.charCodeAt(0)] = KEY_6;
common_scanmap['7'.charCodeAt(0)] = KEY_7;
common_scanmap['8'.charCodeAt(0)] = KEY_8;
common_scanmap['9'.charCodeAt(0)] = KEY_9;
common_scanmap['0'.charCodeAt(0)] = KEY_0;
common_scanmap[145] = KEY_ScrollLock;
common_scanmap[103] = KEY_KP_7;
common_scanmap[104] = KEY_KP_8;
common_scanmap[105] = KEY_KP_9;
common_scanmap[100] = KEY_KP_4;
common_scanmap[101] = KEY_KP_5;
common_scanmap[102] = KEY_KP_6;
common_scanmap[107] = KEY_KP_Plus;
common_scanmap[97] = KEY_KP_1;
common_scanmap[98] = KEY_KP_2;
common_scanmap[99] = KEY_KP_3;
common_scanmap[96] = KEY_KP_0;
common_scanmap[110] = KEY_KP_Decimal;
common_scanmap[191] = KEY_Slash;
common_scanmap[190] = KEY_Period;
common_scanmap[188] = KEY_Comma;
common_scanmap[220] = KEY_BSlash;
common_scanmap[192] = KEY_Tilde;
common_scanmap[222] = KEY_Quote;
common_scanmap[219] = KEY_LBrace;
common_scanmap[221] = KEY_RBrace;
common_scanmap['Q'.charCodeAt(0)] = KeyNames.KEY_Q;
common_scanmap['W'.charCodeAt(0)] = KeyNames.KEY_W;
common_scanmap['E'.charCodeAt(0)] = KeyNames.KEY_E;
common_scanmap['R'.charCodeAt(0)] = KeyNames.KEY_R;
common_scanmap['T'.charCodeAt(0)] = KeyNames.KEY_T;
common_scanmap['Y'.charCodeAt(0)] = KeyNames.KEY_Y;
common_scanmap['U'.charCodeAt(0)] = KeyNames.KEY_U;
common_scanmap['I'.charCodeAt(0)] = KeyNames.KEY_I;
common_scanmap['O'.charCodeAt(0)] = KeyNames.KEY_O;
common_scanmap['P'.charCodeAt(0)] = KeyNames.KEY_P;
common_scanmap['A'.charCodeAt(0)] = KeyNames.KEY_A;
common_scanmap['S'.charCodeAt(0)] = KeyNames.KEY_S;
common_scanmap['D'.charCodeAt(0)] = KeyNames.KEY_D;
common_scanmap['F'.charCodeAt(0)] = KeyNames.KEY_F;
common_scanmap['G'.charCodeAt(0)] = KeyNames.KEY_G;
common_scanmap['H'.charCodeAt(0)] = KeyNames.KEY_H;
common_scanmap['J'.charCodeAt(0)] = KeyNames.KEY_J;
common_scanmap['K'.charCodeAt(0)] = KeyNames.KEY_K;
common_scanmap['L'.charCodeAt(0)] = KeyNames.KEY_L;
common_scanmap['Z'.charCodeAt(0)] = KeyNames.KEY_Z;
common_scanmap['X'.charCodeAt(0)] = KeyNames.KEY_X;
common_scanmap['C'.charCodeAt(0)] = KeyNames.KEY_C;
common_scanmap['V'.charCodeAt(0)] = KeyNames.KEY_V;
common_scanmap['B'.charCodeAt(0)] = KeyNames.KEY_B;
common_scanmap['N'.charCodeAt(0)] = KeyNames.KEY_N;
common_scanmap['M'.charCodeAt(0)] = KeyNames.KEY_M;
common_scanmap[' '.charCodeAt(0)] = KeyNames.KEY_Space;
common_scanmap[13] = KeyNames.KEY_Enter;
common_scanmap[27] = KeyNames.KEY_Escape;
common_scanmap[8] = KeyNames.KEY_BackSpace;
common_scanmap[9] = KeyNames.KEY_Tab;
common_scanmap[16] = KeyNames.KEY_ShiftL;
common_scanmap[17] = KeyNames.KEY_LCtrl;
common_scanmap[18] = KeyNames.KEY_Alt;
common_scanmap[20] = KeyNames.KEY_CapsLock;
common_scanmap[44] = KeyNames.KEY_SysReqest;
common_scanmap[144] = KeyNames.KEY_NumLock;
common_scanmap[112] = KeyNames.KEY_F1;
common_scanmap[113] = KeyNames.KEY_F2;
common_scanmap[114] = KeyNames.KEY_F3;
common_scanmap[115] = KeyNames.KEY_F4;
common_scanmap[116] = KeyNames.KEY_F5;
common_scanmap[117] = KeyNames.KEY_F6;
common_scanmap[118] = KeyNames.KEY_F7;
common_scanmap[119] = KeyNames.KEY_F8;
common_scanmap[120] = KeyNames.KEY_F9;
common_scanmap[121] = KeyNames.KEY_F10;
common_scanmap[122] = KeyNames.KEY_F11;
common_scanmap[123] = KeyNames.KEY_F12;
common_scanmap[91] = 0xE05B; //KEY_LMeta
common_scanmap[92] = 0xE05C; //KEY_RMeta
common_scanmap[93] = 0xE05D; //KEY_Menu
/* TODO: Break and Print are complex scan codes. XSpice cheats and
uses Xorg synthesized codes to simplify them. Fixing this will
require XSpice to handle the scan codes correctly, and then
fix spice-html5 to send the complex scan codes. */
common_scanmap[42] = 99; // Print, XSpice only
common_scanmap[19] = 101;// Break, XSpice only
/* Handle the so called 'GREY' keys, for the extended keys that
were grey on the original AT keyboard. These are
prefixed, as they were on the PS/2 controller, with an
0xE0 byte to indicate that they are extended */
common_scanmap[111] = 0xE0 | (KeyNames.KEY_Slash << 8);// KP_Divide
common_scanmap[106] = 0xE0 | (KeyNames.KEY_KP_Multiply << 8); // KP_Multiply
common_scanmap[36] = 0xE0 | (KeyNames.KEY_KP_7 << 8); // Home
common_scanmap[38] = 0xE0 | (KeyNames.KEY_KP_8 << 8); // Up
common_scanmap[33] = 0xE0 | (KeyNames.KEY_KP_9 << 8); // PgUp
common_scanmap[37] = 0xE0 | (KeyNames.KEY_KP_4 << 8); // Left
common_scanmap[39] = 0xE0 | (KeyNames.KEY_KP_6 << 8); // Right
common_scanmap[35] = 0xE0 | (KeyNames.KEY_KP_1 << 8); // End
common_scanmap[40] = 0xE0 | (KeyNames.KEY_KP_2 << 8); // Down
common_scanmap[34] = 0xE0 | (KeyNames.KEY_KP_3 << 8); // PgDown
common_scanmap[45] = 0xE0 | (KeyNames.KEY_KP_0 << 8); // Insert
common_scanmap[46] = 0xE0 | (KeyNames.KEY_KP_Decimal << 8); // Delete
common_scanmap[91] = 0xE0 | (0x5B << 8); //KeyNames.KEY_LMeta
common_scanmap[92] = 0xE0 | (0x5C << 8); //KeyNames.KEY_RMeta
common_scanmap[93] = 0xE0 | (0x5D << 8); //KeyNames.KEY_Menu
/* Firefox/Mozilla codes */
var firefox_scanmap = [];
firefox_scanmap[173] = KEY_Minus;
firefox_scanmap[109] = KEY_Minus;
firefox_scanmap[61] = KEY_Equal;
firefox_scanmap[59] = KEY_SemiColon;
firefox_scanmap[173] = KeyNames.KEY_Minus;
firefox_scanmap[61] = KeyNames.KEY_Equal;
firefox_scanmap[59] = KeyNames.KEY_SemiColon;
/* DOM3 codes */
var DOM_scanmap = [];
DOM_scanmap[189] = KEY_Minus;
DOM_scanmap[187] = KEY_Equal;
DOM_scanmap[186] = KEY_SemiColon;
DOM_scanmap[189] = KeyNames.KEY_Minus;
DOM_scanmap[187] = KeyNames.KEY_Equal;
DOM_scanmap[186] = KeyNames.KEY_SemiColon;
function get_scancode(code)
{
@ -258,11 +273,7 @@ function keycode_to_start_scan(code)
return 0;
}
if (scancode < 0x100) {
return scancode;
} else {
return 0xe0 | ((scancode - 0x100) << 8);
}
return scancode;
}
function keycode_to_end_scan(code)
@ -274,7 +285,7 @@ function keycode_to_end_scan(code)
if (scancode < 0x100) {
return scancode | 0x80;
} else {
return 0x80e0 | ((scancode - 0x100) << 8);
return scancode | 0x8000;
}
}
@ -330,3 +341,20 @@ function dump_timerange(tr)
return ret;
}
export {
DEBUG,
PLAYBACK_DEBUG,
STREAM_DEBUG,
DUMP_DRAWS,
DUMP_CANVASES,
EMPTY_GIF_IMAGE,
combine_array_buffers,
hexdump_buffer,
arraybuffer_to_str,
keycode_to_start_scan,
keycode_to_end_scan,
dump_media_element,
dump_media_source,
dump_source_buffer,
};