2014-11-26 23:23:26 +00:00
|
|
|
/*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
2014-11-26 23:23:26 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-26 23:23:26 +00:00
|
|
|
*
|
2016-03-25 19:59:40 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2014-11-26 23:23:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
#include "resolution.h"
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
#include <guacamole/user.h>
|
2014-11-26 23:23:26 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
int guac_rdp_resolution_reasonable(guac_user* user, int resolution) {
|
2014-11-26 23:23:26 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
int width = user->info.optimal_width;
|
|
|
|
int height = user->info.optimal_height;
|
2014-11-26 23:23:26 +00:00
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Convert user pixels to remote pixels */
|
|
|
|
width = width * resolution / user->info.optimal_resolution;
|
|
|
|
height = height * resolution / user->info.optimal_resolution;
|
2014-11-26 23:23:26 +00:00
|
|
|
|
|
|
|
/*
|
2016-03-01 05:50:00 +00:00
|
|
|
* Resolution is reasonable if the same as the user optimal resolution
|
2014-11-26 23:23:26 +00:00
|
|
|
* OR if the resulting display area is reasonable
|
|
|
|
*/
|
2016-03-01 05:50:00 +00:00
|
|
|
return user->info.optimal_resolution == resolution
|
2014-11-26 23:23:26 +00:00
|
|
|
|| width*height >= GUAC_RDP_REASONABLE_AREA;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
int guac_rdp_suggest_resolution(guac_user* user) {
|
2014-11-26 23:23:26 +00:00
|
|
|
|
|
|
|
/* Prefer RDP's native resolution */
|
2016-03-01 05:50:00 +00:00
|
|
|
if (guac_rdp_resolution_reasonable(user, GUAC_RDP_NATIVE_RESOLUTION))
|
2014-11-26 23:23:26 +00:00
|
|
|
return GUAC_RDP_NATIVE_RESOLUTION;
|
|
|
|
|
|
|
|
/* If native resolution is too tiny, try higher resolution */
|
2016-03-01 05:50:00 +00:00
|
|
|
if (guac_rdp_resolution_reasonable(user, GUAC_RDP_HIGH_RESOLUTION))
|
2014-11-26 23:23:26 +00:00
|
|
|
return GUAC_RDP_HIGH_RESOLUTION;
|
|
|
|
|
2016-03-01 05:50:00 +00:00
|
|
|
/* Fallback to user-suggested resolution */
|
|
|
|
return user->info.optimal_resolution;
|
2014-11-26 23:23:26 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|