]>
Commit | Line | Data |
---|---|---|
15046f00 JM |
1 | /* |
2 | * noVNC: HTML5 VNC client | |
d58f8b51 | 3 | * Copyright (C) 2012 Joel Martin |
777cb7a0 | 4 | * Copyright (C) 2016 Samuel Mannehed for Cendio AB |
6cba147d | 5 | * Copyright (C) 2016 Pierre Ossman for Cendio AB |
1d728ace | 6 | * Licensed under MPL 2.0 (see LICENSE.txt) |
15046f00 JM |
7 | * |
8 | * See README.md for usage and integration instructions. | |
9 | */ | |
43cf7bd8 | 10 | |
bbbf42bb | 11 | /* jslint white: false, browser: true */ |
ae510306 SR |
12 | /* global window, document.getElementById, Util, WebUtil, RFB, Display */ |
13 | ||
14 | /* [module] | |
15 | * import Util from "../core/util"; | |
bd5340c7 | 16 | * import KeyTable from "../core/input/keysym"; |
ae510306 SR |
17 | * import RFB from "../core/rfb"; |
18 | * import Display from "../core/display"; | |
19 | * import WebUtil from "./webutil"; | |
20 | */ | |
bbbf42bb SR |
21 | |
22 | var UI; | |
23 | ||
24 | (function () { | |
25 | "use strict"; | |
26 | ||
ae510306 | 27 | /* [begin skip-as-module] */ |
bbbf42bb | 28 | // Load supporting scripts |
72bdd06e | 29 | WebUtil.load_scripts( |
bd5340c7 SR |
30 | {'core': ["base64.js", "websock.js", "des.js", "input/keysymdef.js", |
31 | "input/xtscancodes.js", "input/util.js", "input/devices.js", | |
32 | "display.js", "inflator.js", "rfb.js", "input/keysym.js"]}); | |
ae510306 | 33 | |
bbbf42bb | 34 | window.onscriptsload = function () { UI.load(); }; |
ae510306 | 35 | /* [end skip-as-module] */ |
bbbf42bb | 36 | |
bd6874e0 | 37 | UI = { |
bbbf42bb | 38 | |
3bb12056 SM |
39 | connected: false, |
40 | desktopName: "", | |
529c64e1 | 41 | |
045d9224 | 42 | resizeTimeout: null, |
ca5c74ad | 43 | statusTimeout: null, |
529c64e1 | 44 | hideKeyboardTimeout: null, |
3f93a385 SM |
45 | idleControlbarTimeout: null, |
46 | closeControlbarTimeout: null, | |
529c64e1 | 47 | |
04b399e2 SM |
48 | controlbarGrabbed: false, |
49 | controlbarDrag: false, | |
50 | controlbarMouseDownClientY: 0, | |
51 | controlbarMouseDownOffsetY: 0, | |
bbbf42bb | 52 | keyboardVisible: false, |
529c64e1 | 53 | |
bbbf42bb | 54 | isTouchDevice: false, |
f620259b | 55 | isSafari: false, |
a6357e82 | 56 | rememberedClipSetting: null, |
529c64e1 | 57 | lastKeyboardinput: null, |
58 | defaultKeyboardinputLen: 100, | |
59 | ||
bbbf42bb SR |
60 | // Setup rfb object, load settings from browser storage, then call |
61 | // UI.init to setup the UI/menus | |
0bd2cbac | 62 | load: function(callback) { |
bbbf42bb SR |
63 | WebUtil.initSettings(UI.start, callback); |
64 | }, | |
65 | ||
66 | // Render default UI and initialize settings menu | |
67 | start: function(callback) { | |
0f6af1e3 | 68 | |
69 | // Setup global variables first | |
bbbf42bb | 70 | UI.isTouchDevice = 'ontouchstart' in document.documentElement; |
0f6af1e3 | 71 | UI.isSafari = (navigator.userAgent.indexOf('Safari') !== -1 && |
72 | navigator.userAgent.indexOf('Chrome') === -1); | |
73 | ||
74 | UI.initSettings(); | |
75 | ||
6244e383 | 76 | // Adapt the interface for touch screen devices |
0f6af1e3 | 77 | if (UI.isTouchDevice) { |
6244e383 | 78 | document.documentElement.classList.add("noVNC_touch"); |
0f6af1e3 | 79 | // Remove the address bar |
80 | setTimeout(function() { window.scrollTo(0, 1); }, 100); | |
81 | UI.forceSetting('clip', true); | |
82 | } else { | |
83 | UI.initSetting('clip', false); | |
84 | } | |
85 | ||
86 | // Setup and initialize event handlers | |
87 | UI.setupWindowEvents(); | |
88 | UI.setupFullscreen(); | |
89 | UI.addControlbarHandlers(); | |
90 | UI.addTouchSpecificHandlers(); | |
ebbec43a | 91 | UI.addExtraKeysHandlers(); |
0f6af1e3 | 92 | UI.addXvpHandlers(); |
93 | UI.addConnectionControlHandlers(); | |
94 | UI.addClipboardHandlers(); | |
95 | UI.addSettingsHandlers(); | |
bbbf42bb | 96 | |
f9fff037 | 97 | // Show the connect panel on first load unless autoconnecting |
ed8cbe4e PO |
98 | if (!autoconnect) { |
99 | UI.openConnectPanel(); | |
100 | } | |
0f6af1e3 | 101 | |
f0d9ab96 | 102 | UI.updateViewClip(); |
0f6af1e3 | 103 | |
104 | UI.updateVisualState(); | |
105 | ||
106 | document.getElementById('noVNC_setting_host').focus(); | |
107 | ||
108 | var autoconnect = WebUtil.getConfigVar('autoconnect', false); | |
109 | if (autoconnect === 'true' || autoconnect == '1') { | |
110 | autoconnect = true; | |
111 | UI.connect(); | |
112 | } else { | |
113 | autoconnect = false; | |
114 | } | |
115 | ||
116 | if (typeof callback === "function") { | |
117 | callback(UI.rfb); | |
118 | } | |
119 | }, | |
120 | ||
121 | initSettings: function() { | |
bbbf42bb SR |
122 | // Stylesheet selection dropdown |
123 | var sheet = WebUtil.selectStylesheet(); | |
124 | var sheets = WebUtil.getStylesheets(); | |
125 | var i; | |
126 | for (i = 0; i < sheets.length; i += 1) { | |
ae510306 | 127 | UI.addOption(document.getElementById('noVNC_setting_stylesheet'),sheets[i].title, sheets[i].title); |
bbbf42bb SR |
128 | } |
129 | ||
130 | // Logging selection dropdown | |
131 | var llevels = ['error', 'warn', 'info', 'debug']; | |
132 | for (i = 0; i < llevels.length; i += 1) { | |
ae510306 | 133 | UI.addOption(document.getElementById('noVNC_setting_logging'),llevels[i], llevels[i]); |
bbbf42bb SR |
134 | } |
135 | ||
136 | // Settings with immediate effects | |
137 | UI.initSetting('logging', 'warn'); | |
138 | WebUtil.init_logging(UI.getSetting('logging')); | |
139 | ||
140 | UI.initSetting('stylesheet', 'default'); | |
141 | WebUtil.selectStylesheet(null); | |
142 | // call twice to get around webkit bug | |
143 | WebUtil.selectStylesheet(UI.getSetting('stylesheet')); | |
144 | ||
145 | // if port == 80 (or 443) then it won't be present and should be | |
146 | // set manually | |
147 | var port = window.location.port; | |
148 | if (!port) { | |
149 | if (window.location.protocol.substring(0,5) == 'https') { | |
150 | port = 443; | |
151 | } | |
152 | else if (window.location.protocol.substring(0,4) == 'http') { | |
153 | port = 80; | |
154 | } | |
155 | } | |
156 | ||
157 | /* Populate the controls if defaults are provided in the URL */ | |
158 | UI.initSetting('host', window.location.hostname); | |
159 | UI.initSetting('port', port); | |
160 | UI.initSetting('password', ''); | |
161 | UI.initSetting('encrypt', (window.location.protocol === "https:")); | |
162 | UI.initSetting('true_color', true); | |
163 | UI.initSetting('cursor', !UI.isTouchDevice); | |
8b46c0de | 164 | UI.initSetting('resize', 'off'); |
bbbf42bb SR |
165 | UI.initSetting('shared', true); |
166 | UI.initSetting('view_only', false); | |
167 | UI.initSetting('path', 'websockify'); | |
168 | UI.initSetting('repeaterID', ''); | |
c55f05f6 | 169 | UI.initSetting('token', ''); |
0f6af1e3 | 170 | }, |
bbbf42bb | 171 | |
0f6af1e3 | 172 | setupWindowEvents: function() { |
173 | window.addEventListener( 'resize', function () { | |
777cb7a0 | 174 | UI.applyResizeMode(); |
f0d9ab96 | 175 | UI.updateViewClip(); |
31ddaa1c | 176 | UI.updateViewDrag(); |
f8b399d7 | 177 | } ); |
ca5c74ad | 178 | |
179 | document.getElementById("noVNC_status") | |
180 | .addEventListener('click', UI.hideStatus); | |
bbbf42bb SR |
181 | }, |
182 | ||
0f6af1e3 | 183 | setupFullscreen: function() { |
184 | // Only show the button if fullscreen is properly supported | |
185 | // * Safari doesn't support alphanumerical input while in fullscreen | |
186 | if (!UI.isSafari && | |
187 | (document.documentElement.requestFullscreen || | |
188 | document.documentElement.mozRequestFullScreen || | |
189 | document.documentElement.webkitRequestFullscreen || | |
190 | document.body.msRequestFullscreen)) { | |
e40978c7 PO |
191 | document.getElementById('noVNC_fullscreen_button') |
192 | .classList.remove("noVNC_hidden"); | |
0f6af1e3 | 193 | UI.addFullscreenHandlers(); |
d9fc1c7b | 194 | } |
e543525f SR |
195 | }, |
196 | ||
0f6af1e3 | 197 | addControlbarHandlers: function() { |
728b5d9e PO |
198 | document.getElementById("noVNC_control_bar") |
199 | .addEventListener('mousemove', UI.activateControlbar); | |
200 | document.getElementById("noVNC_control_bar") | |
201 | .addEventListener('mouseup', UI.activateControlbar); | |
202 | document.getElementById("noVNC_control_bar") | |
203 | .addEventListener('mousedown', UI.activateControlbar); | |
204 | document.getElementById("noVNC_control_bar") | |
205 | .addEventListener('keypress', UI.activateControlbar); | |
206 | ||
3f93a385 SM |
207 | document.getElementById("noVNC_control_bar") |
208 | .addEventListener('mousedown', UI.keepControlbar); | |
209 | document.getElementById("noVNC_control_bar") | |
210 | .addEventListener('keypress', UI.keepControlbar); | |
211 | ||
d7f79071 | 212 | document.getElementById("noVNC_view_drag_button") |
213 | .addEventListener('click', UI.toggleViewDrag); | |
04b399e2 SM |
214 | |
215 | document.getElementById("noVNC_control_bar_handle") | |
216 | .addEventListener('mousedown', UI.controlbarHandleMouseDown); | |
217 | document.getElementById("noVNC_control_bar_handle") | |
218 | .addEventListener('mouseup', UI.controlbarHandleMouseUp); | |
219 | document.getElementById("noVNC_control_bar_handle") | |
220 | .addEventListener('mousemove', UI.dragControlbarHandle); | |
221 | // resize events aren't available for elements | |
222 | window.addEventListener('resize', UI.updateControlbarHandle); | |
0f6af1e3 | 223 | }, |
224 | ||
225 | addTouchSpecificHandlers: function() { | |
d7f79071 | 226 | document.getElementById("noVNC_mouse_button0") |
227 | .addEventListener('click', function () { UI.setMouseButton(1); }); | |
228 | document.getElementById("noVNC_mouse_button1") | |
229 | .addEventListener('click', function () { UI.setMouseButton(2); }); | |
230 | document.getElementById("noVNC_mouse_button2") | |
231 | .addEventListener('click', function () { UI.setMouseButton(4); }); | |
232 | document.getElementById("noVNC_mouse_button4") | |
233 | .addEventListener('click', function () { UI.setMouseButton(0); }); | |
234 | document.getElementById("noVNC_keyboard_button") | |
4b30f9ce | 235 | .addEventListener('click', UI.toggleVirtualKeyboard); |
d7f79071 | 236 | |
237 | document.getElementById("noVNC_keyboardinput") | |
238 | .addEventListener('input', UI.keyInput); | |
239 | document.getElementById("noVNC_keyboardinput") | |
4b30f9ce | 240 | .addEventListener('blur', UI.onblurVirtualKeyboard); |
d7f79071 | 241 | document.getElementById("noVNC_keyboardinput") |
242 | .addEventListener('submit', function () { return false; }); | |
243 | ||
728b5d9e PO |
244 | document.getElementById("noVNC_control_bar") |
245 | .addEventListener('touchstart', UI.activateControlbar); | |
246 | document.getElementById("noVNC_control_bar") | |
247 | .addEventListener('touchmove', UI.activateControlbar); | |
248 | document.getElementById("noVNC_control_bar") | |
249 | .addEventListener('touchend', UI.activateControlbar); | |
250 | document.getElementById("noVNC_control_bar") | |
251 | .addEventListener('input', UI.activateControlbar); | |
252 | ||
3f93a385 SM |
253 | document.getElementById("noVNC_control_bar") |
254 | .addEventListener('touchstart', UI.keepControlbar); | |
255 | document.getElementById("noVNC_control_bar") | |
256 | .addEventListener('input', UI.keepControlbar); | |
257 | ||
04b399e2 SM |
258 | document.getElementById("noVNC_control_bar_handle") |
259 | .addEventListener('touchstart', UI.controlbarHandleMouseDown); | |
260 | document.getElementById("noVNC_control_bar_handle") | |
261 | .addEventListener('touchend', UI.controlbarHandleMouseUp); | |
262 | document.getElementById("noVNC_control_bar_handle") | |
263 | .addEventListener('touchmove', UI.dragControlbarHandle); | |
264 | ||
0f6af1e3 | 265 | window.addEventListener('load', UI.keyboardinputReset); |
ebbec43a | 266 | }, |
0f6af1e3 | 267 | |
ebbec43a | 268 | addExtraKeysHandlers: function() { |
a49d9298 | 269 | document.getElementById("noVNC_toggle_extra_keys_button") |
d7f79071 | 270 | .addEventListener('click', UI.toggleExtraKeys); |
a49d9298 | 271 | document.getElementById("noVNC_toggle_ctrl_button") |
d7f79071 | 272 | .addEventListener('click', UI.toggleCtrl); |
a49d9298 | 273 | document.getElementById("noVNC_toggle_alt_button") |
d7f79071 | 274 | .addEventListener('click', UI.toggleAlt); |
a49d9298 | 275 | document.getElementById("noVNC_send_tab_button") |
d7f79071 | 276 | .addEventListener('click', UI.sendTab); |
a49d9298 | 277 | document.getElementById("noVNC_send_esc_button") |
d7f79071 | 278 | .addEventListener('click', UI.sendEsc); |
ca25d2ae PO |
279 | document.getElementById("noVNC_send_ctrl_alt_del_button") |
280 | .addEventListener('click', UI.sendCtrlAltDel); | |
0f6af1e3 | 281 | }, |
d7f79071 | 282 | |
0f6af1e3 | 283 | addXvpHandlers: function() { |
a49d9298 | 284 | document.getElementById("noVNC_xvp_shutdown_button") |
d7f79071 | 285 | .addEventListener('click', function() { UI.rfb.xvpShutdown(); }); |
a49d9298 | 286 | document.getElementById("noVNC_xvp_reboot_button") |
d7f79071 | 287 | .addEventListener('click', function() { UI.rfb.xvpReboot(); }); |
a49d9298 | 288 | document.getElementById("noVNC_xvp_reset_button") |
d7f79071 | 289 | .addEventListener('click', function() { UI.rfb.xvpReset(); }); |
a49d9298 | 290 | document.getElementById("noVNC_xvp_button") |
d7f79071 | 291 | .addEventListener('click', UI.toggleXvpPanel); |
0f6af1e3 | 292 | }, |
293 | ||
294 | addConnectionControlHandlers: function() { | |
a49d9298 | 295 | document.getElementById("noVNC_connect_controls_button") |
d7f79071 | 296 | .addEventListener('click', UI.toggleConnectPanel); |
297 | document.getElementById("noVNC_disconnect_button") | |
298 | .addEventListener('click', UI.disconnect); | |
0f6af1e3 | 299 | document.getElementById("noVNC_connect_button") |
300 | .addEventListener('click', UI.connect); | |
8a7ec6ea SM |
301 | |
302 | document.getElementById("noVNC_password_button") | |
303 | .addEventListener('click', UI.setPassword); | |
0f6af1e3 | 304 | }, |
d7f79071 | 305 | |
0f6af1e3 | 306 | addClipboardHandlers: function() { |
307 | document.getElementById("noVNC_clipboard_button") | |
308 | .addEventListener('click', UI.toggleClipboardPanel); | |
d7f79071 | 309 | document.getElementById("noVNC_clipboard_text") |
310 | .addEventListener('focus', UI.displayBlur); | |
311 | document.getElementById("noVNC_clipboard_text") | |
312 | .addEventListener('blur', UI.displayFocus); | |
313 | document.getElementById("noVNC_clipboard_text") | |
314 | .addEventListener('change', UI.clipboardSend); | |
315 | document.getElementById("noVNC_clipboard_clear_button") | |
316 | .addEventListener('click', UI.clipboardClear); | |
0f6af1e3 | 317 | }, |
d7f79071 | 318 | |
0f6af1e3 | 319 | addSettingsHandlers: function() { |
320 | document.getElementById("noVNC_settings_button") | |
321 | .addEventListener('click', UI.toggleSettingsPanel); | |
d7f79071 | 322 | document.getElementById("noVNC_settings_apply") |
323 | .addEventListener('click', UI.settingsApply); | |
324 | ||
d7f79071 | 325 | document.getElementById("noVNC_setting_resize") |
326 | .addEventListener('change', UI.enableDisableViewClip); | |
bbbf42bb SR |
327 | }, |
328 | ||
0f6af1e3 | 329 | addFullscreenHandlers: function() { |
330 | document.getElementById("noVNC_fullscreen_button") | |
331 | .addEventListener('click', UI.toggleFullscreen); | |
332 | ||
333 | window.addEventListener('fullscreenchange', UI.updateFullscreenButton); | |
334 | window.addEventListener('mozfullscreenchange', UI.updateFullscreenButton); | |
335 | window.addEventListener('webkitfullscreenchange', UI.updateFullscreenButton); | |
336 | window.addEventListener('msfullscreenchange', UI.updateFullscreenButton); | |
337 | }, | |
338 | ||
339 | initRFB: function() { | |
340 | try { | |
341 | UI.rfb = new RFB({'target': document.getElementById('noVNC_canvas'), | |
a7127fee | 342 | 'onNotification': UI.notification, |
0f6af1e3 | 343 | 'onUpdateState': UI.updateState, |
3bb12056 | 344 | 'onDisconnected': UI.disconnectFinished, |
7d714b15 | 345 | 'onPasswordRequired': UI.passwordRequired, |
0f6af1e3 | 346 | 'onXvpInit': UI.updateXvpButton, |
347 | 'onClipboard': UI.clipboardReceive, | |
348 | 'onFBUComplete': UI.initialResize, | |
349 | 'onFBResize': UI.updateViewDrag, | |
3bb12056 | 350 | 'onDesktopName': UI.updateDesktopName}); |
0f6af1e3 | 351 | return true; |
352 | } catch (exc) { | |
3bb12056 | 353 | UI.showStatus('Unable to create RFB client -- ' + exc, 'error'); |
0f6af1e3 | 354 | return false; |
355 | } | |
356 | }, | |
357 | ||
95dd6001 | 358 | /* ------^------- |
359 | * /INIT | |
360 | * ============== | |
361 | * VISUAL | |
362 | * ------v------*/ | |
58ded70d | 363 | |
3bb12056 SM |
364 | updateState: function(rfb, state, oldstate) { |
365 | switch (state) { | |
366 | case 'connecting': | |
367 | UI.showStatus("Connecting"); | |
368 | break; | |
369 | case 'connected': | |
370 | UI.connected = true; | |
371 | if (rfb && rfb.get_encrypt()) { | |
372 | UI.showStatus("Connected (encrypted) to " + | |
373 | UI.desktopName); | |
374 | } else { | |
375 | UI.showStatus("Connected (unencrypted) to " + | |
376 | UI.desktopName); | |
377 | } | |
378 | break; | |
379 | case 'disconnecting': | |
380 | UI.showStatus("Disconnecting"); | |
381 | break; | |
382 | case 'disconnected': | |
383 | UI.connected = false; | |
384 | UI.showStatus("Disconnected"); | |
385 | break; | |
386 | default: | |
387 | UI.showStatus("Invalid state", 'error'); | |
388 | break; | |
fdedbafb | 389 | } |
29475d77 | 390 | |
391 | UI.updateVisualState(); | |
fdedbafb | 392 | }, |
393 | ||
29475d77 | 394 | // Disable/enable controls depending on connection state |
395 | updateVisualState: function() { | |
29475d77 | 396 | //Util.Debug(">> updateVisualState"); |
3bb12056 SM |
397 | document.getElementById('noVNC_setting_encrypt').disabled = UI.connected; |
398 | document.getElementById('noVNC_setting_true_color').disabled = UI.connected; | |
29475d77 | 399 | if (Util.browserSupportsCursorURIs()) { |
3bb12056 | 400 | document.getElementById('noVNC_setting_cursor').disabled = UI.connected; |
29475d77 | 401 | } else { |
402 | UI.updateSetting('cursor', !UI.isTouchDevice); | |
ae510306 | 403 | document.getElementById('noVNC_setting_cursor').disabled = true; |
29475d77 | 404 | } |
fdedbafb | 405 | |
29475d77 | 406 | UI.enableDisableViewClip(); |
3bb12056 SM |
407 | document.getElementById('noVNC_setting_resize').disabled = UI.connected; |
408 | document.getElementById('noVNC_setting_shared').disabled = UI.connected; | |
409 | document.getElementById('noVNC_setting_view_only').disabled = UI.connected; | |
410 | document.getElementById('noVNC_setting_path').disabled = UI.connected; | |
411 | document.getElementById('noVNC_setting_repeaterID').disabled = UI.connected; | |
fdedbafb | 412 | |
3bb12056 | 413 | if (UI.connected) { |
6244e383 | 414 | document.documentElement.classList.add("noVNC_connected"); |
f0d9ab96 | 415 | UI.updateViewClip(); |
29475d77 | 416 | UI.setMouseButton(1); |
3f93a385 SM |
417 | |
418 | // Hide the controlbar after 2 seconds | |
419 | UI.closeControlbarTimeout = setTimeout(UI.closeControlbar, 2000); | |
29475d77 | 420 | } else { |
6244e383 | 421 | document.documentElement.classList.remove("noVNC_connected"); |
9e45354e | 422 | UI.updateXvpButton(0); |
7520ba52 | 423 | UI.keepControlbar(); |
29475d77 | 424 | } |
fdedbafb | 425 | |
29475d77 | 426 | // State change disables viewport dragging. |
427 | // It is enabled (toggled) by direct click on the button | |
f0d9ab96 | 428 | UI.setViewDrag(false); |
29475d77 | 429 | |
8a7ec6ea SM |
430 | // State change also closes the password dialog |
431 | document.getElementById('noVNC_password_dlg') | |
432 | .classList.remove('noVNC_open'); | |
433 | ||
29475d77 | 434 | //Util.Debug("<< updateVisualState"); |
435 | }, | |
436 | ||
8d7708c8 | 437 | showStatus: function(text, status_type, time) { |
ca5c74ad | 438 | var statusElem = document.getElementById('noVNC_status'); |
4e471b5b | 439 | |
ca5c74ad | 440 | clearTimeout(UI.statusTimeout); |
4e471b5b | 441 | |
8d7708c8 SM |
442 | if (typeof status_type === 'undefined') { |
443 | status_type = 'normal'; | |
444 | } | |
445 | ||
446 | statusElem.classList.remove("noVNC_status_normal", | |
447 | "noVNC_status_warn", | |
448 | "noVNC_status_error"); | |
449 | ||
450 | switch (status_type) { | |
451 | case 'warning': | |
452 | case 'warn': | |
453 | statusElem.classList.add("noVNC_status_warn"); | |
454 | break; | |
455 | case 'error': | |
456 | statusElem.classList.add("noVNC_status_error"); | |
457 | break; | |
458 | case 'normal': | |
459 | case 'info': | |
460 | default: | |
461 | statusElem.classList.add("noVNC_status_normal"); | |
462 | break; | |
463 | } | |
464 | ||
ca5c74ad | 465 | statusElem.innerHTML = text; |
466 | statusElem.classList.add("noVNC_open"); | |
467 | ||
468 | // If no time was specified, show the status for 1.5 seconds | |
469 | if (typeof time === 'undefined') { | |
470 | time = 1500; | |
fdedbafb | 471 | } |
4e471b5b | 472 | |
ca5c74ad | 473 | // A specified time of zero means no timeout |
474 | if (time != 0) { | |
475 | UI.statusTimeout = window.setTimeout(UI.hideStatus, time); | |
476 | } | |
fdedbafb | 477 | }, |
478 | ||
ca5c74ad | 479 | hideStatus: function() { |
480 | clearTimeout(UI.statusTimeout); | |
481 | document.getElementById('noVNC_status').classList.remove("noVNC_open"); | |
4e471b5b | 482 | }, |
483 | ||
a7127fee SM |
484 | notification: function (rfb, msg, level, options) { |
485 | UI.showStatus(msg, level); | |
486 | }, | |
487 | ||
3f93a385 SM |
488 | activateControlbar: function(event) { |
489 | clearTimeout(UI.idleControlbarTimeout); | |
728b5d9e PO |
490 | // We manipulate the anchor instead of the actual control |
491 | // bar in order to avoid creating new a stacking group | |
492 | document.getElementById('noVNC_control_bar_anchor') | |
493 | .classList.remove("noVNC_idle"); | |
3f93a385 | 494 | UI.idleControlbarTimeout = window.setTimeout(UI.idleControlbar, 2000); |
728b5d9e PO |
495 | }, |
496 | ||
497 | idleControlbar: function() { | |
498 | document.getElementById('noVNC_control_bar_anchor') | |
499 | .classList.add("noVNC_idle"); | |
500 | }, | |
501 | ||
3f93a385 SM |
502 | keepControlbar: function() { |
503 | clearTimeout(UI.closeControlbarTimeout); | |
504 | }, | |
505 | ||
38323d4d PO |
506 | openControlbar: function() { |
507 | document.getElementById('noVNC_control_bar') | |
508 | .classList.add("noVNC_open"); | |
509 | }, | |
510 | ||
511 | closeControlbar: function() { | |
512 | UI.closeAllPanels(); | |
513 | document.getElementById('noVNC_control_bar') | |
514 | .classList.remove("noVNC_open"); | |
515 | }, | |
516 | ||
517 | toggleControlbar: function() { | |
518 | if (document.getElementById('noVNC_control_bar') | |
519 | .classList.contains("noVNC_open")) { | |
520 | UI.closeControlbar(); | |
521 | } else { | |
522 | UI.openControlbar(); | |
523 | } | |
524 | }, | |
525 | ||
04b399e2 SM |
526 | dragControlbarHandle: function (e) { |
527 | if (!UI.controlbarGrabbed) return; | |
528 | ||
529 | var ptr = Util.getPointerEvent(e); | |
530 | ||
531 | if (!UI.controlbarDrag) { | |
532 | // The goal is to trigger on a certain physical width, the | |
533 | // devicePixelRatio brings us a bit closer but is not optimal. | |
534 | var dragThreshold = 10 * (window.devicePixelRatio || 1); | |
535 | var dragDistance = Math.abs(ptr.clientY - UI.controlbarMouseDownClientY); | |
536 | ||
537 | if (dragDistance < dragThreshold) return; | |
538 | ||
539 | UI.controlbarDrag = true; | |
540 | } | |
541 | ||
542 | var eventY = ptr.clientY - UI.controlbarMouseDownOffsetY; | |
543 | ||
544 | UI.moveControlbarHandle(eventY); | |
545 | ||
546 | e.preventDefault(); | |
547 | e.stopPropagation(); | |
548 | }, | |
549 | ||
550 | // Move the handle but don't allow any position outside the bounds | |
551 | moveControlbarHandle: function (posY) { | |
552 | var handle = document.getElementById("noVNC_control_bar_handle"); | |
553 | var handleHeight = Util.getPosition(handle).height; | |
554 | var controlbar = document.getElementById("noVNC_control_bar"); | |
555 | var controlbarBounds = Util.getPosition(controlbar); | |
556 | var controlbarTop = controlbarBounds.y; | |
557 | var controlbarBottom = controlbarBounds.y + controlbarBounds.height; | |
558 | var margin = 10; | |
559 | ||
560 | var viewportY = posY; | |
561 | ||
562 | // Refuse coordinates outside the control bar | |
563 | if (viewportY < controlbarTop + margin) { | |
564 | viewportY = controlbarTop + margin; | |
565 | } else if (viewportY > controlbarBottom - handleHeight - margin) { | |
566 | viewportY = controlbarBottom - handleHeight - margin; | |
567 | } | |
568 | ||
569 | // Corner case: control bar too small for stable position | |
570 | if (controlbarBounds.height < (handleHeight + margin * 2)) { | |
571 | viewportY = controlbarTop + (controlbarBounds.height - handleHeight) / 2; | |
572 | } | |
573 | ||
574 | var relativeY = viewportY - controlbarTop; | |
575 | handle.style.transform = "translateY(" + relativeY + "px)"; | |
576 | }, | |
577 | ||
578 | updateControlbarHandle: function () { | |
579 | var handle = document.getElementById("noVNC_control_bar_handle"); | |
580 | var pos = Util.getPosition(handle); | |
581 | UI.moveControlbarHandle(pos.y); | |
582 | }, | |
583 | ||
584 | controlbarHandleMouseUp: function(e) { | |
1c1cc1d0 | 585 | if ((e.type == "mouseup") && (e.button != 0)) return; |
04b399e2 SM |
586 | |
587 | // mouseup and mousedown on the same place toggles the controlbar | |
588 | if (UI.controlbarGrabbed && !UI.controlbarDrag) { | |
589 | UI.toggleControlbar(); | |
590 | e.preventDefault(); | |
591 | e.stopPropagation(); | |
592 | } | |
593 | UI.controlbarGrabbed = false; | |
594 | }, | |
595 | ||
596 | controlbarHandleMouseDown: function(e) { | |
1c1cc1d0 | 597 | if ((e.type == "mousedown") && (e.button != 0)) return; |
04b399e2 SM |
598 | |
599 | var ptr = Util.getPointerEvent(e); | |
600 | ||
601 | var handle = document.getElementById("noVNC_control_bar_handle"); | |
602 | var bounds = handle.getBoundingClientRect(); | |
603 | ||
604 | WebUtil.setCapture(handle); | |
605 | UI.controlbarGrabbed = true; | |
606 | UI.controlbarDrag = false; | |
607 | ||
608 | UI.controlbarMouseDownClientY = ptr.clientY; | |
609 | UI.controlbarMouseDownOffsetY = ptr.clientY - bounds.top; | |
610 | e.preventDefault(); | |
611 | e.stopPropagation(); | |
612 | }, | |
613 | ||
95dd6001 | 614 | /* ------^------- |
615 | * /VISUAL | |
616 | * ============== | |
617 | * SETTINGS | |
618 | * ------v------*/ | |
619 | ||
45c70c9e | 620 | // Initial page load read/initialization of settings |
621 | initSetting: function(name, defVal) { | |
622 | // Check Query string followed by cookie | |
623 | var val = WebUtil.getConfigVar(name); | |
624 | if (val === null) { | |
625 | val = WebUtil.readSetting(name, defVal); | |
bbbf42bb | 626 | } |
45c70c9e | 627 | UI.updateSetting(name, val); |
bbbf42bb SR |
628 | return val; |
629 | }, | |
630 | ||
631 | // Update cookie and form control setting. If value is not set, then | |
632 | // updates from control to current cookie setting. | |
633 | updateSetting: function(name, value) { | |
634 | ||
635 | // Save the cookie for this session | |
636 | if (typeof value !== 'undefined') { | |
637 | WebUtil.writeSetting(name, value); | |
638 | } | |
639 | ||
640 | // Update the settings control | |
641 | value = UI.getSetting(name); | |
642 | ||
ae510306 | 643 | var ctrl = document.getElementById('noVNC_setting_' + name); |
bbbf42bb SR |
644 | if (ctrl.type === 'checkbox') { |
645 | ctrl.checked = value; | |
646 | ||
647 | } else if (typeof ctrl.options !== 'undefined') { | |
648 | for (var i = 0; i < ctrl.options.length; i += 1) { | |
649 | if (ctrl.options[i].value === value) { | |
650 | ctrl.selectedIndex = i; | |
651 | break; | |
652 | } | |
653 | } | |
654 | } else { | |
655 | /*Weird IE9 error leads to 'null' appearring | |
656 | in textboxes instead of ''.*/ | |
657 | if (value === null) { | |
658 | value = ""; | |
659 | } | |
660 | ctrl.value = value; | |
661 | } | |
662 | }, | |
663 | ||
664 | // Save control setting to cookie | |
665 | saveSetting: function(name) { | |
ae510306 | 666 | var val, ctrl = document.getElementById('noVNC_setting_' + name); |
bbbf42bb SR |
667 | if (ctrl.type === 'checkbox') { |
668 | val = ctrl.checked; | |
669 | } else if (typeof ctrl.options !== 'undefined') { | |
670 | val = ctrl.options[ctrl.selectedIndex].value; | |
671 | } else { | |
672 | val = ctrl.value; | |
673 | } | |
674 | WebUtil.writeSetting(name, val); | |
675 | //Util.Debug("Setting saved '" + name + "=" + val + "'"); | |
676 | return val; | |
677 | }, | |
678 | ||
bbbf42bb SR |
679 | // Force a setting to be a certain value |
680 | forceSetting: function(name, val) { | |
681 | UI.updateSetting(name, val); | |
682 | return val; | |
683 | }, | |
684 | ||
45c70c9e | 685 | // Read form control compatible setting from cookie |
686 | getSetting: function(name) { | |
ae510306 | 687 | var ctrl = document.getElementById('noVNC_setting_' + name); |
45c70c9e | 688 | var val = WebUtil.readSetting(name); |
689 | if (typeof val !== 'undefined' && val !== null && ctrl.type === 'checkbox') { | |
690 | if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) { | |
691 | val = false; | |
4f19e5c6 | 692 | } else { |
45c70c9e | 693 | val = true; |
4f19e5c6 | 694 | } |
bbbf42bb | 695 | } |
bbbf42bb | 696 | return val; |
bbbf42bb SR |
697 | }, |
698 | ||
95dd6001 | 699 | // Save/apply settings when 'Apply' button is pressed |
700 | settingsApply: function() { | |
701 | //Util.Debug(">> settingsApply"); | |
702 | UI.saveSetting('encrypt'); | |
703 | UI.saveSetting('true_color'); | |
704 | if (Util.browserSupportsCursorURIs()) { | |
705 | UI.saveSetting('cursor'); | |
bbbf42bb | 706 | } |
bbbf42bb | 707 | |
95dd6001 | 708 | UI.saveSetting('resize'); |
bbbf42bb | 709 | |
95dd6001 | 710 | if (UI.getSetting('resize') === 'downscale' || UI.getSetting('resize') === 'scale') { |
711 | UI.forceSetting('clip', false); | |
7d1dc09a | 712 | } |
7d1dc09a | 713 | |
95dd6001 | 714 | UI.saveSetting('clip'); |
715 | UI.saveSetting('shared'); | |
716 | UI.saveSetting('view_only'); | |
717 | UI.saveSetting('path'); | |
718 | UI.saveSetting('repeaterID'); | |
719 | UI.saveSetting('stylesheet'); | |
720 | UI.saveSetting('logging'); | |
721 | ||
722 | // Settings with immediate (non-connected related) effect | |
723 | WebUtil.selectStylesheet(UI.getSetting('stylesheet')); | |
724 | WebUtil.init_logging(UI.getSetting('logging')); | |
f0d9ab96 | 725 | UI.updateViewClip(); |
95dd6001 | 726 | UI.updateViewDrag(); |
727 | //Util.Debug("<< settingsApply"); | |
7d1dc09a | 728 | }, |
729 | ||
ed8cbe4e PO |
730 | /* ------^------- |
731 | * /SETTINGS | |
732 | * ============== | |
733 | * PANELS | |
734 | * ------v------*/ | |
735 | ||
736 | closeAllPanels: function() { | |
737 | UI.closeSettingsPanel(); | |
738 | UI.closeXvpPanel(); | |
739 | UI.closeClipboardPanel(); | |
740 | UI.closeConnectPanel(); | |
fb7c3b3b | 741 | UI.closeExtraKeys(); |
ed8cbe4e PO |
742 | }, |
743 | ||
744 | /* ------^------- | |
745 | * /PANELS | |
746 | * ============== | |
747 | * SETTINGS (panel) | |
748 | * ------v------*/ | |
749 | ||
750 | openSettingsPanel: function() { | |
751 | UI.closeAllPanels(); | |
38323d4d | 752 | UI.openControlbar(); |
ed8cbe4e PO |
753 | |
754 | UI.updateSetting('encrypt'); | |
755 | UI.updateSetting('true_color'); | |
756 | if (Util.browserSupportsCursorURIs()) { | |
757 | UI.updateSetting('cursor'); | |
758 | } else { | |
759 | UI.updateSetting('cursor', !UI.isTouchDevice); | |
760 | document.getElementById('noVNC_setting_cursor').disabled = true; | |
bbbf42bb | 761 | } |
ed8cbe4e PO |
762 | UI.updateSetting('clip'); |
763 | UI.updateSetting('resize'); | |
764 | UI.updateSetting('shared'); | |
765 | UI.updateSetting('view_only'); | |
766 | UI.updateSetting('path'); | |
767 | UI.updateSetting('repeaterID'); | |
768 | UI.updateSetting('stylesheet'); | |
769 | UI.updateSetting('logging'); | |
770 | ||
e40978c7 PO |
771 | document.getElementById('noVNC_settings') |
772 | .classList.add("noVNC_open"); | |
773 | document.getElementById('noVNC_settings_button') | |
d9e86214 | 774 | .classList.add("noVNC_selected"); |
45c70c9e | 775 | }, |
bbbf42bb | 776 | |
ed8cbe4e | 777 | closeSettingsPanel: function() { |
e40978c7 PO |
778 | document.getElementById('noVNC_settings') |
779 | .classList.remove("noVNC_open"); | |
780 | document.getElementById('noVNC_settings_button') | |
d9e86214 | 781 | .classList.remove("noVNC_selected"); |
bbbf42bb SR |
782 | }, |
783 | ||
784 | // Toggle the settings menu: | |
785 | // On open, settings are refreshed from saved cookies. | |
786 | // On close, settings are applied | |
787 | toggleSettingsPanel: function() { | |
ed8cbe4e PO |
788 | if (document.getElementById('noVNC_settings') |
789 | .classList.contains("noVNC_open")) { | |
bbbf42bb | 790 | UI.settingsApply(); |
ed8cbe4e | 791 | UI.closeSettingsPanel(); |
bbbf42bb | 792 | } else { |
ed8cbe4e | 793 | UI.openSettingsPanel(); |
bbbf42bb SR |
794 | } |
795 | }, | |
796 | ||
95dd6001 | 797 | /* ------^------- |
798 | * /SETTINGS | |
799 | * ============== | |
800 | * XVP | |
801 | * ------v------*/ | |
802 | ||
ed8cbe4e PO |
803 | openXvpPanel: function() { |
804 | UI.closeAllPanels(); | |
38323d4d | 805 | UI.openControlbar(); |
ed8cbe4e PO |
806 | |
807 | document.getElementById('noVNC_xvp') | |
808 | .classList.add("noVNC_open"); | |
809 | document.getElementById('noVNC_xvp_button') | |
810 | .classList.add("noVNC_selected"); | |
811 | }, | |
812 | ||
813 | closeXvpPanel: function() { | |
814 | document.getElementById('noVNC_xvp') | |
815 | .classList.remove("noVNC_open"); | |
816 | document.getElementById('noVNC_xvp_button') | |
817 | .classList.remove("noVNC_selected"); | |
818 | }, | |
819 | ||
bbbf42bb | 820 | toggleXvpPanel: function() { |
ed8cbe4e PO |
821 | if (document.getElementById('noVNC_xvp') |
822 | .classList.contains("noVNC_open")) { | |
823 | UI.closeXvpPanel(); | |
bbbf42bb | 824 | } else { |
ed8cbe4e | 825 | UI.openXvpPanel(); |
bbbf42bb | 826 | } |
bbbf42bb SR |
827 | }, |
828 | ||
829 | // Disable/enable XVP button | |
9e45354e | 830 | updateXvpButton: function(ver) { |
bbbf42bb | 831 | if (ver >= 1) { |
a49d9298 | 832 | document.getElementById('noVNC_xvp_button') |
e40978c7 | 833 | .classList.remove("noVNC_hidden"); |
bbbf42bb | 834 | } else { |
a49d9298 | 835 | document.getElementById('noVNC_xvp_button') |
e40978c7 | 836 | .classList.add("noVNC_hidden"); |
bbbf42bb | 837 | // Close XVP panel if open |
ed8cbe4e | 838 | UI.closeXvpPanel(); |
bbbf42bb SR |
839 | } |
840 | }, | |
841 | ||
95dd6001 | 842 | /* ------^------- |
843 | * /XVP | |
844 | * ============== | |
845 | * CLIPBOARD | |
846 | * ------v------*/ | |
f8b399d7 | 847 | |
ed8cbe4e PO |
848 | openClipboardPanel: function() { |
849 | UI.closeAllPanels(); | |
38323d4d | 850 | UI.openControlbar(); |
ed8cbe4e PO |
851 | |
852 | document.getElementById('noVNC_clipboard') | |
853 | .classList.add("noVNC_open"); | |
854 | document.getElementById('noVNC_clipboard_button') | |
855 | .classList.add("noVNC_selected"); | |
856 | }, | |
857 | ||
858 | closeClipboardPanel: function() { | |
859 | document.getElementById('noVNC_clipboard') | |
860 | .classList.remove("noVNC_open"); | |
861 | document.getElementById('noVNC_clipboard_button') | |
862 | .classList.remove("noVNC_selected"); | |
863 | }, | |
864 | ||
bbbf42bb | 865 | toggleClipboardPanel: function() { |
ed8cbe4e PO |
866 | if (document.getElementById('noVNC_clipboard') |
867 | .classList.contains("noVNC_open")) { | |
868 | UI.closeClipboardPanel(); | |
bbbf42bb | 869 | } else { |
ed8cbe4e | 870 | UI.openClipboardPanel(); |
bbbf42bb | 871 | } |
bbbf42bb SR |
872 | }, |
873 | ||
4d26f58e | 874 | clipboardReceive: function(rfb, text) { |
875 | Util.Debug(">> UI.clipboardReceive: " + text.substr(0,40) + "..."); | |
ae510306 | 876 | document.getElementById('noVNC_clipboard_text').value = text; |
4d26f58e | 877 | Util.Debug("<< UI.clipboardReceive"); |
95dd6001 | 878 | }, |
879 | ||
4d26f58e | 880 | clipboardClear: function() { |
ae510306 | 881 | document.getElementById('noVNC_clipboard_text').value = ""; |
95dd6001 | 882 | UI.rfb.clipboardPasteFrom(""); |
883 | }, | |
884 | ||
4d26f58e | 885 | clipboardSend: function() { |
ae510306 | 886 | var text = document.getElementById('noVNC_clipboard_text').value; |
4d26f58e | 887 | Util.Debug(">> UI.clipboardSend: " + text.substr(0,40) + "..."); |
95dd6001 | 888 | UI.rfb.clipboardPasteFrom(text); |
4d26f58e | 889 | Util.Debug("<< UI.clipboardSend"); |
95dd6001 | 890 | }, |
891 | ||
892 | /* ------^------- | |
893 | * /CLIPBOARD | |
894 | * ============== | |
895 | * CONNECTION | |
896 | * ------v------*/ | |
897 | ||
ed8cbe4e PO |
898 | openConnectPanel: function() { |
899 | UI.closeAllPanels(); | |
38323d4d | 900 | UI.openControlbar(); |
ab81ddf5 | 901 | |
ed8cbe4e PO |
902 | document.getElementById('noVNC_connect_controls') |
903 | .classList.add("noVNC_open"); | |
904 | document.getElementById('noVNC_connect_controls_button') | |
905 | .classList.add("noVNC_selected"); | |
906 | ||
907 | document.getElementById('noVNC_setting_host').focus(); | |
908 | }, | |
909 | ||
910 | closeConnectPanel: function() { | |
911 | document.getElementById('noVNC_connect_controls') | |
912 | .classList.remove("noVNC_open"); | |
913 | document.getElementById('noVNC_connect_controls_button') | |
914 | .classList.remove("noVNC_selected"); | |
915 | ||
916 | UI.saveSetting('host'); | |
917 | UI.saveSetting('port'); | |
918 | UI.saveSetting('token'); | |
919 | //UI.saveSetting('password'); | |
920 | }, | |
921 | ||
922 | toggleConnectPanel: function() { | |
923 | if (document.getElementById('noVNC_connect_controls') | |
924 | .classList.contains("noVNC_open")) { | |
925 | UI.closeConnectPanel(); | |
ab81ddf5 | 926 | } else { |
ed8cbe4e | 927 | UI.openConnectPanel(); |
ab81ddf5 | 928 | } |
bbbf42bb SR |
929 | }, |
930 | ||
931 | connect: function() { | |
ed8cbe4e | 932 | UI.closeAllPanels(); |
f00b1e37 | 933 | |
ae510306 SR |
934 | var host = document.getElementById('noVNC_setting_host').value; |
935 | var port = document.getElementById('noVNC_setting_port').value; | |
936 | var password = document.getElementById('noVNC_setting_password').value; | |
937 | var token = document.getElementById('noVNC_setting_token').value; | |
938 | var path = document.getElementById('noVNC_setting_path').value; | |
c55f05f6 MXPN |
939 | |
940 | //if token is in path then ignore the new token variable | |
941 | if (token) { | |
942 | path = WebUtil.injectParamIfMissing(path, "token", token); | |
943 | } | |
944 | ||
bbbf42bb | 945 | if ((!host) || (!port)) { |
3bb12056 SM |
946 | UI.showStatus("Must set host and port", 'error'); |
947 | return; | |
bbbf42bb | 948 | } |
53fc7392 | 949 | |
d9fc1c7b | 950 | if (!UI.initRFB()) return; |
58ded70d | 951 | |
bbbf42bb SR |
952 | UI.rfb.set_encrypt(UI.getSetting('encrypt')); |
953 | UI.rfb.set_true_color(UI.getSetting('true_color')); | |
954 | UI.rfb.set_local_cursor(UI.getSetting('cursor')); | |
955 | UI.rfb.set_shared(UI.getSetting('shared')); | |
956 | UI.rfb.set_view_only(UI.getSetting('view_only')); | |
957 | UI.rfb.set_repeaterID(UI.getSetting('repeaterID')); | |
53fc7392 | 958 | |
bbbf42bb | 959 | UI.rfb.connect(host, port, password, path); |
bbbf42bb | 960 | }, |
5299db1a | 961 | |
bbbf42bb | 962 | disconnect: function() { |
ed8cbe4e | 963 | UI.closeAllPanels(); |
bbbf42bb | 964 | UI.rfb.disconnect(); |
8e0f0088 | 965 | |
f8b399d7 | 966 | // Restore the callback used for initial resize |
ab81ddf5 | 967 | UI.rfb.set_onFBUComplete(UI.initialResize); |
f8b399d7 | 968 | |
e543525f | 969 | // Don't display the connection settings until we're actually disconnected |
bbbf42bb SR |
970 | }, |
971 | ||
3bb12056 SM |
972 | disconnectFinished: function (rfb, reason) { |
973 | if (typeof reason !== 'undefined') { | |
974 | UI.showStatus(reason, 'error'); | |
975 | } | |
976 | UI.openConnectPanel(); | |
977 | }, | |
978 | ||
7d714b15 SM |
979 | /* ------^------- |
980 | * /CONNECTION | |
981 | * ============== | |
982 | * PASSWORD | |
983 | * ------v------*/ | |
984 | ||
985 | passwordRequired: function(rfb, msg) { | |
986 | ||
987 | document.getElementById('noVNC_password_dlg') | |
988 | .classList.add('noVNC_open'); | |
989 | ||
990 | setTimeout(function () { | |
991 | document.getElementById('noVNC_password_input').focus(); | |
992 | }, 100); | |
993 | ||
994 | if (typeof msg === 'undefined') { | |
995 | msg = "Password is required"; | |
996 | } | |
3bb12056 | 997 | UI.showStatus(msg, "warning"); |
7d714b15 SM |
998 | }, |
999 | ||
95dd6001 | 1000 | setPassword: function() { |
8a7ec6ea SM |
1001 | UI.rfb.sendPassword(document.getElementById('noVNC_password_input').value); |
1002 | document.getElementById('noVNC_password_dlg') | |
1003 | .classList.remove('noVNC_open'); | |
95dd6001 | 1004 | return false; |
1005 | }, | |
58ded70d | 1006 | |
95dd6001 | 1007 | /* ------^------- |
7d714b15 | 1008 | * /PASSWORD |
95dd6001 | 1009 | * ============== |
1010 | * FULLSCREEN | |
1011 | * ------v------*/ | |
1012 | ||
7d1dc09a | 1013 | toggleFullscreen: function() { |
1014 | if (document.fullscreenElement || // alternative standard method | |
1015 | document.mozFullScreenElement || // currently working methods | |
1016 | document.webkitFullscreenElement || | |
a6357e82 | 1017 | document.msFullscreenElement) { |
7d1dc09a | 1018 | if (document.exitFullscreen) { |
1019 | document.exitFullscreen(); | |
1020 | } else if (document.mozCancelFullScreen) { | |
1021 | document.mozCancelFullScreen(); | |
1022 | } else if (document.webkitExitFullscreen) { | |
1023 | document.webkitExitFullscreen(); | |
1024 | } else if (document.msExitFullscreen) { | |
1025 | document.msExitFullscreen(); | |
1026 | } | |
1027 | } else { | |
1028 | if (document.documentElement.requestFullscreen) { | |
1029 | document.documentElement.requestFullscreen(); | |
1030 | } else if (document.documentElement.mozRequestFullScreen) { | |
1031 | document.documentElement.mozRequestFullScreen(); | |
1032 | } else if (document.documentElement.webkitRequestFullscreen) { | |
1033 | document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); | |
1034 | } else if (document.body.msRequestFullscreen) { | |
1035 | document.body.msRequestFullscreen(); | |
1036 | } | |
1037 | } | |
a6357e82 | 1038 | UI.enableDisableViewClip(); |
7d1dc09a | 1039 | UI.updateFullscreenButton(); |
bbbf42bb SR |
1040 | }, |
1041 | ||
7d1dc09a | 1042 | updateFullscreenButton: function() { |
1043 | if (document.fullscreenElement || // alternative standard method | |
1044 | document.mozFullScreenElement || // currently working methods | |
1045 | document.webkitFullscreenElement || | |
1046 | document.msFullscreenElement ) { | |
a49d9298 | 1047 | document.getElementById('noVNC_fullscreen_button') |
d9e86214 | 1048 | .classList.add("noVNC_selected"); |
7d1dc09a | 1049 | } else { |
a49d9298 | 1050 | document.getElementById('noVNC_fullscreen_button') |
d9e86214 | 1051 | .classList.remove("noVNC_selected"); |
7d1dc09a | 1052 | } |
1053 | }, | |
1054 | ||
95dd6001 | 1055 | /* ------^------- |
1056 | * /FULLSCREEN | |
1057 | * ============== | |
1058 | * RESIZE | |
1059 | * ------v------*/ | |
777cb7a0 | 1060 | |
1061 | // Apply remote resizing or local scaling | |
0bd2cbac | 1062 | applyResizeMode: function() { |
58ded70d SR |
1063 | if (!UI.rfb) return; |
1064 | ||
777cb7a0 | 1065 | var screen = UI.screenSize(); |
1066 | ||
3bb12056 | 1067 | if (screen && UI.connected && UI.rfb.get_display()) { |
777cb7a0 | 1068 | |
1069 | var display = UI.rfb.get_display(); | |
1070 | var resizeMode = UI.getSetting('resize'); | |
1071 | ||
1072 | if (resizeMode === 'remote') { | |
1073 | ||
1074 | // Request changing the resolution of the remote display to | |
1075 | // the size of the local browser viewport. | |
1076 | ||
1077 | // In order to not send multiple requests before the browser-resize | |
1078 | // is finished we wait 0.5 seconds before sending the request. | |
1079 | clearTimeout(UI.resizeTimeout); | |
1080 | UI.resizeTimeout = setTimeout(function(){ | |
1081 | ||
1082 | // Limit the viewport to the size of the browser window | |
1083 | display.set_maxWidth(screen.w); | |
1084 | display.set_maxHeight(screen.h); | |
1085 | ||
5fd3f88e | 1086 | Util.Debug('Attempting requestDesktopSize(' + |
777cb7a0 | 1087 | screen.w + ', ' + screen.h + ')'); |
1088 | ||
1089 | // Request a remote size covering the viewport | |
5fd3f88e | 1090 | UI.rfb.requestDesktopSize(screen.w, screen.h); |
777cb7a0 | 1091 | }, 500); |
1092 | ||
1093 | } else if (resizeMode === 'scale' || resizeMode === 'downscale') { | |
1094 | var downscaleOnly = resizeMode === 'downscale'; | |
1095 | var scaleRatio = display.autoscale(screen.w, screen.h, downscaleOnly); | |
1096 | UI.rfb.get_mouse().set_scale(scaleRatio); | |
1097 | Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale()); | |
1098 | } | |
1099 | } | |
bbbf42bb SR |
1100 | }, |
1101 | ||
777cb7a0 | 1102 | // The screen is always the same size as the available viewport |
1103 | // in the browser window minus the height of the control bar | |
0bd2cbac | 1104 | screenSize: function() { |
ae510306 | 1105 | var screen = document.getElementById('noVNC_screen'); |
777cb7a0 | 1106 | |
1107 | // Hide the scrollbars until the size is calculated | |
1108 | screen.style.overflow = "hidden"; | |
1109 | ||
1110 | var pos = Util.getPosition(screen); | |
1111 | var w = pos.width; | |
1112 | var h = pos.height; | |
1113 | ||
1114 | screen.style.overflow = "visible"; | |
1115 | ||
1116 | if (isNaN(w) || isNaN(h)) { | |
1117 | return false; | |
1118 | } else { | |
1119 | return {w: w, h: h}; | |
1120 | } | |
bbbf42bb SR |
1121 | }, |
1122 | ||
777cb7a0 | 1123 | // Normally we only apply the current resize mode after a window resize |
1124 | // event. This means that when a new connection is opened, there is no | |
1125 | // resize mode active. | |
1126 | // We have to wait until the first FBU because this is where the client | |
1127 | // will find the supported encodings of the server. Some calls later in | |
1128 | // the chain is dependant on knowing the server-capabilities. | |
1129 | initialResize: function(rfb, fbu) { | |
1130 | UI.applyResizeMode(); | |
1131 | // After doing this once, we remove the callback. | |
1132 | UI.rfb.set_onFBUComplete(function() { }); | |
bbbf42bb SR |
1133 | }, |
1134 | ||
95dd6001 | 1135 | /* ------^------- |
1136 | * /RESIZE | |
1137 | * ============== | |
1138 | * CLIPPING | |
1139 | * ------v------*/ | |
1140 | ||
30bfff81 | 1141 | // Set and configure viewport clipping |
bbbf42bb | 1142 | setViewClip: function(clip) { |
f0d9ab96 | 1143 | UI.updateSetting('clip', clip); |
1144 | UI.updateViewClip(); | |
1145 | }, | |
1146 | ||
1147 | // Update parameters that depend on the clip setting | |
1148 | updateViewClip: function() { | |
bbbf42bb | 1149 | var display; |
1c1cc1d0 | 1150 | if (!UI.rfb) return; |
8e0f0088 | 1151 | |
f0d9ab96 | 1152 | var display = UI.rfb.get_display(); |
bbbf42bb | 1153 | var cur_clip = display.get_viewport(); |
f0d9ab96 | 1154 | var new_clip = UI.getSetting('clip'); |
bbbf42bb | 1155 | |
f0d9ab96 | 1156 | if (cur_clip !== new_clip) { |
1157 | display.set_viewport(new_clip); | |
bbbf42bb | 1158 | } |
8e0f0088 | 1159 | |
f0d9ab96 | 1160 | var size = UI.screenSize(); |
fdedbafb | 1161 | |
f0d9ab96 | 1162 | if (new_clip && size) { |
1163 | // When clipping is enabled, the screen is limited to | |
1164 | // the size of the browser window. | |
1165 | display.set_maxWidth(size.w); | |
1166 | display.set_maxHeight(size.h); | |
fdedbafb | 1167 | |
f0d9ab96 | 1168 | var screen = document.getElementById('noVNC_screen'); |
1169 | var canvas = document.getElementById('noVNC_canvas'); | |
fdedbafb | 1170 | |
f0d9ab96 | 1171 | // Hide potential scrollbars that can skew the position |
1172 | screen.style.overflow = "hidden"; | |
fdedbafb | 1173 | |
f0d9ab96 | 1174 | // The x position marks the left margin of the canvas, |
1175 | // remove the margin from both sides to keep it centered. | |
1176 | var new_w = size.w - (2 * Util.getPosition(canvas).x); | |
fdedbafb | 1177 | |
f0d9ab96 | 1178 | screen.style.overflow = "visible"; |
1179 | ||
1180 | display.viewportChangeSize(new_w, size.h); | |
1181 | } else { | |
1182 | // Disable max dimensions | |
1183 | display.set_maxWidth(0); | |
1184 | display.set_maxHeight(0); | |
1185 | display.viewportChangeSize(); | |
bbbf42bb SR |
1186 | } |
1187 | }, | |
1188 | ||
30bfff81 | 1189 | // Handle special cases where clipping is forced on/off or locked |
0bd2cbac | 1190 | enableDisableViewClip: function() { |
ae510306 | 1191 | var resizeSetting = document.getElementById('noVNC_setting_resize'); |
a6357e82 | 1192 | |
f620259b | 1193 | if (UI.isSafari) { |
1194 | // Safari auto-hides the scrollbars which makes them | |
1195 | // impossible to use in most cases | |
1196 | UI.setViewClip(true); | |
ae510306 | 1197 | document.getElementById('noVNC_setting_clip').disabled = true; |
682fd02b | 1198 | } else if (resizeSetting.value === 'downscale' || resizeSetting.value === 'scale') { |
a6357e82 | 1199 | // Disable clipping if we are scaling |
1200 | UI.setViewClip(false); | |
ae510306 | 1201 | document.getElementById('noVNC_setting_clip').disabled = true; |
a6357e82 | 1202 | } else if (document.msFullscreenElement) { |
1203 | // The browser is IE and we are in fullscreen mode. | |
1204 | // - We need to force clipping while in fullscreen since | |
1205 | // scrollbars doesn't work. | |
ca5c74ad | 1206 | UI.showStatus("Forcing clipping mode since scrollbars aren't supported by IE in fullscreen"); |
a6357e82 | 1207 | UI.rememberedClipSetting = UI.getSetting('clip'); |
1208 | UI.setViewClip(true); | |
ae510306 | 1209 | document.getElementById('noVNC_setting_clip').disabled = true; |
a6357e82 | 1210 | } else if (document.body.msRequestFullscreen && UI.rememberedClip !== null) { |
1211 | // Restore view clip to what it was before fullscreen on IE | |
1212 | UI.setViewClip(UI.rememberedClipSetting); | |
3bb12056 SM |
1213 | document.getElementById('noVNC_setting_clip').disabled = |
1214 | UI.connected || UI.isTouchDevice; | |
30bfff81 | 1215 | } else { |
3bb12056 SM |
1216 | document.getElementById('noVNC_setting_clip').disabled = |
1217 | UI.connected || UI.isTouchDevice; | |
30bfff81 | 1218 | if (UI.isTouchDevice) { |
a6357e82 | 1219 | UI.setViewClip(true); |
30bfff81 | 1220 | } |
1221 | } | |
1222 | }, | |
1223 | ||
95dd6001 | 1224 | /* ------^------- |
1225 | * /CLIPPING | |
1226 | * ============== | |
1227 | * VIEWDRAG | |
1228 | * ------v------*/ | |
1229 | ||
f0d9ab96 | 1230 | toggleViewDrag: function() { |
58ded70d | 1231 | if (!UI.rfb) return; |
bbbf42bb | 1232 | |
f0d9ab96 | 1233 | var drag = UI.rfb.get_viewportDrag(); |
1234 | UI.setViewDrag(!drag); | |
1235 | }, | |
1236 | ||
1237 | // Set the view drag mode which moves the viewport on mouse drags | |
1238 | setViewDrag: function(drag) { | |
1239 | if (!UI.rfb) return; | |
1240 | ||
1241 | UI.rfb.set_viewportDrag(drag); | |
1242 | ||
1243 | UI.updateViewDrag(); | |
1244 | }, | |
1245 | ||
1246 | updateViewDrag: function() { | |
1247 | var clipping = false; | |
bbbf42bb | 1248 | |
3bb12056 | 1249 | if (!UI.connected) return; |
6244e383 | 1250 | |
e00698fe | 1251 | // Check if viewport drag is possible. It is only possible |
1252 | // if the remote display is clipping the client display. | |
6244e383 | 1253 | if (UI.rfb.get_display().get_viewport() && |
fdedbafb | 1254 | UI.rfb.get_display().clippingDisplay()) { |
f0d9ab96 | 1255 | clipping = true; |
1256 | } | |
31ddaa1c | 1257 | |
f0d9ab96 | 1258 | var viewDragButton = document.getElementById('noVNC_view_drag_button'); |
29a0e6a8 | 1259 | |
6244e383 PO |
1260 | if (!clipping && |
1261 | UI.rfb.get_viewportDrag()) { | |
1262 | // The size of the remote display is the same or smaller | |
1263 | // than the client display. Make sure viewport drag isn't | |
1264 | // active when it can't be used. | |
1265 | UI.rfb.set_viewportDrag(false); | |
1266 | } | |
1267 | ||
1268 | if (UI.rfb.get_viewportDrag()) { | |
1269 | viewDragButton.classList.add("noVNC_selected"); | |
31ddaa1c | 1270 | } else { |
6244e383 PO |
1271 | viewDragButton.classList.remove("noVNC_selected"); |
1272 | } | |
31ddaa1c | 1273 | |
6244e383 PO |
1274 | // Different behaviour for touch vs non-touch |
1275 | // The button is disabled instead of hidden on touch devices | |
1276 | if (UI.isTouchDevice) { | |
1277 | viewDragButton.classList.remove("noVNC_hidden"); | |
1278 | ||
1279 | if (clipping) { | |
1280 | viewDragButton.disabled = false; | |
31ddaa1c | 1281 | } else { |
6244e383 | 1282 | viewDragButton.disabled = true; |
31ddaa1c | 1283 | } |
6244e383 PO |
1284 | } else { |
1285 | viewDragButton.disabled = false; | |
29a0e6a8 | 1286 | |
6244e383 | 1287 | if (clipping) { |
e40978c7 | 1288 | viewDragButton.classList.remove("noVNC_hidden"); |
f0d9ab96 | 1289 | } else { |
6244e383 | 1290 | viewDragButton.classList.add("noVNC_hidden"); |
f0d9ab96 | 1291 | } |
f8b399d7 | 1292 | } |
1293 | }, | |
1294 | ||
95dd6001 | 1295 | /* ------^------- |
1296 | * /VIEWDRAG | |
1297 | * ============== | |
1298 | * KEYBOARD | |
1299 | * ------v------*/ | |
fdf21468 | 1300 | |
4b30f9ce | 1301 | showVirtualKeyboard: function() { |
1c1cc1d0 | 1302 | if (!UI.isTouchDevice) return; |
4b30f9ce SM |
1303 | |
1304 | var input = document.getElementById('noVNC_keyboardinput'); | |
1305 | ||
1c1cc1d0 | 1306 | if (document.activeElement == input) return; |
4b30f9ce SM |
1307 | |
1308 | UI.keyboardVisible = true; | |
1309 | document.getElementById('noVNC_keyboard_button') | |
1310 | .classList.add("noVNC_selected"); | |
1311 | input.focus(); | |
1312 | ||
1313 | try { | |
1314 | var l = input.value.length; | |
1315 | // Move the caret to the end | |
1316 | input.setSelectionRange(l, l); | |
1317 | } catch (err) {} // setSelectionRange is undefined in Google Chrome | |
1318 | }, | |
1319 | ||
1320 | hideVirtualKeyboard: function() { | |
1c1cc1d0 | 1321 | if (!UI.isTouchDevice) return; |
4b30f9ce SM |
1322 | |
1323 | var input = document.getElementById('noVNC_keyboardinput'); | |
1324 | ||
1c1cc1d0 | 1325 | if (document.activeElement != input) return; |
4b30f9ce SM |
1326 | |
1327 | input.blur(); | |
1328 | }, | |
1329 | ||
1330 | toggleVirtualKeyboard: function () { | |
1331 | if (UI.keyboardVisible) { | |
1332 | UI.hideVirtualKeyboard(); | |
1333 | } else { | |
1334 | UI.showVirtualKeyboard(); | |
bbbf42bb SR |
1335 | } |
1336 | }, | |
1337 | ||
4b30f9ce | 1338 | onblurVirtualKeyboard: function() { |
fdf21468 | 1339 | //Weird bug in iOS if you change keyboardVisible |
1340 | //here it does not actually occur so next time | |
1341 | //you click keyboard icon it doesnt work. | |
1342 | UI.hideKeyboardTimeout = setTimeout(function() { | |
1343 | UI.keyboardVisible = false; | |
4b30f9ce SM |
1344 | document.getElementById('noVNC_keyboard_button') |
1345 | .classList.remove("noVNC_selected"); | |
fdf21468 | 1346 | },100); |
1347 | }, | |
1348 | ||
bbbf42bb SR |
1349 | keepKeyboard: function() { |
1350 | clearTimeout(UI.hideKeyboardTimeout); | |
1351 | if(UI.keyboardVisible === true) { | |
4b30f9ce | 1352 | UI.showVirtualKeyboard(); |
bbbf42bb | 1353 | } else if(UI.keyboardVisible === false) { |
4b30f9ce | 1354 | UI.hideVirtualKeyboard(); |
bbbf42bb SR |
1355 | } |
1356 | }, | |
1357 | ||
1358 | keyboardinputReset: function() { | |
ae510306 | 1359 | var kbi = document.getElementById('noVNC_keyboardinput'); |
bbbf42bb SR |
1360 | kbi.value = new Array(UI.defaultKeyboardinputLen).join("_"); |
1361 | UI.lastKeyboardinput = kbi.value; | |
1362 | }, | |
1363 | ||
1364 | // When normal keyboard events are left uncought, use the input events from | |
1365 | // the keyboardinput element instead and generate the corresponding key events. | |
1366 | // This code is required since some browsers on Android are inconsistent in | |
1367 | // sending keyCodes in the normal keyboard events when using on screen keyboards. | |
1368 | keyInput: function(event) { | |
3b8ec46f | 1369 | |
58ded70d | 1370 | if (!UI.rfb) return; |
3b8ec46f | 1371 | |
bbbf42bb | 1372 | var newValue = event.target.value; |
1138bdd4 | 1373 | |
1374 | if (!UI.lastKeyboardinput) { | |
1375 | UI.keyboardinputReset(); | |
1376 | } | |
cb3e4deb | 1377 | var oldValue = UI.lastKeyboardinput; |
bbbf42bb SR |
1378 | |
1379 | var newLen; | |
1380 | try { | |
1381 | // Try to check caret position since whitespace at the end | |
1382 | // will not be considered by value.length in some browsers | |
1383 | newLen = Math.max(event.target.selectionStart, newValue.length); | |
1384 | } catch (err) { | |
1385 | // selectionStart is undefined in Google Chrome | |
1386 | newLen = newValue.length; | |
1387 | } | |
1388 | var oldLen = oldValue.length; | |
1389 | ||
1390 | var backspaces; | |
1391 | var inputs = newLen - oldLen; | |
1392 | if (inputs < 0) { | |
1393 | backspaces = -inputs; | |
1394 | } else { | |
1395 | backspaces = 0; | |
1396 | } | |
8e0f0088 | 1397 | |
bbbf42bb SR |
1398 | // Compare the old string with the new to account for |
1399 | // text-corrections or other input that modify existing text | |
1400 | var i; | |
1401 | for (i = 0; i < Math.min(oldLen, newLen); i++) { | |
1402 | if (newValue.charAt(i) != oldValue.charAt(i)) { | |
1403 | inputs = newLen - i; | |
1404 | backspaces = oldLen - i; | |
1405 | break; | |
1406 | } | |
1407 | } | |
1408 | ||
1409 | // Send the key events | |
1410 | for (i = 0; i < backspaces; i++) { | |
ae510306 | 1411 | UI.rfb.sendKey(KeyTable.XK_BackSpace); |
bbbf42bb SR |
1412 | } |
1413 | for (i = newLen - inputs; i < newLen; i++) { | |
1414 | UI.rfb.sendKey(newValue.charCodeAt(i)); | |
1415 | } | |
1416 | ||
1417 | // Control the text content length in the keyboardinput element | |
1418 | if (newLen > 2 * UI.defaultKeyboardinputLen) { | |
1419 | UI.keyboardinputReset(); | |
1420 | } else if (newLen < 1) { | |
1421 | // There always have to be some text in the keyboardinput | |
1422 | // element with which backspace can interact. | |
1423 | UI.keyboardinputReset(); | |
1424 | // This sometimes causes the keyboard to disappear for a second | |
1425 | // but it is required for the android keyboard to recognize that | |
1426 | // text has been added to the field | |
1427 | event.target.blur(); | |
1428 | // This has to be ran outside of the input handler in order to work | |
67685d07 | 1429 | setTimeout(UI.keepKeyboard, 0); |
bbbf42bb SR |
1430 | } else { |
1431 | UI.lastKeyboardinput = newValue; | |
1432 | } | |
1433 | }, | |
1434 | ||
4b30f9ce SM |
1435 | /* ------^------- |
1436 | * /KEYBOARD | |
1437 | * ============== | |
1438 | * EXTRA KEYS | |
1439 | * ------v------*/ | |
1440 | ||
ed8cbe4e | 1441 | openExtraKeys: function() { |
fb7c3b3b | 1442 | UI.closeAllPanels(); |
38323d4d | 1443 | UI.openControlbar(); |
fb7c3b3b | 1444 | |
ed8cbe4e PO |
1445 | document.getElementById('noVNC_modifiers') |
1446 | .classList.add("noVNC_open"); | |
1447 | document.getElementById('noVNC_toggle_extra_keys_button') | |
1448 | .classList.add("noVNC_selected"); | |
1449 | }, | |
1450 | ||
1451 | closeExtraKeys: function() { | |
1452 | document.getElementById('noVNC_modifiers') | |
1453 | .classList.remove("noVNC_open"); | |
1454 | document.getElementById('noVNC_toggle_extra_keys_button') | |
1455 | .classList.remove("noVNC_selected"); | |
1456 | }, | |
1457 | ||
cd611a53 | 1458 | toggleExtraKeys: function() { |
bbbf42bb | 1459 | UI.keepKeyboard(); |
ed8cbe4e PO |
1460 | if(document.getElementById('noVNC_modifiers') |
1461 | .classList.contains("noVNC_open")) { | |
1462 | UI.closeExtraKeys(); | |
1463 | } else { | |
1464 | UI.openExtraKeys(); | |
bbbf42bb SR |
1465 | } |
1466 | }, | |
1467 | ||
fdf21468 | 1468 | sendEsc: function() { |
1469 | UI.keepKeyboard(); | |
ae510306 | 1470 | UI.rfb.sendKey(KeyTable.XK_Escape); |
fdf21468 | 1471 | }, |
1472 | ||
1473 | sendTab: function() { | |
1474 | UI.keepKeyboard(); | |
ae510306 | 1475 | UI.rfb.sendKey(KeyTable.XK_Tab); |
fdf21468 | 1476 | }, |
1477 | ||
bbbf42bb SR |
1478 | toggleCtrl: function() { |
1479 | UI.keepKeyboard(); | |
b0c6d3c6 | 1480 | var btn = document.getElementById('noVNC_toggle_ctrl_button'); |
1481 | if (btn.classList.contains("noVNC_selected")) { | |
ae510306 | 1482 | UI.rfb.sendKey(KeyTable.XK_Control_L, false); |
b0c6d3c6 | 1483 | btn.classList.remove("noVNC_selected"); |
1484 | } else { | |
1485 | UI.rfb.sendKey(KeyTable.XK_Control_L, true); | |
1486 | btn.classList.add("noVNC_selected"); | |
bbbf42bb SR |
1487 | } |
1488 | }, | |
1489 | ||
1490 | toggleAlt: function() { | |
1491 | UI.keepKeyboard(); | |
b0c6d3c6 | 1492 | var btn = document.getElementById('noVNC_toggle_alt_button'); |
1493 | if (btn.classList.contains("noVNC_selected")) { | |
ae510306 | 1494 | UI.rfb.sendKey(KeyTable.XK_Alt_L, false); |
b0c6d3c6 | 1495 | btn.classList.remove("noVNC_selected"); |
1496 | } else { | |
1497 | UI.rfb.sendKey(KeyTable.XK_Alt_L, true); | |
1498 | btn.classList.add("noVNC_selected"); | |
bbbf42bb SR |
1499 | } |
1500 | }, | |
1501 | ||
fdf21468 | 1502 | sendCtrlAltDel: function() { |
ca25d2ae | 1503 | UI.keepKeyboard(); |
fdf21468 | 1504 | UI.rfb.sendCtrlAltDel(); |
bbbf42bb SR |
1505 | }, |
1506 | ||
95dd6001 | 1507 | /* ------^------- |
4b30f9ce | 1508 | * /EXTRA KEYS |
95dd6001 | 1509 | * ============== |
1510 | * MISC | |
1511 | * ------v------*/ | |
1512 | ||
1513 | setMouseButton: function(num) { | |
95dd6001 | 1514 | if (UI.rfb) { |
1515 | UI.rfb.get_mouse().set_touchButton(num); | |
1516 | } | |
1517 | ||
1518 | var blist = [0, 1,2,4]; | |
1519 | for (var b = 0; b < blist.length; b++) { | |
ae510306 | 1520 | var button = document.getElementById('noVNC_mouse_button' + blist[b]); |
95dd6001 | 1521 | if (blist[b] === num) { |
e40978c7 | 1522 | button.classList.remove("noVNC_hidden"); |
95dd6001 | 1523 | } else { |
e40978c7 | 1524 | button.classList.add("noVNC_hidden"); |
95dd6001 | 1525 | } |
1526 | } | |
1527 | }, | |
1528 | ||
1529 | displayBlur: function() { | |
1530 | if (!UI.rfb) return; | |
1531 | ||
1532 | UI.rfb.get_keyboard().set_focused(false); | |
1533 | UI.rfb.get_mouse().set_focused(false); | |
1534 | }, | |
1535 | ||
1536 | displayFocus: function() { | |
1537 | if (!UI.rfb) return; | |
1538 | ||
1539 | UI.rfb.get_keyboard().set_focused(true); | |
1540 | UI.rfb.get_mouse().set_focused(true); | |
bbbf42bb SR |
1541 | }, |
1542 | ||
3bb12056 SM |
1543 | updateDesktopName: function(rfb, name) { |
1544 | UI.desktopName = name; | |
1545 | // Display the desktop name in the document title | |
95dd6001 | 1546 | document.title = name + " - noVNC"; |
bbbf42bb SR |
1547 | }, |
1548 | ||
bbbf42bb SR |
1549 | //Helper to add options to dropdown. |
1550 | addOption: function(selectbox, text, value) { | |
1551 | var optn = document.createElement("OPTION"); | |
1552 | optn.text = text; | |
1553 | optn.value = value; | |
1554 | selectbox.options.add(optn); | |
1555 | }, | |
1556 | ||
95dd6001 | 1557 | /* ------^------- |
1558 | * /MISC | |
1559 | * ============== | |
1560 | */ | |
bbbf42bb | 1561 | }; |
ae510306 SR |
1562 | |
1563 | /* [module] UI.load(); */ | |
bbbf42bb | 1564 | })(); |
ae510306 SR |
1565 | |
1566 | /* [module] export default UI; */ |