Skip to content

Commit

Permalink
#1484: if we know that the character typed requires a specific keyboa…
Browse files Browse the repository at this point in the history
…rd layout, request the server to switch to it

git-svn-id: https://xpra.org/svn/Xpra/trunk@15511 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 4, 2017
1 parent 6d7fab8 commit fd21624
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
40 changes: 29 additions & 11 deletions src/html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ XpraClient.prototype.init_state = function(container) {
// detect locale change:
this.browser_language = Utilities.getFirstBrowserLanguage();
this.browser_language_change_embargo_time = 0;
this.key_layout = null;
// clipboard
this.clipboard_buffer = "";
this.clipboard_pending = false;
Expand Down Expand Up @@ -486,22 +487,33 @@ XpraClient.prototype._keyb_get_modifiers = function(event) {
return modifiers;
}

XpraClient.prototype._check_browser_language = function() {
XpraClient.prototype._check_browser_language = function(key_layout) {
/**
* If the browser's language changes,
* send the new detected keyboard layout.
* Use the "key_language" if we have it,
* otherwise use the browser's language.
* This function may ssend the new detected keyboard layout.
* (ignoring the keyboard_layout preference)
*/
var now = new Date().getTime();
if (now<this.browser_language_change_embargo_time) {
return;
}
var l = Utilities.getFirstBrowserLanguage();
if (l && this.browser_language != l) {
var layout = Utilities.getKeyboardLayout();
console.log("browser language changed from", this.browser_language, "to", l, ", sending new keyboard layout:", layout);
this.browser_language = l;
this.send(["layout-changed", layout, ""]);
var new_layout = null;
if (key_layout && this.key_layout!=key_layout) {
console.log("input language changed from", this.key_layout, "to", key_layout);
new_layout = key_layout;
this.key_layout = key_layout;
}
else {
var l = Utilities.getFirstBrowserLanguage();
if (l && this.browser_language != l) {
new_layout = Utilities.getKeyboardLayout();
console.log("browser language changed from", this.browser_language, "to", l, ", sending new keyboard layout:", layout);
this.browser_language = l;
}
}
if (new_layout!=null) {
this.send(["layout-changed", new_layout, ""]);
//changing the language too quickly can cause problems server side,
//wait at least 2 seconds before checking again:
this.browser_language_change_embargo_time = now + 2000;
Expand All @@ -523,8 +535,6 @@ XpraClient.prototype._keyb_process = function(pressed, event) {
if (window.event)
event = window.event;

this._check_browser_language();

var keyname = event.code || "";
var keycode = event.which || event.keyCode;
var str = event.key || String.fromCharCode(keycode);
Expand All @@ -538,19 +548,27 @@ XpraClient.prototype._keyb_process = function(pressed, event) {
this.num_lock = !this.num_lock;
}

var key_language = null;
//some special keys are better mapped by name:
if (keyname in KEY_TO_NAME){
keyname = KEY_TO_NAME[keyname];
}
//next try mapping the actual character
else if (str in CHAR_TO_NAME) {
keyname = CHAR_TO_NAME[str];
if (keyname.indexOf("_")>0) {
//ie: Thai_dochada
var lang = keyname.split("_")[0];
key_language = KEYSYM_TO_LAYOUT[lang];
}
}
//fallback to keycode map:
else if (keycode in CHARCODE_TO_NAME) {
keyname = CHARCODE_TO_NAME[keycode];
}

this._check_browser_language(key_language);

//if (this.num_lock && keycode>=96 && keycode<106)
// keyname = "KP_"+(keycode-96);
var DOM_KEY_LOCATION_RIGHT = 2;
Expand Down
16 changes: 16 additions & 0 deletions src/html5/js/Keycodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,22 @@ for (var keysym in KEYSYM_TO_UNICODE) {
//console.debug("CHAR_TO_NAME=", KEYSYM_TO_UNICODE);


//some keysyms require specific layouts
KEYSYM_TO_LAYOUT = {
"kana" : "jp",
"Farsi" : "ir",
"Arabic" : "ar",
"Cyrillic" : "ru",
"Ukrainian" : "uk",
"Macedonia" : "mk",
"Greek" : "gr",
"hebrew" : "he",
"Thai" : "th",
"Armenian" : "am",
"Georgian" : "ge",
"braille" : "brai",
}


/**
* Maps web keycodes to the corresponding X11 keysym:
Expand Down

0 comments on commit fd21624

Please sign in to comment.