summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-07-27 11:29:44 +0300
committerDevaev Maxim <[email protected]>2018-07-27 11:29:44 +0300
commitd2da0829b98e9aca474867f5ce9d5929f8b234af (patch)
treeb0902959494cf6a50c4eb3b671c642f5c9b2a197 /kvmd
parentb7d933b6ce128d466a9e0e031ead9e083c370374 (diff)
release keys when window loosing focus
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/web/js/hid.js8
-rw-r--r--kvmd/web/js/keyboard.js8
-rw-r--r--kvmd/web/js/ui.js26
3 files changed, 40 insertions, 2 deletions
diff --git a/kvmd/web/js/hid.js b/kvmd/web/js/hid.js
index ccab02cc..64ccb0e6 100644
--- a/kvmd/web/js/hid.js
+++ b/kvmd/web/js/hid.js
@@ -2,11 +2,19 @@ var hid = new function() {
var __install_timer = null;
var __installed = false;
+ var __hidden_attr = null;
+ var __visibility_change_attr = null;
+
this.init = function() {
keyboard.init();
mouse.init();
}
+ this.releaseAll = function() {
+ keyboard.releaseAll();
+ mouse.releaseAll();
+ };
+
this.emitShortcut = function(...codes) {
console.log(codes);
var delay = 0;
diff --git a/kvmd/web/js/keyboard.js b/kvmd/web/js/keyboard.js
index 13b96561..4ea38e5b 100644
--- a/kvmd/web/js/keyboard.js
+++ b/kvmd/web/js/keyboard.js
@@ -24,13 +24,17 @@ var keyboard = new function() {
};
this.setSocket = function(ws) {
+ keyboard.releaseAll();
+ __ws = ws;
+ $("hid-keyboard-led").className = (ws ? "led-on" : "led-off");
+ };
+
+ this.releaseAll = function(ws) {
__keys.concat(__modifiers).forEach(function(el_key) {
if (__isActive(el_key)) {
keyboard.fireEvent(el_key.id, false);
}
});
- __ws = ws;
- $("hid-keyboard-led").className = (ws ? "led-on" : "led-off");
};
this.fireEvent = function(code, state) {
diff --git a/kvmd/web/js/ui.js b/kvmd/web/js/ui.js
index 59968956..596a63ee 100644
--- a/kvmd/web/js/ui.js
+++ b/kvmd/web/js/ui.js
@@ -12,6 +12,32 @@ var ui = new function() {
var el_header = el_window.querySelector(".window-header");
__makeWindowMovable(el_header, el_window);
});
+
+ if (typeof document.hidden !== "undefined") {
+ __hidden_attr = "hidden";
+ __visibility_change_attr = "visibilitychange";
+ } else if (typeof document.webkitHidden !== "undefined") {
+ __hidden_attr = "webkitHidden";
+ __visibility_change_attr = "webkitvisibilitychange";
+ } else if (typeof document.mozHidden !== "undefined") {
+ __hidden_attr = "mozHidden";
+ __visibility_change_attr = "mozvisibilitychange";
+ }
+
+ if (__visibility_change_attr) {
+ document.addEventListener(
+ __visibility_change_attr,
+ function() {
+ if (document[__hidden_attr]) {
+ hid.releaseAll();
+ }
+ },
+ false,
+ );
+ }
+
+ window.onpagehide = hid.releaseAll;
+ window.onblur = hid.releaseAll;
};
var __toggleMenu = function(el_a) {