cscg24-guacamole

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

input.c (2902B)


      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 "input.h"
     21#include "kubernetes.h"
     22#include "terminal/terminal.h"
     23
     24#include <guacamole/client.h>
     25#include <guacamole/recording.h>
     26#include <guacamole/user.h>
     27
     28#include <stdlib.h>
     29
     30int guac_kubernetes_user_mouse_handler(guac_user* user,
     31        int x, int y, int mask) {
     32
     33    guac_client* client = user->client;
     34    guac_kubernetes_client* kubernetes_client =
     35        (guac_kubernetes_client*) client->data;
     36
     37    /* Skip if terminal not yet ready */
     38    guac_terminal* term = kubernetes_client->term;
     39    if (term == NULL)
     40        return 0;
     41
     42    /* Report mouse position within recording */
     43    if (kubernetes_client->recording != NULL)
     44        guac_recording_report_mouse(kubernetes_client->recording, x, y,
     45                mask);
     46
     47    guac_terminal_send_mouse(term, user, x, y, mask);
     48    return 0;
     49
     50}
     51
     52int guac_kubernetes_user_key_handler(guac_user* user, int keysym, int pressed) {
     53
     54    guac_client* client = user->client;
     55    guac_kubernetes_client* kubernetes_client =
     56        (guac_kubernetes_client*) client->data;
     57
     58    /* Report key state within recording */
     59    if (kubernetes_client->recording != NULL)
     60        guac_recording_report_key(kubernetes_client->recording,
     61                keysym, pressed);
     62
     63    /* Skip if terminal not yet ready */
     64    guac_terminal* term = kubernetes_client->term;
     65    if (term == NULL)
     66        return 0;
     67
     68    guac_terminal_send_key(term, keysym, pressed);
     69    return 0;
     70
     71}
     72
     73int guac_kubernetes_user_size_handler(guac_user* user, int width, int height) {
     74
     75    /* Get terminal */
     76    guac_client* client = user->client;
     77    guac_kubernetes_client* kubernetes_client =
     78        (guac_kubernetes_client*) client->data;
     79
     80    /* Skip if terminal not yet ready */
     81    guac_terminal* terminal = kubernetes_client->term;
     82    if (terminal == NULL)
     83        return 0;
     84
     85    /* Resize terminal */
     86    guac_terminal_resize(terminal, width, height);
     87
     88    /* Update Kubernetes terminal window size if connected */
     89    guac_kubernetes_resize(client,
     90            guac_terminal_get_rows(terminal),
     91            guac_terminal_get_columns(terminal));
     92
     93    return 0;
     94}
     95