Browse Source

Split the setDesktopSize function (#618)

In order to follow the surrounding coding-standards, the
setDesktopSize client message is split from the public function which
now is called requestDesktopSize().
Samuel 9 years ago
parent
commit
ae11605141
4 changed files with 46 additions and 26 deletions
  1. 39 19
      include/rfb.js
  2. 2 2
      include/ui.js
  3. 4 4
      tests/test.rfb.js
  4. 1 1
      vnc_auto.html

+ 39 - 19
include/rfb.js

@@ -311,28 +311,13 @@ var RFB;
             this._sock.flush();
             this._sock.flush();
         },
         },
 
 
-        setDesktopSize: function (width, height) {
+        requestDesktopSize: function (width, height) {
             if (this._rfb_state !== "normal") { return; }
             if (this._rfb_state !== "normal") { return; }
 
 
             if (this._supportsSetDesktopSize) {
             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);
+                RFB.messages.setDesktopSize(this._sock, width, height,
+                                            this._screen_id, this._screen_flags);
+                this._sock.flush();
             }
             }
         },
         },
 
 
@@ -1340,6 +1325,41 @@ var RFB;
             sock._sQlen += 8 + n;
             sock._sQlen += 8 + n;
         },
         },
 
 
+        setDesktopSize: function (sock, width, height, id, flags) {
+            var buff = sock._sQ;
+            var offset = sock._sQlen;
+
+            buff[offset] = 251;              // msg-type
+            buff[offset + 1] = 0;            // padding
+            buff[offset + 2] = width >> 8;   // width
+            buff[offset + 3] = width;
+            buff[offset + 4] = height >> 8;  // height
+            buff[offset + 5] = height;
+
+            buff[offset + 6] = 1;            // number-of-screens
+            buff[offset + 7] = 0;            // padding
+
+            // screen array
+            buff[offset + 8] = id >> 24;     // id
+            buff[offset + 9] = id >> 16;
+            buff[offset + 10] = id >> 8;
+            buff[offset + 11] = id;
+            buff[offset + 12] = 0;           // x-position
+            buff[offset + 13] = 0;
+            buff[offset + 14] = 0;           // y-position
+            buff[offset + 15] = 0;
+            buff[offset + 16] = width >> 8;  // width
+            buff[offset + 17] = width;
+            buff[offset + 18] = height >> 8; // height
+            buff[offset + 19] = height;
+            buff[offset + 20] = flags >> 24; // flags
+            buff[offset + 21] = flags >> 16;
+            buff[offset + 22] = flags >> 8;
+            buff[offset + 23] = flags;
+
+            sock._sQlen += 24;
+        },
+
         pixelFormat: function (sock, bpp, depth, true_color) {
         pixelFormat: function (sock, bpp, depth, true_color) {
             var buff = sock._sQ;
             var buff = sock._sQ;
             var offset = sock._sQlen;
             var offset = sock._sQlen;

+ 2 - 2
include/ui.js

@@ -263,9 +263,9 @@ var UI;
                     UI.resizeTimeout = setTimeout(function(){
                     UI.resizeTimeout = setTimeout(function(){
                         display.set_maxWidth(size.w);
                         display.set_maxWidth(size.w);
                         display.set_maxHeight(size.h);
                         display.set_maxHeight(size.h);
-                        Util.Debug('Attempting setDesktopSize(' +
+                        Util.Debug('Attempting requestDesktopSize(' +
                                    size.w + ', ' + size.h + ')');
                                    size.w + ', ' + size.h + ')');
-                        UI.rfb.setDesktopSize(size.w, size.h);
+                        UI.rfb.requestDesktopSize(size.w, size.h);
                     }, 500);
                     }, 500);
                 } else if (scaleType === 'scale' || scaleType === 'downscale') {
                 } else if (scaleType === 'scale' || scaleType === 'downscale') {
                     // use local scaling
                     // use local scaling

+ 4 - 4
tests/test.rfb.js

@@ -219,7 +219,7 @@ describe('Remote Frame Buffer Protocol Client', function() {
             });
             });
         });
         });
 
 
-        describe("#setDesktopSize", function () {
+        describe("#requestDesktopSize", function () {
             beforeEach(function() {
             beforeEach(function() {
                 client._sock = new Websock();
                 client._sock = new Websock();
                 client._sock.open('ws://', 'binary');
                 client._sock.open('ws://', 'binary');
@@ -244,19 +244,19 @@ describe('Remote Frame Buffer Protocol Client', function() {
                 expected.push16(2); // height
                 expected.push16(2); // height
                 expected.push32(0); // flags
                 expected.push32(0); // flags
 
 
-                client.setDesktopSize(1, 2);
+                client.requestDesktopSize(1, 2);
                 expect(client._sock).to.have.sent(new Uint8Array(expected));
                 expect(client._sock).to.have.sent(new Uint8Array(expected));
             });
             });
 
 
             it('should not send the request if the client has not recieved a ExtendedDesktopSize rectangle', function () {
             it('should not send the request if the client has not recieved a ExtendedDesktopSize rectangle', function () {
                 client._supportsSetDesktopSize = false;
                 client._supportsSetDesktopSize = false;
-                client.setDesktopSize(1,2);
+                client.requestDesktopSize(1,2);
                 expect(client._sock.flush).to.not.have.been.called;
                 expect(client._sock.flush).to.not.have.been.called;
             });
             });
 
 
             it('should not send the request if we are not in a normal state', function () {
             it('should not send the request if we are not in a normal state', function () {
                 client._rfb_state = "broken";
                 client._rfb_state = "broken";
-                client.setDesktopSize(1,2);
+                client.requestDesktopSize(1,2);
                 expect(client._sock.flush).to.not.have.been.called;
                 expect(client._sock.flush).to.not.have.been.called;
             });
             });
         });
         });

+ 1 - 1
vnc_auto.html

@@ -92,7 +92,7 @@
                 var controlbarH = $D('noVNC_status_bar').offsetHeight;
                 var controlbarH = $D('noVNC_status_bar').offsetHeight;
                 var padding = 5;
                 var padding = 5;
                 if (innerW !== undefined && innerH !== undefined)
                 if (innerW !== undefined && innerH !== undefined)
-                    rfb.setDesktopSize(innerW, innerH - controlbarH - padding);
+                    rfb.requestDesktopSize(innerW, innerH - controlbarH - padding);
             }
             }
         }
         }
         function FBUComplete(rfb, fbu) {
         function FBUComplete(rfb, fbu) {