summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
Diffstat (limited to 'quantum')
-rw-r--r--quantum/keymap_common.c12
-rw-r--r--quantum/process_keycode/process_magic.c179
-rw-r--r--quantum/process_keycode/process_magic.h20
-rw-r--r--quantum/process_keycode/process_rgb.c141
-rw-r--r--quantum/process_keycode/process_rgb.h20
-rw-r--r--quantum/quantum.c457
-rw-r--r--quantum/quantum.h8
-rw-r--r--quantum/quantum_keycodes.h35
-rw-r--r--quantum/rgb_matrix.h40
9 files changed, 477 insertions, 435 deletions
diff --git a/quantum/keymap_common.c b/quantum/keymap_common.c
index 4fa45ac37b..5877273931 100644
--- a/quantum/keymap_common.c
+++ b/quantum/keymap_common.c
@@ -52,9 +52,6 @@ action_t action_for_key(uint8_t layer, keypos_t key) {
uint8_t action_layer, when, mod;
switch (keycode) {
- case KC_FN0 ... KC_FN31:
- action.code = keymap_function_id_to_action(FN_INDEX(keycode));
- break;
case KC_A ... KC_EXSEL:
case KC_LCTRL ... KC_RGUI:
action.code = ACTION_KEY(keycode);
@@ -65,9 +62,11 @@ action_t action_for_key(uint8_t layer, keypos_t key) {
case KC_AUDIO_MUTE ... KC_BRIGHTNESS_DOWN:
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
break;
+#ifdef MOUSEKEY_ENABLE
case KC_MS_UP ... KC_MS_ACCEL2:
action.code = ACTION_MOUSEKEY(keycode);
break;
+#endif
case KC_TRNS:
action.code = ACTION_TRANSPARENT;
break;
@@ -76,17 +75,24 @@ action_t action_for_key(uint8_t layer, keypos_t key) {
// Split it up
action.code = ACTION_MODS_KEY(keycode >> 8, keycode & 0xFF); // adds modifier to key
break;
+#ifndef NO_ACTION_FUNCTION
+ case KC_FN0 ... KC_FN31:
+ action.code = keymap_function_id_to_action(FN_INDEX(keycode));
+ break;
case QK_FUNCTION ... QK_FUNCTION_MAX:;
// Is a shortcut for function action_layer, pull last 12bits
// This means we have 4,096 FN macros at our disposal
action.code = keymap_function_id_to_action((int)keycode & 0xFFF);
break;
+#endif
+#ifndef NO_ACTION_MACRO
case QK_MACRO ... QK_MACRO_MAX:
if (keycode & 0x800) // tap macros have upper bit set
action.code = ACTION_MACRO_TAP(keycode & 0xFF);
else
action.code = ACTION_MACRO(keycode & 0xFF);
break;
+#endif
case QK_LAYER_TAP ... QK_LAYER_TAP_MAX:
action.code = ACTION_LAYER_TAP_KEY((keycode >> 0x8) & 0xF, keycode & 0xFF);
break;
diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c
new file mode 100644
index 0000000000..c70764dea1
--- /dev/null
+++ b/quantum/process_keycode/process_magic.c
@@ -0,0 +1,179 @@
+/* Copyright 2019 Jack Humbert
+ *
+ * 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/>.
+ */
+#include "process_magic.h"
+
+#ifdef AUDIO_ENABLE
+# ifndef AG_NORM_SONG
+# define AG_NORM_SONG SONG(AG_NORM_SOUND)
+# endif
+# ifndef AG_SWAP_SONG
+# define AG_SWAP_SONG SONG(AG_SWAP_SOUND)
+# endif
+# ifndef CG_NORM_SONG
+# define CG_NORM_SONG SONG(AG_NORM_SOUND)
+# endif
+# ifndef CG_SWAP_SONG
+# define CG_SWAP_SONG SONG(AG_SWAP_SOUND)
+# endif
+float ag_norm_song[][2] = AG_NORM_SONG;
+float ag_swap_song[][2] = AG_SWAP_SONG;
+float cg_norm_song[][2] = CG_NORM_SONG;
+float cg_swap_song[][2] = CG_SWAP_SONG;
+#endif
+
+/**
+ * MAGIC actions (BOOTMAGIC without the boot)
+ */
+bool process_magic(uint16_t keycode, keyrecord_t *record) {
+ // skip anything that isn't a keyup
+ if (record->event.pressed) {
+ switch (keycode) {
+ case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI:
+ case MAGIC_SWAP_LCTL_LGUI ... MAGIC_TOGGLE_CTL_GUI:
+ /* keymap config */
+ keymap_config.raw = eeconfig_read_keymap();
+ switch (keycode) {
+ case MAGIC_SWAP_CONTROL_CAPSLOCK:
+ keymap_config.swap_control_capslock = true;
+ break;
+ case MAGIC_CAPSLOCK_TO_CONTROL:
+ keymap_config.capslock_to_control = true;
+ break;
+ case MAGIC_SWAP_LALT_LGUI:
+ keymap_config.swap_lalt_lgui = true;
+ break;
+ case MAGIC_SWAP_RALT_RGUI:
+ keymap_config.swap_ralt_rgui = true;
+ break;
+ case MAGIC_SWAP_LCTL_LGUI:
+ keymap_config.swap_lctl_lgui = true;
+ break;
+ case MAGIC_SWAP_RCTL_RGUI:
+ keymap_config.swap_rctl_rgui = true;
+ break;
+ case MAGIC_NO_GUI:
+ keymap_config.no_gui = true;
+ break;
+ case MAGIC_SWAP_GRAVE_ESC:
+ keymap_config.swap_grave_esc = true;
+ break;
+ case MAGIC_SWAP_BACKSLASH_BACKSPACE:
+ keymap_config.swap_backslash_backspace = true;
+ break;
+ case MAGIC_HOST_NKRO:
+ clear_keyboard(); // clear first buffer to prevent stuck keys
+ keymap_config.nkro = true;
+ break;
+ case MAGIC_SWAP_ALT_GUI:
+ keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true;
+#ifdef AUDIO_ENABLE
+ PLAY_SONG(ag_swap_song);
+#endif
+ break;
+ case MAGIC_SWAP_CTL_GUI:
+ keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true;
+#ifdef AUDIO_ENABLE
+ PLAY_SONG(cg_swap_song);
+#endif
+ break;
+ case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
+ keymap_config.swap_control_capslock = false;
+ break;
+ case MAGIC_UNCAPSLOCK_TO_CONTROL:
+ keymap_config.capslock_to_control = false;
+ break;
+ case MAGIC_UNSWAP_LALT_LGUI:
+ keymap_config.swap_lalt_lgui = false;
+ break;
+ case MAGIC_UNSWAP_RALT_RGUI:
+ keymap_config.swap_ralt_rgui = false;
+ break;
+ case MAGIC_UNSWAP_LCTL_LGUI:
+ keymap_config.swap_lctl_lgui = false;
+ break;
+ case MAGIC_UNSWAP_RCTL_RGUI:
+ keymap_config.swap_rctl_rgui = false;
+ break;
+ case MAGIC_UNNO_GUI:
+ keymap_config.no_gui = false;
+ break;
+ case MAGIC_UNSWAP_GRAVE_ESC:
+ keymap_config.swap_grave_esc = false;
+ break;
+ case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
+ keymap_config.swap_backslash_backspace = false;
+ break;
+ case MAGIC_UNHOST_NKRO:
+ clear_keyboard(); // clear first buffer to prevent stuck keys
+ keymap_config.nkro = false;
+ break;
+ case MAGIC_UNSWAP_ALT_GUI:
+ keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false;
+#ifdef AUDIO_ENABLE
+ PLAY_SONG(ag_norm_song);
+#endif
+ break;
+ case MAGIC_UNSWAP_CTL_GUI:
+ keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false;
+#ifdef AUDIO_ENABLE
+ PLAY_SONG(cg_norm_song);
+#endif
+ break;
+ case MAGIC_TOGGLE_ALT_GUI:
+ keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
+ keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui;
+#ifdef AUDIO_ENABLE
+ if (keymap_config.swap_ralt_rgui) {
+ PLAY_SONG(ag_swap_song);
+ } else {
+ PLAY_SONG(ag_norm_song);
+ }
+#endif
+ break;
+ case MAGIC_TOGGLE_CTL_GUI:
+ keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui;
+ keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui;
+#ifdef AUDIO_ENABLE
+ if (keymap_config.swap_rctl_rgui) {
+ PLAY_SONG(cg_swap_song);
+ } else {
+ PLAY_SONG(cg_norm_song);
+ }
+#endif
+ break;
+ case MAGIC_TOGGLE_NKRO:
+ clear_keyboard(); // clear first buffer to prevent stuck keys
+ keymap_config.nkro = !keymap_config.nkro;
+ break;
+#if 0
+ case MAGIC_EE_HANDS_LEFT:
+ eeconfig_update_handedness(true);
+ break;
+ case MAGIC_EE_HANDS_RIGHT:
+ eeconfig_update_handedness(false);
+ break;
+#endif
+ }
+ eeconfig_update_keymap(keymap_config.raw);
+ clear_keyboard(); // clear to prevent stuck keys
+
+ return false;
+ }
+ }
+
+ // Not a magic keycode so continue processing
+ return true;
+}
diff --git a/quantum/process_keycode/process_magic.h b/quantum/process_keycode/process_magic.h
new file mode 100644
index 0000000000..1eb39f1455
--- /dev/null
+++ b/quantum/process_keycode/process_magic.h
@@ -0,0 +1,20 @@
+/* Copyright 2019
+ *
+ * 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/>.
+ */
+#pragma once
+
+#include "quantum.h"
+
+bool process_magic(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/process_keycode/process_rgb.c b/quantum/process_keycode/process_rgb.c
new file mode 100644
index 0000000000..c76166342f
--- /dev/null
+++ b/quantum/process_keycode/process_rgb.c
@@ -0,0 +1,141 @@
+/* Copyright 2019
+ *
+ * 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/>.
+ */
+#include "process_rgb.h"
+#include "rgb.h"
+
+typedef void (*rgb_func_pointer)(void);
+
+/**
+ * Wrapper for inc/dec rgb keycode
+ *
+ * noinline to optimise for firmware size not speed (not in hot path)
+ */
+static void __attribute__((noinline)) handleKeycodeRGB(const uint8_t is_shifted, const rgb_func_pointer inc_func, const rgb_func_pointer dec_func) {
+ if (is_shifted) {
+ dec_func();
+ } else {
+ inc_func();
+ }
+}
+
+/**
+ * Wrapper for animation mode
+ * - if not in animation family -> jump to that animation
+ * - otherwise -> wrap round animation speed
+ *
+ * noinline to optimise for firmware size not speed (not in hot path)
+ */
+static void __attribute__((noinline,unused)) handleKeycodeRGBMode(const uint8_t start, const uint8_t end) {
+ if ((start <= rgblight_get_mode()) && (rgblight_get_mode() < end)) {
+ rgblight_step();
+ } else {
+ rgblight_mode(start);
+ }
+}
+
+/**
+ * Handle keycodes for both rgblight and rgbmatrix
+ */
+bool process_rgb(const uint16_t keycode, const keyrecord_t *record) {
+#ifndef SPLIT_KEYBOARD
+ if (record->event.pressed) {
+#else
+ // Split keyboards need to trigger on key-up for edge-case issue
+ if (!record->event.pressed) {
+#endif
+ uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
+ switch (keycode) {
+ case RGB_TOG:
+ rgblight_toggle();
+ return false;
+ case RGB_MODE_FORWARD:
+ handleKeycodeRGB(shifted, rgblight_step, rgblight_step_reverse);
+ return false;
+ case RGB_MODE_REVERSE:
+ handleKeycodeRGB(shifted, rgblight_step_reverse, rgblight_step);
+ return false;
+ case RGB_HUI:
+ handleKeycodeRGB(shifted, rgblight_increase_hue, rgblight_decrease_hue);
+ return false;
+ case RGB_HUD:
+ handleKeycodeRGB(shifted, rgblight_decrease_hue, rgblight_increase_hue);
+ return false;
+ case RGB_SAI:
+ handleKeycodeRGB(shifted, rgblight_increase_sat, rgblight_decrease_sat);
+ return false;
+ case RGB_SAD:
+ handleKeycodeRGB(shifted, rgblight_decrease_sat, rgblight_increase_sat);
+ return false;
+ case RGB_VAI:
+ handleKeycodeRGB(shifted, rgblight_increase_val, rgblight_decrease_val);
+ return false;
+ case RGB_VAD:
+ handleKeycodeRGB(shifted, rgblight_decrease_val, rgblight_increase_val);
+ return false;
+ case RGB_SPI:
+ handleKeycodeRGB(shifted, rgblight_increase_speed, rgblight_decrease_speed);
+ return false;
+ case RGB_SPD:
+ handleKeycodeRGB(shifted, rgblight_decrease_speed, rgblight_increase_speed);
+ return false;
+ case RGB_MODE_PLAIN:
+ rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
+ return false;
+ case RGB_MODE_BREATHE:
+#ifdef RGBLIGHT_EFFECT_BREATHING
+ handleKeycodeRGBMode(RGBLIGHT_MODE_BREATHING, RGBLIGHT_MODE_BREATHING_end);
+#endif
+ return false;
+ case RGB_MODE_RAINBOW:
+#ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
+ handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_MOOD, RGBLIGHT_MODE_RAINBOW_MOOD_end);
+#endif
+ return false;
+ case RGB_MODE_SWIRL:
+#ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
+ handleKeycodeRGBMode(RGBLIGHT_MODE_RAINBOW_SWIRL, RGBLIGHT_MODE_RAINBOW_SWIRL_end);
+#endif
+ return false;
+ case RGB_MODE_SNAKE:
+#ifdef RGBLIGHT_EFFECT_SNAKE
+ handleKeycodeRGBMode(RGBLIGHT_MODE_SNAKE, RGBLIGHT_MODE_SNAKE_end);
+#endif
+ return false;
+ case RGB_MODE_KNIGHT:
+#ifdef RGBLIGHT_EFFECT_KNIGHT
+ handleKeycodeRGBMode(RGBLIGHT_MODE_KNIGHT, RGBLIGHT_MODE_KNIGHT_end);
+#endif
+ return false;
+ case RGB_MODE_XMAS:
+#ifdef RGBLIGHT_EFFECT_CHRISTMAS
+ rgblight_mode(RGBLIGHT_MODE_CHRISTMAS);
+#endif
+ return false;
+ case RGB_MODE_GRADIENT:
+#ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
+ handleKeycodeRGBMode(RGBLIGHT_MODE_STATIC_GRADIENT, RGBLIGHT_MODE_STATIC_GRADIENT_end);
+#endif
+ return false;
+ case RGB_MODE_RGBTEST:
+#ifdef RGBLIGHT_EFFECT_RGB_TEST
+ rgblight_mode(RGBLIGHT_MODE_RGB_TEST);
+#endif
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/quantum/process_keycode/process_rgb.h b/quantum/process_keycode/process_rgb.h
new file mode 100644
index 0000000000..26aca46896
--- /dev/null
+++ b/quantum/process_keycode/process_rgb.h
@@ -0,0 +1,20 @@
+/* Copyright 2019
+ *
+ * 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/>.
+ */
+#pragma once
+
+#include "quantum.h"
+
+bool process_rgb(const uint16_t keycode, const keyrecord_t *record);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index 141a153400..a3ff7adfbd 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -16,10 +16,6 @@
#include "quantum.h"
-#if !defined(RGBLIGHT_ENABLE) && !defined(RGB_MATRIX_ENABLE)
-# include "rgb.h"
-#endif
-
#ifdef PROTOCOL_LUFA
# include "outputselect.h"
#endif
@@ -61,23 +57,7 @@ extern backlight_config_t backlight_config;
# ifndef GOODBYE_SONG
# define GOODBYE_SONG SONG(GOODBYE_SOUND)
# endif
-# ifndef AG_NORM_SONG
-# define AG_NORM_SONG SONG(AG_NORM_SOUND)
-# endif
-# ifndef AG_SWAP_SONG
-# define AG_SWAP_SONG SONG(AG_SWAP_SOUND)
-# endif
-# ifndef CG_NORM_SONG
-# define CG_NORM_SONG SONG(AG_NORM_SOUND)
-# endif
-# ifndef CG_SWAP_SONG
-# define CG_SWAP_SONG SONG(AG_SWAP_SOUND)
-# endif
float goodbye_song[][2] = GOODBYE_SONG;
-float ag_norm_song[][2] = AG_NORM_SONG;
-float ag_swap_song[][2] = AG_SWAP_SONG;
-float cg_norm_song[][2] = CG_NORM_SONG;
-float cg_swap_song[][2] = CG_SWAP_SONG;
# ifdef DEFAULT_LAYER_SONGS
float default_layer_songs[][16][2] = DEFAULT_LAYER_SONGS;
# endif
@@ -168,11 +148,6 @@ void reset_keyboard(void) {
bootloader_jump();
}
-/* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
- * Used to ensure that the correct keycode is released if the key is released.
- */
-static bool grave_esc_was_shifted = false;
-
/* Convert record into usable keycode via the contained event. */
uint16_t get_record_keycode(keyrecord_t *record) { return get_event_keycode(record->event); }
@@ -276,402 +251,82 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef SPACE_CADET_ENABLE
process_space_cadet(keycode, record) &&
#endif
+#ifdef MAGIC_KEYCODE_ENABLE
+ process_magic(keycode, record) &&
+#endif
+#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
+ process_rgb(keycode, record) &&
+#endif
true)) {
return false;
}
- // Shift / paren setup
-
- switch (keycode) {
- case RESET:
- if (record->event.pressed) {
+ if (record->event.pressed) {
+ switch (keycode) {
+ case RESET:
reset_keyboard();
- }
- return false;
- case DEBUG:
- if (record->event.pressed) {
+ return false;
+#ifndef NO_DEBUG
+ case DEBUG:
debug_enable ^= 1;
if (debug_enable) {
print("DEBUG: enabled.\n");
} else {
print("DEBUG: disabled.\n");
}
- }
- return false;
- case EEPROM_RESET:
- if (record->event.pressed) {
+#endif
+ return false;
+ case EEPROM_RESET:
eeconfig_init();
- }
- return false;
+ return false;
#ifdef FAUXCLICKY_ENABLE
- case FC_TOG:
- if (record->event.pressed) {
+ case FC_TOG:
FAUXCLICKY_TOGGLE;
- }
- return false;
- case FC_ON:
- if (record->event.pressed) {
+ return false;
+ case FC_ON:
FAUXCLICKY_ON;
- }
- return false;
- case FC_OFF:
- if (record->event.pressed) {
+ return false;
+ case FC_OFF:
FAUXCLICKY_OFF;
- }
- return false;
+ return false;
#endif
-#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
- case RGB_TOG:
-// Split keyboards need to trigger on key-up for edge-case issue
-# ifndef SPLIT_KEYBOARD
- if (record->event.pressed) {
-# else
- if (!record->event.pressed) {
-# endif
- rgblight_toggle();
- }
- return false;
- case RGB_MODE_FORWARD:
- if (record->event.pressed) {
- uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
- if (shifted) {
- rgblight_step_reverse();
- } else {
- rgblight_step();
- }
- }
- return false;
- case RGB_MODE_REVERSE:
- if (record->event.pressed) {
- uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
- if (shifted) {
- rgblight_step();
- } else {
- rgblight_step_reverse();
- }
- }
- return false;
- case RGB_HUI:
-// Split keyboards need to trigger on key-up for edge-case issue
-# ifndef SPLIT_KEYBOARD
- if (record->event.pressed) {
-# else
- if (!record->event.pressed) {
-# endif
- rgblight_increase_hue();
- }
- return false;
- case RGB_HUD:
-// Split keyboards need to trigger on key-up for edge-case issue
-# ifndef SPLIT_KEYBOARD
- if (record->event.pressed) {
-# else
- if (!record->event.pressed) {
-# endif
- rgblight_decrease_hue();
- }
- return false;
- case RGB_SAI:
-// Split keyboards need to trigger on key-up for edge-case issue
-# ifndef SPLIT_KEYBOARD
- if (record->event.pressed) {
-# else
- if (!record->event.pressed) {
-# endif
- rgblight_increase_sat();
- }
- return false;
- case RGB_SAD:
-// Split keyboards need to trigger on key-up for edge-case issue
-# ifndef SPLIT_KEYBOARD
- if (record->event.pressed) {
-# else
- if (!record->event.pressed) {
-# endif
- rgblight_decrease_sat();
- }
- return false;
- case RGB_VAI:
-// Split keyboards need to trigger on key-up for edge-case issue
-# ifndef SPLIT_KEYBOARD
- if (record->event.pressed) {
-# else
- if (!record->event.pressed) {
-# endif
- rgblight_increase_val();
- }
- return false;
- case RGB_VAD:
-// Split keyboards need to trigger on key-up for edge-case issue
-# ifndef SPLIT_KEYBOARD
- if (record->event.pressed) {
-# else
- if (!record->event.pressed) {
-# endif
- rgblight_decrease_val();
- }
- return false;
- case RGB_SPI:
- if (record->event.pressed) {
- rgblight_increase_speed();
- }
- return false;
- case RGB_SPD:
- if (record->event.pressed) {
- rgblight_decrease_speed();
- }
- return false;
- case RGB_MODE_PLAIN:
- if (record->event.pressed) {
- rgblight_mode(RGBLIGHT_MODE_STATIC_LIGHT);
- }
- return false;
- case RGB_MODE_BREATHE:
-# ifdef RGBLIGHT_EFFECT_BREATHING
- if (record->event.pressed) {
- if ((RGBLIGHT_MODE_BREATHING <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_BREATHING_end)) {
- rgblight_step();
- } else {
- rgblight_mode(RGBLIGHT_MODE_BREATHING);
- }
- }
-# endif
- return false;
- case RGB_MODE_RAINBOW:
-# ifdef RGBLIGHT_EFFECT_RAINBOW_MOOD
- if (record->event.pressed) {
- if ((RGBLIGHT_MODE_RAINBOW_MOOD <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_MOOD_end)) {
- rgblight_step();
- } else {
- rgblight_mode(RGBLIGHT_MODE_RAINBOW_MOOD);
- }
- }
-# endif
- return false;
- case RGB_MODE_SWIRL:
-# ifdef RGBLIGHT_EFFECT_RAINBOW_SWIRL
- if (record->event.pressed) {
- if ((RGBLIGHT_MODE_RAINBOW_SWIRL <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_RAINBOW_SWIRL_end)) {
- rgblight_step();
- } else {
- rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL);
- }
- }
-# endif
- return false;
- case RGB_MODE_SNAKE:
-# ifdef RGBLIGHT_EFFECT_SNAKE
- if (record->event.pressed) {
- if ((RGBLIGHT_MODE_SNAKE <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_SNAKE_end)) {
- rgblight_step();
- } else {
- rgblight_mode(RGBLIGHT_MODE_SNAKE);
- }
- }
-# endif
- return false;
- case RGB_MODE_KNIGHT:
-# ifdef RGBLIGHT_EFFECT_KNIGHT
- if (record->event.pressed) {
- if ((RGBLIGHT_MODE_KNIGHT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_KNIGHT_end)) {
- rgblight_step();
- } else {
- rgblight_mode(RGBLIGHT_MODE_KNIGHT);
- }
- }
-# endif
- return false;
- case RGB_MODE_XMAS:
-# ifdef RGBLIGHT_EFFECT_CHRISTMAS
- if (record->event.pressed) {
- rgblight_mode(RGBLIGHT_MODE_CHRISTMAS);
- }
-# endif
- return false;
- case RGB_MODE_GRADIENT:
-# ifdef RGBLIGHT_EFFECT_STATIC_GRADIENT
- if (record->event.pressed) {
- if ((RGBLIGHT_MODE_STATIC_GRADIENT <= rgblight_get_mode()) && (rgblight_get_mode() < RGBLIGHT_MODE_STATIC_GRADIENT_end)) {
- rgblight_step();
- } else {
- rgblight_mode(RGBLIGHT_MODE_STATIC_GRADIENT);
- }
- }
-# endif
- return false;
- case RGB_MODE_RGBTEST:
-# ifdef RGBLIGHT_EFFECT_RGB_TEST
- if (record->event.pressed) {
- rgblight_mode(RGBLIGHT_MODE_RGB_TEST);
- }
-# endif
- return false;
-#endif // defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
#ifdef VELOCIKEY_ENABLE
- case VLK_TOG:
- if (record->event.pressed) {
+ case VLK_TOG:
velocikey_toggle();
- }
- return false;
+ return false;
#endif
-#ifdef PROTOCOL_LUFA
- case OUT_AUTO:
- if (record->event.pressed) {
+#ifdef BLUETOOTH_ENABLE
+ case OUT_AUTO:
set_output(OUTPUT_AUTO);
- }
- return false;
- case OUT_USB:
- if (record->event.pressed) {
+ return false;
+ case OUT_USB:
set_output(OUTPUT_USB);
- }
- return false;
-# ifdef BLUETOOTH_ENABLE
- case OUT_BT:
- if (record->event.pressed) {
+ return false;
+ case OUT_BT:
set_output(OUTPUT_BLUETOOTH);
- }
- return false;
-# endif
-#endif
- case MAGIC_SWAP_CONTROL_CAPSLOCK ... MAGIC_TOGGLE_ALT_GUI:
- case MAGIC_SWAP_LCTL_LGUI ... MAGIC_EE_HANDS_RIGHT:
- if (record->event.pressed) {
- // MAGIC actions (BOOTMAGIC without the boot)
- if (!eeconfig_is_enabled()) {
- eeconfig_init();
- }
- /* keymap config */
- keymap_config.raw = eeconfig_read_keymap();
- switch (keycode) {
- case MAGIC_SWAP_CONTROL_CAPSLOCK:
- keymap_config.swap_control_capslock = true;
- break;
- case MAGIC_CAPSLOCK_TO_CONTROL:
- keymap_config.capslock_to_control = true;
- break;
- case MAGIC_SWAP_LALT_LGUI:
- keymap_config.swap_lalt_lgui = true;
- break;
- case MAGIC_SWAP_RALT_RGUI:
- keymap_config.swap_ralt_rgui = true;
- break;
- case MAGIC_SWAP_LCTL_LGUI:
- keymap_config.swap_lctl_lgui = true;
- break;
- case MAGIC_SWAP_RCTL_RGUI:
- keymap_config.swap_rctl_rgui = true;
- break;
- case MAGIC_NO_GUI:
- keymap_config.no_gui = true;
- break;
- case MAGIC_SWAP_GRAVE_ESC:
- keymap_config.swap_grave_esc = true;
- break;
- case MAGIC_SWAP_BACKSLASH_BACKSPACE:
- keymap_config.swap_backslash_backspace = true;
- break;
- case MAGIC_HOST_NKRO:
- clear_keyboard(); // clear first buffer to prevent stuck keys
- keymap_config.nkro = true;
- break;
- case MAGIC_SWAP_ALT_GUI:
- keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = true;
-#ifdef AUDIO_ENABLE
- PLAY_SONG(ag_swap_song);
-#endif
- break;
- case MAGIC_SWAP_CTL_GUI:
- keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = true;
-#ifdef AUDIO_ENABLE
- PLAY_SONG(cg_swap_song);
-#endif
- break;
- case MAGIC_UNSWAP_CONTROL_CAPSLOCK:
- keymap_config.swap_control_capslock = false;
- break;
- case MAGIC_UNCAPSLOCK_TO_CONTROL:
- keymap_config.capslock_to_control = false;
- break;
- case MAGIC_UNSWAP_LALT_LGUI:
- keymap_config.swap_lalt_lgui = false;
- break;
- case MAGIC_UNSWAP_RALT_RGUI:
- keymap_config.swap_ralt_rgui = false;
- break;
- case MAGIC_UNSWAP_LCTL_LGUI:
- keymap_config.swap_lctl_lgui = false;
- break;
- case MAGIC_UNSWAP_RCTL_RGUI:
- keymap_config.swap_rctl_rgui = false;
- break;
- case MAGIC_UNNO_GUI:
- keymap_config.no_gui = false;
- break;
- case MAGIC_UNSWAP_GRAVE_ESC:
- keymap_config.swap_grave_esc = false;
- break;
- case MAGIC_UNSWAP_BACKSLASH_BACKSPACE:
- keymap_config.swap_backslash_backspace = false;
- break;
- case MAGIC_UNHOST_NKRO:
- clear_keyboard(); // clear first buffer to prevent stuck keys
- keymap_config.nkro = false;
- break;
- case MAGIC_UNSWAP_ALT_GUI:
- keymap_config.swap_lalt_lgui = keymap_config.swap_ralt_rgui = false;
-#ifdef AUDIO_ENABLE
- PLAY_SONG(ag_norm_song);
+ return false;
#endif
- break;
- case MAGIC_UNSWAP_CTL_GUI:
- keymap_config.swap_lctl_lgui = keymap_config.swap_rctl_rgui = false;
-#ifdef AUDIO_ENABLE
- PLAY_SONG(cg_norm_song);
+#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
+ case BL_BRTG:
+ backlight_toggle_breathing();
+ return false;
#endif
- break;
- case MAGIC_TOGGLE_ALT_GUI:
- keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
- keymap_config.swap_ralt_rgui = keymap_config.swap_lalt_lgui;
-#ifdef AUDIO_ENABLE
- if (keymap_config.swap_ralt_rgui) {
- PLAY_SONG(ag_swap_song);
- } else {
- PLAY_SONG(ag_norm_song);
- }
-#endif
- break;
- case MAGIC_TOGGLE_CTL_GUI:
- keymap_config.swap_lctl_lgui = !keymap_config.swap_lctl_lgui;
- keymap_config.swap_rctl_rgui = keymap_config.swap_lctl_lgui;
-#ifdef AUDIO_ENABLE
- if (keymap_config.swap_rctl_rgui) {
- PLAY_SONG(cg_swap_song);
- } else {
- PLAY_SONG(cg_norm_song);
- }
-#endif
- break;
- case MAGIC_TOGGLE_NKRO:
- clear_keyboard(); // clear first buffer to prevent stuck keys
- keymap_config.nkro = !keymap_config.nkro;
- break;
- case MAGIC_EE_HANDS_LEFT:
- eeconfig_update_handedness(true);
- break;
- case MAGIC_EE_HANDS_RIGHT:
- eeconfig_update_handedness(false);
- break;
- default:
- break;
- }
- eeconfig_update_keymap(keymap_config.raw);
- clear_keyboard(); // clear to prevent stuck keys
-
+#ifdef WEBUSB_ENABLE
+ case WEBUSB_PAIR:
+ webusb_state.pairing = true;
return false;
- }
- break;
+#endif
+ }
+ }
+ // keycodes that depend on both pressed and non-pressed state
+ switch (keycode) {
case GRAVE_ESC: {
+ /* true if the last press of GRAVE_ESC was shifted (i.e. GUI or SHIFT were pressed), false otherwise.
+ * Used to ensure that the correct keycode is released if the key is released.
+ */
+ static bool grave_esc_was_shifted = false;
+
uint8_t shifted = get_mods() & ((MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT) | MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)));
#ifdef GRAVE_ESC_ALT_OVERRIDE
@@ -714,22 +369,6 @@ bool process_record_quantum(keyrecord_t *record) {
send_keyboard_report();
return false;
}
-
-#if defined(BACKLIGHT_ENABLE) && defined(BACKLIGHT_BREATHING)
- case BL_BRTG: {
- if (record->event.pressed) {
- backlight_toggle_breathing();
- }
- return false;
- }
-#endif
-#ifdef WEBUSB_ENABLE
- case WEBUSB_PAIR:
- if (record->event.pressed) {
- webusb_state.pairing = true;
- }
- return false;
-#endif
}
return process_action_kb(record);
diff --git a/quantum/quantum.h b/quantum/quantum.h
index c288a76457..d1f9c086f0 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -133,6 +133,14 @@ extern layer_state_t layer_state;
# include "process_space_cadet.h"
#endif
+#ifdef MAGIC_KEYCODE_ENABLE
+# include "process_magic.h"
+#endif
+
+#if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
+# include "process_rgb.h"
+#endif
+
#ifdef HD44780_ENABLE
# include "hd44780.h"
#endif
diff --git a/quantum/quantum_keycodes.h b/quantum/quantum_keycodes.h
index 90c7a03d81..278b445a41 100644
--- a/quantum/quantum_keycodes.h
+++ b/quantum/quantum_keycodes.h
@@ -657,13 +657,42 @@ enum quantum_keycodes {
// L-ayer, T-ap - 256 keycode max, 16 layer max
#define LT(layer, kc) (QK_LAYER_TAP | (((layer)&0xF) << 8) | ((kc)&0xFF))
+#define CL_SWAP MAGIC_SWAP_CONTROL_CAPSLOCK
+#define CL_NORM MAGIC_UNSWAP_CONTROL_CAPSLOCK
+#define CL_CTRL MAGIC_CAPSLOCK_TO_CONTROL
+#define CL_CAPS MAGIC_UNCAPSLOCK_TO_CONTROL
+
+#define LCG_SWP MAGIC_SWAP_LCTL_LGUI
+#define LCG_NRM MAGIC_UNSWAP_LCTL_LGUI
+#define RCG_SWP MAGIC_SWAP_RCTL_RGUI
+#define RCG_NRM MAGIC_UNSWAP_RCTL_RGUI
+#define CG_SWAP MAGIC_SWAP_CTL_GUI
+#define CG_NORM MAGIC_UNSWAP_CTL_GUI
+#define CG_TOGG MAGIC_TOGGLE_CTL_GUI
+
+#define LAG_SWP MAGIC_SWAP_LALT_LGUI
+#define LAG_NRM MAGIC_UNSWAP_LALT_LGUI
+#define RAG_SWP MAGIC_SWAP_RALT_RGUI
+#define RAG_NRM MAGIC_UNSWAP_RALT_RGUI
#define AG_SWAP MAGIC_SWAP_ALT_GUI
#define AG_NORM MAGIC_UNSWAP_ALT_GUI
#define AG_TOGG MAGIC_TOGGLE_ALT_GUI
-#define CG_SWAP MAGIC_SWAP_CTL_GUI
-#define CG_NORM MAGIC_UNSWAP_CTL_GUI
-#define CG_TOGG MAGIC_TOGGLE_CTL_GUI
+#define GUI_OFF MAGIC_NO_GUI
+#define GUI_ON MAGIC_UNNO_GUI
+
+#define GE_SWAP MAGIC_SWAP_GRAVE_ESC
+#define GE_NORM MAGIC_UNSWAP_GRAVE_ESC
+
+#define BS_SWAP MAGIC_SWAP_BACKSLASH_BACKSPACE
+#define BS_NORM MAGIC_UNSWAP_BACKSLASH_BACKSPACE
+
+#define NK_ON MAGIC_HOST_NKRO
+#define NK_OFF MAGIC_UNHOST_NKRO
+#define NK_TOGG MAGIC_TOGGLE_NKRO
+
+#define EH_LEFT MAGIC_EE_HANDS_LEFT
+#define EH_RGHT MAGIC_EE_HANDS_RIGHT
// GOTO layer - 16 layers max
// when:
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index 16ec96f036..96494836ee 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -128,26 +128,26 @@ void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
#ifndef RGBLIGHT_ENABLE
-# define rgblight_toggle() rgb_matrix_toggle()
-# define rgblight_enable() rgb_matrix_enable()
-# define rgblight_enable_noeeprom() rgb_matrix_enable_noeeprom()
-# define rgblight_disable() rgb_matrix_disable()
-# define rgblight_disable_noeeprom() rgb_matrix_disable_noeeprom()
-# define rgblight_step() rgb_matrix_step()
-# define rgblight_sethsv(hue, sat, val) rgb_matrix_sethsv(hue, sat, val)
-# define rgblight_sethsv_noeeprom(hue, sat, val) rgb_matrix_sethsv_noeeprom(hue, sat, val)
-# define rgblight_step_reverse() rgb_matrix_step_reverse()
-# define rgblight_increase_hue() rgb_matrix_increase_hue()
-# define rgblight_decrease_hue() rgb_matrix_decrease_hue()
-# define rgblight_increase_sat() rgb_matrix_increase_sat()
-# define rgblight_decrease_sat() rgb_matrix_decrease_sat()
-# define rgblight_increase_val() rgb_matrix_increase_val()
-# define rgblight_decrease_val() rgb_matrix_decrease_val()
-# define rgblight_increase_speed() rgb_matrix_increase_speed()
-# define rgblight_decrease_speed() rgb_matrix_decrease_speed()
-# define rgblight_mode(mode) rgb_matrix_mode(mode)
-# define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
-# define rgblight_get_mode() rgb_matrix_get_mode()
+# define rgblight_toggle rgb_matrix_toggle
+# define rgblight_enable rgb_matrix_enable
+# define rgblight_enable_noeeprom rgb_matrix_enable_noeeprom
+# define rgblight_disable rgb_matrix_disable
+# define rgblight_disable_noeeprom rgb_matrix_disable_noeeprom
+# define rgblight_step rgb_matrix_step
+# define rgblight_sethsv rgb_matrix_sethsv
+# define rgblight_sethsv_noeeprom rgb_matrix_sethsv_noeeprom
+# define rgblight_step_reverse rgb_matrix_step_reverse
+# define rgblight_increase_hue rgb_matrix_increase_hue
+# define rgblight_decrease_hue rgb_matrix_decrease_hue
+# define rgblight_increase_sat rgb_matrix_increase_sat
+# define rgblight_decrease_sat rgb_matrix_decrease_sat
+# define rgblight_increase_val rgb_matrix_increase_val
+# define rgblight_decrease_val rgb_matrix_decrease_val
+# define rgblight_increase_speed rgb_matrix_increase_speed
+# define rgblight_decrease_speed rgb_matrix_decrease_speed
+# define rgblight_mode rgb_matrix_mode
+# define rgblight_mode_noeeprom rgb_matrix_mode_noeeprom
+# define rgblight_get_mode rgb_matrix_get_mode
#endif
typedef struct {