Skip to content

Commit cefb40c

Browse files
authored
Merge pull request kevoreilly#2959 from wmetcalf/fix/guac-vnc-scale-to-fit
Scale guacamole VNC display to fit browser window
2 parents 576c21f + 168f808 commit cefb40c

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

web/static/css/guac-main.css

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
html, body {
2+
margin: 0;
3+
padding: 0;
4+
height: 100%;
5+
overflow: hidden;
6+
}
7+
8+
.guaconsole {
9+
display: flex;
10+
flex-direction: column;
11+
height: 100vh;
12+
}
13+
114
#container {
215
position: relative;
3-
width: 100%;
4-
height: 20em;
16+
flex: 1;
17+
overflow: hidden;
518
}
619

720
#terminal {
821
height: 100%;
9-
width: 100%
22+
width: 100%;
1023
}
1124

1225
.dialog,

web/static/js/guac-main.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,37 @@ function GuacMe(element, guest_ip, vncport, session_id, recording_name) {
2727
/* Show the terminal. */
2828
$('#terminal').append(terminal_element);
2929

30+
/* Scale display to fit the browser window. */
31+
var scaleDisplay = function() {
32+
var display = terminal_client.getDisplay();
33+
var displayWidth = display.getWidth();
34+
var displayHeight = display.getHeight();
35+
if (!displayWidth || !displayHeight) return;
36+
37+
var container = document.getElementById('container');
38+
var containerWidth = container.offsetWidth;
39+
var containerHeight = container.offsetHeight;
40+
if (!containerWidth || !containerHeight) return;
41+
42+
var scale = Math.min(
43+
containerWidth / displayWidth,
44+
containerHeight / displayHeight
45+
);
46+
display.scale(scale);
47+
};
48+
49+
/* Re-scale when the display size changes (initial connect). */
50+
terminal_client.getDisplay().onresize = function() {
51+
scaleDisplay();
52+
};
53+
54+
/* Re-scale on browser window resize (debounced). */
55+
var resizeTimeout;
56+
window.addEventListener('resize', function() {
57+
clearTimeout(resizeTimeout);
58+
resizeTimeout = setTimeout(scaleDisplay, 100);
59+
});
60+
3061
/* Disconnect on tab close. */
3162
window.onunload = function() {
3263
terminal_client.disconnect();
@@ -38,7 +69,7 @@ function GuacMe(element, guest_ip, vncport, session_id, recording_name) {
3869
mouse.onmousedown =
3970
mouse.onmouseup =
4071
mouse.onmousemove = function(mouseState) {
41-
terminal_client.sendMouseState(mouseState);
72+
terminal_client.sendMouseState(mouseState, true);
4273
};
4374

4475
/* Keyboard handling. */

0 commit comments

Comments
 (0)