action.h
4034 bytes
1/*
2Copyright 2012,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 <stdbool.h>
22#include "progmem.h"
23#include "keyboard.h"
24#include "keycode.h"
25#include "action_code.h"
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#ifndef TAP_CODE_DELAY
32# define TAP_CODE_DELAY 0
33#endif
34#ifndef TAP_HOLD_CAPS_DELAY
35# define TAP_HOLD_CAPS_DELAY 80
36#endif
37
38/* tapping count and state */
39typedef struct {
40 bool interrupted : 1;
41 bool reserved2 : 1;
42 bool reserved1 : 1;
43 bool reserved0 : 1;
44 uint8_t count : 4;
45} tap_t;
46
47/* Key event container for recording */
48typedef struct {
49 keyevent_t event;
50#ifndef NO_ACTION_TAPPING
51 tap_t tap;
52#endif
53#if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE)
54 uint16_t keycode;
55#endif
56} keyrecord_t;
57
58/* Execute action per keyevent */
59void action_exec(keyevent_t event);
60
61/* action for key */
62action_t action_for_key(uint8_t layer, keypos_t key);
63action_t action_for_keycode(uint16_t keycode);
64
65/* keyboard-specific key event (pre)processing */
66bool process_record_quantum(keyrecord_t *record);
67
68/* Utilities for actions. */
69#if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
70extern bool disable_action_cache;
71#endif
72
73/* Code for handling one-handed key modifiers. */
74#ifdef SWAP_HANDS_ENABLE
75extern bool swap_hands;
76extern const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
77# if (MATRIX_COLS <= 8)
78typedef uint8_t swap_state_row_t;
79# elif (MATRIX_COLS <= 16)
80typedef uint16_t swap_state_row_t;
81# elif (MATRIX_COLS <= 32)
82typedef uint32_t swap_state_row_t;
83# else
84# error "MATRIX_COLS: invalid value"
85# endif
86
87/**
88 * @brief Enable swap hands
89 */
90void swap_hands_on(void);
91/**
92 * @brief Disable swap hands
93 */
94void swap_hands_off(void);
95/**
96 * @brief Toggle swap hands enable state
97 */
98void swap_hands_toggle(void);
99/**
100 * @brief Get the swap hands enable state
101 *
102 * @return true
103 * @return false
104 */
105bool is_swap_hands_on(void);
106
107void process_hand_swap(keyevent_t *record);
108#endif
109
110void process_record_nocache(keyrecord_t *record);
111void process_record(keyrecord_t *record);
112void process_record_handler(keyrecord_t *record);
113void post_process_record_quantum(keyrecord_t *record);
114void process_action(keyrecord_t *record, action_t action);
115void register_code(uint8_t code);
116void unregister_code(uint8_t code);
117void tap_code(uint8_t code);
118void tap_code_delay(uint8_t code, uint16_t delay);
119void register_mods(uint8_t mods);
120void unregister_mods(uint8_t mods);
121void register_weak_mods(uint8_t mods);
122void unregister_weak_mods(uint8_t mods);
123// void set_mods(uint8_t mods);
124void clear_keyboard(void);
125void clear_keyboard_but_mods(void);
126void clear_keyboard_but_mods_and_keys(void);
127void layer_switch(uint8_t new_layer);
128bool is_tap_record(keyrecord_t *record);
129bool is_tap_action(action_t action);
130
131#ifndef NO_ACTION_TAPPING
132void process_record_tap_hint(keyrecord_t *record);
133#endif
134
135////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
136// Helpers
137
138#ifdef ACTION_DEBUG
139# include "debug.h"
140# include "print.h"
141# define ac_dprintf(...) dprintf(__VA_ARGS__)
142#else
143# define ac_dprintf(...) \
144 do { \
145 } while (0)
146#endif
147
148void debug_event(keyevent_t event);
149void debug_record(keyrecord_t record);
150void debug_action(action_t action);
151
152#ifdef __cplusplus
153}
154#endif