document.documentElement
.addEventListener('mousedown', UI.keepVirtualKeyboard, true);
- document.documentElement
- .addEventListener('touchstart', UI.keepVirtualKeyboard, true);
document.getElementById("noVNC_control_bar")
.addEventListener('touchstart', UI.activateControlbar);
onfocusVirtualKeyboard: function(event) {
document.getElementById('noVNC_keyboard_button')
.classList.add("noVNC_selected");
+ if (UI.rfb) {
+ UI.rfb.set_focus_on_click(false);
+ }
},
onblurVirtualKeyboard: function(event) {
document.getElementById('noVNC_keyboard_button')
.classList.remove("noVNC_selected");
+ if (UI.rfb) {
+ UI.rfb.set_focus_on_click(true);
+ }
},
keepVirtualKeyboard: function(event) {
}
}
- // The default action of touchstart is to generate other
- // events, which other elements might depend on. So we can't
- // blindly prevent that. Instead restore focus right away.
- if (event.type === "touchstart") {
- setTimeout(input.focus.bind(input));
- } else {
- event.preventDefault();
- }
+ event.preventDefault();
},
keyboardinputReset: function() {
'local_cursor': false, // Request locally rendered cursor
'shared': true, // Request shared mode
'view_only': false, // Disable client mouse/keyboard
+ 'focus_on_click': true, // Grab focus on canvas on mouse click
'xvp_password_sep': '@', // Separator for XVP password fields
'disconnectTimeout': 3, // Time (s) to wait for disconnection
'wsProtocols': ['binary'], // Protocols to use in the WebSocket connection
'onXvpInit': function () { } // onXvpInit(version): XVP extensions active for this connection
});
+ // Bound event handlers
+ this._eventHandlers = {
+ focusCanvas: this._focusCanvas.bind(this),
+ };
+
// main setup
Log.Debug(">> RFB.constructor");
}
// Always grab focus on some kind of click event
- this._target.addEventListener("mousedown", this._focusCanvas);
- this._target.addEventListener("touchstart", this._focusCanvas);
+ this._target.addEventListener("mousedown", this._eventHandlers.focusCanvas);
+ this._target.addEventListener("touchstart", this._eventHandlers.focusCanvas);
Log.Debug("<< RFB.connect");
},
_disconnect: function () {
Log.Debug(">> RFB.disconnect");
- this._target.removeEventListener("mousedown", this._focusCanvas);
- this._target.removeEventListener("touchstart", this._focusCanvas);
+ this._target.removeEventListener("mousedown", this._eventHandlers.focusCanvas);
+ this._target.removeEventListener("touchstart", this._eventHandlers.focusCanvas);
this._cleanup();
this._sock.close();
this._print_stats();
}
},
- // Event handler for canvas so this points to the canvas element
_focusCanvas: function(event) {
// Respect earlier handlers' request to not do side-effects
- if (!event.defaultPrevented)
- this.focus();
+ if (event.defaultPrevented) {
+ return;
+ }
+
+ if (!this._focus_on_click) {
+ return;
+ }
+
+ this._target.focus();
},
/*
['local_cursor', 'rw', 'bool'], // Request locally rendered cursor
['shared', 'rw', 'bool'], // Request shared mode
['view_only', 'rw', 'bool'], // Disable client mouse/keyboard
+ ['focus_on_click', 'rw', 'bool'], // Grab focus on canvas on mouse click
['xvp_password_sep', 'rw', 'str'], // Separator for XVP password fields
['disconnectTimeout', 'rw', 'int'], // Time (s) to wait for disconnection
['wsProtocols', 'rw', 'arr'], // Protocols to use in the WebSocket connection