cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

resolution.c (1963B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#include "client.h"
     21#include "resolution.h"
     22
     23#include <guacamole/user.h>
     24
     25int guac_rdp_resolution_reasonable(guac_user* user, int resolution) {
     26
     27    int width  = user->info.optimal_width;
     28    int height = user->info.optimal_height;
     29
     30    /* Convert user pixels to remote pixels */
     31    width  = width  * resolution / user->info.optimal_resolution;
     32    height = height * resolution / user->info.optimal_resolution;
     33
     34    /*
     35     * Resolution is reasonable if the same as the user optimal resolution
     36     * OR if the resulting display area is reasonable
     37     */
     38    return user->info.optimal_resolution == resolution
     39        || width*height >= GUAC_RDP_REASONABLE_AREA;
     40
     41}
     42
     43int guac_rdp_suggest_resolution(guac_user* user) {
     44
     45    /* Prefer RDP's native resolution */
     46    if (guac_rdp_resolution_reasonable(user, GUAC_RDP_NATIVE_RESOLUTION))
     47        return GUAC_RDP_NATIVE_RESOLUTION;
     48
     49    /* If native resolution is too tiny, try higher resolution */
     50    if (guac_rdp_resolution_reasonable(user, GUAC_RDP_HIGH_RESOLUTION))
     51        return GUAC_RDP_HIGH_RESOLUTION;
     52
     53    /* Fallback to user-suggested resolution */
     54    return user->info.optimal_resolution;
     55
     56}
     57