diff --git a/common_features.mk b/common_features.mk
index e50207b0b4..1c814286c7 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -407,12 +407,18 @@ ifeq ($(strip $(SPACE_CADET_ENABLE)), yes)
OPT_DEFS += -DSPACE_CADET_ENABLE
endif
-ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes)
- SRC += $(QUANTUM_DIR)/dip_switch.c
- OPT_DEFS += -DDIP_SWITCH_ENABLE
+MAGIC_ENABLE ?= yes
+ifeq ($(strip $(MAGIC_ENABLE)), yes)
+ SRC += $(QUANTUM_DIR)/process_keycode/process_magic.c
+ OPT_DEFS += -DMAGIC_KEYCODE_ENABLE
endif
ifeq ($(strip $(DYNAMIC_MACRO_ENABLE)), yes)
SRC += $(QUANTUM_DIR)/process_keycode/process_dynamic_macro.c
OPT_DEFS += -DDYNAMIC_MACRO_ENABLE
endif
+
+ifeq ($(strip $(DIP_SWITCH_ENABLE)), yes)
+ SRC += $(QUANTUM_DIR)/dip_switch.c
+ OPT_DEFS += -DDIP_SWITCH_ENABLE
+endif
diff --git a/quantum/process_keycode/process_magic.c b/quantum/process_keycode/process_magic.c
new file mode 100644
index 0000000000..9668a50f7f
--- /dev/null
+++ b/quantum/process_keycode/process_magic.c
@@ -0,0 +1,176 @@
+/* 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 .
+ */
+#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) {
+ return true;
+ }
+
+ /* 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;
+ case MAGIC_EE_HANDS_LEFT:
+ eeconfig_update_handedness(true);
+ break;
+ case MAGIC_EE_HANDS_RIGHT:
+ eeconfig_update_handedness(false);
+ break;
+ default:
+ // Not a magic keycode so continue processing
+ return true;
+ }
+
+ eeconfig_update_keymap(keymap_config.raw);
+ clear_keyboard(); // clear to prevent stuck keys
+
+ return false;
+}
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 .
+ */
+#pragma once
+
+#include "quantum.h"
+
+bool process_magic(uint16_t keycode, keyrecord_t *record);
diff --git a/quantum/quantum.c b/quantum/quantum.c
index dd57d7a5e9..7463c9d732 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -57,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
@@ -266,6 +250,9 @@ bool process_record_quantum(keyrecord_t *record) {
#endif
#ifdef SPACE_CADET_ENABLE
process_space_cadet(keycode, record) &&
+#endif
+#ifdef MAGIC_KEYCODE_ENABLE
+ process_magic(keycode, record) &&
#endif
true)) {
return false;
@@ -478,144 +465,6 @@ bool process_record_quantum(keyrecord_t *record) {
// keycodes that depend on both pressed and non-pressed state
switch (keycode) {
- 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);
-#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;
- 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
-
- return false;
- }
- break;
-
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.
diff --git a/quantum/quantum.h b/quantum/quantum.h
index 91b9170b16..2ee261e60d 100644
--- a/quantum/quantum.h
+++ b/quantum/quantum.h
@@ -133,6 +133,10 @@ extern layer_state_t layer_state;
# include "process_space_cadet.h"
#endif
+#ifdef MAGIC_KEYCODE_ENABLE
+# include "process_magic.h"
+#endif
+
#ifdef HD44780_ENABLE
# include "hd44780.h"
#endif