Kaleidoscope
OneShot.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2  * Kaleidoscope-OneShot -- One-shot modifiers and layers
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 OSM(kc) (Key) {.raw = kaleidoscope::ranges::OSM_FIRST + (Key_ ## kc).keyCode - Key_LeftControl.keyCode}
25 #define OSL(n) (Key) {.raw = kaleidoscope::ranges::OSL_FIRST + n}
26 
27 namespace kaleidoscope {
28 
29 class OneShot : public KaleidoscopePlugin {
30  public:
31  OneShot(void);
32 
33  void begin(void) final;
34 
35  static bool isActive(void);
36  static void cancel(bool with_stickies);
37  static void cancel(void) {
38  cancel(false);
39  }
40  static uint16_t time_out;
41  static uint16_t hold_time_out;
42 
43  static bool isModifierActive(Key key);
44 
45  void inject(Key key, uint8_t key_state);
46 
47  private:
48  typedef union {
49  struct {
50  uint8_t mods;
51  uint8_t layers;
52  };
53  uint16_t all;
54  } state_t;
55  static uint32_t start_time_;
56  static state_t state_;
57  static state_t sticky_state_;
58  static state_t pressed_state_;
59  static Key prev_key_;
60  static bool should_cancel_;
61  static bool should_cancel_stickies_;
62  static bool should_mask_on_interrupt_;
63 
64  static void injectNormalKey(uint8_t idx, uint8_t key_state);
65  static void activateOneShot(uint8_t idx);
66  static void cancelOneShot(uint8_t idx);
67 
68  static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
69  static void loopHook(bool is_post_clear);
70 };
71 
72 }
73 
static bool isActive(void)
Definition: OneShot.cpp:210
Definition: hid.cpp:4
static uint16_t hold_time_out
Definition: OneShot.h:41
Definition: OneShot.h:29
byte byte col
Definition: TapDance.cpp:229
Definition: key_defs.h:13
void begin(void) final
Definition: OneShot.cpp:205
void inject(Key key, uint8_t key_state)
Definition: OneShot.cpp:226
static void cancel(void)
Definition: OneShot.h:37
OneShot(void)
Definition: OneShot.cpp:202
Definition: Kaleidoscope.h:40
byte row
Definition: TapDance.cpp:229
static uint16_t time_out
Definition: OneShot.h:40
static bool isModifierActive(Key key)
Definition: OneShot.cpp:214