Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support the 'ExtendedDesktopSize' and the 'SetDesktopSize' encodings #271

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0bb4537
automatically resizes the noVNC session to fit the browser window, so…
samhed Jun 20, 2013
b0871c1
fixed some errors in the logic from my last commit, also some minor i…
samhed Jun 25, 2013
bcf3b08
Additional fixes for the code in my previous commits:
samhed Jul 2, 2013
9a6bcce
Merge branch 'master' of https://github.com/kanaka/noVNC
samhed Jul 19, 2013
4579940
Merge branch 'master' of https://github.com/kanaka/noVNC
samhed Jul 24, 2013
01f9d2e
Merge branch 'master' of https://github.com/kanaka/noVNC
samhed Aug 30, 2013
21256e9
Small fix for deducting the correct number of pixels from the height …
samhed Aug 30, 2013
359f88a
Fixed a bug which sometimes occured on touch devices.
samhed Sep 10, 2013
0ac6c31
Added the automatic resize functionality for vnc_auto.html.
samhed Sep 11, 2013
af82a2c
Merge branch 'master' of https://github.com/kanaka/noVNC
samhed Oct 10, 2013
e894bf7
TESTING, TO BE REMOVED
samhed Nov 12, 2013
6f4310e
Revert "TESTING, TO BE REMOVED"
samhed Jan 22, 2015
9ae9fde
Merge to keep up to date with upstream
samhed Jan 22, 2015
8bb048c
Make sure to take the clipping setting into account and do show scrol…
samhed Jan 22, 2015
dd54a45
Fixed merge-errors
samhed Jan 22, 2015
1f57d1e
Hide the view_drag_button (the hand) when the display area is the sam…
samhed Jan 22, 2015
87002c8
Split viewportChange into viewportChangePos and viewportChangeSize to…
samhed Jan 23, 2015
9b9ead6
removed duplicate code in vnc_auto
samhed Jan 23, 2015
9891d8a
noVNC-control-bar doesn't exist in vnc_auto.html, check noVNC_status_…
samhed Jan 23, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ that.absY = function(y) {


that.resize = function(width, height) {
c_prevStyle = "";
c_prevStyle = "";

fb_width = width;
fb_height = height;

rescale(conf.scale);
that.viewportChange();
that.viewportChange(0, 0, width, height);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems this change breaks the viewport pan function.. @kanaka do you have a quick explanation? Otherwise I will keep digging.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's doesn't work on my project,i used libvirt in centos,javascript in the browser,i just can't let the vnc's width&height follow the browser change.could u help me?thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. first of all you need a VNC server which supports the ExtendedDesktopSize encoding. Then you need the functionality that this PR is supposed to give. As I mentioned here, this function works but sadly it breaks the viewport pan function.

};

that.clear = function() {
Expand Down
73 changes: 72 additions & 1 deletion include/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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 = {},
Expand Down Expand Up @@ -121,6 +122,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 */
Expand Down Expand Up @@ -1589,6 +1594,47 @@ encHandlers.last_rect = function last_rect() {
return true;
};

encHandlers.ext_desktop_size = function () {
FBU.bytes = 1;
if (ws.rQwait("ext_desktop_size", FBU.bytes)) { return false; }

supportsSetDesktopSize = true;
var number_of_screens = ws.rQpeek8();

FBU.bytes = 4 + (number_of_screens * 16);
if (ws.rQwait("ext_desktop_size", FBU.bytes)) { return false; }

ws.rQshift8(); // number-of-screens
ws.rQshift8(); // padding
ws.rQshift16(); // padding

for (var i=0; i<number_of_screens; i += 1) {
// Save the id and flags of the first screen
if (i == 0) {
screen_id = ws.rQshift32(); // id
ws.rQshift16(); // x-position
ws.rQshift16(); // y-position
ws.rQshift16(); // width
ws.rQshift16(); // height
screen_flags = ws.rQshift32(); // flags
} else {
ws.rQshiftBytes(16);
}
}

if (FBU.x == 0 && FBU.y != 0) { return true; }

fb_width = FBU.width;
fb_height = FBU.height;
conf.onFBResize(that, fb_width, fb_height);
display.resize(fb_width, fb_height);

FBU.bytes = 0;
FBU.rects -= 1;

return true;
};

encHandlers.DesktopSize = function set_desktopsize() {
Util.Debug(">> set_desktopsize");
fb_width = FBU.width;
Expand Down Expand Up @@ -1851,6 +1897,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;
Expand Down
30 changes: 30 additions & 0 deletions include/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,20 @@
/*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 () {
// 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.load_scripts(["webutil.js", "base64.js", "websock.js", "des.js",
"input.js", "display.js", "jsunzip.js", "rfb.js"]);

Expand All @@ -32,6 +44,12 @@ load: function (callback) {
WebUtil.initSettings(UI.start, callback);
},

onresize: function (callback) {
// Control-bar height: 36px +
// border height: 5px = 41px to be deducted from the height
UI.rfb.setDesktopSize(window.innerWidth, window.innerHeight - 41);
},

// Render default UI and initialize settings menu
start: function(callback) {
var html = '', i, sheet, sheets, llevels, port, autoconnect;
Expand Down Expand Up @@ -88,6 +106,7 @@ start: function(callback) {
UI.rfb = RFB({'target': $D('noVNC_canvas'),
'onUpdateState': UI.updateState,
'onClipboard': UI.clipReceive,
'onFBUComplete': UI.FBUComplete,
'onDesktopName': UI.updateDocumentTitle});

autoconnect = WebUtil.getQueryVar('autoconnect', false);
Expand Down Expand Up @@ -576,6 +595,17 @@ updateVisualState: function() {
},


// 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) {
onresize();
UI.rfb.set_onFBUComplete(function() { });
},


// Display the desktop name in the document title
updateDocumentTitle: function(rfb, name) {
document.title = name + " - noVNC";
Expand Down
24 changes: 23 additions & 1 deletion vnc_auto.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,18 @@
"input.js", "display.js", "jsunzip.js", "rfb.js"]);

var rfb;
var resizeTimeout;


function UIresize() {
// Control-bar height: 36px +
// border height: 5px = 41px to be deducted from the height
rfb.setDesktopSize(window.innerWidth, window.innerHeight - 41);
}
function FBUComplete(rfb, fbu) {
UIresize();
rfb.set_onFBUComplete(function() { });
}
function passwordRequired(rfb) {
var msg;
msg = '<form onsubmit="return setPassword();"';
Expand Down Expand Up @@ -113,6 +124,16 @@
}
}

window.onresize = function () {
// 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(){
UIresize();
}, 500);
};

window.onscriptsload = function () {
var host, port, password, path, token;

Expand Down Expand Up @@ -161,7 +182,8 @@
'shared': WebUtil.getQueryVar('shared', true),
'view_only': WebUtil.getQueryVar('view_only', false),
'updateState': updateState,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should still be onUpdateState (otherwise the status bar doesn't function correctly)

'onPasswordRequired': passwordRequired});
'onPasswordRequired': passwordRequired,
'onFBUComplete': FBUComplete});
rfb.connect(host, port, password, path);
};
</script>
Expand Down