Skip to content

Commit

Permalink
Fix resizes back to initial remote session size
Browse files Browse the repository at this point in the history
Since the expected client size wasn't updated when the browser window
resized, noVNC didn't resize the canvas properly when going back to
the exact same dimensions.

Fixes issue #1903
  • Loading branch information
samhed committed Dec 27, 2024
1 parent 673cb34 commit e6e03a2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ export default class RFB extends EventTargetMixin {
window.requestAnimationFrame(() => {
this._updateClip();
this._updateScale();
this._saveExpectedClientSize();
});

if (this._resizeSession) {
Expand Down
65 changes: 65 additions & 0 deletions tests/test.rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,28 @@ describe('Remote Frame Buffer protocol client', function () {
container.style.width = '70px';
container.style.height = '80px';
client.scaleViewport = true;

const incoming = [ 0x00, // msg-type=FBU
0x00, // padding
0x00, 0x01, // number of rects = 1
0x00, 0x00, // reason = server initialized
0x00, 0x00, // status = no error
0x00, 0x04, // new width = 4
0x00, 0x04, // new height = 4
0xff, 0xff,
0xfe, 0xcc, // enc = (-308) ExtendedDesktopSize
0x01, // number of screens = 1
0x00, 0x00,
0x00, // padding
0x78, 0x90,
0xab, 0xcd, // screen id = 0
0x00, 0x00, // screen x = 0
0x00, 0x00, // screen y = 0
0x00, 0x04, // screen width = 4
0x00, 0x04, // screen height = 4
0x12, 0x34,
0x56, 0x78]; // screen flags
client._sock._websocket._receiveData(new Uint8Array(incoming));
});

it('should update display scale factor when changing the property', function () {
Expand Down Expand Up @@ -774,6 +796,28 @@ describe('Remote Frame Buffer protocol client', function () {
expect(client._display.autoscale).to.have.been.calledWith(40, 50);
});

it('should update the scaling resized back to initial size', function () {
sinon.spy(client._display, "autoscale");

container.style.width = '40px';
container.style.height = '50px';
fakeResizeObserver.fire();
clock.tick(1000);

expect(client._display.autoscale).to.have.been.calledOnce;
expect(client._display.autoscale).to.have.been.calledWith(40, 50);
client._display.autoscale.resetHistory();

container.style.width = '70px';
container.style.height = '80px';
fakeResizeObserver.fire();
clock.tick(1000);

expect(client._display.autoscale).to.have.been.calledOnce;
expect(client._display.autoscale).to.have.been.calledWith(70, 80);
client._display.autoscale.resetHistory();
});

it('should update the scaling when the remote session resizes', function () {
// Simple ExtendedDesktopSize FBU message
const incoming = [ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
Expand Down Expand Up @@ -941,6 +985,27 @@ describe('Remote Frame Buffer protocol client', function () {
expect(RFB.messages.setDesktopSize).to.not.have.been.called;
});

it('should request a resize when resized back to initial size', function () {
container.style.width = '40px';
container.style.height = '50px';
fakeResizeObserver.fire();
clock.tick(1000);

expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
expect(RFB.messages.setDesktopSize).to.have.been.calledWith(
sinon.match.object, 40, 50, 0x7890abcd, 0x12345678);
RFB.messages.setDesktopSize.resetHistory();

container.style.width = '70px';
container.style.height = '80px';
fakeResizeObserver.fire();
clock.tick(1000);

expect(RFB.messages.setDesktopSize).to.have.been.calledOnce;
expect(RFB.messages.setDesktopSize).to.have.been.calledWith(
sinon.match.object, 70, 80, 0x7890abcd, 0x12345678);
});

it('should not resize until the container size is stable', function () {
container.style.width = '20px';
container.style.height = '30px';
Expand Down

0 comments on commit e6e03a2

Please sign in to comment.