diff --git a/include/rfb.js b/include/rfb.js index d9137370..6c6bc3f5 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -63,7 +63,8 @@ var that = {}, // Public API methods //['JPEG_quality_hi', -23 ], //['compress_lo', -255 ], ['compress_hi', -247 ], - ['last_rect', -224 ] + ['last_rect', -224 ], + ['ext_desktop_size', -308 ] ], encHandlers = {}, @@ -120,6 +121,10 @@ var that = {}, // Public API methods test_mode = false, + supportsSetDesktopSize = false, + screen_id = 0, + screen_flags = 0, + def_con_timeout = Websock_native ? 2 : 5, /* Mouse state */ @@ -1585,6 +1590,45 @@ encHandlers.last_rect = function last_rect() { 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> set_desktopsize"); fb_width = FBU.width; @@ -1847,6 +1891,31 @@ that.clipboardPasteFrom = function(text) { //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 that.testMode = function(override_send, data_mode) { test_mode = true; diff --git a/include/ui.js b/include/ui.js index 3387567a..4c06fce2 100644 --- a/include/ui.js +++ b/include/ui.js @@ -10,8 +10,12 @@ /*jslint white: false, browser: true */ /*global window, $D, Util, WebUtil, RFB, Display */ +var resizeTimeout; + // Load supporting scripts window.onscriptsload = function () { UI.load(); }; +window.onresize = function () { UI.onresize(); }; + Util.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js", "input.js", "display.js", "jsunzip.js", "rfb.js"]); @@ -29,6 +33,19 @@ load: function (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 start: function(callback) { var html = '', i, sheet, sheets, llevels, port; @@ -445,6 +462,11 @@ updateState: function(rfb, state, oldstate, msg) { klass = "noVNC_status_error"; break; 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"; break; case 'disconnected':