action_util.h (4264B)
1 /* 2 Copyright 2013 Jun Wako <wakojun@gmail.com> 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #pragma once 19 20 #include <stdint.h> 21 22 #include "compiler_support.h" 23 #include "report.h" 24 #include "modifiers.h" 25 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 typedef union { 31 uint8_t raw; 32 struct { 33 bool left_ctrl : 1; 34 bool left_shift : 1; 35 bool left_alt : 1; 36 bool left_gui : 1; 37 bool right_ctrl : 1; 38 bool right_shift : 1; 39 bool right_alt : 1; 40 bool right_gui : 1; 41 }; 42 } PACKED mod_t; 43 STATIC_ASSERT(sizeof(mod_t) == sizeof(uint8_t), "Invalid size for 'mod_t'"); 44 45 extern report_keyboard_t *keyboard_report; 46 #ifdef NKRO_ENABLE 47 extern report_nkro_t *nkro_report; 48 #endif 49 50 void send_keyboard_report(void); 51 52 /* key */ 53 inline void add_key(uint8_t key) { 54 add_key_to_report(key); 55 } 56 57 inline void del_key(uint8_t key) { 58 del_key_from_report(key); 59 } 60 61 inline void clear_keys(void) { 62 clear_keys_from_report(); 63 } 64 65 /* modifier */ 66 uint8_t get_mods(void); 67 mod_t get_mod_state(void); 68 void add_mods(uint8_t mods); 69 void del_mods(uint8_t mods); 70 void set_mods(uint8_t mods); 71 void clear_mods(void); 72 73 /* weak modifier */ 74 uint8_t get_weak_mods(void); 75 mod_t get_weak_mod_state(void); 76 void add_weak_mods(uint8_t mods); 77 void del_weak_mods(uint8_t mods); 78 void set_weak_mods(uint8_t mods); 79 void clear_weak_mods(void); 80 81 /* oneshot modifier */ 82 uint8_t get_oneshot_mods(void); 83 mod_t get_oneshot_mod_state(void); 84 void add_oneshot_mods(uint8_t mods); 85 void del_oneshot_mods(uint8_t mods); 86 void set_oneshot_mods(uint8_t mods); 87 void clear_oneshot_mods(void); 88 bool has_oneshot_mods_timed_out(void); 89 90 uint8_t get_oneshot_locked_mods(void); 91 mod_t get_oneshot_locked_mod_state(void); 92 void add_oneshot_locked_mods(uint8_t mods); 93 void set_oneshot_locked_mods(uint8_t mods); 94 void clear_oneshot_locked_mods(void); 95 void del_oneshot_locked_mods(uint8_t mods); 96 97 typedef enum { ONESHOT_PRESSED = 0b01, ONESHOT_OTHER_KEY_PRESSED = 0b10, ONESHOT_START = 0b11, ONESHOT_TOGGLED = 0b100 } oneshot_fullfillment_t; 98 void set_oneshot_layer(uint8_t layer, uint8_t state); 99 uint8_t get_oneshot_layer(void); 100 void clear_oneshot_layer_state(oneshot_fullfillment_t state); 101 void reset_oneshot_layer(void); 102 bool is_oneshot_layer_active(void); 103 uint8_t get_oneshot_layer_state(void); 104 bool has_oneshot_layer_timed_out(void); 105 bool has_oneshot_swaphands_timed_out(void); 106 107 void oneshot_locked_mods_changed_user(uint8_t mods); 108 void oneshot_locked_mods_changed_kb(uint8_t mods); 109 void oneshot_mods_changed_user(uint8_t mods); 110 void oneshot_mods_changed_kb(uint8_t mods); 111 void oneshot_layer_changed_user(uint8_t layer); 112 void oneshot_layer_changed_kb(uint8_t layer); 113 114 void oneshot_toggle(void); 115 void oneshot_enable(void); 116 void oneshot_disable(void); 117 bool is_oneshot_enabled(void); 118 119 /* inspect */ 120 uint8_t has_anymod(void); 121 122 #ifdef SWAP_HANDS_ENABLE 123 void set_oneshot_swaphands(void); 124 void release_oneshot_swaphands(void); 125 void use_oneshot_swaphands(void); 126 void clear_oneshot_swaphands(void); 127 #endif 128 129 #ifdef DUMMY_MOD_NEUTRALIZER_KEYCODE 130 // KC_A is used as the lowerbound instead of QK_BASIC because the range QK_BASIC...KC_A includes 131 // internal keycodes like KC_NO and KC_TRANSPARENT which are unsuitable for use with `tap_code(kc)`. 132 # if !(KC_A <= DUMMY_MOD_NEUTRALIZER_KEYCODE && DUMMY_MOD_NEUTRALIZER_KEYCODE <= QK_BASIC_MAX) 133 # error "DUMMY_MOD_NEUTRALIZER_KEYCODE must be a basic, unmodified, HID keycode!" 134 # endif 135 void neutralize_flashing_modifiers(uint8_t active_mods); 136 #endif 137 #ifndef MODS_TO_NEUTRALIZE 138 # define MODS_TO_NEUTRALIZE {MOD_BIT(KC_LEFT_ALT), MOD_BIT(KC_LEFT_GUI)} 139 #endif 140 141 #ifdef __cplusplus 142 } 143 #endif