From 81bd2d6682ea176ff083b252c80d34d98d8f9606 Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Thu, 1 Sep 2016 15:03:39 +0200 Subject: [PATCH 1/5] Don't grab keyboard or mouse in view-only mode Fixes #644. --- core/rfb.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/rfb.js b/core/rfb.js index ca173eae..4a5f4344 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -415,8 +415,8 @@ } if (this._display && this._display.get_context()) { - this._keyboard.ungrab(); - this._mouse.ungrab(); + if (!this._view_only) { this._keyboard.ungrab(); } + if (!this._view_only) { this._mouse.ungrab(); } this._display.defaultCursor(); if (Util.get_logging() !== 'debug') { // Show noVNC logo on load and when disconnected, unless in @@ -1028,8 +1028,9 @@ this._display.set_true_color(this._true_color); this._display.resize(this._fb_width, this._fb_height); this._onFBResize(this, this._fb_width, this._fb_height); - this._keyboard.grab(); - this._mouse.grab(); + + if (!this._view_only) { this._keyboard.grab(); } + if (!this._view_only) { this._mouse.grab(); } if (this._true_color) { this._fb_Bpp = 4; From 7ae53db9cd8ed063b1f603a135949a13129c5004 Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Thu, 1 Sep 2016 15:35:31 +0200 Subject: [PATCH 2/5] Don't request a new desktop size in view_only --- app/ui.js | 8 ++++---- core/rfb.js | 8 +++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/ui.js b/app/ui.js index 52078856..7f9bc04a 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1084,11 +1084,11 @@ var UI; display.set_maxWidth(screen.w); display.set_maxHeight(screen.h); - Util.Debug('Attempting requestDesktopSize(' + - screen.w + ', ' + screen.h + ')'); - // Request a remote size covering the viewport - UI.rfb.requestDesktopSize(screen.w, screen.h); + if (UI.rfb.requestDesktopSize(screen.w, screen.h)) { + Util.Debug('Requested new desktop size: ' + + screen.w + 'x' + screen.h); + } }, 500); } else if (resizeMode === 'scale' || resizeMode === 'downscale') { diff --git a/core/rfb.js b/core/rfb.js index 4a5f4344..7f8ae6d0 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -339,12 +339,18 @@ // Requests a change of remote desktop size. This message is an extension // and may only be sent if we have received an ExtendedDesktopSize message requestDesktopSize: function (width, height) { - if (this._rfb_connection_state !== 'connected') { return; } + if (this._rfb_connection_state !== 'connected' || + this._view_only) { + return; + } if (this._supportsSetDesktopSize) { RFB.messages.setDesktopSize(this._sock, width, height, this._screen_id, this._screen_flags); this._sock.flush(); + return true; + } else { + return false; } }, From 301dc0e20b669a00b8993ff85e3ff17512b217ef Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Thu, 1 Sep 2016 15:36:04 +0200 Subject: [PATCH 3/5] Add logging when creation of RFB fails --- app/ui.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/ui.js b/app/ui.js index 7f9bc04a..c9a43507 100644 --- a/app/ui.js +++ b/app/ui.js @@ -351,7 +351,9 @@ var UI; 'onDesktopName': UI.updateDesktopName}); return true; } catch (exc) { - UI.showStatus('Unable to create RFB client -- ' + exc, 'error'); + var msg = 'Unable to create RFB client -- ' + exc; + Util.Error(msg); + UI.showStatus(msg, 'error'); return false; } }, From ceb847b0e3acb40c68fbc8c801d271965a42a5d3 Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Thu, 1 Sep 2016 15:39:26 +0200 Subject: [PATCH 4/5] Don't modify mouse or keyboard in view_only mode The UI previously didn't respect view_only in a number of cases. --- app/ui.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/app/ui.js b/app/ui.js index c9a43507..50e2400b 100644 --- a/app/ui.js +++ b/app/ui.js @@ -1096,8 +1096,11 @@ var UI; } else if (resizeMode === 'scale' || resizeMode === 'downscale') { var downscaleOnly = resizeMode === 'downscale'; var scaleRatio = display.autoscale(screen.w, screen.h, downscaleOnly); - UI.rfb.get_mouse().set_scale(scaleRatio); - Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale()); + + if (!UI.rfb.get_view_only()) { + UI.rfb.get_mouse().set_scale(scaleRatio); + Util.Debug('Scaling by ' + UI.rfb.get_mouse().get_scale()); + } } } }, @@ -1513,7 +1516,7 @@ var UI; * ------v------*/ setMouseButton: function(num) { - if (UI.rfb) { + if (UI.rfb && !UI.rfb.get_view_only()) { UI.rfb.get_mouse().set_touchButton(num); } @@ -1529,17 +1532,17 @@ var UI; }, displayBlur: function() { - if (!UI.rfb) return; - - UI.rfb.get_keyboard().set_focused(false); - UI.rfb.get_mouse().set_focused(false); + if (UI.rfb && !UI.rfb.get_view_only()) { + UI.rfb.get_keyboard().set_focused(false); + UI.rfb.get_mouse().set_focused(false); + } }, displayFocus: function() { - if (!UI.rfb) return; - - UI.rfb.get_keyboard().set_focused(true); - UI.rfb.get_mouse().set_focused(true); + if (UI.rfb && !UI.rfb.get_view_only()) { + UI.rfb.get_keyboard().set_focused(true); + UI.rfb.get_mouse().set_focused(true); + } }, updateDesktopName: function(rfb, name) { From eef91bf9e3a2e6bba0ebf214f6dc1243460f0cdd Mon Sep 17 00:00:00 2001 From: Samuel Mannehed Date: Fri, 14 Oct 2016 01:44:53 +0200 Subject: [PATCH 5/5] Hide input related buttons in view only --- app/ui.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/ui.js b/app/ui.js index 50e2400b..324119c9 100644 --- a/app/ui.js +++ b/app/ui.js @@ -426,6 +426,19 @@ var UI; UI.keepControlbar(); } + // Hide input related buttons in view only mode + if (UI.rfb && UI.rfb.get_view_only()) { + document.getElementById('noVNC_keyboard_button') + .classList.add('noVNC_hidden'); + document.getElementById('noVNC_toggle_extra_keys_button') + .classList.add('noVNC_hidden'); + } else { + document.getElementById('noVNC_keyboard_button') + .classList.remove('noVNC_hidden'); + document.getElementById('noVNC_toggle_extra_keys_button') + .classList.remove('noVNC_hidden'); + } + // State change disables viewport dragging. // It is enabled (toggled) by direct click on the button UI.setViewDrag(false); @@ -831,7 +844,7 @@ var UI; // Disable/enable XVP button updateXvpButton: function(ver) { - if (ver >= 1) { + if (ver >= 1 && !UI.rfb.get_view_only()) { document.getElementById('noVNC_xvp_button') .classList.remove("noVNC_hidden"); } else { @@ -1516,14 +1529,16 @@ var UI; * ------v------*/ setMouseButton: function(num) { - if (UI.rfb && !UI.rfb.get_view_only()) { + var view_only = UI.rfb.get_view_only(); + if (UI.rfb && !view_only) { UI.rfb.get_mouse().set_touchButton(num); } var blist = [0, 1,2,4]; for (var b = 0; b < blist.length; b++) { - var button = document.getElementById('noVNC_mouse_button' + blist[b]); - if (blist[b] === num) { + var button = document.getElementById('noVNC_mouse_button' + + blist[b]); + if (blist[b] === num && !view_only) { button.classList.remove("noVNC_hidden"); } else { button.classList.add("noVNC_hidden");