From b0ec6509f11469569c438e5f5e4300e6a1ce4dad Mon Sep 17 00:00:00 2001 From: samhed Date: Fri, 6 Feb 2015 17:06:48 +0100 Subject: [PATCH] Support automatic resize [Part 2/4]: rfb.js * Support sending the setDesktopSize encoding (client -> server) * Support recieving the ExtendedDesktopSize encoding (server <- client) --- include/rfb.js | 79 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/include/rfb.js b/include/rfb.js index 559eccbc..03d4b816 100644 --- a/include/rfb.js +++ b/include/rfb.js @@ -53,7 +53,8 @@ var RFB; //['compress_lo', -255 ], ['compress_hi', -247 ], ['last_rect', -224 ], - ['xvp', -309 ] + ['xvp', -309 ], + ['ext_desktop_size', -308 ] ]; this._encHandlers = {}; @@ -106,6 +107,10 @@ var RFB; pixels: 0 }; + this._supportsSetDesktopSize = false; + this._screen_id = 0; + this._screen_flags = 0; + // Mouse state this._mouse_buttonMask = 0; this._mouse_arr = []; @@ -305,6 +310,32 @@ var RFB; this._sock.send(RFB.messages.clientCutText(text)); }, + setDesktopSize: function (width, height) { + if (this._rfb_state !== "normal") { return; } + + if (this._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(this._screen_id); // id + arr.push16(0); // x-position + arr.push16(0); // y-position + arr.push16(width); // width + arr.push16(height); // height + arr.push32(this._screen_flags); // flags + + this._sock.send(arr); + } + }, + + // Private methods _connect: function () { @@ -585,7 +616,7 @@ var RFB; var deltaY = this._viewportDragPos.y - y; this._viewportDragPos = {'x': x, 'y': y}; - this._display.viewportChange(deltaX, deltaY); + this._display.viewportChangePos(deltaX, deltaY); // Skip sending mouse events return; @@ -944,8 +975,8 @@ var RFB; } this._display.set_true_color(this._true_color); - this._onFBResize(this, this._fb_width, this._fb_height); this._display.resize(this._fb_width, this._fb_height); + this._onFBResize(this, this._fb_width, this._fb_height); this._keyboard.grab(); this._mouse.grab(); @@ -1839,12 +1870,52 @@ var RFB; return true; }, + ext_desktop_size: function () { + this._FBU.bytes = 1; + if (this._sock.rQwait("ext_desktop_size", this._FBU.bytes)) { return false; } + + this._supportsSetDesktopSize = true; + var number_of_screens = this._sock.rQpeek8(); + + this._FBU.bytes = 4 + (number_of_screens * 16); + if (this._sock.rQwait("ext_desktop_size", this._FBU.bytes)) { return false; } + + this._sock.rQskipBytes(1); // number-of-screens + this._sock.rQskipBytes(3); // padding + + for (var i=0; i> set_desktopsize"); this._fb_width = this._FBU.width; this._fb_height = this._FBU.height; - this._onFBResize(this, this._fb_width, this._fb_height); this._display.resize(this._fb_width, this._fb_height); + this._onFBResize(this, this._fb_width, this._fb_height); this._timing.fbu_rt_start = (new Date()).getTime(); this._FBU.bytes = 0;