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