Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to existing keymaps and userspace #14503

Merged
merged 16 commits into from
Sep 19, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions keyboards/doro67/multi/keymaps/konstantin/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once

#define DYNAMIC_KEYMAP_LAYER_COUNT 3

#define LAYER_FN
#define LAYER_NUMPAD
2 changes: 1 addition & 1 deletion keyboards/doro67/multi/keymaps/konstantin/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generic features
BOOTMAGIC_ENABLE = lite # Enable Bootmagic Lite
BOOTMAGIC_ENABLE = lite
COMMAND_ENABLE = yes
CONSOLE_ENABLE = yes
EXTRAKEY_ENABLE = yes
Expand Down
18 changes: 13 additions & 5 deletions keyboards/dz60/keymaps/konstantin_b/rules.mk
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
BACKLIGHT_ENABLE = no
BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite
USER_NAME := konstantin

# Generic features
BOOTMAGIC_ENABLE = lite
COMMAND_ENABLE = yes
CONSOLE_ENABLE = yes
EXTRAKEY_ENABLE = yes
MOUSEKEY_ENABLE = yes
NKRO_ENABLE = yes
RGBLIGHT_ENABLE = no
SPACE_CADET_ENABLE = no
TAP_DANCE_ENABLE = yes
UNICODEMAP_ENABLE = no

USER_NAME = konstantin
# Keyboard-specific features
BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = no
VIA_ENABLE = yes

# Firmware size reduction
GRAVE_ESC_ENABLE = no
MAGIC_ENABLE = no
SPACE_CADET_ENABLE = no
2 changes: 0 additions & 2 deletions keyboards/evyd13/wasdat/keymaps/konstantin/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once

#define DYNAMIC_KEYMAP_LAYER_COUNT 3

#define LAYER_FN
#define LAYER_NUMPAD
2 changes: 1 addition & 1 deletion keyboards/evyd13/wasdat/keymaps/konstantin/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generic features
BOOTMAGIC_ENABLE = lite # Enable Bootmagic Lite
BOOTMAGIC_ENABLE = lite
COMMAND_ENABLE = yes
CONSOLE_ENABLE = yes
EXTRAKEY_ENABLE = yes
Expand Down
2 changes: 0 additions & 2 deletions keyboards/kbdfans/kbd6x/keymaps/konstantin/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#pragma once

#define DYNAMIC_KEYMAP_LAYER_COUNT 3

#define LAYER_FN
106 changes: 58 additions & 48 deletions keyboards/kbdfans/kbd6x/keymaps/konstantin/keymap.c
Original file line number Diff line number Diff line change
@@ -1,93 +1,73 @@
#include QMK_KEYBOARD_H
#include "konstantin.h"

enum keycodes_keymap {
RCTRL = RANGE_KEYMAP,
};

enum layers_keymap {
L_RCTRL = LAYERS_KEYMAP,
};

void eeconfig_init_keymap(void) {
rgblight_sethsv(MODERN_DOLCH_RED);
rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
}

bool indicator_light = false;

bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case RGB_TOG ... RGB_SPD:
// Disable RGB controls when Fn/Caps indicator lights are on
if (indicator_light) {
return false;
}
// Shift+Toggle = reset RGB
if (record->event.pressed && keycode == RGB_TOG && get_mods() & MOD_MASK_SHIFT) {
eeconfig_init_keymap();
return false;
}
break;

// Combined RCtrl and layer
case RCTRL:
if (record->event.pressed) {
register_code(KC_RCTRL);
layer_on(L_RCTRL);
} else {
unregister_code(KC_RCTRL);
layer_off(L_RCTRL);
}
break;
}
enum keycodes_keymap {
RCTRL = RANGE_KEYMAP,
};

return true;
static inline void reset_light(void) {
rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
rgblight_sethsv(MODERN_DOLCH_RED);
}

static inline void fn_light(void) {
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
rgblight_sethsv_noeeprom(modern_dolch_red.h, modern_dolch_red.s, rgblight_get_val());
indicator_light = true;
}

static inline void caps_light(void) {
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
rgblight_sethsv_noeeprom(modern_dolch_cyan.h, modern_dolch_cyan.s, rgblight_get_val());
indicator_light = true;
}

static inline void restore_light(void) {
rgblight_config_t saved = { .raw = eeconfig_read_rgblight() };
rgblight_sethsv_noeeprom(saved.hue, saved.sat, saved.val);
rgblight_mode_noeeprom(saved.mode);
indicator_light = false;
rgblight_sethsv_noeeprom(saved.hue, saved.sat, saved.val);
}

static void check_light_layer(uint32_t state) {
static bool last_checked_layer;

static void check_light_layer(layer_state_t state) {
if (IS_LAYER_ON_STATE(state, L_FN)) {
fn_light();
} else if (IS_HOST_LED_ON(USB_LED_CAPS_LOCK)) {
caps_light();
} else {
restore_light();
}
last_checked_layer = true;
}

static void check_light_led(uint8_t usb_led) {
if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
static void check_light_led(uint8_t leds) {
if (IS_LED_ON(leds, USB_LED_CAPS_LOCK)) {
caps_light();
} else if (IS_LAYER_ON(L_FN)) {
fn_light();
} else {
restore_light();
}
last_checked_layer = false;
}

static void inline check_light(void) {
last_checked_layer
? check_light_layer(layer_state)
: check_light_led(host_keyboard_leds());
}

void eeconfig_init_keymap(void) {
reset_light();
}

static bool skip_led = false;

uint32_t layer_state_set_keymap(uint32_t state) {
static uint32_t prev_state = L_BASE;
layer_state_t layer_state_set_keymap(layer_state_t state) {
static layer_state_t prev_state = L_BASE;
if (IS_LAYER_ON_STATE(state, L_FN) != IS_LAYER_ON_STATE(prev_state, L_FN)) {
check_light_layer(state); // Fn state changed since last time
skip_led = IS_LAYER_ON_STATE(state, L_FN);
Expand All @@ -104,6 +84,36 @@ void led_set_keymap(uint8_t usb_led) {
check_light_led(usb_led);
}

bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case RGB_TOG ... RGB_SPD:
if (record->event.pressed) {
// Shift+Toggle = reset RGB
if (keycode == RGB_TOG && get_mods() & MOD_MASK_SHIFT) {
reset_light();
return false;
}
restore_light();
} else {
check_light();
}
break;

// Combined RCtrl and layer
case RCTRL:
if (record->event.pressed) {
register_code(KC_RCTRL);
layer_on(L_RCTRL);
} else {
unregister_code(KC_RCTRL);
layer_off(L_RCTRL);
}
break;
}

return true;
}

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/* Base layer
* ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐
Expand Down Expand Up @@ -157,14 +167,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────┬───┤
* │ │RTg│RV-│RV+│RMd│ │ │ │ │ │ │ │ │
* └─────┬──┴┬──┴──┬┴───┴───┴───┴───┴───┴───┴──┬┴───┴┬───┬─┴───┘
* │DPR│DstNA│ │ │ │
* │DPR│DstNA│ │RGui │ │
* └───┴─────┴───────────────────────────┴─────┴───┘
*/
[L_RCTRL] = LAYOUT(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, CLEAR,
_______, TOP, MV_UP, BOTTOM, TAB_PRV, _______, _______, _______, _______, _______, _______, _______, _______, DEL_NXT,
_______, MV_LEFT, MV_DOWN, MV_RGHT, TAB_NXT, _______, _______, _______, _______, _______, _______, _______, _______,
_______, RGB_TOG, RGB_VAD, RGB_VAI, RGB_MOD, _______, _______, _______, _______, _______, _______, _______, _______,
XXXXXXX, DST_P_R, DST_N_A, _______, _______, _______, XXXXXXX
XXXXXXX, DST_P_R, DST_N_A, _______, KC_RGUI, _______, XXXXXXX
),
};
4 changes: 2 additions & 2 deletions keyboards/kbdfans/kbd6x/keymaps/konstantin/rules.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generic features
BOOTMAGIC_ENABLE = lite # Enable Bootmagic Lite
BOOTMAGIC_ENABLE = lite
COMMAND_ENABLE = yes
CONSOLE_ENABLE = no
CONSOLE_ENABLE = yes
EXTRAKEY_ENABLE = yes
MOUSEKEY_ENABLE = yes
NKRO_ENABLE = yes
Expand Down
3 changes: 2 additions & 1 deletion keyboards/melody96/keymaps/konstantin/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generic features
BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite
BOOTMAGIC_ENABLE = lite
COMMAND_ENABLE = yes
CONSOLE_ENABLE = yes
EXTRAKEY_ENABLE = yes
Expand All @@ -11,6 +11,7 @@ UNICODEMAP_ENABLE = yes
# Keyboard-specific features
BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = yes
VIA_ENABLE = yes

# Firmware size reduction
GRAVE_ESC_ENABLE = no
Expand Down
2 changes: 1 addition & 1 deletion keyboards/whitefox/keymaps/konstantin/rules.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generic features
BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite
BOOTMAGIC_ENABLE = lite
COMMAND_ENABLE = yes
CONSOLE_ENABLE = yes
EXTRAKEY_ENABLE = yes
Expand Down
2 changes: 1 addition & 1 deletion users/konstantin/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// Tapping
#define PERMISSIVE_HOLD
#define TAPPING_TERM 200
#define TAPPING_TOGGLE 3
#define TAPPING_TOGGLE 2

// Unicode
#define UNICODE_CYCLE_PERSIST false
Expand Down
70 changes: 35 additions & 35 deletions users/konstantin/konstantin.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,41 @@ void keyboard_post_init_user(void) {
keyboard_post_init_keymap();
}

__attribute__((weak))
layer_state_t layer_state_set_keymap(layer_state_t state) {
return state;
}

layer_state_t layer_state_set_user(layer_state_t state) {
state = layer_state_set_keymap(state);

#ifdef LAYER_NUMPAD
bool numpad = IS_LAYER_ON_STATE(state, L_NUMPAD);
bool num_lock = IS_HOST_LED_ON(USB_LED_NUM_LOCK);
if (numpad != num_lock) {
tap_code(KC_NLCK); // Toggle Num Lock to match Numpad layer state
}
#endif

return state;
}

__attribute__((weak))
void led_set_keymap(uint8_t usb_led) {}

void led_set_user(uint8_t usb_led) {
led_set_keymap(usb_led);
}

__attribute__((weak))
bool led_update_keymap(led_t led_state) {
return true;
}

bool led_update_user(led_t led_state) {
return led_update_keymap(led_state);
}

__attribute__((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
Expand Down Expand Up @@ -91,38 +126,3 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {

return true;
}

__attribute__((weak))
uint32_t layer_state_set_keymap(uint32_t state) {
return state;
}

layer_state_t layer_state_set_user(layer_state_t state) {
state = layer_state_set_keymap(state);

#ifdef LAYER_NUMPAD
bool numpad = IS_LAYER_ON_STATE(state, L_NUMPAD);
bool num_lock = IS_HOST_LED_ON(USB_LED_NUM_LOCK);
if (numpad != num_lock) {
tap_code(KC_NLCK); // Toggle Num Lock to match Numpad layer state
}
#endif

return state;
}

__attribute__((weak))
void led_set_keymap(uint8_t usb_led) {}

void led_set_user(uint8_t usb_led) {
led_set_keymap(usb_led);
}

__attribute__((weak))
bool led_update_keymap(led_t led_state) {
return true;
}

bool led_update_user(led_t led_state) {
return led_update_keymap(led_state);
}
26 changes: 14 additions & 12 deletions users/konstantin/konstantin.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@
set_mods(mods); \
}

enum keycodes_user {
CLEAR = SAFE_RANGE,
DST_P_R,
DST_N_A,

RANGE_KEYMAP,
};

enum layers_user {
L_BASE,
#ifdef LAYER_FN
Expand All @@ -76,11 +68,21 @@ enum layers_user {
LAYERS_KEYMAP,
};

enum keycodes_user {
CLEAR = SAFE_RANGE,
DST_P_R,
DST_N_A,

RANGE_KEYMAP,
};

void keyboard_pre_init_keymap(void);
void eeconfig_init_keymap(void);
void keyboard_post_init_keymap(void);

bool process_record_keymap(uint16_t keycode, keyrecord_t *record);
uint32_t layer_state_set_keymap(uint32_t state);
void led_set_keymap(uint8_t usb_led);
bool led_update_keymap(led_t led_state);
layer_state_t layer_state_set_keymap(layer_state_t state);

void led_set_keymap(uint8_t usb_led);
bool led_update_keymap(led_t led_state);

bool process_record_keymap(uint16_t keycode, keyrecord_t *record);
Loading