[pve-devel] [PATCH 1/2] implement autoresize first try
Alexandre Derumier
aderumier at odiso.com
Wed Jun 24 03:27:46 CEST 2015
bump to f675e03cccc5ac6a7f68e992331403ba557b0452 commit
port resize ui https://github.com/kanaka/noVNC/commit/f8b399d7dfb180f2e173b3cc567a4ad543dda655
don't work currently, maybe some changes needed to match proxmox ui
after this one, they are another patch which seem good:
"Support local scaling"
https://github.com/kanaka/noVNC/commit/72747869a7a95b72d26914508ce8ec5670eecc5b
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
Makefile | 5 ++-
pveui.js | 119 +++++++++++++++++++++++++++++++--------------------------------
2 files changed, 63 insertions(+), 61 deletions(-)
diff --git a/Makefile b/Makefile
index 877b203..8c2e441 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,10 @@ deb ${DEB}: ${TARSRC}
.PHONY: download
download:
rm -rf ${NOVNCDIR}
- git clone --branch v${NOVNCVER} git://github.com/kanaka/noVNC ${NOVNCDIR}
+ git clone git://github.com/kanaka/noVNC ${NOVNCDIR}
+ cd ${NOVNCDIR}
+ git checkout f675e03cccc5ac6a7f68e992331403ba557b0452
+ cd ..
tar czf ${NOVNCSRC} ${NOVNCDIR}
.PHONY: upload
diff --git a/pveui.js b/pveui.js
index acf84ac..9bc12f5 100644
--- a/pveui.js
+++ b/pveui.js
@@ -18,6 +18,7 @@ window.onload = function () { UI.keyboardinputReset(); };
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
"keysymdef.js", "keyboard.js", "input.js", "display.js",
"jsunzip.js", "rfb.js", "keysym.js"]);
+var resizeTimeout;
var UI = {
@@ -511,6 +512,7 @@ pve_start: function(callback) {
UI.updateSetting('cursor', !UI.isTouchDevice);
UI.updateSetting('shared', true);
UI.updateSetting('view_only', false);
+ UI.updateSetting('resize', true);
UI.updateSetting('path', 'api2/json' + wsurl + "?" + wsparams);
@@ -534,54 +536,6 @@ lastFBWidth: undefined,
lastFBHeight: undefined,
sizeUpdateTimer: undefined,
-updateFBSize: function(rfb, width, height) {
- try {
- // Note1: CSS Canvas size is wrong by a few pixels in Chrome
- // Note2: window size must be even number for firefox
- UI.lastFBWidth = Math.floor((width + 1)/2)*2;;
- UI.lastFBHeight = Math.floor((height + 6)/2)*2;
-
- if (UI.sizeUpdateTimer !== undefined) {
- clearInterval(UI.sizeUpdateTimer);
- }
- if (UI.getSetting('clip')) return;
-
- var update_size = function() {
- var oh;
- var ow;
-
- if (window.innerHeight) {
- oh = window.innerHeight;
- ow = window.innerWidth;
- } else if (document.documentElement &&
- document.documentElement.clientHeight) {
- oh = document.documentElement.clientHeight;
- ow = document.documentElement.clientWidth;
- } else if (document.body) {
- oh = document.body.clientHeight;
- ow = document.body.clientWidth;
- } else {
- throw "can't get window size";
- }
-
- // see base.css/noVNC_screen_pad
- var toolbar_height = 36;
-
- var offsetw = UI.lastFBWidth - ow;
- var offseth = UI.lastFBHeight + toolbar_height - oh;
- if (offsetw !== 0 || offseth !== 0) {
- //console.log("try resize by " + offsetw + " " + offseth);
- window.resizeBy(offsetw, offseth);
- }
- };
-
- update_size();
- UI.sizeUpdateTimer = setInterval(update_size, 1000);
-
- } catch(e) {
- console.log(e);
- }
-},
// Open/close PVE commandand menu
togglePVECommandPanel: function() {
@@ -651,6 +605,18 @@ togglePVESendKeysPanel: function() {
}
},
+onresize: function (callback) {
+ if (UI.getSetting('resize')) {
+ var innerW = window.innerWidth;
+ var innerH = window.innerHeight;
+ var controlbarH = $D('noVNC-control-bar').offsetHeight;
+ // For some unknown reason the container is higher than the canvas,
+ // 5px higher in Firefox and 4px higher in Chrome
+ var padding = 5;
+ if (innerW !== undefined && innerH !== undefined)
+ UI.rfb.setDesktopSize(innerW, innerH - controlbarH - padding);
+ }
+},
// Render default UI and initialize settings menu
start: function(callback) {
var html = '', i, sheet, sheets, llevels, port, autoconnect;
@@ -687,7 +653,8 @@ start: function(callback) {
'onXvpInit': UI.updateXvpVisualState,
'onClipboard': UI.clipReceive,
//'onDesktopName': UI.updateDocumentTitle,
- 'onFBResize': UI.updateFBSize});
+ 'onFBUComplete': UI.FBUComplete,
+ 'onFBResize': UI.updateViewDragButton});
autoconnect = true;
if (autoconnect === 'true' || autoconnect == '1') {
@@ -716,7 +683,6 @@ start: function(callback) {
// Remove the address bar
setTimeout(function() { window.scrollTo(0, 1); }, 100);
UI.forceSetting('clip', true);
- $D('noVNC_clip').disabled = true;
} else {
$D('showSendKeysButton').style.display = (UI.consoletype === 'kvm') ? "inline" : "none";
UI.initSetting('clip', false);
@@ -735,8 +701,18 @@ start: function(callback) {
$D('noVNC_host').focus();
UI.setViewClip();
- Util.addEvent(window, 'resize', UI.setViewClip);
+ Util.addEvent(window, 'resize', function () {
+ UI.setViewClip();
+ // When the window has been resized, wait until the size remains
+ // the same for 0.5 seconds before sending the request for changing
+ // the resolution of the session
+ clearTimeout(resizeTimeout);
+ resizeTimeout = setTimeout(function(){
+ UI.onresize();
+ }, 500);
+ } );
+
Util.addEvent(window, 'beforeunload', function () {
if (UI.rfb_state === 'normal') {
return "You are currently connected.";
@@ -813,7 +789,7 @@ addMouseHandlers: function() {
getSetting: function(name) {
var val, ctrl = $D('noVNC_' + name);
val = WebUtil.readSetting(name);
- if (val !== null && ctrl.type === 'checkbox') {
+ if (typeof val !== 'undefined' && val !== null && ctrl.type === 'checkbox') {
if (val.toString().toLowerCase() in {'0':1, 'no':1, 'false':1}) {
val = false;
} else {
@@ -1043,6 +1019,7 @@ toggleSettingsPanel: function() {
$D('noVNC_cursor').disabled = true;
}
UI.updateSetting('clip');
+ UI.updateSetting('resize');
UI.updateSetting('shared');
UI.updateSetting('view_only');
UI.updateSetting('path');
@@ -1098,6 +1075,7 @@ settingsApply: function() {
UI.saveSetting('cursor');
}
UI.saveSetting('clip');
+ UI.saveSetting('resize');
UI.saveSetting('shared');
UI.saveSetting('view_only');
UI.saveSetting('path');
@@ -1226,6 +1204,8 @@ updateVisualState: function() {
UI.updateSetting('cursor', !UI.isTouchDevice);
$D('noVNC_cursor').disabled = true;
}
+ $D('noVNC_clip').disabled = connected || UI.isTouchDevice;
+ $D('noVNC_resize').disabled = connected;
$D('noVNC_shared').disabled = connected;
$D('noVNC_view_only').disabled = connected;
$D('noVNC_path').disabled = connected;
@@ -1280,6 +1260,15 @@ updateXvpVisualState: function(ver) {
}
},
+// This resize can not be done until we know from the first Frame Buffer Update
+// if it is supported or not.
+// The resize is needed to make sure the server desktop size is updated to the
+// corresponding size of the current local window when reconnecting to an
+// existing session.
+FBUComplete: function(rfb, fbu) {
+ UI.onresize();
+ UI.rfb.set_onFBUComplete(function() { });
+},
// Display the desktop name in the document title
updateDocumentTitle: function(rfb, name) {
@@ -1326,6 +1315,9 @@ disconnect: function() {
UI.closeSettingsMenu();
UI.rfb.disconnect();
+ // Restore the callback used for initial resize
+ UI.rfb.set_onFBUComplete(UI.FBUComplete);
+
$D('noVNC_logo').style.display = "block";
UI.connSettingsOpen = false;
UI.toggleConnectPanel();
@@ -1379,7 +1371,7 @@ setViewClip: function(clip) {
UI.updateSetting('clip', false);
display.set_viewport(false);
$D('noVNC_canvas').style.position = 'static';
- display.viewportChange();
+ display.viewportChangeSize();
}
if (UI.getSetting('clip')) {
// If clipping, update clipping settings
@@ -1394,21 +1386,17 @@ setViewClip: function(clip) {
// Toggle/set/unset the viewport drag/move button
setViewDrag: function(drag) {
- var vmb = $D('noVNC_view_drag_button');
+
if (!UI.rfb) { return; }
- if (UI.rfb_state === 'normal' &&
- UI.rfb.get_display().get_viewport()) {
- vmb.style.display = "inline";
- } else {
- vmb.style.display = "none";
- }
+ UI.updateViewDragButton();
if (typeof(drag) === "undefined" ||
typeof(drag) === "object") {
// If not specified, then toggle
drag = !UI.rfb.get_viewportDrag();
}
+ var vmb = $D('noVNC_view_drag_button');
if (drag) {
vmb.className = "noVNC_status_button_selected";
UI.rfb.set_viewportDrag(true);
@@ -1418,6 +1406,17 @@ setViewDrag: function(drag) {
}
},
+updateViewDragButton: function() {
+ var vmb = $D('noVNC_view_drag_button');
+ if (UI.rfb_state === 'normal' &&
+ UI.rfb.get_display().get_viewport() &&
+ UI.rfb.get_display().fbuClip()) {
+ vmb.style.display = "inline";
+ } else {
+ vmb.style.display = "none";
+ }
+},
+
// On touch devices, show the OS keyboard
showKeyboard: function() {
var kbi, skb, l;
--
2.1.4
More information about the pve-devel
mailing list