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

New zoom mode to resize the browser #1849

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/locale/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"None": "无",
"Local Scaling": "本地缩放",
"Remote Resizing": "远程调整大小",
"Resizing browser": "调整浏览器大小",
"Advanced": "高级",
"Repeater ID:": "中继站 ID",
"WebSocket": "WebSocket",
Expand Down
13 changes: 12 additions & 1 deletion app/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ const UI = {
UI.rfb.clipViewport = UI.getSetting('view_clip');
UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale';
UI.rfb.resizeSession = UI.getSetting('resize') === 'remote';
UI.rfb.resizeBrowser = UI.getSetting('resize') === 'browser';
UI.rfb.qualityLevel = parseInt(UI.getSetting('quality'));
UI.rfb.compressionLevel = parseInt(UI.getSetting('compression'));
UI.rfb.showDotCursor = UI.getSetting('show_dot');
Expand Down Expand Up @@ -1319,6 +1320,7 @@ const UI = {

UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale';
UI.rfb.resizeSession = UI.getSetting('resize') === 'remote';
UI.rfb.resizeBrowser = UI.getSetting('resize') === 'browser';
},

/* ------^-------
Expand Down Expand Up @@ -1360,7 +1362,16 @@ const UI = {
UI.enableSetting('view_clip');
UI.rfb.clipViewport = UI.getSetting('view_clip');
}


// Determines whether it is a window.open window
// as window.open(\'/vnc/?token=token&autoconnect=1&resize=browser\',\'_blank\',\'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420\');
var win = window.opener;
if(win == null){
document.getElementById("noVNC_setting_browser_resize").disabled = true;
}else{
document.getElementById("noVNC_setting_browser_resize").disabled = false;
}

// Changing the viewport may change the state of
// the dragging button
UI.updateViewDrag();
Expand Down
23 changes: 23 additions & 0 deletions core/rfb.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export default class RFB extends EventTargetMixin {
this._clippingViewport = false;
this._scaleViewport = false;
this._resizeSession = false;
this._resizeBrowser = false;

this._showDotCursor = false;
if (options.showDotCursor !== undefined) {
Expand Down Expand Up @@ -352,6 +353,14 @@ export default class RFB extends EventTargetMixin {
}
}

get resizeBrowser() { return this._resizeBrowser; }
set resizeBrowser(resize) {
this._resizeBrowser = resize;
if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){
this._updateBrowserWindows(this._fbWidth, this._fbHeight);
}
}

get resizeSession() { return this._resizeSession; }
set resizeSession(resize) {
this._resizeSession = resize;
Expand Down Expand Up @@ -2863,9 +2872,23 @@ export default class RFB extends EventTargetMixin {
this._fbWidth, this._fbHeight);
}

_updateBrowserWindows(width, height) {
if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){
var fbWidth = width;
var fbHeight = height;
var bodyWidth = document.body.clientWidth;
var bodyHeight = document.body.clientHeight;
if((fbWidth != 0) && (fbHeight != 0)){
window.resizeBy(fbWidth - bodyWidth,fbHeight - bodyHeight);
}
}
}

_resize(width, height) {
this._fbWidth = width;
this._fbHeight = height;

this._updateBrowserWindows(width, height);

this._display.resize(this._fbWidth, this._fbHeight);

Expand Down
1 change: 1 addition & 0 deletions vnc.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ <h1 class="noVNC_logo" translate="no"><span>no</span><br>VNC</h1>
<option value="off">None</option>
<option value="scale">Local Scaling</option>
<option value="remote">Remote Resizing</option>
<option value="browser" disabled="" id="noVNC_setting_browser_resize">Resizing browser</option>
</select>
</li>
<li><hr></li>
Expand Down