Kaleidoscope
Leader.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2  * Kaleidoscope-Leader -- VIM-style leader keys
3  * Copyright (C) 2016, 2017 Gergely Nagy
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <Kaleidoscope.h>
22 #include <Kaleidoscope-Ranges.h>
23 
24 #define LEADER_MAX_SEQUENCE_LENGTH 4
25 
26 #define LEAD(n) (Key) { .raw = kaleidoscope::ranges::LEAD_FIRST + n }
27 
28 #define LEADER_SEQ(...) { __VA_ARGS__, Key_NoKey }
29 #define LEADER_DICT(...) { __VA_ARGS__, {{Key_NoKey}, NULL} }
30 
31 namespace kaleidoscope {
32 
33 class Leader : public KaleidoscopePlugin {
34  public:
35  typedef void (*action_t)(uint8_t seq_index);
36  typedef struct {
39  } dictionary_t;
40 
41  Leader(void);
42  static const dictionary_t *dictionary;
43 
44  void begin(void) final;
45 
46  static void reset(void);
47  static uint16_t time_out;
48 
49  void inject(Key key, uint8_t key_state);
50 
51  private:
52  static Key sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1];
53  static uint8_t sequence_pos_;
54  static uint32_t end_time_;
55 
56  static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
57  static void loopHook(bool is_post_clear);
58  static int8_t lookup(void);
59 };
60 
61 }
62 
static void reset(void)
Definition: Leader.cpp:82
Definition: hid.cpp:4
byte byte col
Definition: TapDance.cpp:229
void(* action_t)(uint8_t seq_index)
Definition: Leader.h:35
Definition: key_defs.h:13
static const dictionary_t * dictionary
Definition: Leader.h:42
Definition: Leader.h:33
static uint16_t time_out
Definition: Leader.h:47
#define LEADER_MAX_SEQUENCE_LENGTH
Definition: Leader.h:24
Definition: Kaleidoscope.h:40
Definition: Leader.h:36
byte row
Definition: TapDance.cpp:229
void inject(Key key, uint8_t key_state)
Definition: Leader.cpp:87
void begin(void) final
Definition: Leader.cpp:77
action_t action
Definition: Leader.h:38
Leader(void)
Definition: Leader.cpp:74