automatically resizes the noVNC session to fit the browser window, somewhat related to noVNC issue #117
This commit is contained in:
parent
8f12ca7a5a
commit
0bb4537529
|
|
@ -63,7 +63,8 @@ var that = {}, // Public API methods
|
||||||
//['JPEG_quality_hi', -23 ],
|
//['JPEG_quality_hi', -23 ],
|
||||||
//['compress_lo', -255 ],
|
//['compress_lo', -255 ],
|
||||||
['compress_hi', -247 ],
|
['compress_hi', -247 ],
|
||||||
['last_rect', -224 ]
|
['last_rect', -224 ],
|
||||||
|
['ext_desktop_size', -308 ]
|
||||||
],
|
],
|
||||||
|
|
||||||
encHandlers = {},
|
encHandlers = {},
|
||||||
|
|
@ -120,6 +121,10 @@ var that = {}, // Public API methods
|
||||||
|
|
||||||
test_mode = false,
|
test_mode = false,
|
||||||
|
|
||||||
|
supportsSetDesktopSize = false,
|
||||||
|
screen_id = 0,
|
||||||
|
screen_flags = 0,
|
||||||
|
|
||||||
def_con_timeout = Websock_native ? 2 : 5,
|
def_con_timeout = Websock_native ? 2 : 5,
|
||||||
|
|
||||||
/* Mouse state */
|
/* Mouse state */
|
||||||
|
|
@ -1585,6 +1590,45 @@ encHandlers.last_rect = function last_rect() {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
encHandlers.ext_desktop_size = function () {
|
||||||
|
//Util.Debug(">> ext_desktop_size");
|
||||||
|
if (ws.rQwait("ext_desktop_size", 4)) { return false; }
|
||||||
|
|
||||||
|
var number_of_screens = ws.rQshift8();
|
||||||
|
|
||||||
|
ws.rQshift8(); // padding
|
||||||
|
ws.rQshift16(); // padding
|
||||||
|
|
||||||
|
for (var i=0; i<number_of_screens; i += 1) {
|
||||||
|
screen_id = ws.rQshift32(); // id
|
||||||
|
ws.rQshift16(); // x-position
|
||||||
|
ws.rQshift16(); // y-position
|
||||||
|
ws.rQshift16(); // width
|
||||||
|
ws.rQshift16(); // height
|
||||||
|
screen_flags = ws.rQshift32(); // flags
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FBU.x == 0) {
|
||||||
|
fb_width = FBU.width;
|
||||||
|
fb_height = FBU.height;
|
||||||
|
conf.onFBResize(that, fb_width, fb_height);
|
||||||
|
display.resize(fb_width, fb_height);
|
||||||
|
timing.fbu_rt_start = (new Date()).getTime();
|
||||||
|
// Send a new non-incremental request
|
||||||
|
ws.send(fbUpdateRequests());
|
||||||
|
|
||||||
|
if (FBU.y == 0) {
|
||||||
|
supportsSetDesktopSize = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FBU.bytes = 0;
|
||||||
|
FBU.rects -= 1;
|
||||||
|
|
||||||
|
//Util.Debug("<< ext_desktop_size");
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
encHandlers.DesktopSize = function set_desktopsize() {
|
encHandlers.DesktopSize = function set_desktopsize() {
|
||||||
Util.Debug(">> set_desktopsize");
|
Util.Debug(">> set_desktopsize");
|
||||||
fb_width = FBU.width;
|
fb_width = FBU.width;
|
||||||
|
|
@ -1847,6 +1891,31 @@ that.clipboardPasteFrom = function(text) {
|
||||||
//Util.Debug("<< clipboardPasteFrom");
|
//Util.Debug("<< clipboardPasteFrom");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.setDesktopSize = function(width, height) {
|
||||||
|
if (rfb_state !== "normal") { return; }
|
||||||
|
|
||||||
|
if (supportsSetDesktopSize) {
|
||||||
|
|
||||||
|
var arr = [251]; // msg-type
|
||||||
|
arr.push8(0); // padding
|
||||||
|
arr.push16(width); // width
|
||||||
|
arr.push16(height); // height
|
||||||
|
|
||||||
|
arr.push8(1); // number-of-screens
|
||||||
|
arr.push8(0); // padding
|
||||||
|
|
||||||
|
// screen array
|
||||||
|
arr.push32(screen_id); // id
|
||||||
|
arr.push16(0); // x-position
|
||||||
|
arr.push16(0); // y-position
|
||||||
|
arr.push16(width); // width
|
||||||
|
arr.push16(height); // height
|
||||||
|
arr.push32(screen_flags); // flags
|
||||||
|
|
||||||
|
ws.send(arr);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Override internal functions for testing
|
// Override internal functions for testing
|
||||||
that.testMode = function(override_send, data_mode) {
|
that.testMode = function(override_send, data_mode) {
|
||||||
test_mode = true;
|
test_mode = true;
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,12 @@
|
||||||
/*jslint white: false, browser: true */
|
/*jslint white: false, browser: true */
|
||||||
/*global window, $D, Util, WebUtil, RFB, Display */
|
/*global window, $D, Util, WebUtil, RFB, Display */
|
||||||
|
|
||||||
|
var resizeTimeout;
|
||||||
|
|
||||||
// Load supporting scripts
|
// Load supporting scripts
|
||||||
window.onscriptsload = function () { UI.load(); };
|
window.onscriptsload = function () { UI.load(); };
|
||||||
|
window.onresize = function () { UI.onresize(); };
|
||||||
|
|
||||||
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
|
Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
|
||||||
"input.js", "display.js", "jsunzip.js", "rfb.js"]);
|
"input.js", "display.js", "jsunzip.js", "rfb.js"]);
|
||||||
|
|
||||||
|
|
@ -29,6 +33,19 @@ load: function (callback) {
|
||||||
WebUtil.initSettings(UI.start, callback);
|
WebUtil.initSettings(UI.start, callback);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 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
|
||||||
|
onresize: function (callback) {
|
||||||
|
clearTimeout(resizeTimeout);
|
||||||
|
resizeTimeout = setTimeout(function(){
|
||||||
|
// Control-bar height: 44px +
|
||||||
|
// Status-bar height: 24px +
|
||||||
|
// border height: 5px = 73px to be deducted from the height
|
||||||
|
UI.rfb.setDesktopSize(window.innerWidth, window.innerHeight - 73);
|
||||||
|
}, 500);
|
||||||
|
},
|
||||||
|
|
||||||
// Render default UI and initialize settings menu
|
// Render default UI and initialize settings menu
|
||||||
start: function(callback) {
|
start: function(callback) {
|
||||||
var html = '', i, sheet, sheets, llevels, port;
|
var html = '', i, sheet, sheets, llevels, port;
|
||||||
|
|
@ -445,6 +462,11 @@ updateState: function(rfb, state, oldstate, msg) {
|
||||||
klass = "noVNC_status_error";
|
klass = "noVNC_status_error";
|
||||||
break;
|
break;
|
||||||
case 'normal':
|
case 'normal':
|
||||||
|
// When reconnecting to an existing session,
|
||||||
|
// make sure the resolution is updated to the window size
|
||||||
|
if (oldstate === 'ServerInitialisation') {
|
||||||
|
onresize();
|
||||||
|
}
|
||||||
klass = "noVNC_status_normal";
|
klass = "noVNC_status_normal";
|
||||||
break;
|
break;
|
||||||
case 'disconnected':
|
case 'disconnected':
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue