mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-09 22:51:22 +00:00
Add auto-fit setting, update property before calling onchange.
This commit is contained in:
@@ -367,18 +367,34 @@ GuacamoleUI.attach = function(guac) {
|
||||
// Enable keyboard by default
|
||||
enableKeyboard();
|
||||
|
||||
function updateDisplayScale() {
|
||||
|
||||
console.log(state.getProperty("auto-fit"));
|
||||
|
||||
// If auto-fit is enabled, scale display
|
||||
if (state.getProperty("auto-fit")) {
|
||||
|
||||
// Calculate scale to fit screen
|
||||
var fit_scale = Math.min(
|
||||
window.innerWidth / guac.getWidth(),
|
||||
window.innerHeight / guac.getHeight()
|
||||
);
|
||||
|
||||
// Scale client
|
||||
if (fit_scale != guac.getScale())
|
||||
guac.scale(fit_scale);
|
||||
|
||||
}
|
||||
|
||||
// Otherwise, scale to 100%
|
||||
else if (guac.getScale() != 1.0)
|
||||
guac.scale(1.0);
|
||||
|
||||
}
|
||||
|
||||
// Handle resize
|
||||
guac.onresize = function(width, height) {
|
||||
|
||||
// Calculate scale to fit screen
|
||||
var fit_scale = Math.min(
|
||||
window.innerWidth / width,
|
||||
window.innerHeight / height
|
||||
);
|
||||
|
||||
// Scale client
|
||||
guac.scale(fit_scale);
|
||||
|
||||
updateDisplayScale();
|
||||
}
|
||||
|
||||
// Handle client state change
|
||||
@@ -472,15 +488,7 @@ GuacamoleUI.attach = function(guac) {
|
||||
window.onresize = function() {
|
||||
|
||||
guac.sendSize(window.innerWidth, window.innerHeight);
|
||||
|
||||
// Calculate scale to fit screen
|
||||
var fit_scale = Math.min(
|
||||
window.innerWidth / guac.getWidth(),
|
||||
window.innerHeight / guac.getHeight()
|
||||
);
|
||||
|
||||
// Scale client
|
||||
guac.scale(fit_scale);
|
||||
updateDisplayScale();
|
||||
|
||||
};
|
||||
|
||||
@@ -492,6 +500,9 @@ GuacamoleUI.attach = function(guac) {
|
||||
state.onchange = function(old_state, new_state, name) {
|
||||
if (name == "clipboard")
|
||||
guac.setClipboard(new_state[name]);
|
||||
else if (name == "auto-fit")
|
||||
updateDisplayScale();
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
@@ -44,11 +44,15 @@ function GuacamoleSessionState() {
|
||||
// Pull current state
|
||||
var new_state = JSON.parse(localStorage.getItem("GUACAMOLE_STATE") || "{}");
|
||||
|
||||
// Check if value is different
|
||||
// Assign new state
|
||||
var old_state = state;
|
||||
state = new_state;
|
||||
|
||||
// Check if any values are different
|
||||
for (var name in new_state) {
|
||||
|
||||
// If value changed, call handler
|
||||
var old = state[name];
|
||||
var old = old_state[name];
|
||||
if (old != new_state[name]) {
|
||||
|
||||
// Call change handler
|
||||
@@ -59,9 +63,6 @@ function GuacamoleSessionState() {
|
||||
|
||||
}
|
||||
|
||||
// Assign new state
|
||||
state = new_state;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -100,6 +101,9 @@ function GuacamoleSessionState() {
|
||||
// Reload properties every second
|
||||
window.setInterval(guac_state.reload, 1000);
|
||||
|
||||
// Reload properties when focus is gained
|
||||
window.addEventListener("focus", guac_state.reload);
|
||||
|
||||
// Initial load
|
||||
guac_state.reload();
|
||||
|
||||
|
Reference in New Issue
Block a user