Skip to content

Commit

Permalink
#142 move keyboard layout query to client
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed May 10, 2022
1 parent eda838d commit 690085e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
25 changes: 1 addition & 24 deletions html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1382,32 +1382,9 @@ <h2>Xpra Bug Report</h2>
xhr.send();
}

function query_keyboard_map() {
var keyboard = navigator.keyboard;
keyboard.getLayoutMap().then(keyboardLayoutMap => {
clog("got a keyboard layout map:", keyboardLayoutMap);
//TODO: build the client keymap somehow
load_default_settings();
clog("keys:", Array.from(keyboardLayoutMap.keys()));
for (const [key, value] of keyboardLayoutMap.entries()) {
cdebug("keyboard", key, "=", value);
}
});
if (keyboard.addEventListener) {
keyboard.addEventListener("layoutchange", function() {
clog("keyboard layout has changed!");
});
}
}

$(document).ready(function() {
clog("document is ready, browser is", navigator.platform, "64-bit:", Utilities.is_64bit());
if (navigator.keyboard && navigator.keyboard.getLayoutMap) {
query_keyboard_map();
}
else {
load_default_settings();
}
load_default_settings();
});
</script>
</body>
Expand Down
21 changes: 21 additions & 0 deletions html5/js/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ XpraClient.prototype._screen_resized = function(event, ctx) {
*/
XpraClient.prototype.init_keyboard = function() {
const me = this;
this.query_keyboard_map();
// modifier keys:
this.num_lock_modifier = null;
this.alt_modifier = null;
Expand Down Expand Up @@ -702,6 +703,26 @@ XpraClient.prototype.init_keyboard = function() {
});
};

XpraClient.prototype.query_keyboard_map = function() {
var keyboard = navigator.keyboard;
this.keyboard_map = {};
if (!navigator.keyboard) {
return;
}
keyboard.getLayoutMap().then(keyboardLayoutMap => {
clog("got a keyboard layout map:", keyboardLayoutMap);
clog("keys:", Array.from(keyboardLayoutMap.keys()));
for (const [key, value] of keyboardLayoutMap.entries()) {
cdebug("keyboard", key, "=", value);
this.keyboard_map[key] = value;
}
});
if (keyboard.addEventListener) {
keyboard.addEventListener("layoutchange", function() {
clog("keyboard layout has changed!");
});
}
};

XpraClient.prototype._keyb_get_modifiers = function(event) {
/**
Expand Down

0 comments on commit 690085e

Please sign in to comment.