cscg24-guacamole

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

state.h (3484B)


      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#ifndef GUACLOG_STATE_H
     21#define GUACLOG_STATE_H
     22
     23#include "config.h"
     24#include "keydef.h"
     25
     26#include <stdbool.h>
     27#include <stdio.h>
     28
     29/**
     30 * The maximum number of keys which may be tracked at any one time before
     31 * newly-pressed keys are ignored.
     32 */
     33#define GUACLOG_MAX_KEYS 256
     34
     35/**
     36 * The current state of a single key.
     37 */
     38typedef struct guaclog_key_state {
     39
     40    /**
     41     * The definition of the key.
     42     */
     43    guaclog_keydef* keydef;
     44
     45    /**
     46     * Whether the key is currently pressed (true) or released (false).
     47     */
     48    bool pressed;
     49
     50} guaclog_key_state;
     51
     52/**
     53 * The current state of the Guacamole input log interpreter.
     54 */
     55typedef struct guaclog_state {
     56
     57    /**
     58     * Output file stream.
     59     */
     60    FILE* output;
     61
     62    /**
     63     * The number of keys currently being tracked within the key_states array.
     64     */
     65    int active_keys;
     66
     67    /**
     68     * Array of all keys currently being tracked. A key is added to the array
     69     * when it is pressed for the first time. Released keys at the end of the
     70     * array are automatically removed from tracking.
     71     */
     72    guaclog_key_state key_states[GUACLOG_MAX_KEYS];
     73
     74} guaclog_state;
     75
     76/**
     77 * Allocates a new state structure for the Guacamole input log interpreter.
     78 * This structure serves as the representation of interpreter state as
     79 * input-related instructions are read and handled.
     80 *
     81 * @param path
     82 *     The full path to the file in which interpreted, human-readable should be
     83 *     written.
     84 *
     85 * @return
     86 *     The newly-allocated Guacamole input log interpreter state, or NULL if
     87 *     the state could not be allocated.
     88 */
     89guaclog_state* guaclog_state_alloc(const char* path);
     90
     91/**
     92 * Frees all memory associated with the given Guacamole input log interpreter
     93 * state, and finishes any remaining interpreting process. If the given state
     94 * is NULL, this function has no effect.
     95 *
     96 * @param state
     97 *     The Guacamole input log interpreter state to free, which may be NULL.
     98 *
     99 * @return
    100 *     Zero if the interpreting process completed successfully, non-zero
    101 *     otherwise.
    102 */
    103int guaclog_state_free(guaclog_state* state);
    104
    105/**
    106 * Updates the given Guacamole input log interpreter state, marking the given
    107 * key as pressed or released.
    108 *
    109 * @param state
    110 *     The Guacamole input log interpreter state being updated.
    111 *
    112 * @param keysym
    113 *     The X11 keysym of the key being pressed or released.
    114 *
    115 * @param pressed
    116 *     true if the key is being pressed, false if the key is being released.
    117 *
    118 * @return
    119 *     Zero if the interpreter state was updated successfully, non-zero
    120 *     otherwise.
    121 */
    122int guaclog_state_update_key(guaclog_state* state, int keysym, bool pressed);
    123
    124#endif
    125