Added resize browser mode

This commit is contained in:
XiaoXianNv-boot 2024-09-05 16:03:21 +00:00
parent 047531e886
commit 94021a7d35
3 changed files with 118 additions and 0 deletions

67
NewWindow.html Normal file
View File

@ -0,0 +1,67 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>noVNC</title>
</head>
<body>
<div id="top_bar">
<ul>
<li>
<label for="noVNC_setting_host">Host:</label>
<input id="noVNC_setting_host"></input>
</li>
<li>
<label for="noVNC_setting_port">Port:</label>
<input id="noVNC_setting_port" value="5701"></input>
</li>
<li>
<label for="noVNC_setting_path">Path:</label>
<input id="noVNC_setting_path" type="text" value="websockify">
</li>
<li>
<label for="noVNC_setting_token">token:</label>
<input id="noVNC_setting_token" type="text" value="">
</li>
<li>
<button type="button" onclick="OpenWindow();">Open Window</button>
</li>
</ul>
</div>
<script>
function OpenWindow() {
let rul;
// vnc. html/?token=token&autoconnect=1&resize=browser','_blank','toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420'
rul = "vnc.html?";
path = document.getElementById('noVNC_setting_path').value;
port = document.getElementById('noVNC_setting_port').value;
host = document.getElementById('noVNC_setting_host').value;
token = document.getElementById('noVNC_setting_token').value;
if (token) {
rul += "token=" + token + "&";
}
if (host) {
rul += "host=" + host + "&";
}
if (port) {
rul += "port=" + port + "&";
}
if (path) {
rul += "path=" + path + "&";
}
rul += "autoconnect=" + "1" + "&";
rul += "resize=" + "off";
window.open(rul,
'_blank',
'toolbar=no,location=no,status=no,menubar=no,resizable=yes,width=800,height=420'
);
}
</script>
</body>
</html>

View File

@ -42,6 +42,10 @@ const UI = {
reconnectCallback: null,
reconnectPassword: null,
// Old browser resolution
bodyWidth_browser_resize: 0,
bodyHeight_browser_resize: 0,
prime() {
return WebUtil.initSettings().then(() => {
if (document.readyState === "interactive" || document.readyState === "complete") {
@ -988,6 +992,28 @@ const UI = {
.classList.remove("noVNC_open");
},
_updateBrowserWindows(width, height) {
let bodyWidth = document.body.clientWidth;
let bodyHeight = document.body.clientHeight;
let OldResolutionEqual = false;
if (UI.bodyWidth_browser_resize === document.body.clientWidth &&
UI.bodyHeight_browser_resize === document.body.clientHeight) {
OldResolutionEqual = true;
}
if (UI.bodyHeight_browser_resize === 0 ||
OldResolutionEqual) {
if((width != 0) && (height != 0)) {
window.resizeBy(width - bodyWidth, height - bodyHeight);
UI.bodyWidth_browser_resize = width;
UI.bodyHeight_browser_resize = height;
}
} else {
// disabled
UI.bodyWidth_browser_resize = 0;
}
},
connect(event, password) {
// Ignore when rfb already exists
@ -1058,6 +1084,12 @@ const UI = {
UI.rfb.clipViewport = UI.getSetting('view_clip');
UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale';
UI.rfb.resizeSession = UI.getSetting('resize') === 'remote';
if (UI.getSetting('resize') === 'off') {
UI.bodyHeight_browser_resize = 0;
UI.rfb.resizeBrowser = UI._updateBrowserWindows;
} else {
UI.rfb.resizeBrowser = false;
}
UI.rfb.qualityLevel = parseInt(UI.getSetting('quality'));
UI.rfb.compressionLevel = parseInt(UI.getSetting('compression'));
UI.rfb.showDotCursor = UI.getSetting('show_dot');
@ -1311,6 +1343,12 @@ const UI = {
UI.rfb.scaleViewport = UI.getSetting('resize') === 'scale';
UI.rfb.resizeSession = UI.getSetting('resize') === 'remote';
if (UI.getSetting('resize') === 'off') {
UI.bodyHeight_browser_resize = 0;
UI.rfb.resizeBrowser = UI._updateBrowserWindows;
} else {
UI.rfb.resizeBrowser = false;
}
},
/* ------^-------

View File

@ -294,6 +294,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) {
@ -364,6 +365,14 @@ export default class RFB extends EventTargetMixin {
}
}
get resizeBrowser() { return this._resizeBrowser; }
set resizeBrowser(void_) {
this._resizeBrowser = void_;
if(this._resizeBrowser && (this._rfbConnectionState === 'connected')){
this._resizeBrowser(this._fbWidth, this._fbHeight);
}
}
get showDotCursor() { return this._showDotCursor; }
set showDotCursor(show) {
this._showDotCursor = show;
@ -2875,6 +2884,10 @@ export default class RFB extends EventTargetMixin {
this._fbWidth = width;
this._fbHeight = height;
if (this._resizeBrowser) {
this._resizeBrowser(width, height);
}
this._display.resize(this._fbWidth, this._fbHeight);
// Adjust the visible viewport based on the new dimensions