Skip to content

Commit 3e2f0d5

Browse files
GUACAMOLE-288: Allow windows to have different dimensions.
1 parent e98bbee commit 3e2f0d5

File tree

8 files changed

+226
-167
lines changed

8 files changed

+226
-167
lines changed

guacamole-common-js/src/main/webapp/modules/Client.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,16 +331,19 @@ Guacamole.Client = function(tunnel) {
331331
* @param {!number} height
332332
* The height of the screen.
333333
*
334-
* @param {!number} monitors
335-
* The count of monitors.
334+
* @param {!number} x_position
335+
* The x position of the screen (relative to the main window).
336+
*
337+
* @param {!number} top_offset
338+
* The top offset of the screen, in pixel.
336339
*/
337-
this.sendSize = function sendSize(width, height, monitors) {
340+
this.sendSize = function sendSize(width, height, x_position, top_offset) {
338341

339342
// Do not send requests if not connected
340343
if (!isConnected())
341344
return;
342345

343-
tunnel.sendMessage("size", width, height, monitors);
346+
tunnel.sendMessage("size", width, height, x_position, top_offset);
344347

345348
};
346349

@@ -1679,10 +1682,10 @@ Guacamole.Client = function(tunnel) {
16791682

16801683
"size": function(parameters) {
16811684

1682-
var layer_index = parseInt(parameters[0]);
1683-
var layer = getLayer(layer_index);
1684-
var width = parseInt(parameters[1]);
1685-
var height = parseInt(parameters[2]);
1685+
const layer_index = parseInt(parameters[0]);
1686+
const layer = getLayer(layer_index);
1687+
const width = parseInt(parameters[1]);
1688+
const height = parseInt(parameters[2]);
16861689

16871690
display.resize(layer, width, height);
16881691

guacamole-common-js/src/main/webapp/modules/Display.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ Guacamole.Display = function() {
3434
* Reference to this Guacamole.Display.
3535
* @private
3636
*/
37-
var guac_display = this;
37+
const guac_display = this;
3838

39-
var displayWidth = 0;
40-
var displayHeight = 0;
41-
var displayMonitors = 1;
42-
var displayScale = 1;
39+
let displayWidth = 0;
40+
let displayHeight = 0;
41+
let monitorWidth = null;
42+
let monitorHeight = null;
43+
let displayScale = 1;
4344

4445
// Create display
45-
var display = document.createElement("div");
46+
const display = document.createElement("div");
4647
display.style.position = "relative";
4748
display.style.width = displayWidth + "px";
4849
display.style.height = displayHeight + "px";
@@ -551,16 +552,6 @@ Guacamole.Display = function() {
551552
return displayHeight;
552553
};
553554

554-
/**
555-
* Returns the number of monitors.
556-
*
557-
* @return {!number}
558-
* The number of monitors.
559-
*/
560-
this.getMonitors = function getMonitors() {
561-
return displayMonitors;
562-
};
563-
564555
/**
565556
* Returns the default layer of this display. Each Guacamole display always
566557
* has at least one layer. Other layers can optionally be created within
@@ -764,13 +755,16 @@ Guacamole.Display = function() {
764755
};
765756

766757
/**
767-
* Change the number of monitors.
758+
* Set the current monitor size.
768759
*
769-
* @param {!number} monitors
770-
* The number of monitors.
760+
* @param {!number} width
761+
* The width of the monitor, in pixels.
762+
* @param {!number} height
763+
* The height of the monitor, in pixels.
771764
*/
772-
this.updateMonitors = function updateMonitors(monitors) {
773-
displayMonitors = monitors;
765+
this.setMonitorSize = function setMonitorSize(width, height) {
766+
monitorWidth = width;
767+
monitorHeight = height;
774768
}
775769

776770
/**
@@ -791,7 +785,12 @@ Guacamole.Display = function() {
791785
scheduleTask(function __display_resize() {
792786

793787
// Adjust width when using multiple monitors
794-
width = width / displayMonitors;
788+
if (monitorWidth)
789+
width = monitorWidth;
790+
791+
// Adjust height when using multiple monitors
792+
if (monitorHeight)
793+
height = monitorHeight;
795794

796795
layer.resize(width, height);
797796

guacamole/src/main/frontend/src/app/client/controllers/secondaryMonitorController.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ angular.module('client').controller('secondaryMonitorController', ['$scope', '$i
4646
MENU_KEYS = angular.extend({}, SHIFT_KEYS, ALT_KEYS, CTRL_KEYS);
4747

4848
guacManageMonitor.init("secondary");
49-
guacManageMonitor.monitorAttributes.monitorId = monitorId;
49+
guacManageMonitor.monitorId = monitorId;
5050

5151
guacManageMonitor.openConsentButton = function openConsentButton() {
5252

@@ -85,15 +85,15 @@ angular.module('client').controller('secondaryMonitorController', ['$scope', '$i
8585

8686
// Ctrl+Alt+Shift has NOT been pressed if any key is currently held
8787
// down that isn't Ctrl, Alt, or Shift
88-
if (_.findKey(keyboard.pressed, (val, keysym) => !MENU_KEYS[keysym]))
88+
if (_.findKey(keyboard.pressed, (_, keysym) => !MENU_KEYS[keysym]))
8989
return false;
9090

9191
// Verify that one of each required key is held, regardless of
9292
// left/right location on the keyboard
9393
return !!(
94-
_.findKey(SHIFT_KEYS, (val, keysym) => keyboard.pressed[keysym])
95-
&& _.findKey(ALT_KEYS, (val, keysym) => keyboard.pressed[keysym])
96-
&& _.findKey(CTRL_KEYS, (val, keysym) => keyboard.pressed[keysym])
94+
_.findKey(SHIFT_KEYS, (_, keysym) => keyboard.pressed[keysym])
95+
&& _.findKey(ALT_KEYS, (_, keysym) => keyboard.pressed[keysym])
96+
&& _.findKey(CTRL_KEYS, (_, keysym) => keyboard.pressed[keysym])
9797
);
9898

9999
};

guacamole/src/main/frontend/src/app/client/directives/guacClient.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -462,27 +462,22 @@ angular.module('client').directive('guacClient', [function guacClient() {
462462
const pixelDensity = $window.devicePixelRatio || 1;
463463
const width = main.offsetWidth * pixelDensity;
464464
const height = main.offsetHeight * pixelDensity;
465-
const monitors = guacManageMonitor.getMonitorCount();
466-
467-
// Monitor count changed
468-
if (display.getMonitors() !== monitors) {
469-
display.updateMonitors(monitors);
470-
client.sendSize(width, height, monitors);
471-
}
472465

473466
// Window resized
474-
else if (display.getWidth() !== width || display.getHeight() !== height)
475-
client.sendSize(width, height, monitors);
467+
if (display.getWidth() !== width || display.getHeight() !== height)
468+
guacManageMonitor.sendSize({
469+
width: width,
470+
height: height,
471+
monitorId: 0,
472+
top: 0,
473+
});
476474

477475
}
478476

479477
$scope.$evalAsync(updateDisplayScale);
480478

481479
};
482480

483-
// Launch resize on monitor count change
484-
$window.addEventListener('monitor-count', $scope.mainElementResized);
485-
486481
// Scroll client display if absolute mouse is in use (the same drag
487482
// gesture is needed for moving the mouse pointer with relative mouse)
488483
$scope.clientDrag = function clientDrag(inProgress, startX, startY, currentX, currentY, deltaX, deltaY) {

guacamole/src/main/frontend/src/app/client/directives/guacClientSecondary.js

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ angular.module('client').directive('guacClientSecondary', [function guacClient()
4747

4848
// Required services
4949
const $document = $injector.get('$document');
50+
const $window = $injector.get('$window');
5051
const clipboardService = $injector.get('clipboardService');
5152
const guacManageMonitor = $injector.get('guacManageMonitor');
5253

@@ -79,6 +80,13 @@ angular.module('client').directive('guacClientSecondary', [function guacClient()
7980
*/
8081
const displayContainer = $element.find('.display')[0];
8182

83+
/**
84+
* The main containing element for the entire directive.
85+
*
86+
* @type Element
87+
*/
88+
const main = $element[0];
89+
8290
/**
8391
* The tracked mouse.
8492
*
@@ -100,13 +108,6 @@ angular.module('client').directive('guacClientSecondary', [function guacClient()
100108
*/
101109
const keyboard = new Guacamole.Keyboard($document[0]);
102110

103-
// Init monitor attributes with default values
104-
guacManageMonitor.monitorAttributes.width = 0;
105-
guacManageMonitor.monitorAttributes.height = 0;
106-
guacManageMonitor.monitorAttributes.position = 0;
107-
guacManageMonitor.monitorAttributes.count = 0;
108-
guacManageMonitor.monitorAttributes.currentScaling = 1;
109-
110111
// Set client instance on guacManageMonitor service
111112
guacManageMonitor.setClient(client);
112113

@@ -123,10 +124,23 @@ angular.module('client').directive('guacClientSecondary', [function guacClient()
123124
};
124125

125126
// Adjust the display scaling according to the window size.
126-
$scope.mainElementResized = guacManageMonitor.mainElementResized;
127+
$scope.mainElementResized = function mainElementResized() {
128+
129+
const pixelDensity = $window.devicePixelRatio ?? 1;
130+
const width = main.offsetWidth * pixelDensity;
131+
const height = main.offsetHeight * pixelDensity;
132+
const top = 0 // TODO: $window.screenY ?? 0;
133+
134+
const size = {
135+
width: width,
136+
height: height,
137+
top: top > 0 ? top : 0,
138+
monitorId: guacManageMonitor.monitorId,
139+
};
127140

128-
// Ready for resize
129-
guacManageMonitor.pushBroadcastMessage('resize', true);
141+
// Send resize event to main window
142+
guacManageMonitor.pushBroadcastMessage('size', size);
143+
}
130144

131145
// Handle any received clipboard data
132146
client.onclipboard = function clientClipboardReceived(stream, mimetype) {
@@ -176,22 +190,20 @@ angular.module('client').directive('guacClientSecondary', [function guacClient()
176190
display.showCursor(true);
177191

178192
// Update client-side cursor
179-
display.moveCursor(
180-
Math.floor(e.state.x / guacManageMonitor.monitorAttributes.currentScaling),
181-
Math.floor(e.state.y / guacManageMonitor.monitorAttributes.currentScaling)
182-
);
193+
display.moveCursor(e.state.x, e.state.y);
183194

184195
// Click on actual display instead of the first
185-
const displayOffset = guacManageMonitor.monitorAttributes.width * guacManageMonitor.monitorAttributes.position;
196+
const displayOffsetX = guacManageMonitor.getOffsetX();
197+
const displayOffsetY = guacManageMonitor.getOffsetY();
186198

187199
// Convert mouse state to serializable object
188200
mouseState.down = e.state.down;
189201
mouseState.up = e.state.up;
190202
mouseState.left = e.state.left;
191203
mouseState.middle = e.state.middle;
192204
mouseState.right = e.state.right;
193-
mouseState.x = e.state.x / guacManageMonitor.monitorAttributes.currentScaling + displayOffset;
194-
mouseState.y = e.state.y / guacManageMonitor.monitorAttributes.currentScaling;
205+
mouseState.x = e.state.x + displayOffsetX;
206+
mouseState.y = e.state.y + displayOffsetY;
195207

196208
// Send mouse state to main window
197209
guacManageMonitor.pushBroadcastMessage('mouseState', mouseState);

0 commit comments

Comments
 (0)