Keymap: xtonhasvim updates (#3768)

* cherrypicking file changes just for updates

* removed unused heat foo

* avoid defining own min/max

* add license

* formatting
This commit is contained in:
xton 2018-08-28 19:54:17 -04:00 committed by Drashna Jaelre
parent 3c20983055
commit 3892829d74
9 changed files with 398 additions and 108 deletions

View File

@ -5,9 +5,13 @@ enum layers {
_QWERTY,
_FUN,
_MOVE,
_MOUSE
_MOUSE,
_CMD
};
extern uint8_t vim_cmd_layer(void) { return _CMD; }
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QWERTY] = LAYOUT(
@ -15,21 +19,21 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
LCTL_T(KC_ESC), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(_MOVE,KC_SCLN), KC_QUOT, KC_ENT,
KC_LSFT, KC_NO, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_NO,
KC_LCTL, KC_LALT, KC_LGUI, VIM_START, TG(_MOUSE), KC_SPC, KC_RGUI, KC_RALT, X_____X, KC_RCTL, MO(_FUN)),
LSFT(KC_LALT), KC_LALT, KC_LGUI, VIM_START, TG(_MOUSE), KC_SPC, KC_RGUI, KC_RALT, X_____X, KC_RCTL, MO(_FUN)),
[_FUN] = LAYOUT(
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_DEL,
_______, RGB_TOG, RGB_MOD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, RGB_VAI, RGB_VAD, _______, _______, _______, _______, RESET,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, BL_DEC, BL_TOGG, BL_INC, BL_STEP, _______, _______, _______, _______, _______, _______,
TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_QWERTY)),
[_MOVE] = LAYOUT(
X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X,
X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, KC_HOME, KC_PGDN, KC_PGUP, KC_END, X_____X, X_____X, X_____X, X_____X,
X_____X, X_____X, LGUI(KC_LBRC), LGUI(LSFT(KC_LBRC)), LGUI(LSFT(KC_RBRC)), LGUI(KC_RBRC), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, X_____X, X_____X, X_____X,
_______, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, _______,
TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_QWERTY)),
[_MOUSE] = LAYOUT(
@ -37,21 +41,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
X_____X, X_____X, X_____X, KC_MS_UP, X_____X, X_____X, KC_MS_WH_LEFT, KC_MS_WH_DOWN, KC_MS_WH_UP, KC_MS_WH_RIGHT, X_____X, X_____X, X_____X, X_____X,
X_____X, X_____X,KC_MS_LEFT, KC_MS_DOWN, KC_MS_RIGHT, X_____X, X_____X, KC_MS_BTN1, KC_MS_BTN2, KC_MS_BTN3, X_____X, X_____X, X_____X,
_______, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, _______,
TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
[_EDIT] = LAYOUT(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
TO(_QWERTY), _______, _______, VIM_START, _______, _______, _______, _______, _______, _______, _______),
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_QWERTY)),
[_CMD] = LAYOUT(
X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X,
X_____X, X_____X, VIM_W, VIM_E, X_____X, X_____X, VIM_Y, VIM_U, VIM_I, VIM_O, VIM_P, X_____X, X_____X, X_____X,
VIM_ESC, VIM_A, VIM_S, VIM_D, X_____X, VIM_G, VIM_H, VIM_J, VIM_K, VIM_L, X_____X, X_____X, X_____X,
VIM_SHIFT, X_____X, X_____X, VIM_X, VIM_C, VIM_V, VIM_B, X_____X, X_____X, VIM_COMMA, VIM_PERIOD, X_____X, VIM_SHIFT,X_____X,
TO(_QWERTY), _______, _______, TO(_QWERTY), X_____X, X_____X, _______, _______, _______, _______, _______),
_______, _______, _______, TO(_QWERTY), X_____X, X_____X, _______, _______, _______, _______, TO(_QWERTY)),
};

View File

@ -3,7 +3,7 @@
#include "../../config.h"
#define MUSIC_MASK (keycode != KC_NO)
// #define MUSIC_MASK (keycode != KC_NO)
/*
* MIDI options
@ -16,7 +16,7 @@
- MIDI notes can be sent when in Music mode is on
*/
#define MIDI_BASIC
// #define MIDI_BASIC
/* enable advanced MIDI features:
- MIDI notes can be added to the keymap
@ -32,12 +32,6 @@
// help for fast typist+dual function keys?
#define PERMISSIVE_HOLD
/* disable debug print */
#define NO_DEBUG
/* disable print */
#define NO_PRINT
/* speed up mousekeys a bit */
#define MOUSEKEY_DELAY 50
#define MOUSEKEY_INTERVAL 20

View File

@ -16,6 +16,7 @@
#include QMK_KEYBOARD_H
#include "xtonhasvim.h"
#include "fancylighting.h"
/************************************
* states
@ -27,7 +28,15 @@ enum layers {
_RAISE,
_ADJUST,
_MOVE,
_MOUSE
_MOUSE,
_CMD
};
extern uint8_t vim_cmd_layer(void) { return _CMD; }
enum keymap_keycodes {
RAISE = VIM_SAFE_RANGE,
LOWER
};
/************************************
@ -48,14 +57,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* `-----------------------------------------------------------------------------------'
*
* - Ctrl acts as Esc when tapped.
* - Holding A or ; switches to movement layer.
* - Holding ; switches to movement layer.
* - Raise and Lower are one-shot layers.
*/
[_QWERTY] = LAYOUT_planck_mit(
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
LCTL_T(KC_ESC), LT(_MOVE,KC_A), KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(_MOVE,KC_SCLN), KC_QUOT,
LCTL_T(KC_ESC), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, LT(_MOVE,KC_SCLN), KC_QUOT,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, RSFT_T(KC_ENT),
TG(_MOUSE), X_____X, KC_LALT, KC_LGUI, OSL(_LOWER), KC_SPC, OSL(_RAISE), KC_LGUI, KC_LALT, X_____X, VIM_START
LSFT(KC_LALT), TG(_MOUSE), KC_LALT, KC_LGUI, LOWER, KC_SPC, RAISE, KC_LGUI, KC_LALT, X_____X, VIM_START
),
/* Lower
@ -72,8 +81,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_LOWER] = LAYOUT_planck_mit(
KC_TILD, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_BSPC,
KC_DEL, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_PIPE,
_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, X_____X, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY,
X_____X, TO(_QWERTY), _______, _______, _______, KC_BSPC, OSL(_ADJUST), _______, _______, TO(_QWERTY), X_____X
_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, X_____X, X_____X, X_____X, X_____X, FIREY_RETURN,
_______, TO(_QWERTY), _______, _______, _______, KC_BSPC, _______, _______, _______, TO(_QWERTY), X_____X
),
/* Raise
@ -90,8 +99,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_RAISE] = LAYOUT_planck_mit(
KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, KC_BSPC,
KC_DEL, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSLS,
_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY,
X_____X, TO(_QWERTY), _______, _______, OSL(_ADJUST), X_____X, _______, _______, _______, TO(_QWERTY), X_____X
_______, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, X_____X, X_____X, X_____X, X_____X, FIREY_RETURN,
_______, TO(_QWERTY), _______, _______, _______, KC_BSPC, _______, _______, _______, TO(_QWERTY), X_____X
),
@ -99,17 +108,17 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* ,-------------------------------------------------------------------------------------.
* |RGBPlain| Reset| | | | | | | | | | Del |
* |--------+------+------+------+------+-------------+------+------+------+------+------|
* |RGBMode-| | |Aud on|Audoff|AGnorm|AGswap| | | | |Lite+ |
* |RGBMode-| | | | | | | | | | |Lite+ |
* |--------+------+------+------+------+------|------+------+------+------+------+------|
* |RGBMode+|Voice-|Voice+|Mus on|Musoff|MIDIon|MIDIof| | | | |Lite- |
* |RGBMode+| | | | | | | Next | Vol- | Vol+ | Play |Lite- |
* |--------+------+------+------+------+------+------+------+------+------+------+------|
* | RGB | Bail | | | | | | | | Bail | |
* `-------------------------------------------------------------------------------------'
*/
[_ADJUST] = LAYOUT_planck_mit(
RGB_MODE_PLAIN, RESET, DEBUG, _______, _______, _______, _______, _______, _______, _______, _______, KC_DEL,
RGB_MODE_REVERSE, _______, MU_MOD, AU_ON, AU_OFF, AG_NORM, AG_SWAP, _______, _______, _______, _______, RGB_VAI,
RGB_MODE_FORWARD, MUV_DE, MUV_IN, MU_ON, MU_OFF, MI_ON, MI_OFF, _______, _______, _______, _______, RGB_VAD,
RGB_MODE_REVERSE, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, RGB_VAI,
RGB_MODE_FORWARD, _______, _______, _______, _______, _______, _______, KC_MNXT, KC_VOLD, KC_VOLU, KC_MPLY, RGB_VAD,
RGB_TOG, TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, TO(_QWERTY), X_____X
),
@ -120,7 +129,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
TO(_QWERTY), X_____X, X_____X, X_____X, X_____X, X_____X, KC_HOME, KC_PGDN, KC_PGUP, KC_END, X_____X, X_____X,
_______, X_____X, LGUI(KC_LBRC), LGUI(LSFT(KC_LBRC)), LGUI(LSFT(KC_RBRC)), LGUI(KC_RBRC), KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, X_____X, X_____X,
_______, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, X_____X, _______,
X_____X, TO(_QWERTY), _______, _______, _______, X_____X, _______, _______, _______, TO(_QWERTY), X_____X
_______, TO(_QWERTY), _______, _______, _______, X_____X, _______, _______, _______, TO(_QWERTY), X_____X
),
/* mouse layer
@ -132,68 +141,124 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, TO(_QWERTY), _______, _______, _______, X_____X, _______, _______, _______, TO(_QWERTY), X_____X
),
/* vim edit mode. just has an escape -> _CMD key */
[_EDIT] = LAYOUT_planck_mit(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
VIM_START, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, TO(_QWERTY), _______, _______, _______, _______, _______, _______, _______, TO(_QWERTY), _______
),
/* vim command layer.
*/
[_CMD] = LAYOUT_planck_mit(
X_____X, X_____X, VIM_W, VIM_E, X_____X, X_____X, VIM_Y, VIM_U, VIM_I, VIM_O, VIM_P, X_____X,
VIM_ESC, VIM_A, VIM_S, VIM_D, X_____X, VIM_G, VIM_H, VIM_J, VIM_K, VIM_L, X_____X, X_____X,
VIM_SHIFT, X_____X, VIM_X, VIM_C, VIM_V, VIM_B, X_____X, X_____X, VIM_COMMA, VIM_PERIOD, X_____X, VIM_SHIFT,
X_____X, TO(_QWERTY), _______, _______, X_____X, X_____X, X_____X, _______, _______, TO(_QWERTY), X_____X
_______, TO(_QWERTY), _______, _______, X_____X, X_____X, X_____X, _______, _______, TO(_QWERTY), X_____X
)
};
#define C_RED 0xFF, 0x00, 0x00
#define C_GRN 0x00, 0xFF, 0x00
#define C_BLU 0x00, 0x00, 0xFF
#define C_YAN 0x00, 0xFF, 0xFF
#define C_PRP 0x7A, 0x00, 0xFF
#define C_ORG 0xFF, 0x93, 0x00
/** Set just 4 LEDs closest to the user. Slightly less annoying to bystanders.*/
void rgbflag(uint8_t r, uint8_t g, uint8_t b) {
for(int i = 0; i < RGBLED_NUM; i++){
switch(i) {
case 9 ... 12:
// rgblight_setrgb_at(r,g,b,i);
led[i].r = r;
led[i].g = g;
led[i].b = b;
void rgbflag(uint8_t r, uint8_t g, uint8_t b, uint8_t rr, uint8_t gg, uint8_t bb) {
LED_TYPE *target_led = user_rgb_mode ? shadowed_led : led;
for (int i = 0; i < RGBLED_NUM; i++) {
switch (i) {
case 12: case 13:
target_led[i].r = r;
target_led[i].g = g;
target_led[i].b = b;
break;
case 8: case 9:
target_led[i].r = rr;
target_led[i].g = gg;
target_led[i].b = bb;
break;
default:
// rgblight_setrgb_at(0,0,0,i);
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
target_led[i].r = 0;
target_led[i].g = 0;
target_led[i].b = 0;
break;
}
}
rgblight_set();
}
uint32_t layer_state_set_user(uint32_t state) {
if(rgblight_get_mode() == 1) {
switch (biton32(state)) {
void set_state_leds(void) {
if (rgblight_get_mode() == 1) {
switch (biton32(layer_state)) {
case _RAISE:
rgbflag(C_BLU, C_GRN);
break;
case _LOWER:
rgbflag(C_BLU, C_RED);
break;
case _ADJUST:
rgbflag(0x00, 0x00, 0xFF);
rgbflag(C_BLU, C_PRP);
break;
case _MOVE:
rgbflag(C_RED, C_PRP);
break;
case _MOUSE:
rgbflag(0xFF, 0x00, 0x00);
rgbflag(C_RED, C_GRN);
break;
case _CMD:
rgbflag(0x00, 0xFF, 0x00);
switch(vstate) {
case VIM_V:
case VIM_VI:
case VIM_VS:
rgbflag(C_GRN, C_YAN);
break;
case _EDIT:
rgbflag(0x7A, 0x00, 0xFF);
case VIM_C:
case VIM_CI:
rgbflag(C_GRN, C_ORG);
break;
case VIM_D:
case VIM_DI:
rgbflag(C_GRN, C_RED);
break;
case VIM_G:
rgbflag(C_GRN, C_BLU);
break;
case VIM_Y:
rgbflag(C_GRN, C_PRP);
break;
case VIM_START:
default:
rgbflag(C_GRN, C_GRN);
break;
}
break;
default: // for any other layers, or the default layer
rgbflag(0x00, 0xFF, 0xFF);
rgbflag(C_YAN, C_YAN);
break;
}
}
return state;
}
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case LOWER:
if (record->event.pressed) {
layer_on(_LOWER);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
} else {
layer_off(_LOWER);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
}
return false;
break;
case RAISE:
if (record->event.pressed) {
layer_on(_RAISE);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
} else {
layer_off(_RAISE);
update_tri_layer(_LOWER, _RAISE, _ADJUST);
}
return false;
break;
}
return true;
}

View File

@ -4,3 +4,5 @@ endif
MOUSEKEY_ENABLE = yes
BACKLIGHT_ENABLE = no
AUDIO_ENABLE = no
CONSOLE_ENABLE = no # Console for debug(+400)

View File

@ -0,0 +1,167 @@
/* Copyright 2015-2017 Christon DeWan
*
* 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, either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef RGBLIGHT_ENABLE
#include <math.h>
#include "rgblight.h"
#include "color.h"
#include "fancylighting.h"
__attribute__ ((weak))
void matrix_scan_keymap(void) {
// override me, if you want.
return;
}
#define ABSDIFF(a,b) ((a)>(b)?(a)-(b):(b)-(a))
#define FADE_BACK_TIME 500
#define BREATH_FIRE_TIME 1000
#define ANIMATION_STEP_INTERVAL 20
#define POWER_KEY_OFFSET (RGBLED_NUM / 2)
#define SPACE_OFFSET_MAX (RGBLED_NUM / 2)
uint16_t effect_start_timer = 0;
uint8_t user_rgb_mode = 0;
LED_TYPE shadowed_led[RGBLED_NUM] = {0};
void start_firey_return(void) {
user_rgb_mode = BREATH_FIRE;
effect_start_timer = timer_read();
for(uint8_t i = 0; i < RGBLED_NUM; i++) {
shadowed_led[i] = led[i];
}
}
/** 0---max
* [___]
* [__/]
* [_/\]
* [/\_]
* [\__]
* [___]
**/
void set_color_for_offsets(uint16_t time_offset, uint16_t space_offset, uint8_t idx) {
float time_progress = (float)time_offset / BREATH_FIRE_TIME;
float space_progress = (float)space_offset / SPACE_OFFSET_MAX;
float progress = time_progress * 5.0 - space_progress;
if(progress > 1.0) {
progress -= 1.0;
progress /= 4.0;
progress = 1.0 - progress;
}
progress = fmax(0.0,progress);
progress *= progress; // squared!
float alpha = (time_progress + 0.1) * 7.0 - space_progress;
alpha = fmin(1.0, alpha*alpha);
LED_TYPE px[1] = {0};
sethsv((uint16_t)(fmod(time_progress * 1.5 + space_progress,1.0)*360), 255, (uint8_t)(progress*255),&px[0]);
led[idx].r = alpha * px[0].r + ( 1.0 - alpha) * shadowed_led[idx].r;
led[idx].g = alpha * px[0].g + ( 1.0 - alpha) * shadowed_led[idx].g;
led[idx].b = alpha * px[0].b + ( 1.0 - alpha) * shadowed_led[idx].b;
}
/**
* It's actually a rainbow: a fire curve didn't really look right.
* it's still cool, though!
*/
void rgb_mode_breath_fire(void) {
static uint16_t last_timer = 0;
if(!last_timer) last_timer = timer_read();
uint16_t this_timer = timer_read();
// too soon. don't spam updates
if(this_timer - last_timer < ANIMATION_STEP_INTERVAL) return;
uint16_t elapsed = this_timer - effect_start_timer;
last_timer = this_timer;
if(elapsed >= BREATH_FIRE_TIME) {
// complete
user_rgb_mode = FADE_BACK;
effect_start_timer = this_timer;
} else {
// linear fade
for(uint16_t i = 0; i < RGBLED_NUM; i++) {
uint16_t space_offset = ABSDIFF(i,POWER_KEY_OFFSET);
if(space_offset > SPACE_OFFSET_MAX) space_offset = RGBLED_NUM - space_offset;
set_color_for_offsets(elapsed, space_offset, i);
}
rgblight_set();
}
}
void rgb_mode_fade_back(void) {
static uint16_t last_timer = 0;
if(!last_timer) last_timer = timer_read();
uint16_t this_timer = timer_read();
// too soon. don't spam updates
if(this_timer - last_timer < ANIMATION_STEP_INTERVAL) return;
uint16_t elapsed = this_timer - effect_start_timer;
last_timer = this_timer;
float progress = (float)elapsed / FADE_BACK_TIME;
progress = fmin(1.0,progress);
for(uint8_t i = 0; i < RGBLED_NUM; i++) {
led[i].r = shadowed_led[i].r * progress;
led[i].g = shadowed_led[i].g * progress;
led[i].b = shadowed_led[i].b * progress;
}
rgblight_set();
if(elapsed >= FADE_BACK_TIME) user_rgb_mode = 0;
}
/** called when layer state or vstate has changed */
__attribute__ ((weak))
void set_state_leds(void) {
return;
}
void matrix_scan_user(void) {
static uint32_t last_layer = 0;
static uint32_t last_vstate = 0;
if(last_layer != layer_state || last_vstate != vstate) set_state_leds();
last_layer = layer_state;
last_vstate = vstate;
switch (user_rgb_mode) {
case BREATH_FIRE:
rgb_mode_breath_fire();
break;
case FADE_BACK:
rgb_mode_fade_back();
break;
}
matrix_scan_keymap();
}
#else
void start_firey_return(void) {}
#endif

View File

@ -0,0 +1,35 @@
p /* Copyright 2015-2017 Christon DeWan
*
* 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, either version 2 of the License, or
* (at your option) any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _fancy_lighting_h
#define _fancy_lighting_h
#ifdef RGBLIGHT_ENABLE
#include "xtonhasvim.h"
extern uint8_t user_rgb_mode;
extern LED_TYPE shadowed_led[];
void start_firey_return(void);
#endif //_fancy_lighting_h
enum xtonhasvim_rgbmodes {
BREATH_FIRE = 1,
FADE_BACK
};
#endif //RGBLIGHT_ENABLE

View File

@ -1 +1,2 @@
SRC += xtonhasvim.c
SRC += fancylighting.c

View File

@ -15,6 +15,7 @@
*/
#include "xtonhasvim.h"
#include "fancylighting.h"
/************************************
* helper foo
@ -53,13 +54,13 @@ static void ALT(uint16_t keycode) {
}
static uint16_t vstate = VIM_START;
uint16_t vstate = VIM_START;
static bool yank_was_lines = false;
static bool SHIFTED = false;
static uint32_t mod_override_layer_state = 0;
static uint16_t mod_override_triggering_key = 0;
static void edit(void) { vstate = VIM_START; layer_on(_EDIT); layer_off(_CMD); }
static void edit(void) { vstate = VIM_START; layer_clear(); }
#define EDIT edit()
@ -102,25 +103,54 @@ static void simple_movement(uint16_t keycode) {
}
}
static void comma_period(uint16_t keycode) {
switch (keycode) {
case VIM_COMMA:
if (SHIFTED) {
// indent
CMD(KC_LBRACKET);
} else {
// toggle comment
CMD(KC_SLASH);
}
break;
case VIM_PERIOD:
if (SHIFTED) {
// outdent
CMD(KC_RBRACKET);
}
break;
}
}
__attribute__ ((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}
#define PASS_THRU process_record_keymap(keycode, record)
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if(record->event.pressed && layer_state_is(_CMD) && IS_MOD(keycode)) {
/* keymap gets first whack */
if(!process_record_keymap(keycode, record)) return false;
/****** FIREY_RETURN *****/
if(record->event.pressed && keycode == FIREY_RETURN) {
start_firey_return();
TAP(KC_ENT);
}
/****** mod passthru *****/
if(record->event.pressed && layer_state_is(vim_cmd_layer()) && (IS_MOD(keycode) || keycode == LSFT(KC_LALT))) {
mod_override_layer_state = layer_state;
mod_override_triggering_key = keycode;
// TODO: change this to track key location instead
layer_clear();
return PASS_THRU; // let the event fall through...
return true; // let the event fall through...
}
if(mod_override_layer_state && !record->event.pressed && keycode == mod_override_triggering_key) {
layer_state_set(mod_override_layer_state);
mod_override_layer_state = 0;
mod_override_triggering_key = 0;
return PASS_THRU;
return true;
}
if (VIM_START <= keycode && keycode <= VIM_ESC) {
@ -132,7 +162,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
if(keycode == VIM_START) {
// entry from anywhere
layer_on(_CMD);
layer_on(vim_cmd_layer());
vstate = VIM_START;
// reset state
@ -176,7 +206,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
break;
case VIM_D:
if(SHIFTED) {
TAP(KC_K);
CTRL(KC_K);
} else {
vstate = VIM_D;
}
@ -300,19 +330,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
break;
case VIM_COMMA:
if(SHIFTED) {
// indent
CMD(KC_LBRACKET);
} else {
// toggle comment
CMD(KC_SLASH);
}
break;
case VIM_PERIOD:
if(SHIFTED) {
// outdent
CMD(KC_RBRACKET);
}
comma_period(keycode);
break;
}
break;
@ -483,6 +502,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
TAP(KC_RIGHT);
vstate = VIM_START;
break;
case VIM_COMMA:
case VIM_PERIOD:
comma_period(keycode);
break;
default:
// do nothing
break;
@ -539,6 +562,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
TAP(KC_RIGHT);
vstate = VIM_START;
break;
case VIM_COMMA:
case VIM_PERIOD:
comma_period(keycode);
break;
default:
// do nothing
break;
@ -610,6 +637,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
return false;
} else {
return PASS_THRU;
return true;
}
}

View File

@ -26,6 +26,7 @@ bool process_record_xtonhasvim(uint16_t keycode, keyrecord_t *record);
enum xtonhasvim_keycodes {
DUMMY = SAFE_RANGE,
FIREY_RETURN, // kick off special effects
VIM_START, // bookend for vim states
VIM_A,
VIM_B,
@ -57,10 +58,10 @@ enum xtonhasvim_keycodes {
VIM_SAFE_RANGE // start other keycodes here.
};
enum xtonhasvim_layers {
_EDIT = 12,
_CMD
};
// NOTE: YOU MUST DEFINE THIS
extern uint8_t vim_cmd_layer(void);
extern uint16_t vstate;
#endif