| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/inputs.hpp" | ||
| 30 | #include "gate/results.hpp" | ||
| 31 | #include "gate/exceptions.hpp" | ||
| 32 | |||
| 33 | namespace gate | ||
| 34 | { | ||
| 35 | |||
| 36 | 1 | void Keyboard::parseNativeKey(nativekey_t native_key, KeyEnum& key, states_t& keyStateBits) | |
| 37 | { | ||
| 38 | 1 | gate_input_keycode_t kbd_key = 0; | |
| 39 | 1 | gate_input_keystates_t kbd_states = 0; | |
| 40 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_keyboard_parse_native_key(native_key, &kbd_key, &kbd_states); |
| 41 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 42 | 1 | key = KeyEnum(kbd_key); | |
| 43 | 1 | keyStateBits = kbd_states; | |
| 44 | 1 | } | |
| 45 | 1 | Keyboard::KeyEnum Keyboard::parseNativeKey(nativekey_t native_key) | |
| 46 | { | ||
| 47 | 1 | KeyEnum key = Keyboard::Key_Unknown; | |
| 48 | 1 | uint32_t state = 0; | |
| 49 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Keyboard::parseNativeKey(native_key, key, state); |
| 50 | 1 | return key; | |
| 51 | } | ||
| 52 | 1 | Keyboard::nativekey_t Keyboard::buildNativeKey(KeyEnum key, states_t keyStateBits) | |
| 53 | { | ||
| 54 | 1 | nativekey_t native_key = 0; | |
| 55 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_keyboard_build_native_key(key, keyStateBits, &native_key); |
| 56 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 57 | 1 | return native_key; | |
| 58 | } | ||
| 59 | |||
| 60 | 1 | size_t Keyboard::parseVT100Symbols(char const* symbols, size_t symbolsCount, | |
| 61 | KeyEnum& key, states_t& keyStateBits, char_32_t& character) | ||
| 62 | { | ||
| 63 | 1 | gate_input_keycode_t k = 0; | |
| 64 | 1 | gate_input_keystates_t s = 0; | |
| 65 | 1 | gate_char32_t c = 0; | |
| 66 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t used = gate_keyboard_parse_vt100_symbols(symbols, symbolsCount, &k, &s, &c); |
| 67 | /* | ||
| 68 | if(used == 0) | ||
| 69 | { | ||
| 70 | GATEXX_RAISE_EXCEPTION(results::InvalidData, "Failed to parse VT100 symbols", 0); | ||
| 71 | } | ||
| 72 | */ | ||
| 73 | 1 | key = KeyEnum(k); | |
| 74 | 1 | keyStateBits = s; | |
| 75 | 1 | character = c; | |
| 76 | 1 | return used; | |
| 77 | } | ||
| 78 | 1 | size_t Keyboard::buildVT100Symbols(KeyEnum key, states_t keyStateBits, | |
| 79 | char* symbolsBuffer, size_t symbolsBufferCapacity) | ||
| 80 | { | ||
| 81 | 1 | return gate_keyboard_build_vt100_symbols(key, keyStateBits, symbolsBuffer, symbolsBufferCapacity); | |
| 82 | } | ||
| 83 | ✗ | void Keyboard::buildVT100Symbols(KeyEnum key, states_t keyStateBits, | |
| 84 | Stream& output) | ||
| 85 | { | ||
| 86 | char buffer[32]; | ||
| 87 | ✗ | size_t used = Keyboard::buildVT100Symbols(key, keyStateBits, buffer, sizeof(buffer)); | |
| 88 | ✗ | if (used == 0) | |
| 89 | { | ||
| 90 | ✗ | GATEXX_RAISE_EXCEPTION(results::InvalidData, "Failed to build VT100 symbols", 0); | |
| 91 | } | ||
| 92 | ✗ | output.writeBlock(buffer, used); | |
| 93 | ✗ | } | |
| 94 | |||
| 95 | |||
| 96 | } // end of namespace gate | ||
| 97 |