Skip to content

Commit 168f808

Browse files
committed
Address review: debounce resize handler and use built-in scale parameter
Use sendMouseState's built-in scale parameter instead of mutating the mouse's internal state object. Debounce the window resize listener to avoid excessive recalculations.
1 parent 1d50e2c commit 168f808

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

web/static/js/guac-main.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,12 @@ function GuacMe(element, guest_ip, vncport, session_id, recording_name) {
5151
scaleDisplay();
5252
};
5353

54-
/* Re-scale on browser window resize. */
55-
window.addEventListener('resize', scaleDisplay);
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+
});
5660

5761
/* Disconnect on tab close. */
5862
window.onunload = function() {
@@ -65,10 +69,7 @@ function GuacMe(element, guest_ip, vncport, session_id, recording_name) {
6569
mouse.onmousedown =
6670
mouse.onmouseup =
6771
mouse.onmousemove = function(mouseState) {
68-
var scale = terminal_client.getDisplay().getScale();
69-
mouseState.x = mouseState.x / scale;
70-
mouseState.y = mouseState.y / scale;
71-
terminal_client.sendMouseState(mouseState);
72+
terminal_client.sendMouseState(mouseState, true);
7273
};
7374

7475
/* Keyboard handling. */

0 commit comments

Comments
 (0)