You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
113 lines
3.4 KiB
113 lines
3.4 KiB
8 years ago
|
/* -*- mode: c++ -*-
|
||
8 years ago
|
* Kaleidoscope-OneShot -- One-shot modifiers and layers
|
||
6 years ago
|
* Copyright (C) 2016-2019 Keyboard.io, Inc.
|
||
8 years ago
|
*
|
||
6 years ago
|
* This program is free software: you can redistribute it and/or modify it under
|
||
|
* the terms of the GNU General Public License as published by the Free Software
|
||
|
* Foundation, version 3.
|
||
8 years ago
|
*
|
||
6 years ago
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||
|
* details.
|
||
8 years ago
|
*
|
||
6 years ago
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
8 years ago
|
*/
|
||
|
|
||
|
#pragma once
|
||
|
|
||
5 years ago
|
#include "kaleidoscope/Runtime.h"
|
||
8 years ago
|
#include <Kaleidoscope-Ranges.h>
|
||
8 years ago
|
|
||
5 years ago
|
#define OSM(kc) Key(kaleidoscope::ranges::OSM_FIRST + (Key_ ## kc).getKeyCode() - Key_LeftControl.getKeyCode())
|
||
6 years ago
|
#define OSL(n) Key(kaleidoscope::ranges::OSL_FIRST + n)
|
||
8 years ago
|
|
||
|
namespace kaleidoscope {
|
||
6 years ago
|
namespace plugin {
|
||
8 years ago
|
|
||
7 years ago
|
class OneShot : public kaleidoscope::Plugin {
|
||
8 years ago
|
public:
|
||
6 years ago
|
OneShot(void) {
|
||
6 years ago
|
for (uint8_t i = 0; i < ONESHOT_KEY_COUNT; i++) {
|
||
6 years ago
|
state_[i].stickable = true;
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
7 years ago
|
static bool isOneShotKey(Key key) {
|
||
5 years ago
|
return (key.getRaw() >= kaleidoscope::ranges::OS_FIRST && key.getRaw() <= kaleidoscope::ranges::OS_LAST);
|
||
7 years ago
|
}
|
||
8 years ago
|
static bool isActive(void);
|
||
7 years ago
|
static bool isActive(Key key);
|
||
6 years ago
|
static bool isPressed();
|
||
|
static bool isSticky();
|
||
7 years ago
|
static bool isSticky(Key key);
|
||
6 years ago
|
static void cancel(bool with_stickies = false);
|
||
6 years ago
|
|
||
8 years ago
|
static uint16_t time_out;
|
||
7 years ago
|
static int16_t double_tap_time_out;
|
||
8 years ago
|
static uint16_t hold_time_out;
|
||
6 years ago
|
|
||
|
static inline void enableStickablity() {}
|
||
|
static void enableStickability(Key key);
|
||
|
template <typename... Keys>
|
||
|
static void enableStickability(Key key, Keys&&... keys) {
|
||
|
enableStickability(key);
|
||
|
enableStickability(keys...);
|
||
|
}
|
||
|
static void enableStickabilityForModifiers();
|
||
|
static void enableStickabilityForLayers();
|
||
|
|
||
|
static inline void disableStickability() {}
|
||
|
static void disableStickability(Key key);
|
||
|
template <typename... Keys>
|
||
|
static void disableStickability(Key key, Keys&&... keys) {
|
||
|
disableStickability(key);
|
||
|
disableStickability(keys...);
|
||
|
}
|
||
|
static void disableStickabilityForModifiers();
|
||
|
static void disableStickabilityForLayers();
|
||
|
|
||
|
static bool isStickable(Key key);
|
||
|
|
||
8 years ago
|
static bool isModifierActive(Key key);
|
||
8 years ago
|
|
||
7 years ago
|
EventHandlerResult beforeReportingState();
|
||
|
EventHandlerResult afterEachCycle();
|
||
5 years ago
|
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState);
|
||
7 years ago
|
|
||
|
void inject(Key mapped_key, uint8_t key_state);
|
||
|
|
||
8 years ago
|
private:
|
||
6 years ago
|
static constexpr uint8_t ONESHOT_KEY_COUNT = 16;
|
||
6 years ago
|
typedef struct {
|
||
|
bool active: 1;
|
||
|
bool pressed: 1;
|
||
|
bool stickable: 1;
|
||
|
bool sticky: 1;
|
||
|
uint8_t __reserved: 4;
|
||
|
uint8_t position;
|
||
|
} key_state_t;
|
||
6 years ago
|
static key_state_t state_[ONESHOT_KEY_COUNT];
|
||
6 years ago
|
|
||
6 years ago
|
static uint16_t start_time_;
|
||
8 years ago
|
static Key prev_key_;
|
||
|
static bool should_cancel_;
|
||
|
static bool should_cancel_stickies_;
|
||
7 years ago
|
|
||
8 years ago
|
static void injectNormalKey(uint8_t idx, uint8_t key_state);
|
||
8 years ago
|
static void activateOneShot(uint8_t idx);
|
||
|
static void cancelOneShot(uint8_t idx);
|
||
6 years ago
|
|
||
|
static bool isOneShotKey_(Key key) {
|
||
5 years ago
|
return key.getRaw() >= ranges::OS_FIRST && key.getRaw() <= ranges::OS_LAST;
|
||
6 years ago
|
}
|
||
|
static bool hasTimedOut() {
|
||
5 years ago
|
return Runtime.hasTimeExpired(start_time_, time_out);
|
||
6 years ago
|
}
|
||
8 years ago
|
};
|
||
6 years ago
|
}
|
||
8 years ago
|
}
|
||
|
|
||
6 years ago
|
extern kaleidoscope::plugin::OneShot OneShot;
|