diff --git a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js index 4beecbacd..980d71b3c 100644 --- a/guacamole/src/main/frontend/src/app/client/controllers/clientController.js +++ b/guacamole/src/main/frontend/src/app/client/controllers/clientController.js @@ -653,8 +653,14 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams * The client to disconnect. */ $scope.closeClientTile = function closeClientTile(client) { + $scope.addRemoveClient(client.id, true); guacClientManager.removeManagedClient(client.id); + + // Ensure at least one client has focus (the only client with + // focus may just have been removed) + ManagedClientGroup.verifyFocus($scope.clientGroup); + }; /** diff --git a/guacamole/src/main/frontend/src/app/client/services/guacClientManager.js b/guacamole/src/main/frontend/src/app/client/services/guacClientManager.js index 2a0ea40b6..6dd8ced52 100644 --- a/guacamole/src/main/frontend/src/app/client/services/guacClientManager.js +++ b/guacamole/src/main/frontend/src/app/client/services/guacClientManager.js @@ -253,15 +253,13 @@ angular.module('client').factory('guacClientManager', ['$injector', clients.push(service.getManagedClient(id)); }); - // Focus the first client if there are no clients focused - if (clients.length >= 1 && _.findIndex(clients, client => client.clientProperties.focused) === -1) { - clients[0].clientProperties.focused = true; - } - var group = new ManagedClientGroup({ clients : clients }); + // Focus the first client if there are no clients focused + ManagedClientGroup.verifyFocus(group); + managedClientGroups.push(group); return group; diff --git a/guacamole/src/main/frontend/src/app/client/types/ManagedClientGroup.js b/guacamole/src/main/frontend/src/app/client/types/ManagedClientGroup.js index 14ff4ea95..e2c342329 100644 --- a/guacamole/src/main/frontend/src/app/client/types/ManagedClientGroup.js +++ b/guacamole/src/main/frontend/src/app/client/types/ManagedClientGroup.js @@ -337,6 +337,23 @@ angular.module('client').factory('ManagedClientGroup', ['$injector', function de }; + /** + * Verifies that focus is assigned to at least one client in the given + * group. If no client has focus, focus is assigned to the first client in + * the group. + * + * @param {ManagedClientGroup} group + * The group to verify. + */ + ManagedClientGroup.verifyFocus = function verifyFocus(group) { + + // Focus the first client if there are no clients focused + if (group.clients.length >= 1 && _.findIndex(group.clients, client => client.clientProperties.focused) === -1) { + group.clients[0].clientProperties.focused = true; + } + + }; + return ManagedClientGroup; }]); \ No newline at end of file